diff --git a/packages/shared/src/utils/Element.js b/packages/shared/src/utils/Element.js index 2a84db321..0cade5578 100644 --- a/packages/shared/src/utils/Element.js +++ b/packages/shared/src/utils/Element.js @@ -19,11 +19,13 @@ import React from 'react'; const findByType = (children: any, component: any) => { const components = []; - const type = [component.displayName || component.name]; + const types = Array.isArray(component) + ? component.map(c => c.displayName || c.name) + : [component.displayName || component.name]; React.Children.forEach(children, (child) => { const childType = child && child.type && (child.type.displayName || child.type.name); - if (type.includes(childType)) { + if (types.includes(childType)) { components.push(child); } }); diff --git a/packages/storybook/src/tailwind-ui/Dropdown.stories.tsx b/packages/storybook/src/tailwind-ui/Dropdown.stories.tsx new file mode 100644 index 000000000..c46bf9c9e --- /dev/null +++ b/packages/storybook/src/tailwind-ui/Dropdown.stories.tsx @@ -0,0 +1,116 @@ +import React from 'react'; +import Dropdown from '../../../tailwind-ui/src/components/Dropdown'; +import { FaPaperclip, FaUser } from 'react-icons/fa'; +import { MdSettings } from 'react-icons/md'; +import faircopyLogo from '../assets/faircopy_logo.svg'; + +export default { + title: 'Components/TailwindUI/Dropdown', + component: Dropdown +}; + +export const Default = () => { + return ( + + + Explore + + + + + + + ); +}; + +export const CustomButton = () => { + return ( + + + + + + + + + + ); +}; + +export const Icons = () => { + return ( + + + Explore + + + + + + + ); +}; + +export const Descriptions = () => { + return ( + + + Explore + + + + + + + ); +}; + +export const Disabled = () => { + return ( + + + Explore + + + + + + + ); +}; \ No newline at end of file diff --git a/packages/tailwind-ui/src/components/Dropdown.tsx b/packages/tailwind-ui/src/components/Dropdown.tsx new file mode 100644 index 000000000..9f2c14149 --- /dev/null +++ b/packages/tailwind-ui/src/components/Dropdown.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { Menu, MenuButton, MenuButtonProps, MenuItem, MenuItems } from '@headlessui/react'; +import { Element } from '@performant-software/shared-components'; +import clsx from 'clsx'; + +interface Props { + children: React.ElementType | React.ElementType[] + className?: string +} + +const Dropdown: React.FC = (props) => { + const button = Element.findByType(props.children, Dropdown.Button); + const menuContents = Element.findByType(props.children, [Dropdown.Item, Dropdown.Divider]); + + return ( + + {button} + + {menuContents} + + + ); +}; + +Dropdown.Button = (props: MenuButtonProps) => { + return ( + + ); +}; + +interface DropdownItemProps { + label?: string + description?: string + icon?: React.FC +} + +Dropdown.Item = (props: DropdownItemProps) => { + return ( + +
+ + {props.icon && } + {props.label} + + {props.description &&

{props.description}

} +
+
+ ); +}; + +Dropdown.Divider = () => { + return ( +
+ ); +}; + +export default Dropdown; diff --git a/packages/tailwind-ui/src/index.ts b/packages/tailwind-ui/src/index.ts index 597323a47..a605705f3 100644 --- a/packages/tailwind-ui/src/index.ts +++ b/packages/tailwind-ui/src/index.ts @@ -1 +1,5 @@ +export { default as Button } from './components/Button'; +export { default as Dropdown } from './components/Dropdown'; +export { default as Input } from './components/Input'; +export { default as Navbar } from './components/Navbar'; export { default as Card } from './components/Card';