diff --git a/src/core/primitives/Dropdown/Select/SelectPrimitive.stories.tsx b/src/core/primitives/Dropdown/Select/SelectPrimitive.stories.tsx new file mode 100644 index 00000000..793ee1d1 --- /dev/null +++ b/src/core/primitives/Dropdown/Select/SelectPrimitive.stories.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor'; +import SelectPrimitive from '.'; + +const options = ['New Tab','New Window','New InPrivate Window'] + +export default { + title: 'Primitives/SelectPrimitive', + component: SelectPrimitive, + render: (args: React.JSX.IntrinsicAttributes) => +
+ {}} {...args} /> + +
+
+ +} + +export const All = { + args: { + children: 'Select Option', + } +} \ No newline at end of file diff --git a/src/core/primitives/Dropdown/Select/index.tsx b/src/core/primitives/Dropdown/Select/index.tsx new file mode 100644 index 00000000..28c1104e --- /dev/null +++ b/src/core/primitives/Dropdown/Select/index.tsx @@ -0,0 +1,38 @@ +import Primitive from '~/core/primitives/Primitive'; +import React, { useState } from 'react'; + +type SelectPrimitiveProps = { + children?: React.ReactNode, + options: string[], + value?: string | null, + onChange?: (value: string) => void; +} + +const SelectPrimitive = ({ children, options, value, onChange, ...props }:SelectPrimitiveProps) => { + + const [isOpen, setIsOpen] = useState(false); + const [selected, setSelected] = useState(value ?? null) + + const handleClick = () => { + setIsOpen(!isOpen) + } + + const handleSelect = (option: string) => { + setSelected(option) + onChange?.(option) + setIsOpen(false) + } + return ( + <> + + {children} + + {isOpen && options.map((option, index) => ( +
handleSelect(option)}>{option}
+ ))} + + ); + +}; + +export default SelectPrimitive \ No newline at end of file