-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Composition modes (v0.0.1-alpha.7) (#22)
- Loading branch information
Showing
14 changed files
with
400 additions
and
124 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
32 changes: 32 additions & 0 deletions
32
src/components/pages/Generator/SettingsSection/Checkboxes/Checkboxes.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,32 @@ | ||
import {Checkbox} from '@/components/ui/Checkbox'; | ||
|
||
type CheckboxesProps<T> = { | ||
items: Array<{ | ||
label: string; | ||
value: T; | ||
}>; | ||
values: T[]; | ||
setValues: (values: T[]) => void; | ||
}; | ||
|
||
export const Checkboxes = <T extends string>({ | ||
items, | ||
values, | ||
setValues, | ||
}: CheckboxesProps<T>) => { | ||
const setIsChecked = (item: T) => (value: boolean) => { | ||
setValues([...values.filter((i) => i !== item), ...(value ? [item] : [])]); | ||
}; | ||
|
||
return items.map(({label, value}) => ( | ||
<Checkbox | ||
key={value} | ||
label={label} | ||
isChecked={isChecked(values, value)} | ||
setIsChecked={setIsChecked(value)} | ||
/> | ||
)); | ||
}; | ||
|
||
const isChecked = <T,>(values: T[], value: T): boolean => | ||
values.includes(value); |
1 change: 1 addition & 0 deletions
1
src/components/pages/Generator/SettingsSection/Checkboxes/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 @@ | ||
export {Checkboxes} from './Checkboxes'; |
13 changes: 13 additions & 0 deletions
13
src/components/pages/Generator/SettingsSection/CheckboxesGroup/CheckboxesGroup.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,13 @@ | ||
type CheckboxesGroupProps = { | ||
readonly title: string; | ||
readonly children: React.ReactNode; | ||
}; | ||
|
||
export function CheckboxesGroup({title, children}: CheckboxesGroupProps) { | ||
return ( | ||
<div> | ||
<div className='pb-1 text-sm'>{`${title}:`}</div> | ||
<div className='border-l border-l-white/80 pl-2'>{children}</div> | ||
</div> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
src/components/pages/Generator/SettingsSection/CheckboxesGroup/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 @@ | ||
export {CheckboxesGroup} from './CheckboxesGroup'; |
Oops, something went wrong.