-
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.
- Loading branch information
1 parent
cf27491
commit 6f9b131
Showing
13 changed files
with
156 additions
and
67 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,35 @@ | ||
import { useCallback, useMemo } from 'react' | ||
import { Checkbox as RsuiteCheckbox } from 'rsuite' | ||
|
||
import type { CheckboxProps as RsuiteCheckboxProps } from 'rsuite' | ||
import type { ValueType } from 'rsuite/esm/Checkbox' | ||
import type { Promisable } from 'type-fest' | ||
|
||
export type CheckboxProps = Omit<RsuiteCheckboxProps, 'checked' | 'onChange'> & { | ||
label: string | ||
name: string | ||
onChange?: (isCheched: boolean) => Promisable<void> | ||
} | ||
export function Checkbox({ label, onChange, ...originalProps }: CheckboxProps) { | ||
const key = useMemo( | ||
() => `${originalProps.name}-${String(originalProps.defaultChecked)}`, | ||
[originalProps.defaultChecked, originalProps.name] | ||
) | ||
|
||
const handleChange = useCallback( | ||
(_: ValueType | undefined, isChecked: boolean) => { | ||
if (!onChange) { | ||
return | ||
} | ||
|
||
onChange(isChecked) | ||
}, | ||
[onChange] | ||
) | ||
|
||
return ( | ||
<RsuiteCheckbox key={key} onChange={handleChange} {...originalProps}> | ||
{label} | ||
</RsuiteCheckbox> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useState } from 'react' | ||
|
||
import { Checkbox } from '../../src' | ||
import { Output } from '../_components/Output' | ||
|
||
import type { CheckboxProps } from '../../src' | ||
|
||
export default { | ||
title: 'Fields/Checkbox', | ||
component: Checkbox, | ||
|
||
argTypes: {}, | ||
|
||
args: { | ||
defaultChecked: false, | ||
label: 'Check me', | ||
name: 'myCheckbox' | ||
} as CheckboxProps | ||
} | ||
|
||
export const _Checkbox = (props: CheckboxProps) => { | ||
const [outputValue, setOutputValue] = useState<boolean | '∅'>('∅') | ||
|
||
return ( | ||
<> | ||
<Checkbox {...props} onChange={setOutputValue} /> | ||
|
||
{outputValue !== '∅' && <Output value={outputValue} />} | ||
</> | ||
) | ||
} |
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.