From cabca302d5ad6b559b37e928fbcfc652884e2c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Andre=CC=81s=20Granero?= Date: Thu, 11 Jan 2024 07:28:34 +0100 Subject: [PATCH] feat: new name for component from Dropdown to Popover. --- .../components/Dropdown/components/index.ts | 1 - .../core/src/components/Dropdown/index.ts | 1 - .../Dropdown.mdx => Popover/Popover.mdx} | 72 +++++----- .../Popover.stories.tsx} | 135 +++++++++++++----- .../Dropdown.tsx => Popover/Popover.tsx} | 67 +++++++-- .../components/PopoverPanel.tsx} | 4 +- .../Popover/components/StyledPopoverArrow.ts | 52 +++++++ .../components/Popover/components/index.ts | 2 + .../core/src/components/Popover/constants.ts | 1 + packages/core/src/components/Popover/index.ts | 1 + packages/core/src/components/Popover/utils.ts | 10 ++ packages/core/src/components/index.ts | 2 +- .../src/editors/DateEditor/DateEditor.tsx | 10 +- .../HeaderBulkRenderer/HeaderBulkRenderer.tsx | 12 +- .../ActionRenderer/ActionRenderer.tsx | 14 +- .../renderers/ActionRenderer/MenuEntry.tsx | 14 +- packages/table/stories/BasicTable.stories.tsx | 24 ++-- .../table/stories/BulkActions.stories.tsx | 47 +++--- 18 files changed, 319 insertions(+), 150 deletions(-) delete mode 100644 packages/core/src/components/Dropdown/components/index.ts delete mode 100644 packages/core/src/components/Dropdown/index.ts rename packages/core/src/components/{Dropdown/Dropdown.mdx => Popover/Popover.mdx} (73%) rename packages/core/src/components/{Dropdown/Dropdown.stories.tsx => Popover/Popover.stories.tsx} (58%) rename packages/core/src/components/{Dropdown/Dropdown.tsx => Popover/Popover.tsx} (57%) rename packages/core/src/components/{Dropdown/components/DropdownPanel.tsx => Popover/components/PopoverPanel.tsx} (76%) create mode 100644 packages/core/src/components/Popover/components/StyledPopoverArrow.ts create mode 100644 packages/core/src/components/Popover/components/index.ts create mode 100644 packages/core/src/components/Popover/constants.ts create mode 100644 packages/core/src/components/Popover/index.ts create mode 100644 packages/core/src/components/Popover/utils.ts diff --git a/packages/core/src/components/Dropdown/components/index.ts b/packages/core/src/components/Dropdown/components/index.ts deleted file mode 100644 index 2db0437fa..000000000 --- a/packages/core/src/components/Dropdown/components/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './DropdownPanel'; diff --git a/packages/core/src/components/Dropdown/index.ts b/packages/core/src/components/Dropdown/index.ts deleted file mode 100644 index 2f29bad4e..000000000 --- a/packages/core/src/components/Dropdown/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './Dropdown'; diff --git a/packages/core/src/components/Dropdown/Dropdown.mdx b/packages/core/src/components/Popover/Popover.mdx similarity index 73% rename from packages/core/src/components/Dropdown/Dropdown.mdx rename to packages/core/src/components/Popover/Popover.mdx index bc4d65be8..246e1aa1d 100644 --- a/packages/core/src/components/Dropdown/Dropdown.mdx +++ b/packages/core/src/components/Popover/Popover.mdx @@ -1,17 +1,17 @@ import { Meta, Canvas, ArgTypes, Source } from '@storybook/blocks'; -import * as Stories from './Dropdown.stories'; +import * as Stories from './Popover.stories'; -# Dropdown +# Popover ## Overview -This Dropdown component allows users to expand hidden contents using a trigger, +This Popover component allows users to expand hidden contents using a trigger, usually a button, link or menu item. -A Dropdown menu variant is a typical way of using this kind of component, +A Popover menu variant is a typical way of using this kind of component, which allows users to select an option from a drop-down menu list. This component is valuable in web applications to enhance usability by @@ -24,14 +24,14 @@ This component is based on [Popper JS library](https://popper.js.org/). ## How to import - + ## Basic usage -The `Dropdown` component must have two children components. +The `Popover` component must have two children components. First, the trigger element and right after the content to be displayed. -This content usually should be wrapped by the `Dropdown.Panel` component, +This content usually should be wrapped by the `Popover.Panel` component, which provides the elevation styles (box shadow, radius, z-index... etc.) according to the design pattern. @@ -42,15 +42,15 @@ indicating when it's opened. - `ref`: used to retrieve the React ref of the _popper_ element. - `toggle`: function to toggle the content of the component. -- `setOpened`: function to force display or hide the dropdown menu. -- `isOpened`: a boolean indicating if the dropdown menu is open. +- `setOpened`: function to force display or hide the Popover floating content. +- `isOpened`: a boolean indicating if the Popover floating content is open. - +import { Button, Popover, Menu } from '@devoinc/genesys-ui'; +export const MyPopover = () => + {({ toggle, ref, isOpened, setOpened }) => ( )} - + - - + + `} /> -## Nested Dropdown +## Nested Popover -`Dropdown` component allows the creation of hierarchical structures, -where one Dropdown can contain other Dropdowns as selectable options. +`Popover` component allows the creation of hierarchical structures, +where one Popover can contain other Popovers as selectable options. **IMPORTANT:** to avoid the parent being closed when a nested one is clicked due to problems with the `ref`, we have to define `appendTo={null}` -in the nested dropdowns. This way, the first parent container will be appended +in the nested popovers. This way, the first parent container will be appended by default to the end of the `body`, and the nested ones will be rendered inside this one. - +import { Button, Popover, Menu } from '@devoinc/genesys-ui'; +export const MyPopover = () => + {({ toggle, ref, isOpened, setOpened }) => ( )} - + - + {({ toggle, ref, isOpened, setOpened }) => ( state={isOpened ? 'expanded' : 'enabled'} /> )} - + - + {({ toggle, ref, isOpened, setOpened }) => ( state={isOpened ? 'expanded' : 'enabled'} /> )} - + - - + + - - + + - - + + `} /> @@ -167,11 +167,11 @@ To ensure full accessibility of the component, we need to consider multiple aspe These include: - Adding a value for the `id` prop of the component. This value is automatically mapped to the attribute - of the 'div' HTML element which wraps the dropdown content. This value has to be used as - the `aria-controls` prop value of the dropdown trigger. + of the 'div' HTML element which wraps the Popover content. This value has to be used as + the `aria-controls` prop value of the Popover trigger. - Each trigger component should have defined the `onClick` property to get the key events. - Add to the trigger the `aria-haspopup` prop value to true. -- Add to the trigger the `aria-expanded` prop value to true when the dropdown is opened. +- Add to the trigger the `aria-expanded` prop value to true when the Popover is opened. - Add to the trigger the `aria-controls` prop value with the same value of the `id` prop of the component. ## Props diff --git a/packages/core/src/components/Dropdown/Dropdown.stories.tsx b/packages/core/src/components/Popover/Popover.stories.tsx similarity index 58% rename from packages/core/src/components/Dropdown/Dropdown.stories.tsx rename to packages/core/src/components/Popover/Popover.stories.tsx index 761e513a4..7d40304fb 100644 --- a/packages/core/src/components/Dropdown/Dropdown.stories.tsx +++ b/packages/core/src/components/Popover/Popover.stories.tsx @@ -1,23 +1,23 @@ import * as React from 'react'; import { Meta, StoryObj } from '@storybook/react'; -import { Button, Dropdown, Menu, Panel, Typography } from '../../components'; +import { Button, Popover, Menu, Panel, Typography } from '../../components'; -const meta: Meta = { - title: 'Components/Core/Navigation/Dropdown', - component: Dropdown, +const meta: Meta = { + title: 'Components/Core/Navigation/Popover', + component: Popover, }; export default meta; -type Story = StoryObj; +type Story = StoryObj; export const Base: Story = { render: () => { - const dropdownId = 'base'; + const popoverId = 'base'; return ( - + {({ toggle, ref, isOpened }) => ( + )} + + + This is the content of the Popover. + + + + ); + }, +}; + +export const AsDropdownMenu: Story = { + render: () => { + const popoverId = 'base'; + return ( + + {({ toggle, ref, isOpened }) => ( + + )} + - - + + ); }, }; export const OnHover: Story = { render: () => { - const dropdownId = 'on-hover'; + const popoverId = 'on-hover'; return ( - + {({ toggle, ref, isOpened, setOpened }) => (