Skip to content

Commit

Permalink
fixup! Refactor(web-react): Refactor Dropdown to controlled component…
Browse files Browse the repository at this point in the history
… #DS-637
  • Loading branch information
pavelklibani committed Nov 6, 2023
1 parent e09f3e9 commit 4a3d15f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/web-react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaultProps = {
};

/**
* @deprecated Dropdown component will be deprecated soon. Please use "DropdownModern" component instead.
* @deprecated Dropdown component is deprecated and will be removed in the next major version. Please use "DropdownModern" component instead.
*/
export const Dropdown = (props: SpiritDropdownProps) => {
const {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const Dropdown = (props: SpiritDropdownProps) => {
trigger: true,
componentName: 'Dropdown',
customText:
'Dropdown component composition will be deprecated in the next major version. Please use "DropdownModern" component composition instead.',
'Dropdown component is deprecated and will be removed in the next major version. Please use "DropdownModern" component instead.',
});

const triggerRenderHandler = () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/web-react/src/components/Dropdown/DropdownContext.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { MutableRefObject, createContext, useContext } from 'react';
import { ClickEvent, PlacementDictionaryType } from '../../types';
import { Placements } from '../../constants';
import { ClickEvent, PlacementDictionaryType } from '../../types';
import { fullWidthModeKeys } from './useDropdownAriaProps';

type DropdownContextType = {
dropdownRef: MutableRefObject<HTMLElement | null>;
fullWidthMode?: keyof typeof fullWidthModeKeys;
id: string;
isOpen: boolean;
placement?: PlacementDictionaryType;
onToggle: (event: ClickEvent) => void;
dropdownRef: MutableRefObject<HTMLElement | null>;
placement?: PlacementDictionaryType;
triggerRef: MutableRefObject<HTMLElement | undefined>;
};

const defaultContext: DropdownContextType = {
dropdownRef: { current: null },
fullWidthMode: fullWidthModeKeys.off,
id: '',
isOpen: false,
onToggle: () => {},
dropdownRef: { current: null },
triggerRef: { current: undefined },
placement: Placements.BOTTOM_LEFT,
triggerRef: { current: undefined },
};

const DropdownContext = createContext<DropdownContextType>(defaultContext);
Expand Down
4 changes: 2 additions & 2 deletions packages/web-react/src/components/Dropdown/DropdownModern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const DropdownModern = (props: DropdownProps) => {
enableAutoClose = true,
fullWidthMode,
id,
onAutoClose,
placement,
isOpen = false,
onAutoClose,
onToggle,
placement,
...rest
} = props;
const { classProps } = useDropdownStyleProps();
Expand Down
55 changes: 25 additions & 30 deletions packages/web-react/src/components/Dropdown/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dropdown

⚠️ Dropdown component composition will be [deprecated][Deprecated] in the next major version. Please use "DropdownModern" component composition instead.
⚠️ Dropdown component is [deprecated][Deprecated] and will be removed in the next major version. Please use "DropdownModern" component instead.
This is the React implementation of the [Dropdown] component.

## Usage
Expand All @@ -17,16 +17,16 @@ import { Dropdown } from '@lmc-eu/spirit-web-react/components';

## API

| Name | Type | Default | Required | Description |
| ------------------ | ------------------------------------------------ | ------------- | -------- | --------------------------------------------------------------------------------------- |
| `enableAutoClose` | `bool` | `true` || Enables close on click outside of Dropdown |
| `fullWidthMode` | [`DropdownFullwidthMode`][dropdownfullwidthmode] | `off` || Full-width mode |
| `id` | `string` | `<random>` || Component id |
| `onAutoClose` . | `(event: Event) => void` ||| Callback on close on click outside of Dropdown |
| `placement` | [Placement dictionary][dictionary-placement] | `bottom-left` || Alignment of the component |
| `renderTrigger` | `(render: DropdownRenderProps) => ReactNode` ||| [**DEPRECATED**][Deprecated] Will be removed in favor of new `DropdownModern` component |
| `UNSAFE_className` | `string` ||| Wrapper custom classname |
| `UNSAFE_style` | `CSSProperties` ||| Wrapper custom style |
| Name | Type | Default | Required | Description |
| ------------------ | ------------------------------------------------ | ------------- | -------- | ---------------------------------------------------------------------------------------- |
| `enableAutoClose` | `bool` | `true` || Enables close on click outside of Dropdown |
| `fullWidthMode` | [`DropdownFullwidthMode`][dropdownfullwidthmode] | `off` || Full-width mode |
| `id` | `string` | `<random>` || Component id |
| `onAutoClose` . | `(event: Event) => void` ||| Callback on close on click outside of Dropdown |
| `placement` | [Placement dictionary][dictionary-placement] | `bottom-left` || Alignment of the component |
| `renderTrigger` | `(render: DropdownRenderProps) => ReactNode` ||| [**DEPRECATED**][Deprecated] Will be removed in favor of new `DropdownTrigger` component |
| `UNSAFE_className` | `string` ||| Wrapper custom classname |
| `UNSAFE_style` | `CSSProperties` ||| Wrapper custom style |

### DropdownRenderProps

Expand All @@ -44,39 +44,35 @@ import { Dropdown } from '@lmc-eu/spirit-web-react/components';

# DropdownModern

⚠️ `DropdownModern` component will be deprecated and renamed to `Dropdown` in the next major version.
This is the React implementation of the [DropdownModern] component.
⚠️ `DropdownModern` component is [deprecated] and will be renamed to `Dropdown` in the next major version.
This is the React implementation of the `DropdownModern` component.

## Usage

```jsx
import { DropdownModern, DropdownModernTrigger, DropdownModernPopover } from '@lmc-eu/spirit-web-react/components';
import { DropdownModern, DropdownTrigger, DropdownPopover } from '@lmc-eu/spirit-web-react/components';
```

```jsx
const [isOpen, setIsOpen] = React.useState(false);
const onToggle = () => setIsOpen(!isOpen);

<DropdownModern id="DropdownExample" isOpen={isOpen} onToggle={onToggle}>
<DropdownModernTrigger elementType="button">Trigger button</DropdownModernTrigger>
<DropdownModernPopover></DropdownModernPopover>
<DropdownTrigger elementType="button">Trigger button</DropdownTrigger>
<DropdownPopover></DropdownPopover>
</DropdownModern>;
```

### Uncontrolled dropdown

```jsx
import {
UncontrolledDropdown,
DropdownModernTrigger,
DropdownModernPopover,
} from '@lmc-eu/spirit-web-react/components';
import { UncontrolledDropdown, DropdownTrigger, DropdownPopover } from '@lmc-eu/spirit-web-react/components';
```

```jsx
<UncontrolledDropdown id="UncontrolledDropdownExample">
<DropdownModernTrigger elementType="button">Trigger button</DropdownModernTrigger>
<DropdownModernPopover></DropdownModernPopover>
<DropdownTrigger elementType="button">Trigger button</DropdownTrigger>
<DropdownPopover></DropdownPopover>
</UncontrolledDropdown>
```

Expand All @@ -96,7 +92,7 @@ import {
| `UNSAFE_className` | `string` ||| Wrapper custom classname |
| `UNSAFE_style` | `CSSProperties` ||| Wrapper custom style |

### DropdownModernTrigger
### DropdownTrigger

| Name | Type | Default | Required | Description |
| ------------------ | ------------------------- | -------- | -------- | -------------------------------- |
Expand All @@ -105,13 +101,13 @@ import {
| `UNSAFE_className` | `string` ||| DropdownTrigger custom classname |
| `UNSAFE_style` | `CSSProperties` ||| DropdownTrigger custom style |

### DropdownModernPopover
### DropdownPopover

| Name | Type | Default | Required | Description |
| ------------------ | ------------------------- | ------- | -------- | -------------------------------- |
| `children` | [`string` \| `ReactNode`] ||| Content of trigger element |
| `UNSAFE_className` | `string` ||| DropdownContent custom classname |
| `UNSAFE_style` | `CSSProperties` ||| DropdownContent custom style |
| `UNSAFE_className` | `string` ||| DropdownPopover custom classname |
| `UNSAFE_style` | `CSSProperties` ||| DropdownPopover custom style |

### UncontrolledDropdown

Expand All @@ -125,9 +121,8 @@ import {
| `UNSAFE_className` | `string` ||| Wrapper custom classname |
| `UNSAFE_style` | `CSSProperties` ||| Wrapper custom style |

[deprecated]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web-react/README.md#deprecations
[dictionary-placement]: https://github.com/lmc-eu/spirit-design-system/tree/main/docs/DICTIONARIES.md#placement
[dropdown]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web/src/scss/components/Dropdown
[DropdownModern]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web/src/scss/components/DropdownModern
[dropdownbreakpoint]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/src/types/dropdown.ts#L11
[dropdownfullwidthmode]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/src/types/dropdown.ts#L19
[dictionary-placement]: https://github.com/lmc-eu/spirit-design-system/tree/main/docs/DICTIONARIES.md#placement
[Deprecated]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web-react/README.md#deprecations
8 changes: 8 additions & 0 deletions packages/web-react/src/components/DropdownModern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# DropdownModern

⚠️ `DropdownModern` component is [deprecated] and will be renamed to `Dropdown` in the next major version.

For more information and implementation examples, please visit the `DropdownModern` section in the [readme][dropdown] for the `Dropdown` component.

[deprecated]: https://github.com/lmc-eu/spirit-design-system/tree/main/packages/web-react/README.md#deprecations
[dropdown]: https://github.com/lmc-eu/spirit-design-system/blob/main/packages/web-react/src/components/Dropdown/README.md

0 comments on commit 4a3d15f

Please sign in to comment.