@wonderflow/react-components 3.0.0-beta.18 → 3.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dropdown/dropdown.d.ts +25 -11
- package/dropdown/dropdown.js +0 -6
- package/dropdown/index.d.ts +0 -2
- package/index.d.ts +3 -1
- package/index.js +1 -0
- package/menu/index.d.ts +6 -0
- package/menu/index.js +3 -0
- package/menu/menu-item/menu-item-checkbox.d.ts +11 -0
- package/menu/menu-item/menu-item-checkbox.js +5 -0
- package/{dropdown/item/dropdown-item.d.ts → menu/menu-item/menu-item.d.ts} +22 -8
- package/menu/menu-item/menu-item.js +23 -0
- package/menu/menu-item/menu-item.module.css +1 -0
- package/menu/menu.d.ts +15 -0
- package/menu/menu.js +15 -0
- package/menu/menu.module.css +1 -0
- package/package.json +2 -2
- package/stack/stack.d.ts +3 -2
- package/stack/stack.module.css +1 -1
- package/themes/dark.css +1 -1
- package/themes/light.css +1 -1
- package/dropdown/item/dropdown-item.js +0 -23
- package/dropdown/item/dropdown-item.module.css +0 -1
- package/dropdown/item-checkbox/dropdown-item-checkbox.d.ts +0 -11
- package/dropdown/item-checkbox/dropdown-item-checkbox.js +0 -5
- package/dropdown/menu/dropdown-menu.d.ts +0 -13
- package/dropdown/menu/dropdown-menu.js +0 -13
- package/dropdown/menu/dropdown-menu.module.css +0 -1
package/dropdown/dropdown.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { ReactNode
|
|
2
|
-
import { DropdownMenuProps } from './menu/dropdown-menu';
|
|
3
|
-
import { DropdownItemProps } from './item/dropdown-item';
|
|
4
|
-
import { DropdownItemCheckboxProps } from './item-checkbox/dropdown-item-checkbox';
|
|
1
|
+
import { ReactNode } from 'react';
|
|
5
2
|
import { AutoPlacement, BasePlacement, VariationPlacement } from '@popperjs/core';
|
|
6
3
|
export declare type DropdownProps = PropsWithClass & {
|
|
7
4
|
/**
|
|
@@ -27,10 +24,27 @@ export declare type DropdownProps = PropsWithClass & {
|
|
|
27
24
|
*/
|
|
28
25
|
placement?: AutoPlacement | BasePlacement | VariationPlacement;
|
|
29
26
|
};
|
|
30
|
-
declare
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
export declare const Dropdown: import("react").ForwardRefExoticComponent<PropsWithClass & {
|
|
28
|
+
/**
|
|
29
|
+
* The content of the dropdown to display when the dropdown is open.
|
|
30
|
+
*/
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* The element to use as the trigger for the dropdown.
|
|
34
|
+
*/
|
|
35
|
+
trigger: ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* The distance from the trigger to the dropdown.
|
|
38
|
+
*/
|
|
39
|
+
offset?: number | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The placement of the dropdown. This is automatically handled based on
|
|
42
|
+
* scroll and viewport edges. By default the dropdown is anchored at
|
|
43
|
+
* the beginning of the trigger.
|
|
44
|
+
*
|
|
45
|
+
* The first key refers to the X axis, the second key refers to the Y axis.
|
|
46
|
+
* Eg: `auto-start` means the dropdown will be placed automatically on left or right
|
|
47
|
+
* based on the available space, and anchored at the top (start) of the trigger.
|
|
48
|
+
*/
|
|
49
|
+
placement?: AutoPlacement | BasePlacement | VariationPlacement | undefined;
|
|
50
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
package/dropdown/dropdown.js
CHANGED
|
@@ -3,9 +3,6 @@ import { useState, Children, cloneElement, useRef, forwardRef } from 'react';
|
|
|
3
3
|
import { useKeyPress, useFocusWithin } from 'ahooks';
|
|
4
4
|
import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
|
|
5
5
|
import { useUIDSeed } from 'react-uid';
|
|
6
|
-
import { DropdownMenu } from './menu/dropdown-menu';
|
|
7
|
-
import { DropdownItem } from './item/dropdown-item';
|
|
8
|
-
import { DropdownItemCheckbox } from './item-checkbox/dropdown-item-checkbox';
|
|
9
6
|
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
10
7
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
11
8
|
import clsx from 'clsx';
|
|
@@ -65,6 +62,3 @@ export const Dropdown = forwardRef(({ children, trigger, offset = 8, placement =
|
|
|
65
62
|
})) }, void 0) }, seedID('tooltip-content'))) }, void 0)] }, void 0));
|
|
66
63
|
});
|
|
67
64
|
Dropdown.displayName = 'Dropdown';
|
|
68
|
-
Dropdown.Menu = DropdownMenu;
|
|
69
|
-
Dropdown.Item = DropdownItem;
|
|
70
|
-
Dropdown.ItemCheckbox = DropdownItemCheckbox;
|
package/dropdown/index.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type { TableProps } from './table';
|
|
|
25
25
|
export { Disclosure } from './disclosure';
|
|
26
26
|
export type { DisclosureProps } from './disclosure';
|
|
27
27
|
export { Dropdown } from './dropdown';
|
|
28
|
-
export type { DropdownProps
|
|
28
|
+
export type { DropdownProps } from './dropdown';
|
|
29
29
|
export { Elevator } from './elevator';
|
|
30
30
|
export type { ElevatorProps } from './elevator';
|
|
31
31
|
export { Icon } from './icon';
|
|
@@ -44,6 +44,8 @@ export { Modal } from './modal';
|
|
|
44
44
|
export type { ModalProps } from './modal';
|
|
45
45
|
export { LinearProgress } from './linear-progress';
|
|
46
46
|
export type { LinearProgressProps } from './linear-progress';
|
|
47
|
+
export { Menu } from './menu';
|
|
48
|
+
export type { MenuProps, MenuItemProps, MenuItemCheckboxProps } from './menu';
|
|
47
49
|
export { OverlayContainer, useOverlayContext, OverlayProvider } from './overlay-container';
|
|
48
50
|
export type { OverlayContainerProps } from './overlay-container';
|
|
49
51
|
export { Prose } from './prose';
|
package/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { List } from './list';
|
|
|
22
22
|
export { SplitButton } from './split-button';
|
|
23
23
|
export { Modal } from './modal';
|
|
24
24
|
export { LinearProgress } from './linear-progress';
|
|
25
|
+
export { Menu } from './menu';
|
|
25
26
|
export { OverlayContainer, useOverlayContext, OverlayProvider } from './overlay-container';
|
|
26
27
|
export { Prose } from './prose';
|
|
27
28
|
export { Pagination } from './pagination';
|
package/menu/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Menu } from './menu';
|
|
2
|
+
export type { MenuProps } from './menu';
|
|
3
|
+
export { MenuItem } from './menu-item/menu-item';
|
|
4
|
+
export type { MenuItemProps } from './menu-item/menu-item';
|
|
5
|
+
export { MenuItemCheckbox } from './menu-item/menu-item-checkbox';
|
|
6
|
+
export type { MenuItemCheckboxProps } from './menu-item/menu-item-checkbox';
|
package/menu/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MenuItem, MenuItemProps } from '..';
|
|
2
|
+
import { Polymorphic } from '../..';
|
|
3
|
+
export declare type MenuItemCheckboxProps = MenuItemProps & {
|
|
4
|
+
/**
|
|
5
|
+
* Set the default checked state of the checkbox item
|
|
6
|
+
*/
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare type MenuItemCheckboxComponent = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuItem>, Polymorphic.OwnProps<typeof MenuItem> & MenuItemCheckboxProps>;
|
|
10
|
+
export declare const MenuItemCheckbox: MenuItemCheckboxComponent;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { MenuItem } from '..';
|
|
4
|
+
export const MenuItemCheckbox = forwardRef(({ children, checked, ...otherProps }, forwardedRef) => (_jsx(MenuItem, { role: "menuitemcheckbox", "aria-checked": checked, ref: forwardedRef, ...otherProps, children: children }, void 0)));
|
|
5
|
+
MenuItemCheckbox.displayName = 'Menu.ItemCheckbox';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { IconNames } from '../../icons/types';
|
|
3
3
|
import { Polymorphic } from '../..';
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type MenuItemProps = {
|
|
5
5
|
/**
|
|
6
|
-
* Content to display in the
|
|
6
|
+
* Content to display in the menu item.
|
|
7
7
|
*/
|
|
8
8
|
children: ReactNode;
|
|
9
9
|
/**
|
|
10
|
-
* Whether the
|
|
10
|
+
* Whether the menu item should have an icon
|
|
11
11
|
*/
|
|
12
12
|
icon?: IconNames;
|
|
13
13
|
/**
|
|
@@ -24,7 +24,7 @@ export declare type DropdownItemProps = {
|
|
|
24
24
|
*/
|
|
25
25
|
onClick?(): void;
|
|
26
26
|
/**
|
|
27
|
-
* Add an extra description to the
|
|
27
|
+
* Add an extra description to the menu item.
|
|
28
28
|
* This uses the `<Tooltip>` component internally.
|
|
29
29
|
*/
|
|
30
30
|
description?: ReactNode;
|
|
@@ -33,15 +33,29 @@ export declare type DropdownItemProps = {
|
|
|
33
33
|
*/
|
|
34
34
|
disabled?: boolean;
|
|
35
35
|
/**
|
|
36
|
-
* Add or remove the padding from the
|
|
36
|
+
* Add or remove the padding from the menu item.
|
|
37
37
|
* This space is used to keep the content aligned across items with or without icons.
|
|
38
38
|
* We suggest to not remove the padding if you have items with icons in the same menu to
|
|
39
39
|
* keep a good readability.
|
|
40
40
|
*
|
|
41
|
-
* Read more: https://design.wonderflow.ai/design/recipes/
|
|
41
|
+
* Read more: https://design.wonderflow.ai/design/recipes/menu/#items-with-icons
|
|
42
42
|
*/
|
|
43
43
|
padding?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Set item to gain focus automatically when the menu is opened.
|
|
46
|
+
* This property is commonly used on the first item in the menu.
|
|
47
|
+
*/
|
|
48
|
+
autoFocus?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Add an element to decorate the menu item. This is useful for adding extra elements
|
|
51
|
+
* and informations to the menu item. The decoration element will be placed on the
|
|
52
|
+
* opposite side of the icon, based on `iconPosition`.
|
|
53
|
+
*
|
|
54
|
+
* @note Don't use interactive elements (link, buttons, etc..) as decoration
|
|
55
|
+
* if `Menu.Item` is rendered as ´<button>´ (default).
|
|
56
|
+
*/
|
|
57
|
+
decoration?: ReactNode;
|
|
44
58
|
};
|
|
45
|
-
declare type
|
|
46
|
-
export declare const
|
|
59
|
+
declare type PolymorphicMenuItem = Polymorphic.ForwardRefComponent<'button', MenuItemProps>;
|
|
60
|
+
export declare const MenuItem: PolymorphicMenuItem;
|
|
47
61
|
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, forwardRef, useRef, useMemo } from 'react';
|
|
3
|
+
import { useRovingTabIndex, useFocusEffect } from 'react-roving-tabindex';
|
|
4
|
+
import { MenuItem as MenuItemClass, Icon as IconClass, ItemContent } from './menu-item.module.css';
|
|
5
|
+
import { Tooltip, Stack, Icon } from '../..';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
export const MenuItem = forwardRef(({ className, children, onClick, icon, dimension = 'regular', as: Wrapper = 'button', iconPosition = 'left', description, padding = true, disabled = false, autoFocus, decoration, ...otherProps }, forwardedRef) => {
|
|
8
|
+
const itemRef = useRef(forwardedRef);
|
|
9
|
+
const [tabIndex, focused, handleKeyDown, handleClick] = useRovingTabIndex(itemRef, disabled);
|
|
10
|
+
const isIconRight = iconPosition === 'right';
|
|
11
|
+
useFocusEffect(focused, itemRef);
|
|
12
|
+
const triggerClick = useCallback(() => {
|
|
13
|
+
if (onClick) {
|
|
14
|
+
handleClick();
|
|
15
|
+
onClick();
|
|
16
|
+
}
|
|
17
|
+
}, [handleClick, onClick]);
|
|
18
|
+
const InnerContent = useMemo(() => (_jsxs(Stack, { direction: isIconRight ? 'row-reverse' : 'row', as: "span", className: ItemContent, horizontalAlign: isIconRight ? 'space-between' : 'start', verticalAlign: "center", columnGap: 8, horizontalPadding: 16, verticalPadding: 8, "data-menu-item-icon-right": isIconRight, "data-menu-item-has-icon": Boolean(icon), "data-menu-item-padding": padding, style: { inlineSize: '100%' }, children: [icon && (_jsx(Icon, { className: IconClass, name: icon, dimension: dimension === 'small' ? 14 : 16 }, void 0)), _jsxs(Stack, { direction: "row", horizontalAlign: "space-between", children: [children, decoration] }, void 0)] }, void 0)), [children, dimension, icon, isIconRight, decoration, padding]);
|
|
19
|
+
return (_jsx(Wrapper, { autoFocus: autoFocus, ref: itemRef, role: "menuitem", className: clsx(MenuItemClass, className), onClick: disabled ? undefined : triggerClick, onKeyDown: disabled ? undefined : handleKeyDown, tabIndex: tabIndex, "aria-disabled": disabled, type: Wrapper === 'button' ? 'button' : undefined, "data-menu-item-dimension": dimension, ...otherProps, children: description
|
|
20
|
+
? (_jsx(Tooltip, { fill: true, open: focused, placement: "right-start", interactive: true, trigger: InnerContent, children: description }, void 0))
|
|
21
|
+
: InnerContent }, void 0));
|
|
22
|
+
});
|
|
23
|
+
MenuItem.displayName = 'Menu.Item';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.MenuItem{background:none;border:0;box-sizing:border-box;color:var(--dimmed-6);cursor:pointer;font:inherit;font-size:.89rem;font-weight:600;inline-size:100%;padding:0;position:relative;text-align:start}.MenuItem:hover{color:var(--global-foreground)}.MenuItem[aria-checked=true]{color:var(--global-interactive-text)}.MenuItem:before{border-radius:.22rem;bottom:0;content:"";left:.44rem;opacity:60%;position:absolute;right:.44rem;top:0;z-index:0}.MenuItem:is(:hover,.focus-visible,[aria-pressed=true]):not([aria-disabled=true]){outline:none}.MenuItem:is(:hover,:focus-visible,[aria-pressed=true]):not([aria-disabled=true]){outline:none}.MenuItem:is(:hover,.focus-visible,[aria-pressed=true]):not([aria-disabled=true]):before{background-color:var(--dimmed-1)}.MenuItem:is(:hover,:focus-visible,[aria-pressed=true]):not([aria-disabled=true]):before{background-color:var(--dimmed-1)}.MenuItem[data-menu-item-dimension=small]{font-size:.78rem}.MenuItem>*{position:relative}.MenuItem[aria-disabled=true]{color:var(--global-disabled-foreground);cursor:not-allowed}.MenuItem [data-menu-item-padding=true][data-menu-item-has-icon=false][data-menu-item-icon-right=false]{padding-left:2.22rem}.MenuItem [data-menu-item-padding=true][data-menu-item-has-icon=false][data-menu-item-icon-right=true]{padding-right:2.22rem}.ItemContent{position:relative}.Icon{align-self:flex-start;flex-grow:0;flex-shrink:0;margin-top:4px}
|
package/menu/menu.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode, HTMLAttributes, ForwardRefExoticComponent } from 'react';
|
|
2
|
+
import { MenuItemProps } from './menu-item/menu-item';
|
|
3
|
+
import { MenuItemCheckboxProps } from './menu-item/menu-item-checkbox';
|
|
4
|
+
export declare type MenuProps = HTMLAttributes<HTMLUListElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* The items of the dropdown menu.
|
|
7
|
+
*/
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
declare type MenuComponent = ForwardRefExoticComponent<MenuProps> & {
|
|
11
|
+
Item: ForwardRefExoticComponent<MenuItemProps>;
|
|
12
|
+
ItemCheckbox: ForwardRefExoticComponent<MenuItemCheckboxProps>;
|
|
13
|
+
};
|
|
14
|
+
export declare const Menu: MenuComponent;
|
|
15
|
+
export {};
|
package/menu/menu.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, forwardRef } from 'react';
|
|
3
|
+
import { RovingTabIndexProvider } from 'react-roving-tabindex';
|
|
4
|
+
import { MenuItem } from './menu-item/menu-item';
|
|
5
|
+
import { MenuItemCheckbox } from './menu-item/menu-item-checkbox';
|
|
6
|
+
import { Stack, Elevator } from '..';
|
|
7
|
+
import { Menu as MenuClass } from './menu.module.css';
|
|
8
|
+
import clsx from 'clsx';
|
|
9
|
+
export const Menu = forwardRef(({ className, children, ...otherProps }, forwardedRef) => {
|
|
10
|
+
const renderedChildren = Children.toArray(children).filter(Boolean);
|
|
11
|
+
return (_jsx(Elevator, { resting: 2, children: _jsx(Stack, { as: "ul", ref: forwardedRef, className: clsx(MenuClass, className), role: "menu", ...otherProps, children: _jsx(RovingTabIndexProvider, { options: { direction: 'vertical', loopAround: true }, children: Children.map(renderedChildren, (child) => (_jsx(Stack, { as: "li", role: "none", verticalPadding: child.type?.displayName === 'Separator' ? 8 : undefined, children: child }, void 0))) }, void 0) }, void 0) }, void 0));
|
|
12
|
+
});
|
|
13
|
+
Menu.displayName = 'Menu';
|
|
14
|
+
Menu.Item = MenuItem;
|
|
15
|
+
Menu.ItemCheckbox = MenuItemCheckbox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.Menu{background-color:var(--global-background);border:1px solid var(--dimmed-1);border-radius:.44rem;list-style-type:none;overflow:hidden;padding:.44rem 0;position:relative}.Menu hr{margin:0 .44rem}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
3
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.21",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@wonderflow/tokens": "1.3.7",
|
|
68
68
|
"ahooks": "3.1.3",
|
|
69
69
|
"clsx": "1.1.1",
|
|
70
|
-
"framer-motion": "
|
|
70
|
+
"framer-motion": "5.5.5",
|
|
71
71
|
"postcss": "^8.4.5",
|
|
72
72
|
"react": "^17.0",
|
|
73
73
|
"react-data-table-component": "7.4.6",
|
package/stack/stack.d.ts
CHANGED
|
@@ -41,9 +41,10 @@ export declare type StackProps = {
|
|
|
41
41
|
*/
|
|
42
42
|
verticalPadding?: TokensTypes['space'];
|
|
43
43
|
/**
|
|
44
|
-
* Renderes children as rows or columns
|
|
44
|
+
* Renderes children as rows or columns. The value can be one of the flex directions.
|
|
45
|
+
* More info: https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction
|
|
45
46
|
*/
|
|
46
|
-
direction?: 'row' | 'column';
|
|
47
|
+
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
|
|
47
48
|
};
|
|
48
49
|
declare type PolymorphicStack = Polymorphic.ForwardRefComponent<'div', StackProps>;
|
|
49
50
|
export declare const Stack: PolymorphicStack;
|
package/stack/stack.module.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:where(.Stack){grid-gap:var(--rGap,0) var(--cGap,0);align-items:var(--hAlign);display:flex;flex-direction:column;justify-content:var(--vAlign);padding:var(--vPadding,0) var(--hPadding,0)}[data-stack-fill=true]:where(.Stack)
|
|
1
|
+
:where(.Stack){grid-gap:var(--rGap,0) var(--cGap,0);align-items:var(--hAlign);display:flex;flex-direction:column;justify-content:var(--vAlign);padding:var(--vPadding,0) var(--hPadding,0)}:where(.Stack):where([data-stack-fill=true]>*){flex-grow:1}[data-stack-direction=column-reverse]:where(.Stack){flex-direction:column-reverse}[data-stack-direction^=row]:where(.Stack){align-items:var(--vAlign);justify-content:var(--hAlign)}[data-stack-direction=row]:where(.Stack){flex-direction:row}[data-stack-direction=row-reverse]:where(.Stack){flex-direction:row-reverse}[data-stack-inline=true]:where(.Stack){display:inline-flex;flex-grow:0}[data-stack-wrap=true]:where(.Stack){flex-wrap:wrap}
|
package/themes/dark.css
CHANGED
package/themes/light.css
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, forwardRef, useRef, useMemo } from 'react';
|
|
3
|
-
import { useRovingTabIndex, useFocusEffect } from 'react-roving-tabindex';
|
|
4
|
-
import { DropdownItem as DropdownItemClass, Icon as IconClass } from './dropdown-item.module.css';
|
|
5
|
-
import { Tooltip, Stack, Icon } from '../..';
|
|
6
|
-
import clsx from 'clsx';
|
|
7
|
-
export const DropdownItem = forwardRef(({ className, children, onClick, icon, dimension = 'regular', as: Wrapper = 'button', iconPosition = 'left', description, padding = true, disabled = false, ...props }, forwardedRef) => {
|
|
8
|
-
const itemRef = useRef(forwardedRef);
|
|
9
|
-
const [tabIndex, focused, handleKeyDown, handleClick] = useRovingTabIndex(itemRef, disabled);
|
|
10
|
-
const isIconRight = iconPosition === 'right';
|
|
11
|
-
useFocusEffect(focused, itemRef);
|
|
12
|
-
const triggerClick = useCallback(() => {
|
|
13
|
-
if (onClick) {
|
|
14
|
-
handleClick();
|
|
15
|
-
onClick();
|
|
16
|
-
}
|
|
17
|
-
}, [handleClick, onClick]);
|
|
18
|
-
const InnerContent = useMemo(() => (_jsxs(Stack, { direction: "row", as: "span", fill: false, horizontalAlign: isIconRight ? 'space-between' : 'start', verticalAlign: "center", columnGap: 8, horizontalPadding: 16, verticalPadding: 8, "data-dropdown-icon-right": isIconRight, "data-dropdown-has-icon": Boolean(icon), "data-dropdown-padding": padding, style: { inlineSize: '100%' }, children: [icon && (_jsx(Icon, { className: IconClass, name: icon, dimension: dimension === 'small' ? 14 : 16 }, void 0)), children] }, void 0)), [children, dimension, icon, isIconRight, padding]);
|
|
19
|
-
return (_jsx(Wrapper, { ref: itemRef, role: "menuitem", className: clsx(DropdownItemClass, className), onClick: disabled ? undefined : triggerClick, onKeyDown: disabled ? undefined : handleKeyDown, tabIndex: tabIndex, "aria-disabled": disabled, type: Wrapper === 'button' ? 'button' : undefined, "data-dropdown-item-dimension": dimension, ...props, children: description
|
|
20
|
-
? (_jsx(Tooltip, { fill: true, open: focused, placement: "right-start", interactive: true, trigger: InnerContent, children: description }, void 0))
|
|
21
|
-
: InnerContent }, void 0));
|
|
22
|
-
});
|
|
23
|
-
DropdownItem.displayName = 'Dropdown.Item';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.DropdownItem{background:none;border:0;box-sizing:border-box;color:var(--dimmed-6);cursor:pointer;font:inherit;font-size:.89rem;font-weight:600;inline-size:100%;line-height:1.2;position:relative;text-align:start}.DropdownItem[aria-checked=true]{color:var(--global-interactive-text)}.DropdownItem:before{border-radius:.22rem;bottom:0;content:"";left:.44rem;opacity:60%;position:absolute;right:.44rem;top:0}.DropdownItem:is(:hover,.focus-visible,[aria-pressed=true]):not([aria-disabled=true]){outline:none}.DropdownItem:is(:hover,:focus-visible,[aria-pressed=true]):not([aria-disabled=true]){outline:none}.DropdownItem:is(:hover,.focus-visible,[aria-pressed=true]):not([aria-disabled=true]):before{background-color:var(--dimmed-1)}.DropdownItem:is(:hover,:focus-visible,[aria-pressed=true]):not([aria-disabled=true]):before{background-color:var(--dimmed-1)}.DropdownItem[data-dropdown-item-dimension=small]{font-size:.78rem}.DropdownItem>*{position:relative}.DropdownItem[aria-disabled=true]{color:var(--global-disabled-foreground);cursor:not-allowed}.DropdownItem [data-dropdown-padding=true][data-dropdown-has-icon=false][data-dropdown-icon-right=false]{padding-left:2.22rem}.DropdownItem [data-dropdown-padding=true][data-dropdown-has-icon=false][data-dropdown-icon-right=true]{padding-right:2.22rem}[data-dropdown-icon-right=true] .Icon{order:2}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DropdownItem, DropdownItemProps } from '../item/dropdown-item';
|
|
2
|
-
import { Polymorphic } from '../..';
|
|
3
|
-
export declare type DropdownItemCheckboxProps = DropdownItemProps & {
|
|
4
|
-
/**
|
|
5
|
-
* Set the default checked state of the checkbox item
|
|
6
|
-
*/
|
|
7
|
-
checked?: boolean;
|
|
8
|
-
};
|
|
9
|
-
declare type PolymorphicDropdownItemCheckbox = Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof DropdownItem>, Polymorphic.OwnProps<typeof DropdownItem> & DropdownItemCheckboxProps>;
|
|
10
|
-
export declare const DropdownItemCheckbox: PolymorphicDropdownItemCheckbox;
|
|
11
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from 'react';
|
|
3
|
-
import { DropdownItem } from '../item/dropdown-item';
|
|
4
|
-
export const DropdownItemCheckbox = forwardRef(({ children, checked, ...props }, forwardedRef) => _jsx(DropdownItem, { role: "menuitemcheckbox", "aria-checked": checked, ref: forwardedRef, ...props, children: children }, void 0));
|
|
5
|
-
DropdownItemCheckbox.displayName = 'Dropdown.ItemCheckbox';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ReactNode, HTMLAttributes } from 'react';
|
|
2
|
-
export declare type DropdownMenuProps = HTMLAttributes<HTMLUListElement> & {
|
|
3
|
-
/**
|
|
4
|
-
* The items of the dropdown menu.
|
|
5
|
-
*/
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
};
|
|
8
|
-
export declare const DropdownMenu: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLUListElement> & {
|
|
9
|
-
/**
|
|
10
|
-
* The items of the dropdown menu.
|
|
11
|
-
*/
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
} & import("react").RefAttributes<HTMLUListElement>>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Children, cloneElement, forwardRef } from 'react';
|
|
3
|
-
import { RovingTabIndexProvider } from 'react-roving-tabindex';
|
|
4
|
-
import { Stack, Elevator } from '../..';
|
|
5
|
-
import clsx from 'clsx';
|
|
6
|
-
import { DropdownMenu as DropdownMenuClass } from './dropdown-menu.module.css';
|
|
7
|
-
export const DropdownMenu = forwardRef(({ className, children, ...otherProps }, forwardedRef) => {
|
|
8
|
-
const renderedChildren = Children.toArray(children).filter(Boolean);
|
|
9
|
-
return (_jsx(Elevator, { resting: 2, children: _jsx(Stack, { as: "ul", ref: forwardedRef, className: clsx(DropdownMenuClass, className), role: "menu", ...otherProps, children: _jsx(RovingTabIndexProvider, { options: { direction: 'vertical', loopAround: true }, children: Children.map(renderedChildren, (child, index) => (_jsx(Stack, { as: "li", role: "none", verticalPadding: child.type?.displayName === 'Separator' ? 8 : undefined, children: cloneElement(child, {
|
|
10
|
-
autoFocus: index === 0 && true
|
|
11
|
-
}) }, void 0))) }, void 0) }, void 0) }, void 0));
|
|
12
|
-
});
|
|
13
|
-
DropdownMenu.displayName = 'Dropdown.Menu';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.DropdownMenu{background-color:var(--global-background);border:1px solid var(--dimmed-1);border-radius:.44rem;list-style-type:none;overflow:hidden;padding:.44rem 0;position:relative}.DropdownMenu hr{margin:0 .44rem}
|