@wonderflow/react-components 3.0.0-beta.3 → 3.0.0-beta.30

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.
Files changed (92) hide show
  1. package/autocomplete/autocomplete-option.d.ts +39 -0
  2. package/autocomplete/autocomplete-option.js +11 -0
  3. package/autocomplete/autocomplete.d.ts +24 -0
  4. package/autocomplete/autocomplete.js +82 -0
  5. package/autocomplete/autocomplete.module.css +1 -0
  6. package/autocomplete/index.d.ts +2 -0
  7. package/autocomplete/index.js +1 -0
  8. package/button/button.module.css +1 -1
  9. package/card/card.module.css +1 -1
  10. package/core/typography.css +1 -1
  11. package/core/utils/media.css +19 -1
  12. package/core/utils/vibrancy.css +0 -24
  13. package/core.css +1 -1
  14. package/datetime/datetime.d.ts +7 -0
  15. package/datetime/datetime.js +16 -0
  16. package/datetime/index.d.ts +2 -0
  17. package/datetime/index.js +1 -0
  18. package/drawer/drawer.d.ts +85 -0
  19. package/drawer/drawer.js +34 -0
  20. package/drawer/drawer.module.css +1 -0
  21. package/drawer/index.d.ts +2 -0
  22. package/drawer/index.js +1 -0
  23. package/dropdown/dropdown.d.ts +25 -11
  24. package/dropdown/dropdown.js +36 -24
  25. package/dropdown/dropdown.module.css +1 -1
  26. package/dropdown/index.d.ts +0 -2
  27. package/icon/icon.d.ts +1 -1
  28. package/index.d.ts +11 -3
  29. package/index.js +6 -2
  30. package/input-group/input-group.js +3 -3
  31. package/list/list.js +2 -2
  32. package/list/list.module.css +1 -1
  33. package/menu/index.d.ts +6 -0
  34. package/menu/index.js +3 -0
  35. package/menu/menu-item/menu-item-checkbox.d.ts +11 -0
  36. package/menu/menu-item/menu-item-checkbox.js +5 -0
  37. package/{dropdown/item/dropdown-item.d.ts → menu/menu-item/menu-item.d.ts} +23 -10
  38. package/menu/menu-item/menu-item.js +23 -0
  39. package/menu/menu-item/menu-item.module.css +1 -0
  40. package/menu/menu.d.ts +16 -0
  41. package/menu/menu.js +15 -0
  42. package/menu/menu.module.css +1 -0
  43. package/modal/content/modal-content.js +4 -3
  44. package/modal/content/modal-content.module.css +1 -1
  45. package/modal/index.d.ts +0 -1
  46. package/modal/index.js +0 -1
  47. package/modal/modal.d.ts +0 -10
  48. package/modal/modal.js +24 -7
  49. package/modal/modal.module.css +1 -1
  50. package/overlay-container/index.d.ts +1 -0
  51. package/overlay-container/index.js +1 -0
  52. package/overlay-container/overlay-container.d.ts +14 -0
  53. package/overlay-container/overlay-container.js +8 -4
  54. package/overlay-container/overlay-container.module.css +1 -0
  55. package/overlay-container/overlay-context.d.ts +9 -0
  56. package/overlay-container/overlay-context.js +23 -0
  57. package/package.json +65 -22
  58. package/select/select.js +2 -2
  59. package/select/select.module.css +1 -1
  60. package/selection-controls/selection-controls.module.css +1 -1
  61. package/snackbar/snackbar.d.ts +1 -1
  62. package/snackbar/snackbar.js +2 -2
  63. package/snackbar/snackbar.module.css +1 -1
  64. package/split-button/split-button.module.css +1 -1
  65. package/stack/stack.d.ts +3 -2
  66. package/stack/stack.module.css +1 -1
  67. package/star-meter/star-meter.d.ts +4 -0
  68. package/star-meter/star-meter.js +4 -4
  69. package/table/index.d.ts +1 -0
  70. package/text/text.d.ts +5 -0
  71. package/text/text.js +2 -2
  72. package/text/text.module.css +1 -1
  73. package/textfield/base-field/base-field.d.ts +1 -1
  74. package/textfield/base-field/base-field.module.css +1 -1
  75. package/textfield/textfield.d.ts +2 -2
  76. package/textfield/textfield.js +9 -8
  77. package/themes/dark.css +1 -1
  78. package/themes/light.css +1 -1
  79. package/title/title.js +1 -1
  80. package/title/title.module.css +1 -1
  81. package/tooltip/tooltip.d.ts +1 -1
  82. package/tooltip/tooltip.js +19 -19
  83. package/tooltip/tooltip.module.css +1 -1
  84. package/dropdown/item/dropdown-item.js +0 -23
  85. package/dropdown/item/dropdown-item.module.css +0 -1
  86. package/dropdown/item-checkbox/dropdown-item-checkbox.d.ts +0 -11
  87. package/dropdown/item-checkbox/dropdown-item-checkbox.js +0 -5
  88. package/dropdown/menu/dropdown-menu.d.ts +0 -13
  89. package/dropdown/menu/dropdown-menu.js +0 -13
  90. package/dropdown/menu/dropdown-menu.module.css +0 -1
  91. package/modal/modal-context.d.ts +0 -9
  92. package/modal/modal-context.js +0 -23
package/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { UIDReset as IdProvider } from 'react-uid';
2
2
  export * as Polymorphic from './polymorphic';
3
3
  export { Avatar } from './avatar';
4
4
  export type { AvatarProps } from './avatar';
5
+ export { Autocomplete } from './autocomplete';
6
+ export type { AutocompleteProps } from './autocomplete';
5
7
  export { Button, ButtonsGroup } from './button';
6
8
  export type { ButtonProps, ButtonsGroupProps } from './button';
7
9
  export { Card } from './card';
@@ -16,12 +18,16 @@ export { ClampText } from './clamp-text';
16
18
  export type { ClampTextProps } from './clamp-text';
17
19
  export { Container } from './container';
18
20
  export type { ContainerProps } from './container';
21
+ export { Datetime } from './datetime';
22
+ export type { DatetimeProps } from './datetime';
23
+ export { Drawer } from './drawer';
24
+ export type { DrawerProps } from './drawer';
19
25
  export { Table } from './table';
20
26
  export type { TableProps } from './table';
21
27
  export { Disclosure } from './disclosure';
22
28
  export type { DisclosureProps } from './disclosure';
23
29
  export { Dropdown } from './dropdown';
24
- export type { DropdownProps, DropdownItemProps, DropdownItemCheckboxProps } from './dropdown';
30
+ export type { DropdownProps } from './dropdown';
25
31
  export { Elevator } from './elevator';
26
32
  export type { ElevatorProps } from './elevator';
27
33
  export { Icon } from './icon';
@@ -36,11 +42,13 @@ export { List } from './list';
36
42
  export type { ListProps } from './list';
37
43
  export { SplitButton } from './split-button';
38
44
  export type { SplitButtonProps } from './split-button';
39
- export { Modal, useModalContext, ModalProvider } from './modal';
45
+ export { Modal } from './modal';
40
46
  export type { ModalProps } from './modal';
41
47
  export { LinearProgress } from './linear-progress';
42
48
  export type { LinearProgressProps } from './linear-progress';
43
- export { OverlayContainer } from './overlay-container';
49
+ export { Menu } from './menu';
50
+ export type { MenuProps, MenuItemProps, MenuItemCheckboxProps } from './menu';
51
+ export { OverlayContainer, useOverlayContext, OverlayProvider } from './overlay-container';
44
52
  export type { OverlayContainerProps } from './overlay-container';
45
53
  export { Prose } from './prose';
46
54
  export type { ProseProps } from './prose';
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { UIDReset as IdProvider } from 'react-uid';
2
2
  export * as Polymorphic from './polymorphic';
3
3
  export { Avatar } from './avatar';
4
+ export { Autocomplete } from './autocomplete';
4
5
  export { Button, ButtonsGroup } from './button';
5
6
  export { Card } from './card';
6
7
  export { Checkbox, Radio, Toggle } from './selection-controls';
@@ -8,6 +9,8 @@ export { Chip } from './chip';
8
9
  export { CircularProgress } from './circular-progress';
9
10
  export { ClampText } from './clamp-text';
10
11
  export { Container } from './container';
12
+ export { Datetime } from './datetime';
13
+ export { Drawer } from './drawer';
11
14
  export { Table } from './table';
12
15
  export { Disclosure } from './disclosure';
13
16
  export { Dropdown } from './dropdown';
@@ -18,9 +21,10 @@ export { InfoState } from './info-state';
18
21
  export { InputGroup } from './input-group';
19
22
  export { List } from './list';
20
23
  export { SplitButton } from './split-button';
21
- export { Modal, useModalContext, ModalProvider } from './modal';
24
+ export { Modal } from './modal';
22
25
  export { LinearProgress } from './linear-progress';
23
- export { OverlayContainer } from './overlay-container';
26
+ export { Menu } from './menu';
27
+ export { OverlayContainer, useOverlayContext, OverlayProvider } from './overlay-container';
24
28
  export { Prose } from './prose';
25
29
  export { Pagination } from './pagination';
26
30
  export { Select } from './select';
@@ -5,11 +5,11 @@ import { Stack, Text } from '../';
5
5
  import { useUIDSeed } from 'react-uid';
6
6
  import { End, InputField, Start, InputGroup as InputGroupClass } from './input-group.module.css';
7
7
  export const InputGroup = forwardRef(({ className, input, end, start, label, dimension = 'regular', ...otherProps }, forwardedRef) => {
8
- const uid = useUIDSeed();
9
- return (_jsxs(Stack, { rowGap: 4, horizontalAlign: "stretch", verticalAlign: "start", fill: false, children: [label && _jsx(Text, { as: "label", size: dimension === 'small' ? 14 : 16, htmlFor: uid('field'), children: label }, void 0), _jsxs(Stack, { as: "fieldset", direction: "row", verticalAlign: "start", horizontalAlign: "start", fill: false, inline: true, ref: forwardedRef, className: clsx(InputGroupClass, className), "data-input-group-has-end": Boolean(end), "data-input-group-has-start": !!start, ...otherProps, children: [_jsx("div", { className: Start, children: Children.map(start, (child) => cloneElement(child, {
8
+ const seedID = useUIDSeed();
9
+ return (_jsxs(Stack, { rowGap: 4, horizontalAlign: "stretch", verticalAlign: "start", fill: false, children: [label && _jsx(Text, { as: "label", size: dimension === 'small' ? 14 : 16, htmlFor: seedID('field'), children: label }, void 0), _jsxs(Stack, { as: "fieldset", direction: "row", verticalAlign: "start", horizontalAlign: "start", fill: false, inline: true, ref: forwardedRef, className: clsx(InputGroupClass, className), "data-input-group-has-end": Boolean(end), "data-input-group-has-start": !!start, ...otherProps, children: [_jsx("div", { className: Start, children: Children.map(start, (child) => cloneElement(child, {
10
10
  dimension
11
11
  })) }, void 0), _jsx("div", { className: InputField, children: Children.map(input, (child) => cloneElement(child, {
12
- id: uid('field'),
12
+ id: seedID('field'),
13
13
  dimension
14
14
  })) }, void 0), _jsx("div", { className: End, children: Children.map(end, (child) => cloneElement(child, {
15
15
  dimension
package/list/list.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Children, forwardRef, useMemo } from 'react';
3
3
  import { List as ListClass, Marker } from './list.module.css';
4
4
  import clsx from 'clsx';
5
- import { Text, Icon } from '../';
5
+ import { Text, Stack, Icon } from '../';
6
6
  export const List = forwardRef(({ as: Wrapper = 'ul', children, marker = 'circle', dimension = 'regular', className, markerColor, hideMarker = false, ...otherProps }, forwardedRef) => {
7
7
  const sizes = {
8
8
  small: {
@@ -19,5 +19,5 @@ export const List = forwardRef(({ as: Wrapper = 'ul', children, marker = 'circle
19
19
  }
20
20
  };
21
21
  const isUnordered = useMemo(() => Wrapper === 'ul', [Wrapper]);
22
- return (_jsx(Wrapper, { ref: forwardedRef, className: clsx(ListClass, className), "data-list-size": dimension, "data-list-ordered": !isUnordered, "data-list-no-marker": hideMarker, ...otherProps, children: Children.map(children, (child) => (_jsxs(Text, { as: "li", size: sizes[dimension].text, children: [isUnordered && (_jsx(Icon, { name: marker, className: Marker, fill: markerColor, dimension: marker !== 'circle' ? sizes[dimension].icon : 16 }, void 0)), child.props.children] }, void 0))) }, void 0));
22
+ return (_jsx(Wrapper, { ref: forwardedRef, className: clsx(ListClass, className), "data-list-size": dimension, "data-list-ordered": !isUnordered, "data-list-no-marker": hideMarker, ...otherProps, children: Children.map(children, (child) => (_jsxs(Stack, { as: "li", direction: "row", horizontalAlign: "start", verticalAlign: "start", fill: false, children: [(isUnordered && !hideMarker) && (_jsx(Icon, { name: marker, className: Marker, fill: markerColor, "data-list-default-marker": marker === 'circle', dimension: marker !== 'circle' ? sizes[dimension].icon : 16 }, void 0)), _jsx(Text, { as: "span", size: sizes[dimension].text, children: child.props.children }, void 0)] }, void 0))) }, void 0));
23
23
  });
@@ -1 +1 @@
1
- .List{--marker-size:0.89rem;--marker-gap:0.44rem}.List[data-list-no-marker=true]{--marker-size:0;--marker-gap:0;list-style:none;padding:0}.List[data-list-ordered=false]{list-style:none;padding:0}.List[data-list-ordered=false] li{padding-inline-start:calc(var(--marker-size) + var(--marker-gap));position:relative}.List[data-list-ordered=true] li{padding-inline-start:var(--marker-gap)}.List[data-list-ordered=true] li::marker{color:var(--dimmed-5)}.List[data-list-size=small]{--marker-size:0.77rem;--marker-gap:0.44rem}.List[data-list-size=big]{--marker-size:1.11rem;--marker-gap:0.89rem}.Marker{block-size:var(--marker-size);inline-size:var(--marker-size);left:0;position:absolute;top:calc(var(--marker-size)/2.4)}.List[data-list-size=small] .Marker{top:3px}.List[data-list-size=big] .Marker{top:calc(var(--marker-size)/3)}
1
+ .List{--marker-size:0.89rem;--marker-gap:0.44rem}.List li{gap:var(--marker-gap)}.List[data-list-ordered=false]{list-style:none;padding:0}.List[data-list-ordered=true] li::marker{color:var(--dimmed-5)}.List[data-list-size=small]{--marker-size:0.77rem;--marker-gap:0.44rem}.List[data-list-size=big]{--marker-size:1.11rem;--marker-gap:0.89rem}.List[data-list-no-marker=true]{--marker-size:0;--marker-gap:0;list-style:none;padding:0}.Marker{block-size:var(--marker-size);flex-shrink:0;inline-size:var(--marker-size);margin-block-start:calc(var(--marker-size)/2.5)}.Marker[data-list-default-marker=true]{transform:scale(.7)}.List[data-list-size=big] .Marker,.Marker[data-list-default-marker=true]{margin-block-start:calc(var(--marker-size)/3)}
@@ -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,3 @@
1
+ export { Menu } from './menu';
2
+ export { MenuItem } from './menu-item/menu-item';
3
+ export { MenuItemCheckbox } from './menu-item/menu-item-checkbox';
@@ -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
+ import { Polymorphic } from '../..';
1
2
  import { ReactNode } from 'react';
2
3
  import { IconNames } from '../../icons/types';
3
- import { Polymorphic } from '../..';
4
- export declare type DropdownItemProps = {
4
+ export declare type MenuItemProps = {
5
5
  /**
6
- * Content to display in the dropdown item.
6
+ * Content to display in the menu item.
7
7
  */
8
8
  children: ReactNode;
9
9
  /**
10
- * Whether the dropdown item should have an icon
10
+ * Whether the menu item should have an icon
11
11
  */
12
12
  icon?: IconNames;
13
13
  /**
@@ -22,9 +22,9 @@ export declare type DropdownItemProps = {
22
22
  /**
23
23
  * Callback function to be called when the menu item is pressed.
24
24
  */
25
- onClick?(): void;
25
+ onClick?(event?: Event): void;
26
26
  /**
27
- * Add an extra description to the dropdown item.
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,28 @@ export declare type DropdownItemProps = {
33
33
  */
34
34
  disabled?: boolean;
35
35
  /**
36
- * Add or remove the padding from the dropdown item.
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/dropdown/#items-with-icons
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.
52
+ *
53
+ * @note Don't use interactive elements (link, buttons, etc..) as decoration
54
+ * if `Menu.Item` is rendered as ´<button>´ (default).
55
+ */
56
+ decoration?: ReactNode;
44
57
  };
45
- declare type PolymorphicDropdownItem = Polymorphic.ForwardRefComponent<'button', DropdownItemProps>;
46
- export declare const DropdownItem: PolymorphicDropdownItem;
58
+ declare type PolymorphicMenuItem = Polymorphic.ForwardRefComponent<'button', MenuItemProps>;
59
+ export declare const MenuItem: PolymorphicMenuItem;
47
60
  export {};
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Icon, Stack, Tooltip } from '../..';
3
+ import { Icon as IconClass, ItemContent, MenuItem as MenuItemClass } from './menu-item.module.css';
4
+ import { forwardRef, useCallback, useMemo, useRef } from 'react';
5
+ import { useFocusEffect, useRovingTabIndex } from 'react-roving-tabindex';
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((e) => {
13
+ if (onClick) {
14
+ handleClick();
15
+ onClick(e);
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, { columnGap: 16, fill: false, 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,16 @@
1
+ import { ReactNode, HTMLAttributes, ForwardRefExoticComponent } from 'react';
2
+ import { MenuItem, MenuItemProps } from './menu-item/menu-item';
3
+ import { MenuItemCheckbox, MenuItemCheckboxProps } from './menu-item/menu-item-checkbox';
4
+ import { Polymorphic } from '..';
5
+ export declare type MenuProps = HTMLAttributes<HTMLUListElement> & {
6
+ /**
7
+ * The items of the dropdown menu.
8
+ */
9
+ children: ReactNode;
10
+ };
11
+ declare type MenuComponent = ForwardRefExoticComponent<MenuProps> & {
12
+ Item: Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuItem>, Polymorphic.OwnProps<typeof MenuItem> & MenuItemProps>;
13
+ ItemCheckbox: Polymorphic.ForwardRefComponent<Polymorphic.IntrinsicElement<typeof MenuItemCheckbox>, Polymorphic.OwnProps<typeof MenuItemCheckbox> & MenuItemCheckboxProps>;
14
+ };
15
+ export declare const Menu: MenuComponent;
16
+ 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}
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import clsx from 'clsx';
3
3
  import { forwardRef } from 'react';
4
+ import { AutoFocusInside } from 'react-focus-on';
4
5
  import { Content, Header, CloseButton } from './modal-content.module.css';
5
6
  import { Title, Elevator, IconButton, Stack } from '../../';
6
- import { useModalContext } from '../modal-context';
7
+ import { useOverlayContext } from '../../overlay-container';
7
8
  export const ModalContent = forwardRef(({ children, className, title, theme = 'light', ...otherProps }, forwardedRef) => {
8
- const { onClose, titleId } = useModalContext();
9
- return (_jsx(Elevator, { resting: 4, children: _jsxs("div", { className: clsx(Content, className), ref: forwardedRef, "data-theme": theme, ...otherProps, children: [_jsxs(Stack, { verticalAlign: "center", fill: false, horizontalAlign: "space-between", direction: "row", className: Header, children: [_jsx(Title, { level: "5", id: titleId, children: title }, void 0), onClose && _jsx(IconButton, { onClick: onClose, className: CloseButton, icon: "xmark", kind: "flat" }, void 0)] }, void 0), children] }, void 0) }, void 0));
9
+ const { onClose, titleId } = useOverlayContext();
10
+ return (_jsx(Elevator, { resting: 4, children: _jsxs("div", { className: clsx(Content, className), ref: forwardedRef, "data-theme": theme, ...otherProps, children: [_jsxs(Stack, { verticalAlign: "center", fill: false, horizontalAlign: "space-between", direction: "row", className: Header, children: [_jsx(Title, { responsive: false, level: "5", id: titleId, children: title }, void 0), onClose && _jsx(IconButton, { onClick: onClose, className: CloseButton, icon: "xmark", kind: "flat" }, void 0)] }, void 0), _jsx(AutoFocusInside, { children: children }, void 0)] }, void 0) }, void 0));
10
11
  });
11
12
  ModalContent.displayName = 'Modal.Content';
@@ -1 +1 @@
1
- .Content{-webkit-overflow-scrolling:touch;align-self:end;background-color:var(--global-background);border-radius:.89rem .89rem 0 0;color:var(--global-foreground);inline-size:100%;justify-self:center;max-block-size:95vh;overflow:auto;overscroll-behavior:contain}@media (min-width:30em){.Content{align-self:center;border-radius:.44rem;justify-self:center;max-block-size:80vh;max-inline-size:600px}}.Header{background-color:inherit;border-bottom:1px solid var(--dimmed-1);padding:.89rem 4.44rem .89rem 1.33rem;position:sticky;top:0}.CloseButton.CloseButton{position:absolute;right:.44rem;top:.44rem}
1
+ .Content{-webkit-overflow-scrolling:touch;align-self:end;background-color:var(--global-background);border-radius:.89rem .89rem 0 0;inline-size:100%;justify-self:center;max-block-size:95vh;overflow:auto;overscroll-behavior:contain}@media (min-width:30em){.Content{align-self:center;border-radius:.44rem;justify-self:center;max-block-size:80vh;max-inline-size:600px}}.Header{background-color:inherit;border-bottom:1px solid var(--dimmed-1);padding:.89rem 4.44rem .89rem 1.33rem;position:sticky;top:0}.CloseButton.CloseButton{position:absolute;right:.44rem;top:.44rem}
package/modal/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { Modal } from './modal';
2
- export { useModalContext, ModalProvider } from './modal-context';
3
2
  export type { ModalProps } from './modal';
package/modal/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { Modal } from './modal';
2
- export { useModalContext, ModalProvider } from './modal-context';
package/modal/modal.d.ts CHANGED
@@ -1,22 +1,12 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { ModalContentProps } from './content/modal-content';
3
3
  export declare type ModalProps = PropsWithChildren<PropsWithClass> & {
4
- /**
5
- * Set the overlay style. This is used to obscure the page content
6
- * behind the modal while it is open. If set to `auto`, the overlay
7
- * color is determined by the global active theme (light or dark).
8
- */
9
- overlayColor?: 'light' | 'dark' | 'auto';
10
4
  /**
11
5
  * This enable the modal to be closed by clicking on the overlay.
12
6
  * Even if this can be set to `false` we strongly recommend to leave
13
7
  * it to `true` as it ensures the accessibility of the modal.
14
8
  */
15
9
  closeOnClickOutside?: boolean;
16
- /**
17
- * The callback function that is called when the modal is closed.
18
- */
19
- onClose(): void;
20
10
  };
21
11
  declare type ModalComponent = React.ForwardRefExoticComponent<ModalProps> & {
22
12
  Content: React.ForwardRefExoticComponent<ModalContentProps>;
package/modal/modal.js CHANGED
@@ -1,15 +1,32 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from 'react';
3
- import { useUIDSeed } from 'react-uid';
4
3
  import { motion } from 'framer-motion';
5
4
  import clsx from 'clsx';
6
5
  import { FocusOn } from 'react-focus-on';
7
6
  import { ModalContent } from './content/modal-content';
8
- import { Modal as ModalClass, Backdrop, Container } from './modal.module.css';
9
- import { ModalContext, ModalProvider } from './modal-context';
10
- export const Modal = forwardRef(({ children, className, overlayColor = 'dark', closeOnClickOutside = true, onClose, ...otherProps }, forwardedRef) => {
11
- const seedID = useUIDSeed();
12
- return (_jsx(ModalProvider, { onClose: onClose, children: _jsx(ModalContext.Consumer, { children: (ctx) => (_jsxs("div", { role: "dialog", "aria-modal": "true", "aria-labelledby": ctx.titleId, className: clsx(ModalClass, className), ref: forwardedRef, ...otherProps, children: [_jsx(motion.span, { className: Backdrop, "data-overlay-color": overlayColor, initial: { opacity: 0 }, animate: { opacity: 0.95 }, transition: { duration: 0.2 } }, seedID('modal-backdrop')), _jsx(FocusOn, { onClickOutside: ctx.onClose, onEscapeKey: ctx.onClose, children: _jsx(motion.div, { className: Container, initial: { y: 20, scale: 0.98, opacity: 0 }, animate: { y: 0, scale: 1, opacity: 1 }, transition: { ease: 'easeOut', duration: 0.1 }, children: children }, seedID('modal-container')) }, void 0)] }, void 0)) }, void 0) }, void 0));
7
+ import { Modal as ModalClass, Container } from './modal.module.css';
8
+ import { useOverlayContext } from '../overlay-container';
9
+ const ModalAnimation = {
10
+ visible: {
11
+ scale: 1,
12
+ opacity: 1,
13
+ transition: {
14
+ ease: [0, 0, 0.34, 1],
15
+ duration: 0.35
16
+ }
17
+ },
18
+ hidden: {
19
+ scale: 0.98,
20
+ opacity: 0,
21
+ transition: {
22
+ ease: [0.3, 0.07, 1, 1],
23
+ duration: 0.2
24
+ }
25
+ }
26
+ };
27
+ export const Modal = forwardRef(({ children, className, closeOnClickOutside = true, ...otherProps }, forwardedRef) => {
28
+ const { titleId, onClose } = useOverlayContext();
29
+ return (_jsx("div", { role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, className: clsx(ModalClass, className), ref: forwardedRef, ...otherProps, children: _jsx(FocusOn, { onClickOutside: closeOnClickOutside ? onClose : undefined, onEscapeKey: onClose, children: _jsx(motion.div, { variants: ModalAnimation, initial: "hidden", animate: "visible", exit: "hidden", className: Container, children: children }, void 0) }, void 0) }, void 0));
13
30
  });
14
31
  Modal.displayName = 'Modal';
15
32
  Modal.Content = ModalContent;
@@ -1 +1 @@
1
- .Modal{position:fixed;z-index:20}.Backdrop,.Modal{bottom:0;left:0;right:0;top:0}.Backdrop{background-color:var(--dimmed-0);display:block;position:absolute;z-index:1}.Backdrop[data-overlay-color=light]{background-color:#f9fafb}.Backdrop[data-overlay-color=dark]{background-color:#202328}.Container{align-items:center;bottom:0;display:grid;justify-content:center;left:0;pointer-events:none;position:absolute;right:0;top:0;z-index:1}@media (min-width:30em){.Container{overflow:auto;padding:0 1.33rem}}.Container>*{pointer-events:auto}
1
+ .Modal{display:contents}.Container{align-items:center;bottom:0;display:grid;justify-content:center;left:0;pointer-events:none;position:absolute;right:0;top:0;z-index:1}@media (min-width:30em){.Container{overflow:auto;padding:0 1.33rem}}.Container>*{pointer-events:auto}
@@ -1,2 +1,3 @@
1
1
  export { OverlayContainer } from './overlay-container';
2
+ export { useOverlayContext, OverlayProvider, OverlayContext } from './overlay-context';
2
3
  export type { OverlayContainerProps } from './overlay-container';
@@ -1 +1,2 @@
1
1
  export { OverlayContainer } from './overlay-container';
2
+ export { useOverlayContext, OverlayProvider, OverlayContext } from './overlay-context';
@@ -15,5 +15,19 @@ export declare type OverlayContainerProps = {
15
15
  * if necessary.
16
16
  */
17
17
  index?: number;
18
+ /**
19
+ * Set the overlay style. This is used to obscure the content
20
+ * behind the overlay if `obfuscate` is `true`. If set to `auto`, the overlay
21
+ * color is determined by the global active theme (light or dark).
22
+ */
23
+ overlayColor?: 'light' | 'dark' | 'auto';
24
+ /**
25
+ * The callback function that is called when the overlay is closed.
26
+ */
27
+ onClose?(): void;
28
+ /**
29
+ * Set the overlay to be obscuring the page content behind it.
30
+ */
31
+ obfuscate?: boolean;
18
32
  };
19
33
  export declare const OverlayContainer: React.FC<OverlayContainerProps>;
@@ -1,13 +1,17 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AnimatePresence, motion } from 'framer-motion';
2
3
  import { useEffect } from 'react';
3
- import { ModalProvider } from '../modal';
4
4
  import { createPortal } from 'react-dom';
5
- export const OverlayContainer = ({ children, root = document.body, index = 4 }) => {
5
+ import { useUIDSeed } from 'react-uid';
6
+ import { OverlayProvider } from './overlay-context';
7
+ import { OverlayContainer as OverlayContainerClass, Backdrop } from './overlay-container.module.css';
8
+ export const OverlayContainer = ({ children, root = document.body, overlayColor = 'dark', index = 4, obfuscate = true, onClose }) => {
9
+ const seedID = useUIDSeed();
6
10
  useEffect(() => {
7
11
  if (root.closest('[data-overlay-container]')) {
8
12
  throw new Error('An OverlayContainer must not be inside another container. Please change the root prop.');
9
13
  }
10
14
  }, [root]);
11
- const content = (_jsx(ModalProvider, { children: _jsx("div", { "data-overlay-container": true, style: { position: 'relative', zIndex: index }, children: children }, void 0) }, void 0));
15
+ const content = (_jsx(OverlayProvider, { onClose: onClose, children: _jsx(AnimatePresence, { exitBeforeEnter: true, children: children && (_jsxs("div", { "data-overlay-container": true, "data-overlay-container-obfuscate": obfuscate, className: OverlayContainerClass, style: { zIndex: index }, children: [obfuscate && (_jsx(motion.span, { className: Backdrop, "data-overlay-color": overlayColor, initial: { opacity: 0 }, animate: { opacity: 0.95 }, transition: { duration: 0.2 }, exit: { opacity: 0 } }, seedID('modal-backdrop'))), children] }, void 0)) }, void 0) }, void 0));
12
16
  return createPortal(content, root);
13
17
  };
@@ -0,0 +1 @@
1
+ .OverlayContainer{bottom:0;display:block;left:0;position:fixed;right:0;top:0}.OverlayContainer[data-overlay-container-obfuscate=false]{pointer-events:none}.Backdrop{background-color:var(--dimmed-0);bottom:0;left:0;position:fixed;right:0;top:0;z-index:-1}.Backdrop[data-overlay-color=light]{background-color:#f9fafb}.Backdrop[data-overlay-color=dark]{background-color:#202328}
@@ -0,0 +1,9 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { OverlayContainerProps } from './overlay-container';
3
+ declare type OverlayContextProps = Partial<OverlayContainerProps> & {
4
+ titleId?: string;
5
+ };
6
+ export declare const OverlayContext: import("react").Context<OverlayContextProps>;
7
+ export declare const OverlayProvider: (props: PropsWithChildren<OverlayContextProps>) => JSX.Element;
8
+ export declare const useOverlayContext: () => OverlayContextProps;
9
+ export {};
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from 'react';
3
+ import { useUIDSeed } from 'react-uid';
4
+ export const OverlayContext = createContext({
5
+ titleId: '',
6
+ onClose: () => { }
7
+ });
8
+ OverlayContext.displayName = 'OverlayContext';
9
+ export const OverlayProvider = (props) => {
10
+ const seedID = useUIDSeed();
11
+ const { children, titleId = seedID('overlay-title'), onClose } = props;
12
+ return (_jsx(OverlayContext.Provider, { value: {
13
+ titleId,
14
+ onClose
15
+ }, children: children }, void 0));
16
+ };
17
+ export const useOverlayContext = () => {
18
+ const context = useContext(OverlayContext);
19
+ if (!context) {
20
+ throw new Error('OverlayContainer component must be used inside OverlayContext to access context data.');
21
+ }
22
+ return context;
23
+ };