@trackunit/react-components 0.0.191 → 0.0.193

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';
@@ -350,7 +350,7 @@ const Icon$1 = ({
350
350
  className: iconSizeClassName
351
351
  })
352
352
  }, {
353
- children: jsx(Root$5, Object.assign({
353
+ children: jsx(Root$6, Object.assign({
354
354
  "$color": color,
355
355
  onClick: onClick,
356
356
  "data-testid": dataTestId,
@@ -369,7 +369,7 @@ const Icon$1 = ({
369
369
  const LoadingDot = tw.span`
370
370
  tu-loading-dot
371
371
  `;
372
- const Root$5 = tw.span`
372
+ const Root$6 = tw.span`
373
373
  tu-icon
374
374
  ${({
375
375
  $color
@@ -1451,7 +1451,7 @@ const Label$2 = ({
1451
1451
  disabled,
1452
1452
  isInvalid
1453
1453
  }) => {
1454
- return jsx(Root$4, Object.assign({
1454
+ return jsx(Root$5, Object.assign({
1455
1455
  id: id || "",
1456
1456
  htmlFor: htmlFor || "",
1457
1457
  className: className,
@@ -1462,7 +1462,7 @@ const Label$2 = ({
1462
1462
  children: children
1463
1463
  }));
1464
1464
  };
1465
- const Root$4 = tw.label`
1465
+ const Root$5 = tw.label`
1466
1466
  tu-label
1467
1467
  ${({
1468
1468
  $disabled
@@ -2568,7 +2568,7 @@ const LegendItem = ({
2568
2568
  dataTestId
2569
2569
  }) => {
2570
2570
  const handleOnClick = onClick && !disabled ? () => onClick() : undefined;
2571
- return jsxs(Root$3, Object.assign({
2571
+ return jsxs(Root$4, Object.assign({
2572
2572
  "data-testid": dataTestId,
2573
2573
  "$disabled": disabled,
2574
2574
  className: className,
@@ -2585,7 +2585,7 @@ const LegendItem = ({
2585
2585
  })]
2586
2586
  }));
2587
2587
  };
2588
- const Root$3 = tw.div`
2588
+ const Root$4 = tw.div`
2589
2589
  inline-flex
2590
2590
  items-center
2591
2591
  transition-all
@@ -2695,46 +2695,92 @@ const MenuList = _a => {
2695
2695
  var {
2696
2696
  dataTestId,
2697
2697
  className,
2698
- menuItems,
2699
- width,
2700
- itemRenderer
2701
- } = _a,
2702
- args = __rest(_a, ["dataTestId", "className", "menuItems", "width", "itemRenderer"]);
2698
+ children,
2699
+ showDivider = false
2700
+ } = _a;
2701
+ __rest(_a, ["dataTestId", "className", "children", "showDivider"]);
2703
2702
 
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
- })
2703
+ const childrenArr = Children.toArray(children);
2704
+
2705
+ const isLastItem = index => index === childrenArr.length - 1;
2706
+
2707
+ return jsx(Container$2, Object.assign({
2708
+ "data-testid": dataTestId,
2709
+ className: className,
2710
+ tabIndex: 0
2711
+ }, {
2712
+ children: Children.map(childrenArr, (menuItem, index) => jsxs(Fragment, {
2713
+ children: [menuItem, showDivider && !isLastItem(index) && jsx(Divider, {})]
2725
2714
  }))
2726
- });
2715
+ }));
2727
2716
  };
2728
- const Wrapper = tw.div`
2729
- tu-menu-list__wrapper
2730
- `;
2731
2717
  const Container$2 = tw.div`
2732
2718
  tu-menu-list
2733
2719
  `;
2734
- const Divider = tw.div`
2720
+ const Divider = tw.hr`
2735
2721
  tu-menu-list__divider
2736
2722
  `;
2737
2723
 
2724
+ var DotsDirection;
2725
+
2726
+ (function (DotsDirection) {
2727
+ DotsDirection[DotsDirection["horizontal"] = 0] = "horizontal";
2728
+ DotsDirection[DotsDirection["vertical"] = 1] = "vertical";
2729
+ })(DotsDirection || (DotsDirection = {}));
2730
+
2731
+ var MenuPlacement;
2732
+
2733
+ (function (MenuPlacement) {
2734
+ MenuPlacement[MenuPlacement["above"] = 0] = "above";
2735
+ MenuPlacement[MenuPlacement["below"] = 1] = "below";
2736
+ })(MenuPlacement || (MenuPlacement = {}));
2737
+ /**
2738
+ * A kebab menu component.
2739
+ * Advice: fill it with MenuList
2740
+ *
2741
+ * @param {MoreMenuProps} props - The props for the MoreMenu component
2742
+ * @returns {JSX.Element} MoreMenu component
2743
+ */
2744
+
2745
+
2746
+ const MoreMenu = ({
2747
+ className,
2748
+ dataTestId,
2749
+ dotsDirection = DotsDirection.horizontal,
2750
+ menuPlacement = MenuPlacement.below,
2751
+ iconProps = {
2752
+ size: "medium"
2753
+ },
2754
+ iconButtonProps = {
2755
+ size: "small",
2756
+ circular: true,
2757
+ color: "tertiary"
2758
+ },
2759
+ children
2760
+ }) => {
2761
+ const [actionMenuIsOpen, setActionMenuIsOpen] = useState(false);
2762
+ const dotsName = dotsDirection === DotsDirection.horizontal ? "DotsHorizontalIcon" : "DotsVerticalIcon";
2763
+ return jsxs(Root$3, Object.assign({
2764
+ className: className,
2765
+ "data-testid": dataTestId
2766
+ }, {
2767
+ children: [actionMenuIsOpen && menuPlacement === MenuPlacement.above && children, jsx(IconButton, Object.assign({}, iconButtonProps, {
2768
+ icon: jsx(Icon$1, Object.assign({
2769
+ name: dotsName
2770
+ }, iconProps)),
2771
+ onClick: () => {
2772
+ setActionMenuIsOpen(!actionMenuIsOpen);
2773
+ }
2774
+ })), actionMenuIsOpen && menuPlacement === MenuPlacement.below && children]
2775
+ }));
2776
+ };
2777
+ const Root$3 = tw.div`
2778
+ tu-more-menu
2779
+ ${({
2780
+ variant
2781
+ }) => variant === "primary" ? tws`tu-more-menu--primary` : ""}
2782
+ `;
2783
+
2738
2784
  /**
2739
2785
  * The Backdrop for the modal.
2740
2786
  *
@@ -5434,4 +5480,4 @@ const Layout = tw.div`
5434
5480
  tu-layout-TwoColumnLayout
5435
5481
  `;
5436
5482
 
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 };
5483
+ 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.191",
3
+ "version": "0.0.193",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {