Skip to content

Commit

Permalink
CheckboxMultiSelect: add variant option to CheckboxMultiSelect.Item (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hoorayimhelping authored Dec 3, 2024
1 parent be544dd commit 5962d3d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/components/Select/CheckboxMultiSelect.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,48 @@ ${
},
},
};

export const CheckboxMultiSelectVariants = {
render: () => {
const [selectedCount, setSetlectedCount] = useState<number>(0);

const label = `Selected (${selectedCount})`;

const handleSelect = (selectedVariants: Array<string>) => {
setSetlectedCount(selectedVariants.length);
};

return (
<CheckboxMultiSelect
onSelect={handleSelect}
placeholder={label}
selectLabel={label}
>
<CheckboxMultiSelect.Item
value="variant 1"
variant="var1"
>
Variant 1
</CheckboxMultiSelect.Item>
<CheckboxMultiSelect.Item
value="variant 2"
variant="var2"
>
Variant 2
</CheckboxMultiSelect.Item>
<CheckboxMultiSelect.Item
value="variant 4"
variant="var4"
>
Variant 4
</CheckboxMultiSelect.Item>
<CheckboxMultiSelect.Item
value="variant 6"
variant="var6"
>
Variant 6
</CheckboxMultiSelect.Item>
</CheckboxMultiSelect>
);
},
};
22 changes: 20 additions & 2 deletions src/components/Select/common/InternalSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ import {
} from "./types";
import { Error, FormElementContainer, FormRoot } from "@/components/commonElement";
import { Portal } from "@radix-ui/react-popover";
import { Checkbox, Icon, IconButton, Label, Separator } from "@/components";
import {
Checkbox,
CheckboxVariants,
Icon,
IconButton,
Label,
Separator,
} from "@/components";
import {
SelectPopoverContent,
SearchBar,
Expand Down Expand Up @@ -594,9 +601,16 @@ export const SelectItem = forwardRef<HTMLDivElement, SelectItemProps>(
}
);

export type MultiSelectCheckboxItemProps = SelectItemProps & {
variant?: CheckboxVariants;
};

SelectItem.displayName = "Select.Item";

export const MultiSelectCheckboxItem = forwardRef<HTMLDivElement, SelectItemProps>(
export const MultiSelectCheckboxItem = forwardRef<
HTMLDivElement,
MultiSelectCheckboxItemProps
>(
(
{
disabled = false,
Expand All @@ -608,6 +622,7 @@ export const MultiSelectCheckboxItem = forwardRef<HTMLDivElement, SelectItemProp
onSelect: onSelectProp,
separator,
value = "",
variant,
...props
},
forwardedRef
Expand Down Expand Up @@ -678,6 +693,7 @@ export const MultiSelectCheckboxItem = forwardRef<HTMLDivElement, SelectItemProp
)
}
onClick={onChange}
variant={variant ?? "default"}
/>
)}
{icon && iconDir === "end" && (
Expand All @@ -691,6 +707,7 @@ export const MultiSelectCheckboxItem = forwardRef<HTMLDivElement, SelectItemProp
disabled={disabled}
label={label ?? children}
onClick={onChange}
variant={variant ?? "default"}
/>
</IconWrapper>
)}
Expand All @@ -701,6 +718,7 @@ export const MultiSelectCheckboxItem = forwardRef<HTMLDivElement, SelectItemProp
disabled={disabled}
label={label ?? children}
onClick={onChange}
variant={variant ?? "default"}
/>
)}
</GenericMenuItem>
Expand Down

0 comments on commit 5962d3d

Please sign in to comment.