@trackunit/react-components 0.0.192 → 0.0.194

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.
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CommonProps } from "../../common/CommonProps";
2
+ import { CommonProps } from "../../../common";
3
3
  export interface MenuItemProps extends CommonProps {
4
4
  /**
5
5
  * The icon to be rendered in the menu item.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { MenuItemProps } from "./MenuItem";
2
+ import { MenuItemProps } from "../MenuItem/MenuItem";
3
3
  export interface MenuListItemProps extends MenuItemProps {
4
4
  showDivider?: boolean;
5
5
  }
@@ -15,15 +15,11 @@ export interface MenuListProps {
15
15
  /**
16
16
  * List of menu items to be rendered.
17
17
  */
18
- menuItems: MenuListItemProps[];
18
+ children: JSX.Element[] | JSX.Element;
19
19
  /**
20
- * A component width
21
- */
22
- width?: string;
23
- /**
24
- * Custom renderer for menu items
20
+ * List of menu items to be rendered.
25
21
  */
26
- itemRenderer?: (item: MenuListItemProps, key: string, index: number) => JSX.Element;
22
+ showDivider?: boolean;
27
23
  }
28
24
  /**
29
25
  * The MenuList component is used for menus and selects.
@@ -31,4 +27,4 @@ export interface MenuListProps {
31
27
  * @param {MenuListProps} props - The props for the MenuList component
32
28
  * @returns {JSX.Element} MenuList component
33
29
  */
34
- export declare const MenuList: ({ dataTestId, className, menuItems, width, itemRenderer, ...args }: MenuListProps) => JSX.Element;
30
+ export declare const MenuList: ({ dataTestId, className, children, showDivider, ...args }: MenuListProps) => JSX.Element;
@@ -0,0 +1,30 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps } from "../../../common/CommonProps";
3
+ import { IconButtonProps } from "../../buttons";
4
+ import { IconProps } from "../../Icon/Icon";
5
+ export declare enum DotsDirection {
6
+ horizontal = 0,
7
+ vertical = 1
8
+ }
9
+ export declare enum MenuPlacement {
10
+ above = 0,
11
+ below = 1
12
+ }
13
+ declare type FilteredIconProps = Omit<IconProps, "name">;
14
+ declare type FilteredIconButtonProps = Omit<IconButtonProps, "icon" | "onClick">;
15
+ export interface MoreMenuProps extends CommonProps {
16
+ children: JSX.Element;
17
+ dotsDirection?: DotsDirection;
18
+ menuPlacement?: MenuPlacement;
19
+ iconProps?: FilteredIconProps;
20
+ iconButtonProps?: FilteredIconButtonProps;
21
+ }
22
+ /**
23
+ * A kebab menu component.
24
+ * Advice: fill it with MenuList
25
+ *
26
+ * @param {MoreMenuProps} props - The props for the MoreMenu component
27
+ * @returns {JSX.Element} MoreMenu component
28
+ */
29
+ export declare const MoreMenu: ({ className, dataTestId, dotsDirection, menuPlacement, iconProps, iconButtonProps, children, }: MoreMenuProps) => JSX.Element;
30
+ export {};
@@ -1,2 +1,3 @@
1
- export * from "./MenuItem";
2
- export * from "./MenuList";
1
+ export * from "./MenuItem/MenuItem";
2
+ export * from "./MenuList/MenuList";
3
+ export * from "./MoreMenu/MoreMenu";
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { tw, tws, twx } from '@trackunit/tailwind-styled-components';
3
3
  import * as React from 'react';
4
- import React__default, { useState, forwardRef, useMemo, cloneElement, useCallback, createElement, useRef, memo, useEffect, useContext } from 'react';
4
+ import React__default, { useState, forwardRef, useMemo, cloneElement, useCallback, Children, useRef, memo, useEffect, useContext } from 'react';
5
5
  import { HeroIconsArray, heroIconLookup, TrackunitSolidIconsArray, TrackunitOutlineIconsArray, trackunitIconLookup } from '@trackunit/ui-icons';
6
6
  import EChart from 'echarts-for-react';
7
7
  import { v4 } from 'uuid';
@@ -11,6 +11,7 @@ import { useFloating, offset, shift, flip, autoUpdate, useInteractions, useClick
11
11
  import { Link, UNSAFE_NavigationContext } from 'react-router-dom';
12
12
  import { DayPicker as DayPicker$1 } from 'react-day-picker';
13
13
  import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
14
+ import { useClickOutside } from 'react-browser-hooks';
14
15
  import usePortal from 'react-useportal';
15
16
  import { Helmet } from 'react-helmet';
16
17
  import ReactSelect, { components } from 'react-select';
@@ -350,7 +351,7 @@ const Icon$1 = ({
350
351
  className: iconSizeClassName
351
352
  })
352
353
  }, {
353
- children: jsx(Root$5, Object.assign({
354
+ children: jsx(Root$6, Object.assign({
354
355
  "$color": color,
355
356
  onClick: onClick,
356
357
  "data-testid": dataTestId,
@@ -369,7 +370,7 @@ const Icon$1 = ({
369
370
  const LoadingDot = tw.span`
370
371
  tu-loading-dot
371
372
  `;
372
- const Root$5 = tw.span`
373
+ const Root$6 = tw.span`
373
374
  tu-icon
374
375
  ${({
375
376
  $color
@@ -1451,7 +1452,7 @@ const Label$2 = ({
1451
1452
  disabled,
1452
1453
  isInvalid
1453
1454
  }) => {
1454
- return jsx(Root$4, Object.assign({
1455
+ return jsx(Root$5, Object.assign({
1455
1456
  id: id || "",
1456
1457
  htmlFor: htmlFor || "",
1457
1458
  className: className,
@@ -1462,7 +1463,7 @@ const Label$2 = ({
1462
1463
  children: children
1463
1464
  }));
1464
1465
  };
1465
- const Root$4 = tw.label`
1466
+ const Root$5 = tw.label`
1466
1467
  tu-label
1467
1468
  ${({
1468
1469
  $disabled
@@ -2568,7 +2569,7 @@ const LegendItem = ({
2568
2569
  dataTestId
2569
2570
  }) => {
2570
2571
  const handleOnClick = onClick && !disabled ? () => onClick() : undefined;
2571
- return jsxs(Root$3, Object.assign({
2572
+ return jsxs(Root$4, Object.assign({
2572
2573
  "data-testid": dataTestId,
2573
2574
  "$disabled": disabled,
2574
2575
  className: className,
@@ -2585,7 +2586,7 @@ const LegendItem = ({
2585
2586
  })]
2586
2587
  }));
2587
2588
  };
2588
- const Root$3 = tw.div`
2589
+ const Root$4 = tw.div`
2589
2590
  inline-flex
2590
2591
  items-center
2591
2592
  transition-all
@@ -2695,46 +2696,97 @@ const MenuList = _a => {
2695
2696
  var {
2696
2697
  dataTestId,
2697
2698
  className,
2698
- menuItems,
2699
- width,
2700
- itemRenderer
2701
- } = _a,
2702
- args = __rest(_a, ["dataTestId", "className", "menuItems", "width", "itemRenderer"]);
2699
+ children,
2700
+ showDivider = false
2701
+ } = _a;
2702
+ __rest(_a, ["dataTestId", "className", "children", "showDivider"]);
2703
2703
 
2704
- const containerProps = useContainerProps(Object.assign({
2705
- className,
2706
- dataTestId
2707
- }, args));
2708
- return jsx(Wrapper, {
2709
- children: jsx(Container$2, Object.assign({}, containerProps, {
2710
- style: width ? {
2711
- width
2712
- } : undefined,
2713
- tabIndex: 0
2714
- }, {
2715
- children: menuItems.map((props, index) => {
2716
- const key = `${index}-${props.label}`;
2717
- const item = itemRenderer ? itemRenderer(props, key, index) : createElement(MenuItem, Object.assign({}, props, {
2718
- key: key,
2719
- onClick: props.onClick
2720
- }));
2721
- return props.showDivider ? jsxs("div", {
2722
- children: [jsx(Divider, {}), " ", item]
2723
- }, key) : item;
2724
- })
2704
+ const childrenArr = Children.toArray(children);
2705
+
2706
+ const isLastItem = index => index === childrenArr.length - 1;
2707
+
2708
+ return jsx(Container$2, Object.assign({
2709
+ "data-testid": dataTestId,
2710
+ className: className,
2711
+ tabIndex: 0
2712
+ }, {
2713
+ children: Children.map(childrenArr, (menuItem, index) => jsxs(Fragment, {
2714
+ children: [menuItem, showDivider && !isLastItem(index) && jsx(Divider, {})]
2725
2715
  }))
2726
- });
2716
+ }));
2727
2717
  };
2728
- const Wrapper = tw.div`
2729
- tu-menu-list__wrapper
2730
- `;
2731
2718
  const Container$2 = tw.div`
2732
2719
  tu-menu-list
2733
2720
  `;
2734
- const Divider = tw.div`
2721
+ const Divider = tw.hr`
2735
2722
  tu-menu-list__divider
2736
2723
  `;
2737
2724
 
2725
+ var DotsDirection;
2726
+
2727
+ (function (DotsDirection) {
2728
+ DotsDirection[DotsDirection["horizontal"] = 0] = "horizontal";
2729
+ DotsDirection[DotsDirection["vertical"] = 1] = "vertical";
2730
+ })(DotsDirection || (DotsDirection = {}));
2731
+
2732
+ var MenuPlacement;
2733
+
2734
+ (function (MenuPlacement) {
2735
+ MenuPlacement[MenuPlacement["above"] = 0] = "above";
2736
+ MenuPlacement[MenuPlacement["below"] = 1] = "below";
2737
+ })(MenuPlacement || (MenuPlacement = {}));
2738
+ /**
2739
+ * A kebab menu component.
2740
+ * Advice: fill it with MenuList
2741
+ *
2742
+ * @param {MoreMenuProps} props - The props for the MoreMenu component
2743
+ * @returns {JSX.Element} MoreMenu component
2744
+ */
2745
+
2746
+
2747
+ const MoreMenu = ({
2748
+ className,
2749
+ dataTestId,
2750
+ dotsDirection = DotsDirection.horizontal,
2751
+ menuPlacement = MenuPlacement.below,
2752
+ iconProps = {
2753
+ size: "medium"
2754
+ },
2755
+ iconButtonProps = {
2756
+ size: "small",
2757
+ circular: true,
2758
+ color: "tertiary"
2759
+ },
2760
+ children
2761
+ }) => {
2762
+ const [actionMenuIsOpen, setActionMenuIsOpen] = useState(false);
2763
+ const dotsName = dotsDirection === DotsDirection.horizontal ? "DotsHorizontalIcon" : "DotsVerticalIcon";
2764
+ const actionMenuRef = useRef(null);
2765
+ useClickOutside(actionMenuRef, () => {
2766
+ setActionMenuIsOpen(false);
2767
+ });
2768
+ return jsxs(Root$3, Object.assign({
2769
+ ref: actionMenuRef,
2770
+ className: className,
2771
+ "data-testid": dataTestId
2772
+ }, {
2773
+ children: [actionMenuIsOpen && menuPlacement === MenuPlacement.above && children, jsx(IconButton, Object.assign({}, iconButtonProps, {
2774
+ icon: jsx(Icon$1, Object.assign({
2775
+ name: dotsName
2776
+ }, iconProps)),
2777
+ onClick: () => {
2778
+ setActionMenuIsOpen(!actionMenuIsOpen);
2779
+ }
2780
+ })), actionMenuIsOpen && menuPlacement === MenuPlacement.below && children]
2781
+ }));
2782
+ };
2783
+ const Root$3 = tw.div`
2784
+ tu-more-menu
2785
+ ${({
2786
+ variant
2787
+ }) => variant === "primary" ? tws`tu-more-menu--primary` : ""}
2788
+ `;
2789
+
2738
2790
  /**
2739
2791
  * The Backdrop for the modal.
2740
2792
  *
@@ -5434,4 +5486,4 @@ const Layout = tw.div`
5434
5486
  tu-layout-TwoColumnLayout
5435
5487
  `;
5436
5488
 
5437
- export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiSelectMenuItem, NumberField, NumberInput, PageHeader, Pagination, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, SectionHeader, Select, SelectPrefix, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePrompt, useTimeout };
5489
+ export { ActionButton, Alert, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, DotsDirection, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading$1 as Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuItem, MenuList, MenuPlacement, MinTopFullContentLayout, Modal, ModalBackdrop, MoreMenu, MultiSelectMenuItem, NumberField, NumberInput, PageHeader, Pagination, Popover, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, SectionHeader, Select, SelectPrefix, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, docs, getOrderedOptions, getValueBarColorByValue, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePrompt, useTimeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.0.192",
3
+ "version": "0.0.194",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -15,6 +15,7 @@
15
15
  "date-fns": "^2.29.3",
16
16
  "react-day-picker": "^8.3.0",
17
17
  "@trackunit/ui-icons": "0.0.53",
18
+ "react-browser-hooks": "^2.2.4",
18
19
  "react-useportal": "1.0.17",
19
20
  "@floating-ui/react-dom-interactions": "^0.10.1",
20
21
  "react-router-dom": "6.4.1",