-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement statefull toggle and adapt new prop (#49)
Because - We need a transition state when deal with toggling the model state This commit - Implement the StatefulToggleButton
- Loading branch information
Showing
41 changed files
with
408 additions
and
60 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 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
77 changes: 77 additions & 0 deletions
77
src/components/formik/FormikField/StatefulToggleField/StatefulToggleField.tsx
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,77 @@ | ||
import { FC } from "react"; | ||
import { Field, FieldProps } from "formik"; | ||
import { | ||
BasicToggleFieldProps, | ||
StatefulToggleField, | ||
} from "@instill-ai/design-system"; | ||
import { Nullable, State } from "@/types/general"; | ||
|
||
export type ToggleFieldProps = Omit<BasicToggleFieldProps, "onChangeInput"> & { | ||
name: string; | ||
additionalOnChangeCb: Nullable<(value: boolean) => void>; | ||
state: State; | ||
}; | ||
|
||
const StatefulToggleFieldWrapper: FC<ToggleFieldProps & FieldProps> = ({ | ||
field, | ||
form, | ||
id, | ||
defaultChecked, | ||
additionalOnChangeCb, | ||
additionalMessageOnLabel, | ||
error, | ||
...props | ||
}) => { | ||
const onChange = (_: string, value: boolean) => { | ||
form.setFieldValue(field.name, value); | ||
if (additionalOnChangeCb) { | ||
additionalOnChangeCb(value); | ||
} | ||
}; | ||
|
||
return ( | ||
<StatefulToggleField | ||
{...props} | ||
id={id} | ||
error={error} | ||
onChangeInput={onChange} | ||
defaultChecked={defaultChecked} | ||
additionalMessageOnLabel={additionalMessageOnLabel} | ||
/> | ||
); | ||
}; | ||
|
||
const StatefulToggleFieldFormikWrapper: FC<ToggleFieldProps> = ({ | ||
id, | ||
name, | ||
disabled, | ||
readOnly, | ||
required, | ||
description, | ||
label, | ||
additionalOnChangeCb, | ||
additionalMessageOnLabel, | ||
defaultChecked, | ||
error, | ||
state, | ||
}) => { | ||
return ( | ||
<Field | ||
id={id} | ||
name={name} | ||
component={StatefulToggleFieldWrapper} | ||
disabled={disabled} | ||
readOnly={readOnly} | ||
required={required} | ||
description={description} | ||
additionalOnChangeCb={additionalOnChangeCb} | ||
label={label} | ||
additionalMessageOnLabel={additionalMessageOnLabel} | ||
defaultChecked={defaultChecked} | ||
error={error} | ||
state={state} | ||
/> | ||
); | ||
}; | ||
|
||
export default StatefulToggleFieldFormikWrapper; |
2 changes: 2 additions & 0 deletions
2
src/components/formik/FormikField/StatefulToggleField/index.ts
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,2 @@ | ||
export { default } from "./StatefulToggleField"; | ||
export * from "./StatefulToggleField"; |
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
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
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
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
Oops, something went wrong.