@trackunit/react-components 0.1.365 → 0.1.367

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/index.cjs.js CHANGED
@@ -4532,6 +4532,44 @@ const WidgetBody = ({ density = "auto", children, dataTestId, className, disable
4532
4532
  return (jsxRuntime.jsx("div", { className: cvaWidgetBodyDensityContainer({ density, disableGap, className }), "data-testid": dataTestId, children: children }));
4533
4533
  };
4534
4534
 
4535
+ const cvaToggleGroup = cssClassVarianceUtilities.cvaMerge(["inline-flex", "divide-x", "divide-slate-300"]);
4536
+ const cvaToggleItem = cssClassVarianceUtilities.cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0"], {
4537
+ variants: {
4538
+ selected: {
4539
+ true: ["bg-slate-300", "hover:bg-slate-300", "text-slate-700"],
4540
+ false: [],
4541
+ },
4542
+ },
4543
+ });
4544
+ const cvaToggleItemText = cssClassVarianceUtilities.cvaMerge(["text-ellipsis", "truncate", "flex-grow"], {
4545
+ variants: {
4546
+ disabledAndSelected: {
4547
+ true: ["text-slate-800"],
4548
+ false: [],
4549
+ },
4550
+ maxWidth: {
4551
+ sm: ["max-w-[80px]"],
4552
+ md: ["max-w-[120px]"],
4553
+ },
4554
+ },
4555
+ });
4556
+
4557
+ /**
4558
+ * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
4559
+ *
4560
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4561
+ * @returns {JSX.Element} ToggleGroup component
4562
+ */
4563
+ const ToggleGroup = ({ list, selected, setSelected, onClick, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4564
+ return (jsxRuntime.jsx("div", { className: cvaToggleGroup(), "data-testid": dataTestId, children: list.map((item, index) => (jsxRuntime.jsx(ToggleItem, { className: tailwindMerge.twMerge(className, index === 0 ? ["rounded-l-md", "border-l"] : "", index === list.length - 1 ? ["rounded-r-md", "border-r"] : ""), dataTestId: item.dataTestId, disabled: disabled, iconName: item.iconName, isIconOnly: isIconOnly, onClick: () => {
4565
+ onClick && onClick();
4566
+ setSelected(item.id);
4567
+ }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4568
+ };
4569
+ const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
4570
+ return isIconOnly ? (jsxRuntime.jsx(Tooltip, { label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsxRuntime.jsx(IconButton, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, icon: iconName ? jsxRuntime.jsx(Icon, { name: iconName, size: "small" }) : null, onClick: onClick, size: size, title: iconName, variant: "secondary" }) })) : (jsxRuntime.jsx(Tooltip, { disabled: !(text === null || text === void 0 ? void 0 : text.truncate) && (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) === undefined, label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsxRuntime.jsx(Button, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, onClick: onClick, prefix: iconName ? jsxRuntime.jsx(Icon, { name: iconName, size: "small" }) : null, size: size, variant: "secondary", children: jsxRuntime.jsx("span", { className: cvaToggleItemText({ disabledAndSelected: disabled && selected, maxWidth: text === null || text === void 0 ? void 0 : text.maxWidth }), children: title }) }) }));
4571
+ };
4572
+
4535
4573
  const cvaClickable = cssClassVarianceUtilities.cvaMerge([
4536
4574
  "shadow-lg",
4537
4575
  "rounded-lg",
@@ -4607,6 +4645,7 @@ exports.Tag = Tag;
4607
4645
  exports.Text = Text;
4608
4646
  exports.Timeline = Timeline;
4609
4647
  exports.TimelineElement = TimelineElement;
4648
+ exports.ToggleGroup = ToggleGroup;
4610
4649
  exports.Tooltip = Tooltip;
4611
4650
  exports.ValueBar = ValueBar;
4612
4651
  exports.VirtualizedList = VirtualizedList;
package/index.esm.js CHANGED
@@ -4501,6 +4501,44 @@ const WidgetBody = ({ density = "auto", children, dataTestId, className, disable
4501
4501
  return (jsx("div", { className: cvaWidgetBodyDensityContainer({ density, disableGap, className }), "data-testid": dataTestId, children: children }));
4502
4502
  };
4503
4503
 
4504
+ const cvaToggleGroup = cvaMerge(["inline-flex", "divide-x", "divide-slate-300"]);
4505
+ const cvaToggleItem = cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0"], {
4506
+ variants: {
4507
+ selected: {
4508
+ true: ["bg-slate-300", "hover:bg-slate-300", "text-slate-700"],
4509
+ false: [],
4510
+ },
4511
+ },
4512
+ });
4513
+ const cvaToggleItemText = cvaMerge(["text-ellipsis", "truncate", "flex-grow"], {
4514
+ variants: {
4515
+ disabledAndSelected: {
4516
+ true: ["text-slate-800"],
4517
+ false: [],
4518
+ },
4519
+ maxWidth: {
4520
+ sm: ["max-w-[80px]"],
4521
+ md: ["max-w-[120px]"],
4522
+ },
4523
+ },
4524
+ });
4525
+
4526
+ /**
4527
+ * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
4528
+ *
4529
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4530
+ * @returns {JSX.Element} ToggleGroup component
4531
+ */
4532
+ const ToggleGroup = ({ list, selected, setSelected, onClick, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4533
+ return (jsx("div", { className: cvaToggleGroup(), "data-testid": dataTestId, children: list.map((item, index) => (jsx(ToggleItem, { className: twMerge(className, index === 0 ? ["rounded-l-md", "border-l"] : "", index === list.length - 1 ? ["rounded-r-md", "border-r"] : ""), dataTestId: item.dataTestId, disabled: disabled, iconName: item.iconName, isIconOnly: isIconOnly, onClick: () => {
4534
+ onClick && onClick();
4535
+ setSelected(item.id);
4536
+ }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4537
+ };
4538
+ const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
4539
+ return isIconOnly ? (jsx(Tooltip, { label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsx(IconButton, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, icon: iconName ? jsx(Icon, { name: iconName, size: "small" }) : null, onClick: onClick, size: size, title: iconName, variant: "secondary" }) })) : (jsx(Tooltip, { disabled: !(text === null || text === void 0 ? void 0 : text.truncate) && (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) === undefined, label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsx(Button, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, onClick: onClick, prefix: iconName ? jsx(Icon, { name: iconName, size: "small" }) : null, size: size, variant: "secondary", children: jsx("span", { className: cvaToggleItemText({ disabledAndSelected: disabled && selected, maxWidth: text === null || text === void 0 ? void 0 : text.maxWidth }), children: title }) }) }));
4540
+ };
4541
+
4504
4542
  const cvaClickable = cvaMerge([
4505
4543
  "shadow-lg",
4506
4544
  "rounded-lg",
@@ -4525,4 +4563,4 @@ const cvaClickable = cvaMerge([
4525
4563
  },
4526
4564
  });
4527
4565
 
4528
- export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange, useWindowActivity };
4566
+ export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange, useWindowActivity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.365",
3
+ "version": "0.1.367",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,72 @@
1
+ /// <reference types="react" />
2
+ import { VariantProps } from "@trackunit/css-class-variance-utilities";
3
+ import { IconName } from "@trackunit/ui-icons";
4
+ import { CommonProps } from "../../common/CommonProps";
5
+ import { TooltipPlacement } from "../Tooltip/Tooltip";
6
+ import { cvaToggleGroup } from "./ToggleGroup.variants";
7
+ export interface BasicToggleGroupListProps {
8
+ /**
9
+ * Used to identify an individual button to be able to highlight the selected one.
10
+ */
11
+ id: string;
12
+ /**
13
+ * Tooltip's fallback and button's text content.
14
+ */
15
+ title: string;
16
+ /**
17
+ * Pass the name of an icon to include one for each of the buttons.
18
+ */
19
+ iconName?: IconName;
20
+ /**
21
+ * Due to size of the text, one might need to truncate a button's content or another.
22
+ * This behaviour is individual for each button.
23
+ * For a button that utilises this feature, the full text can be read on hover.
24
+ * Truncation should be avoided if possible.
25
+ */
26
+ text?: {
27
+ truncate: boolean;
28
+ maxWidth: "sm" | "md";
29
+ };
30
+ /**
31
+ * A tooltip's position can be modified for extreme cases where it's default state breaks the UI.
32
+ * Defaults to top.
33
+ * Use content for the cases where the title doesn't use the same exact text.
34
+ */
35
+ tooltip?: {
36
+ content?: string;
37
+ placement?: TooltipPlacement;
38
+ };
39
+ dataTestId?: string;
40
+ }
41
+ export interface ToggleGroupProps extends CommonProps, Omit<VariantProps<typeof cvaToggleGroup>, "className"> {
42
+ list: BasicToggleGroupListProps[];
43
+ selected: string;
44
+ setSelected: React.Dispatch<React.SetStateAction<string>>;
45
+ /**
46
+ * For when the click event needs to do more than select an id
47
+ */
48
+ onClick?: () => void;
49
+ disabled?: boolean;
50
+ /**
51
+ * ToggleGroup buttons can be one of two sizes
52
+ */
53
+ size?: "small" | "medium";
54
+ /**
55
+ * Enable to use toggle buttons with icons only and a tooltip on hover
56
+ */
57
+ isIconOnly?: boolean;
58
+ }
59
+ /**
60
+ * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
61
+ *
62
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
63
+ * @returns {JSX.Element} ToggleGroup component
64
+ */
65
+ export declare const ToggleGroup: ({ list, selected, setSelected, onClick, disabled, size, isIconOnly, className, dataTestId, }: ToggleGroupProps) => JSX.Element;
66
+ export interface ToggleItemProps extends CommonProps, Omit<BasicToggleGroupListProps, "id"> {
67
+ onClick: () => void;
68
+ disabled: boolean;
69
+ isIconOnly: boolean;
70
+ size: "small" | "medium";
71
+ selected: boolean;
72
+ }
@@ -0,0 +1,8 @@
1
+ export declare const cvaToggleGroup: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
+ export declare const cvaToggleItem: (props?: ({
3
+ selected?: boolean | null | undefined;
4
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
5
+ export declare const cvaToggleItemText: (props?: ({
6
+ disabledAndSelected?: boolean | null | undefined;
7
+ maxWidth?: "sm" | "md" | null | undefined;
8
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -39,3 +39,4 @@ export * from "./ValueBar";
39
39
  export * from "./VirtualizedList/VirtualizedList";
40
40
  export * from "./Widget";
41
41
  export * from "./buttons";
42
+ export * from "./ToggleGroup/ToggleGroup";