@doist/reactist 21.2.0 → 22.0.0-beta

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.
@@ -2647,12 +2647,18 @@ function TabAwareSlot({
2647
2647
  }) : null;
2648
2648
  }
2649
2649
 
2650
+ var modules_2befbba6 = {"menuList":"c63e79f3","subMenuList":"_1e89cfc6","iconMenuItem":"_1b808bea","menuItem":"_8607099d","legacyLayout":"_609759d5","menuGroupLabel":"f1730843","menuItemIcon":"_7cec7dce","menuItemLabel":"_91c012d8","menuItemDescription":"bb494fd4","destructive":"_503b074a","menuGroupInfo":"ad6d2e4a","iconsMenuGroup":"_410b11f2"};
2651
+
2650
2652
  const _excluded$t = ["children", "onItemSelect"],
2651
2653
  _excluded2$3 = ["exceptionallySetClassName"],
2652
- _excluded3$2 = ["as"],
2653
- _excluded4$1 = ["exceptionallySetClassName", "modal"],
2654
- _excluded5$1 = ["value", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName", "as"],
2655
- _excluded6 = ["label", "children", "exceptionallySetClassName"];
2654
+ _excluded3$2 = ["exceptionallySetClassName", "label", "icon"],
2655
+ _excluded4$1 = ["as"],
2656
+ _excluded5$1 = ["exceptionallySetClassName", "modal"],
2657
+ _excluded6 = ["exceptionallySetClassName", "modal"],
2658
+ _excluded7 = ["value", "label", "description", "icon", "shortcut", "tone", "children", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName", "as"],
2659
+ _excluded8 = ["label", "info", "children", "exceptionallySetClassName"],
2660
+ _excluded9 = ["value", "label", "description", "icon", "onSelect", "hideOnSelect", "onClick", "exceptionallySetClassName", "as"],
2661
+ _excluded10 = ["children"];
2656
2662
  const MenuContext = /*#__PURE__*/React.createContext( // Ariakit gives us no means to obtain a valid initial/default value of type MenuStateReturn
2657
2663
  // (it is normally obtained by calling useMenuState but we can't call hooks outside components).
2658
2664
  // This is however of little consequence since this value is only used if some of the components
@@ -2664,7 +2670,7 @@ const MenuContext = /*#__PURE__*/React.createContext( // Ariakit gives us no mea
2664
2670
  * management for the menu components inside it.
2665
2671
  */
2666
2672
 
2667
- function Menu(_ref) {
2673
+ const Menu = /*#__PURE__*/React.forwardRef(function Menu(_ref, ref) {
2668
2674
  let {
2669
2675
  children,
2670
2676
  onItemSelect
@@ -2684,6 +2690,9 @@ function Menu(_ref) {
2684
2690
  React.useEffect(() => {
2685
2691
  if (!state.open) handleAnchorRectChange(null);
2686
2692
  }, [state.open]);
2693
+ React.useImperativeHandle(ref, () => ({
2694
+ open: state.show
2695
+ }));
2687
2696
  const handleItemSelect = React.useCallback(function handleItemSelect(value) {
2688
2697
  if (onItemSelect) onItemSelect(value);
2689
2698
  }, [onItemSelect]);
@@ -2695,12 +2704,11 @@ function Menu(_ref) {
2695
2704
  return /*#__PURE__*/React.createElement(MenuContext.Provider, {
2696
2705
  value: value
2697
2706
  }, children);
2698
- }
2707
+ });
2699
2708
  /**
2700
2709
  * A button to toggle a dropdown menu open or closed.
2701
2710
  */
2702
2711
 
2703
-
2704
2712
  const MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2, ref) {
2705
2713
  let {
2706
2714
  exceptionallySetClassName
@@ -2713,17 +2721,104 @@ const MenuButton = /*#__PURE__*/polymorphicComponent(function MenuButton(_ref2,
2713
2721
  return /*#__PURE__*/React.createElement(Ariakit.MenuButton, _objectSpread2(_objectSpread2({}, props), {}, {
2714
2722
  state: state,
2715
2723
  ref: ref,
2716
- className: classNames('reactist_menubutton', exceptionallySetClassName)
2724
+ className: exceptionallySetClassName
2725
+ }));
2726
+ });
2727
+ /**
2728
+ * Renders the content inside a standard MenuItem. It is extracted into a component for reuse in
2729
+ * the SubMenuItem, which is a MenuItem visually, but semantically it's closer to be a MenuButton.
2730
+ * @private
2731
+ */
2732
+
2733
+ function MenuItemContent({
2734
+ label,
2735
+ description,
2736
+ icon,
2737
+ shortcut,
2738
+ id
2739
+ }) {
2740
+ if (!label) return null;
2741
+ return /*#__PURE__*/React.createElement(Box, {
2742
+ display: "flex",
2743
+ gap: "small",
2744
+ alignItems: "center",
2745
+ width: "full",
2746
+ "aria-hidden": true
2747
+ }, icon ? /*#__PURE__*/React.createElement("div", {
2748
+ className: modules_2befbba6.menuItemIcon
2749
+ }, icon) : null, /*#__PURE__*/React.createElement(Box, {
2750
+ display: "inlineFlex",
2751
+ flexDirection: "column",
2752
+ gap: "xsmall",
2753
+ paddingY: "xsmall",
2754
+ alignItems: "flexStart",
2755
+ overflow: "hidden",
2756
+ flexGrow: 1
2757
+ }, /*#__PURE__*/React.createElement(Text, {
2758
+ id: id + "-label",
2759
+ weight: description ? 'semibold' : 'regular',
2760
+ size: "copy",
2761
+ lineClamp: 1,
2762
+ exceptionallySetClassName: modules_2befbba6.menuItemLabel
2763
+ }, label), description ? /*#__PURE__*/React.createElement(Text, {
2764
+ id: id + "-description",
2765
+ size: "copy",
2766
+ tone: "secondary",
2767
+ exceptionallySetClassName: modules_2befbba6.menuItemDescription
2768
+ }, description) : null), shortcut ? /*#__PURE__*/React.createElement("div", null, shortcut) : null);
2769
+ } //
2770
+ // SubMenuItem
2771
+ //
2772
+
2773
+
2774
+ function ArrowRightIcon() {
2775
+ return /*#__PURE__*/React.createElement("svg", {
2776
+ width: "24",
2777
+ height: "24"
2778
+ }, /*#__PURE__*/React.createElement("path", {
2779
+ d: "M14.243 12L9.646 7.404a.5.5 0 1 1 .708-.707l4.95 4.95a.5.5 0 0 1 0 .707l-4.95 4.95a.5.5 0 0 1-.708-.708L14.243 12z",
2780
+ fill: "currentColor",
2781
+ fillRule: "evenodd"
2782
+ }));
2783
+ }
2784
+ /**
2785
+ * A menu item to toggle a sub-menu open or closed.
2786
+ */
2787
+
2788
+
2789
+ const SubMenuItem = /*#__PURE__*/polymorphicComponent(function SubMenuItem(_ref3, ref) {
2790
+ let {
2791
+ exceptionallySetClassName,
2792
+ label,
2793
+ icon
2794
+ } = _ref3,
2795
+ props = _objectWithoutProperties(_ref3, _excluded3$2);
2796
+
2797
+ const id = useId(props.id);
2798
+ const {
2799
+ state
2800
+ } = React.useContext(MenuContext);
2801
+ return /*#__PURE__*/React.createElement(Ariakit.MenuButton, _objectSpread2(_objectSpread2({
2802
+ "aria-labelledby": label && !props['aria-label'] ? id + "-label" : undefined
2803
+ }, props), {}, {
2804
+ state: state,
2805
+ ref: ref,
2806
+ className: classNames(modules_2befbba6.menuItem, exceptionallySetClassName)
2807
+ }), /*#__PURE__*/React.createElement(MenuItemContent, {
2808
+ id: id,
2809
+ icon: icon,
2810
+ label: label,
2811
+ shortcut: /*#__PURE__*/React.createElement(ArrowRightIcon, null)
2717
2812
  }));
2718
2813
  }); //
2719
2814
  // ContextMenuTrigger
2720
2815
  //
2721
2816
 
2722
- const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMenuTrigger(_ref3, ref) {
2817
+ const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMenuTrigger(_ref4, ref) {
2723
2818
  let {
2724
2819
  as: component = 'div'
2725
- } = _ref3,
2726
- props = _objectWithoutProperties(_ref3, _excluded3$2);
2820
+ } = _ref4,
2821
+ props = _objectWithoutProperties(_ref4, _excluded4$1);
2727
2822
 
2728
2823
  const {
2729
2824
  handleAnchorRectChange,
@@ -2746,42 +2841,59 @@ const ContextMenuTrigger = /*#__PURE__*/polymorphicComponent(function ContextMen
2746
2841
  * The dropdown menu itself, containing a list of menu items.
2747
2842
  */
2748
2843
 
2749
- const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref4, ref) {
2844
+ const MenuList = /*#__PURE__*/polymorphicComponent(function MenuList(_ref5, ref) {
2750
2845
  let {
2751
2846
  exceptionallySetClassName,
2752
2847
  modal = true
2753
- } = _ref4,
2754
- props = _objectWithoutProperties(_ref4, _excluded4$1);
2848
+ } = _ref5,
2849
+ props = _objectWithoutProperties(_ref5, _excluded5$1);
2755
2850
 
2756
2851
  const {
2757
2852
  state
2758
2853
  } = React.useContext(MenuContext);
2759
- return state.open ? /*#__PURE__*/React.createElement(portal.Portal, {
2854
+ if (!state.open) return null;
2855
+ return /*#__PURE__*/React.createElement(portal.Portal, {
2760
2856
  preserveTabOrder: true
2761
2857
  }, /*#__PURE__*/React.createElement(Ariakit.Menu, _objectSpread2(_objectSpread2({}, props), {}, {
2762
2858
  state: state,
2763
2859
  ref: ref,
2764
- className: classNames('reactist_menulist', exceptionallySetClassName),
2860
+ className: classNames(modules_2befbba6.menuList, exceptionallySetClassName),
2765
2861
  modal: modal
2766
- }))) : null;
2862
+ })));
2767
2863
  });
2768
2864
  /**
2769
- * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`
2770
- * callback.
2865
+ * Mostly equivalent to the `MenuList`, but to be used inside a `SubMenu`.
2771
2866
  */
2772
2867
 
2773
- const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref) {
2868
+ const SubMenuList = /*#__PURE__*/polymorphicComponent(function SubMenuList(_ref6, ref) {
2774
2869
  let {
2775
- value,
2776
- children,
2777
- onSelect,
2778
- hideOnSelect = true,
2779
- onClick,
2780
2870
  exceptionallySetClassName,
2781
- as = 'button'
2782
- } = _ref5,
2783
- props = _objectWithoutProperties(_ref5, _excluded5$1);
2871
+ modal = true
2872
+ } = _ref6,
2873
+ props = _objectWithoutProperties(_ref6, _excluded6);
2784
2874
 
2875
+ const {
2876
+ state
2877
+ } = React.useContext(MenuContext);
2878
+ if (!state.open) return null;
2879
+ return /*#__PURE__*/React.createElement(portal.Portal, {
2880
+ preserveTabOrder: true
2881
+ }, /*#__PURE__*/React.createElement(Ariakit.Menu, _objectSpread2(_objectSpread2({}, props), {}, {
2882
+ state: state,
2883
+ ref: ref,
2884
+ className: classNames(modules_2befbba6.menuList, modules_2befbba6.subMenuList, exceptionallySetClassName),
2885
+ modal: modal
2886
+ })));
2887
+ }); //
2888
+ // MenuItem
2889
+ //
2890
+
2891
+ function useMenuItemClickHandler({
2892
+ value,
2893
+ hideOnSelect,
2894
+ onClick,
2895
+ onSelect
2896
+ }) {
2785
2897
  const {
2786
2898
  handleItemSelect,
2787
2899
  state
@@ -2789,42 +2901,95 @@ const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref5, ref)
2789
2901
  const {
2790
2902
  hide
2791
2903
  } = state;
2792
- const handleClick = React.useCallback(function handleClick(event) {
2904
+ return React.useCallback(function handleClick(event) {
2793
2905
  onClick == null ? void 0 : onClick(event);
2794
2906
  const onSelectResult = onSelect && !event.defaultPrevented ? onSelect() : undefined;
2795
2907
  const shouldClose = onSelectResult !== false && hideOnSelect;
2796
2908
  handleItemSelect(value);
2797
2909
  if (shouldClose) hide();
2798
2910
  }, [onSelect, onClick, handleItemSelect, hideOnSelect, hide, value]);
2799
- return /*#__PURE__*/React.createElement(Ariakit.MenuItem, _objectSpread2(_objectSpread2({}, props), {}, {
2911
+ }
2912
+ /**
2913
+ * A menu item inside a menu list. It can be selected by the user, triggering the `onSelect`
2914
+ * callback.
2915
+ */
2916
+
2917
+
2918
+ const MenuItem = /*#__PURE__*/polymorphicComponent(function MenuItem(_ref7, ref) {
2919
+ let {
2920
+ value,
2921
+ label,
2922
+ description,
2923
+ icon,
2924
+ shortcut,
2925
+ tone,
2926
+ children,
2927
+ onSelect,
2928
+ hideOnSelect = true,
2929
+ onClick,
2930
+ exceptionallySetClassName,
2931
+ as = 'button'
2932
+ } = _ref7,
2933
+ props = _objectWithoutProperties(_ref7, _excluded7);
2934
+
2935
+ const id = useId(props.id);
2936
+ const {
2937
+ state
2938
+ } = React.useContext(MenuContext);
2939
+ const handleClick = useMenuItemClickHandler({
2940
+ value,
2941
+ onSelect,
2942
+ onClick,
2943
+ hideOnSelect
2944
+ });
2945
+ return /*#__PURE__*/React.createElement(Ariakit.MenuItem, _objectSpread2(_objectSpread2({
2946
+ "aria-labelledby": label && !props['aria-label'] ? id + "-label" : undefined,
2947
+ "aria-describedby": label && description ? id + "-description" : undefined
2948
+ }, props), {}, {
2800
2949
  as: as,
2801
2950
  state: state,
2802
2951
  ref: ref,
2803
2952
  onClick: handleClick,
2804
- className: exceptionallySetClassName,
2953
+ className: classNames(modules_2befbba6.menuItem, tone === 'destructive' ? modules_2befbba6.destructive : null, exceptionallySetClassName),
2805
2954
  hideOnClick: false
2806
- }), children);
2955
+ }), children ? /*#__PURE__*/React.createElement(Box, {
2956
+ width: "full",
2957
+ className: label ? undefined : modules_2befbba6.legacyLayout
2958
+ }, children) : null, /*#__PURE__*/React.createElement(MenuItemContent, {
2959
+ id: id,
2960
+ icon: icon,
2961
+ label: label,
2962
+ description: description,
2963
+ shortcut: shortcut
2964
+ }));
2807
2965
  });
2808
2966
  /**
2809
- * This component can be rendered alongside other `MenuItem` inside a `MenuList` in order to have
2810
- * a sub-menu.
2967
+ * This component can be rendered alongside other `MenuItem` elements inside a `MenuList` to show a
2968
+ * sub-menu.
2969
+ *
2970
+ * Its children are expected to be exactly two elements, in the following order:
2971
+ *
2972
+ * 1. A `SubMenuItem` element: the menu item that triggers the sub-menu to open.
2973
+ * 2. A `SubMenuList` element: the list of menu items that will be shown when the sub-menu is open.
2811
2974
  *
2812
- * Its children are expected to have the structure of a first level menu (a `MenuButton` and a
2813
- * `MenuList`).
2975
+ * ## Usage
2814
2976
  *
2815
2977
  * ```jsx
2816
- * <MenuItem label="Edit profile" />
2817
- * <SubMenu>
2818
- * <MenuButton>More options</MenuButton>
2978
+ * <Menu>
2979
+ * <MenuButton>Menu</MenuButton>
2819
2980
  * <MenuList>
2820
- * <MenuItem label="Preferences" />
2821
- * <MenuItem label="Sign out" />
2981
+ * <MenuItem label="Item 1" />
2982
+ * <MenuItem label="Item 2" />
2983
+ * <SubMenu>
2984
+ * <SubMenuItem label="Submenu" />
2985
+ * <SubMenuList>
2986
+ * <MenuItem label="Submenu Item 1" />
2987
+ * <MenuItem label="Submenu Item 2" />
2988
+ * </SubMenuList>
2989
+ * </SubMenu>
2822
2990
  * </MenuList>
2823
- * </SubMenu>
2991
+ * </Menu>
2824
2992
  * ```
2825
- *
2826
- * The `MenuButton` will become a menu item in the current menu items list, and it will lead to
2827
- * opening a sub-menu with the menu items list below it.
2828
2993
  */
2829
2994
 
2830
2995
  const SubMenu = /*#__PURE__*/React.forwardRef(function SubMenu({
@@ -2856,7 +3021,9 @@ const SubMenu = /*#__PURE__*/React.forwardRef(function SubMenu({
2856
3021
  state: state,
2857
3022
  ref: ref,
2858
3023
  hideOnClick: false
2859
- }, renderMenuButton), list);
3024
+ }, renderMenuButton), /*#__PURE__*/React.createElement("div", {
3025
+ className: modules_2befbba6.subMenuContainer
3026
+ }, list));
2860
3027
  });
2861
3028
  /**
2862
3029
  * A way to semantically group some menu items.
@@ -2865,25 +3032,100 @@ const SubMenu = /*#__PURE__*/React.forwardRef(function SubMenu({
2865
3032
  * before and/or after the group if you so wish.
2866
3033
  */
2867
3034
 
2868
- const MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroup(_ref6, ref) {
3035
+ const MenuGroup = /*#__PURE__*/polymorphicComponent(function MenuGroup(_ref8, ref) {
2869
3036
  let {
2870
3037
  label,
3038
+ info,
2871
3039
  children,
2872
3040
  exceptionallySetClassName
2873
- } = _ref6,
2874
- props = _objectWithoutProperties(_ref6, _excluded6);
3041
+ } = _ref8,
3042
+ props = _objectWithoutProperties(_ref8, _excluded8);
2875
3043
 
3044
+ const id = useId(props.id);
2876
3045
  const {
2877
3046
  state
2878
3047
  } = React.useContext(MenuContext);
2879
- return /*#__PURE__*/React.createElement(Ariakit.MenuGroup, _objectSpread2(_objectSpread2({}, props), {}, {
3048
+ return /*#__PURE__*/React.createElement(Ariakit.MenuGroup, _objectSpread2(_objectSpread2({
3049
+ "aria-labelledby": "menugroup-label-" + id
3050
+ }, props), {}, {
3051
+ id: id,
2880
3052
  ref: ref,
2881
3053
  state: state,
2882
3054
  className: exceptionallySetClassName
2883
- }), label ? /*#__PURE__*/React.createElement("div", {
2884
- role: "presentation",
2885
- className: "reactist_menugroup__label"
2886
- }, label) : null, children);
3055
+ }), /*#__PURE__*/React.createElement(Box, {
3056
+ display: "flex",
3057
+ alignItems: "center",
3058
+ gap: "small",
3059
+ className: modules_2befbba6.menuGroupLabel
3060
+ }, /*#__PURE__*/React.createElement(Text, {
3061
+ id: "menugroup-label-" + id,
3062
+ size: "copy",
3063
+ weight: "semibold"
3064
+ }, label), info ? /*#__PURE__*/React.createElement(Box, {
3065
+ flexShrink: 0,
3066
+ display: "flex",
3067
+ alignItems: "center",
3068
+ justifyContent: "center",
3069
+ className: modules_2befbba6.menuGroupInfo
3070
+ }, info) : null), children);
3071
+ });
3072
+ /**
3073
+ * A menu item that visually only shows as an icon. It must be used inside an `IconsMenuGroup`.
3074
+ */
3075
+
3076
+ const IconMenuItem = /*#__PURE__*/polymorphicComponent(function IconMenuItem(_ref9, ref) {
3077
+ let {
3078
+ value,
3079
+ label,
3080
+ description,
3081
+ icon,
3082
+ onSelect,
3083
+ hideOnSelect = true,
3084
+ onClick,
3085
+ exceptionallySetClassName,
3086
+ as = 'button'
3087
+ } = _ref9,
3088
+ props = _objectWithoutProperties(_ref9, _excluded9);
3089
+
3090
+ const id = useId(props.id);
3091
+ const {
3092
+ state
3093
+ } = React.useContext(MenuContext);
3094
+ const handleClick = useMenuItemClickHandler({
3095
+ value,
3096
+ onSelect,
3097
+ onClick,
3098
+ hideOnSelect
3099
+ });
3100
+ return /*#__PURE__*/React.createElement(Tooltip, {
3101
+ content: label
3102
+ }, /*#__PURE__*/React.createElement(Ariakit.MenuItem, _objectSpread2(_objectSpread2({
3103
+ "aria-label": label,
3104
+ "aria-describedby": id + "-description"
3105
+ }, props), {}, {
3106
+ as: as,
3107
+ state: state,
3108
+ ref: ref,
3109
+ onClick: handleClick,
3110
+ className: classNames(modules_2befbba6.iconMenuItem, exceptionallySetClassName),
3111
+ hideOnClick: false
3112
+ }), icon));
3113
+ });
3114
+ /**
3115
+ * Semantically equivalent to `MenuGroup`, but meant to group `IconMenuItem`s only.
3116
+ */
3117
+
3118
+ const IconsMenuGroup = /*#__PURE__*/polymorphicComponent(function IconsMenuGroup(_ref10, ref) {
3119
+ let {
3120
+ children
3121
+ } = _ref10,
3122
+ props = _objectWithoutProperties(_ref10, _excluded10);
3123
+
3124
+ return /*#__PURE__*/React.createElement(MenuGroup, _objectSpread2(_objectSpread2({}, props), {}, {
3125
+ ref: ref
3126
+ }), /*#__PURE__*/React.createElement("div", {
3127
+ className: modules_2befbba6.iconsMenuGroup
3128
+ }, children));
2887
3129
  });
2888
3130
 
2889
3131
  const _excluded$u = ["type", "variant", "size", "loading", "disabled", "tooltip", "onClick", "children"];
@@ -3970,6 +4212,8 @@ exports.Divider = Divider;
3970
4212
  exports.Heading = Heading;
3971
4213
  exports.Hidden = Hidden;
3972
4214
  exports.HiddenVisually = HiddenVisually;
4215
+ exports.IconMenuItem = IconMenuItem;
4216
+ exports.IconsMenuGroup = IconsMenuGroup;
3973
4217
  exports.Inline = Inline;
3974
4218
  exports.KeyCapturer = KeyCapturer;
3975
4219
  exports.KeyboardShortcut = KeyboardShortcut;
@@ -3994,6 +4238,8 @@ exports.SelectField = SelectField;
3994
4238
  exports.Stack = Stack;
3995
4239
  exports.StaticToast = StaticToast;
3996
4240
  exports.SubMenu = SubMenu;
4241
+ exports.SubMenuItem = SubMenuItem;
4242
+ exports.SubMenuList = SubMenuList;
3997
4243
  exports.SwitchField = SwitchField;
3998
4244
  exports.Tab = Tab;
3999
4245
  exports.TabAwareSlot = TabAwareSlot;