generated from stabledata/surface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🚧 starting to refactor rdf with shadcn-ui
- Loading branch information
Showing
18 changed files
with
742 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { SwitchInputFieldProps } from "switch/types"; | ||
import { Label } from "switch/components/ui/label"; | ||
import { Input } from "switch/components/ui/input"; | ||
/** | ||
* | ||
* @props see {@link RDFTextFieldProps} | ||
* @returns field with given options | ||
*/ | ||
export const SwitchTextField = ({ | ||
name, | ||
type, | ||
label, | ||
placeholder, | ||
helperText, | ||
errors, | ||
options, | ||
register, | ||
disabled, | ||
// hidden, | ||
}: SwitchInputFieldProps) => { | ||
const labelClasses = ["label", `label-${name}`]; | ||
const inputClasses = ["input", `input-${name}`]; | ||
const error = errors !== undefined ? errors[name] : undefined; | ||
if (error) { | ||
inputClasses.push("input-has-error"); | ||
labelClasses.push("label-has-error"); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="grid w-full max-w-sm items-center gap-2"> | ||
<Label htmlFor={name}>{label}</Label> | ||
<Input | ||
type={type} | ||
id={name} | ||
placeholder={placeholder} | ||
{...register(name, options)} | ||
disabled={disabled as boolean} | ||
/> | ||
</div> | ||
{/* <RDFErrorMessage error={error} /> */} | ||
{JSON.stringify(error)} | ||
{helperText} | ||
{/* <RDFHelpText helper={helper} /> */} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { Form, useInputSwitches } from "../hooks/use-form"; | ||
import { SwitchTextField } from "./controls/text"; | ||
// import { RDFCheckbox } from "./RDFCheckbox"; | ||
// import { RDFSelect } from "./RDFSelect"; | ||
// import { RDFRadio } from "./RDFRadios"; | ||
// import { RDFSwitch } from "./RDFSwitch"; | ||
// import { RDFMedia } from "./RDFMedia"; | ||
// import { RDFList } from "./RDFList"; | ||
// import { RDFTable } from "./RDFTable"; | ||
// import { RDFDatePicker } from "./RDFDatePicker"; | ||
|
||
export type FormProps<T> = { | ||
form: Form<T>; | ||
submitButtonLabel?: string | React.ReactNode; | ||
submitButtonLabelInFlight?: string | React.ReactNode; | ||
isInFlight?: boolean; | ||
}; | ||
|
||
export function SwitchForm<T extends object>({ | ||
form, | ||
submitButtonLabel = "Send it", | ||
submitButtonLabelInFlight = "Sending...", | ||
isInFlight = false, | ||
}: FormProps<T>) { | ||
const { | ||
register, | ||
errors, | ||
// control, | ||
handleSubmit: rhfSubmitHandler, | ||
handleSubmitWithFormData, | ||
} = useInputSwitches<T>(form); | ||
|
||
return ( | ||
<form onSubmit={rhfSubmitHandler(handleSubmitWithFormData)}> | ||
{form.fields.map((field, index) => { | ||
switch (field.type) { | ||
// text field | ||
case "text": | ||
case "multiline": | ||
case "number": | ||
case "email": | ||
case "password": | ||
return ( | ||
<SwitchTextField | ||
key={`${field.name}-${index}`} | ||
type={field.type} | ||
name={field.name} | ||
label={field.label} | ||
placeholder={field.placeholder} | ||
helperText={field.helperText} | ||
disabled={field.disabled} | ||
hidden={field.hidden} | ||
options={field.options} | ||
register={register} | ||
errors={errors} | ||
/> | ||
); | ||
// text field | ||
// case "media": | ||
// return ( | ||
// <RDFMedia | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// helper={field.helpText || field.HelpText} | ||
// previewType={field.previewType} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// errors={errors} | ||
// /> | ||
// ); | ||
// // checkbox | ||
// case "checkbox": | ||
// return ( | ||
// <RDFCheckbox | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// helper={field.helpText || field.HelpText} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// /> | ||
// ); | ||
// // switch | ||
// case "switch": | ||
// return ( | ||
// <RDFSwitch | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// defaultValue={field.default as boolean} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// /> | ||
// ); | ||
// // select | ||
// case "select": | ||
// return ( | ||
// <RDFSelect | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// choices={field.choices as RDFChoiceOption[]} | ||
// placeholder={field.placeholder} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// /> | ||
// ); | ||
// // radio | ||
// case "radio": | ||
// return ( | ||
// <RDFRadio | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// choices={field.choices as RDFChoiceOption[]} | ||
// placeholder={field.placeholder} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// /> | ||
// ); | ||
// // list | ||
// case "list": | ||
// return ( | ||
// <RDFList | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// placeholder={field.placeholder} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// addItemText={field.addItemButtonText} | ||
// /> | ||
// ); | ||
|
||
// // date picker: | ||
// case "date": | ||
// case "datetime": | ||
// return ( | ||
// <RDFDatePicker | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// showTimeSelect={field.type === "datetime"} | ||
// /> | ||
// ); | ||
// // table | ||
// case "table": | ||
// return ( | ||
// <RDFTable | ||
// key={`${field.name}-${index}`} | ||
// name={field.name} | ||
// label={field.label} | ||
// options={field.options} | ||
// helper={field.helpText || field.HelpText} | ||
// disabled={field.disabled} | ||
// hidden={field.hidden} | ||
// control={control} | ||
// register={register} | ||
// errors={errors} | ||
// addItemText={field.addItemButtonText} | ||
// columns={field.columns} | ||
// /> | ||
// ); | ||
} | ||
})} | ||
<button type="submit" className="submit" disabled={isInFlight}> | ||
{isInFlight ? submitButtonLabelInFlight : submitButtonLabel} | ||
</button> | ||
</form> | ||
); | ||
} |
Oops, something went wrong.