-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backups): updated modal, new FormikSwitchV2
- Loading branch information
Showing
4 changed files
with
84 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Field, FieldProps } from 'formik'; | ||
|
||
import FormikFieldWrapper from '@/components/elements/FormikFieldWrapper'; | ||
import SwitchV2Wrapper, { SwitchProps } from '@/components/elements/SwitchV2Wrapper'; | ||
|
||
const FormikSwitch = ({ name, label, ...props }: SwitchProps) => { | ||
return ( | ||
<FormikFieldWrapper name={name}> | ||
<Field name={name}> | ||
{({ field, form }: FieldProps) => ( | ||
<SwitchV2Wrapper | ||
name={name} | ||
label={label} | ||
onChange={() => { | ||
form.setFieldTouched(name); | ||
form.setFieldValue(field.name, !field.value); | ||
}} | ||
defaultChecked={field.value} | ||
{...props} | ||
/> | ||
)} | ||
</Field> | ||
</FormikFieldWrapper> | ||
); | ||
}; | ||
|
||
export default FormikSwitch; |
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,50 @@ | ||
import { useMemo } from 'react'; | ||
import { v4 } from 'uuid'; | ||
import { Switch } from '@/components/elements/SwitchV2'; | ||
|
||
export interface SwitchProps { | ||
name: string; | ||
label: string; | ||
description: string; | ||
defaultChecked?: boolean; | ||
readOnly?: boolean; | ||
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const SwitchV2Wrapper = ({ name, label, description, defaultChecked, readOnly, onChange, children }: SwitchProps) => { | ||
const uuid = useMemo(() => v4(), []); | ||
|
||
return ( | ||
<div className='flex items-center justify-between gap-2 bg-[#3333332a] border-[1px] border-[#ffffff0e] p-4 rounded-lg'> | ||
<div className='flex flex-col'> | ||
<label htmlFor={uuid} className='text-neutral-300 text-md font-bold'> | ||
{label} | ||
</label> | ||
<label | ||
htmlFor={uuid} | ||
className='text-neutral-500 text-sm font-semibold' | ||
> | ||
{description} | ||
</label> | ||
</div> | ||
{children || ( | ||
<Switch | ||
name={name} | ||
onCheckedChange={(checked) => { | ||
if (onChange) { | ||
onChange({ | ||
target: { checked } as HTMLInputElement | ||
} as React.ChangeEvent<HTMLInputElement>); | ||
} | ||
}} | ||
defaultChecked={defaultChecked} | ||
disabled={readOnly} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
SwitchV2Wrapper.displayName = 'SwitchV2Wrapper'; | ||
|
||
export default SwitchV2Wrapper; |
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