diff --git a/apps/storybook/stories/Select.stories.tsx b/apps/storybook/stories/Select.stories.tsx index 5fcb7e96f517f..265f7548ef7c4 100644 --- a/apps/storybook/stories/Select.stories.tsx +++ b/apps/storybook/stories/Select.stories.tsx @@ -1,13 +1,24 @@ import { ComponentMeta } from "@storybook/react"; import { Select } from "@calcom/ui/v2"; +import MultiDropdownSelect from "@calcom/ui/v2/modules/event-types/MultiDropdownSelect"; export default { title: "Form/Select", component: Select, } as ComponentMeta; -const testOptions = [ +const singleOptions = [ + { + label: "Select", + value: 0, + }, + ...[5, 10, 15, 20, 30, 45, 60, 90, 120].map((minutes) => ({ + label: minutes + " " + "minutes", + value: minutes, + })), +]; +const multiOptions = [ { label: "Select", value: 0, @@ -18,4 +29,5 @@ const testOptions = [ })), ]; -export const Single = () => ; +export const Multi = () => ; diff --git a/packages/ui/v2/modules/event-types/MultiDropdownSelect.tsx b/packages/ui/v2/modules/event-types/MultiDropdownSelect.tsx new file mode 100644 index 0000000000000..287fba40b7977 --- /dev/null +++ b/packages/ui/v2/modules/event-types/MultiDropdownSelect.tsx @@ -0,0 +1,112 @@ +import autoAnimate from "@formkit/auto-animate"; +import React, { useEffect, useRef } from "react"; +import { components, GroupBase, Props, ValueContainerProps } from "react-select"; + +import { Icon } from "@calcom/ui/Icon"; + +import { Select } from "../.."; + +const LimitedChipsContainer = >({ + children, + ...props +}: ValueContainerProps) => { + if (!props.hasValue) { + return {children as React.ReactNode[]}; + } + const CHIPS_LIMIT = 2; + // TODO:: fix the following ts error + // @ts-expect-error: @see children is an array but identified as object resulting in the error + const [chips, other] = children; + const overflowCounter = chips.slice(CHIPS_LIMIT).length; + const displayChips = chips.slice(overflowCounter, overflowCounter + CHIPS_LIMIT); + + return ( + + {displayChips} + {overflowCounter > 0 && ( + + <> + {overflowCounter} more + + + )} + {other} + + ); +}; + +export const MultiDropdownSelect = ({ options = [], value = [], ...props }: Props) => { + // const { t } = useLocale(); + const animationRef = useRef(null); + + useEffect(() => { + animationRef.current && autoAnimate(animationRef.current); + }, [animationRef]); + + return ( +