Skip to content

Commit

Permalink
feat(font-select): change onChange return value
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineHbnt authored and WilliamTraoreee committed Sep 9, 2022
1 parent 1051a26 commit 502ba08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ const Template: ComponentStory<typeof FontSelect> = (args) => (
);

export const Primary = Template.bind({});
Primary.args = {};
Primary.args = {
onChange: (fontName: string, variants: string[]) => {
console.log({fontName, variants});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface FontSelectProps {
className?: string;
value?: string;
defaultValue?: { value: string; label: string };
onChange?: (value: SingleValue<{ value: string; label: string }>) => void;
onChange?: (fontName: string, variants: string[]) => void;
disabled?: boolean;
}

Expand All @@ -22,6 +22,17 @@ export function FontSelect(props: FontSelectProps) {

const { data: fonts } = useGoogleFonts();

const handleChange = (
value: SingleValue<{ value: string; label: string }>
) => {
const font = fonts?.find((f) => f.family === value?.value);
const variants = font?.variants.filter((v) => !v.includes('italic'));

if (font) {
onChange && onChange(font.family, variants ? variants : []);
}
};

return (
<Select
options={fonts.map((font) => {
Expand All @@ -32,7 +43,7 @@ export function FontSelect(props: FontSelectProps) {
placeholder="Choose a font..."
defaultValue={defaultValue}
disabled={disabled}
onChange={onChange}
onChange={(e) => handleChange(e)}
/>
);
}
Expand Down

0 comments on commit 502ba08

Please sign in to comment.