@trackunit/react-components 0.3.5 → 0.3.7
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 +5 -5
- package/index.esm.js +5 -5
- package/package.json +1 -1
- package/src/common/AllOrNone.d.ts +12 -0
- package/src/common/index.d.ts +1 -0
- package/src/components/ToggleGroup/ToggleGroup.d.ts +16 -15
package/index.cjs.js
CHANGED
|
@@ -4096,7 +4096,7 @@ const MenuItem = ({ className, dataTestId, label, size, children, selected, pref
|
|
|
4096
4096
|
}, tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0, children: [prefix ? (jsxRuntime.jsx("div", { className: cvaMenuItemPrefix({ selected }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, children && typeof children !== "string" ? (children) : (jsxRuntime.jsx("div", { className: cvaMenuItemLabel(), "data-testid": dataTestId ? `${dataTestId}-label` : null, children: children !== null && children !== void 0 ? children : label })), suffix ? (jsxRuntime.jsx("div", { className: cvaMenuItemSuffix({ selected }), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null] }));
|
|
4097
4097
|
};
|
|
4098
4098
|
|
|
4099
|
-
const cvaMenuList = cssClassVarianceUtilities.cvaMerge(["shadow-md", "rounded-lg", "z-
|
|
4099
|
+
const cvaMenuList = cssClassVarianceUtilities.cvaMerge(["shadow-md", "rounded-lg", "z-popover", "bg-white", "border", "border-slate-300", "grid"], {
|
|
4100
4100
|
variants: {
|
|
4101
4101
|
stickyHeader: {
|
|
4102
4102
|
true: "grid-rows-min-fr grid overflow-y-hidden p-0",
|
|
@@ -4709,13 +4709,13 @@ const cvaToggleItemText = cssClassVarianceUtilities.cvaMerge(["text-ellipsis", "
|
|
|
4709
4709
|
/**
|
|
4710
4710
|
* Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
|
|
4711
4711
|
*
|
|
4712
|
-
* @param {ToggleGroupProps} props - The props for the
|
|
4713
|
-
* @returns {JSX.Element}
|
|
4712
|
+
* @param {ToggleGroupProps} props - The props for the ToggleGroup component
|
|
4713
|
+
* @returns {JSX.Element} ToggleGroup component
|
|
4714
4714
|
*/
|
|
4715
|
-
const ToggleGroup = ({ list, selected, setSelected,
|
|
4715
|
+
const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
|
|
4716
4716
|
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: () => {
|
|
4717
|
-
onClick && onClick();
|
|
4718
4717
|
setSelected(item.id);
|
|
4718
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
|
|
4719
4719
|
}, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
|
|
4720
4720
|
};
|
|
4721
4721
|
const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
|
package/index.esm.js
CHANGED
|
@@ -4076,7 +4076,7 @@ const MenuItem = ({ className, dataTestId, label, size, children, selected, pref
|
|
|
4076
4076
|
}, tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0, children: [prefix ? (jsx("div", { className: cvaMenuItemPrefix({ selected }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, children: prefix })) : null, children && typeof children !== "string" ? (children) : (jsx("div", { className: cvaMenuItemLabel(), "data-testid": dataTestId ? `${dataTestId}-label` : null, children: children !== null && children !== void 0 ? children : label })), suffix ? (jsx("div", { className: cvaMenuItemSuffix({ selected }), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null] }));
|
|
4077
4077
|
};
|
|
4078
4078
|
|
|
4079
|
-
const cvaMenuList = cvaMerge(["shadow-md", "rounded-lg", "z-
|
|
4079
|
+
const cvaMenuList = cvaMerge(["shadow-md", "rounded-lg", "z-popover", "bg-white", "border", "border-slate-300", "grid"], {
|
|
4080
4080
|
variants: {
|
|
4081
4081
|
stickyHeader: {
|
|
4082
4082
|
true: "grid-rows-min-fr grid overflow-y-hidden p-0",
|
|
@@ -4689,13 +4689,13 @@ const cvaToggleItemText = cvaMerge(["text-ellipsis", "truncate", "flex-grow"], {
|
|
|
4689
4689
|
/**
|
|
4690
4690
|
* Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
|
|
4691
4691
|
*
|
|
4692
|
-
* @param {ToggleGroupProps} props - The props for the
|
|
4693
|
-
* @returns {JSX.Element}
|
|
4692
|
+
* @param {ToggleGroupProps} props - The props for the ToggleGroup component
|
|
4693
|
+
* @returns {JSX.Element} ToggleGroup component
|
|
4694
4694
|
*/
|
|
4695
|
-
const ToggleGroup = ({ list, selected, setSelected,
|
|
4695
|
+
const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
|
|
4696
4696
|
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: () => {
|
|
4697
|
-
onClick && onClick();
|
|
4698
4697
|
setSelected(item.id);
|
|
4698
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
|
|
4699
4699
|
}, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
|
|
4700
4700
|
};
|
|
4701
4701
|
const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type that ensures that if one property is passed, ALL are required.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* AllOrNone<{
|
|
6
|
+
selected?: TSelectedId | null;
|
|
7
|
+
setSelected?: React.Dispatch<React.SetStateAction<TSelectedId | null>>;
|
|
8
|
+
}>
|
|
9
|
+
*/
|
|
10
|
+
export type AllOrNone<TProps> = (TProps & Required<TProps>) | {
|
|
11
|
+
[Key in keyof TProps]?: never;
|
|
12
|
+
};
|
package/src/common/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { VariantProps } from "@trackunit/css-class-variance-utilities";
|
|
2
|
+
import { MappedOmit } from "@trackunit/shared-utils";
|
|
2
3
|
import { IconName } from "@trackunit/ui-icons";
|
|
3
4
|
import { CommonProps } from "../../common/CommonProps";
|
|
4
5
|
import { TooltipPlacement } from "../Tooltip/Tooltip";
|
|
5
6
|
import { cvaToggleGroup } from "./ToggleGroup.variants";
|
|
6
|
-
export interface BasicToggleGroupListProps {
|
|
7
|
+
export interface BasicToggleGroupListProps<TSelectedId extends string = string> {
|
|
7
8
|
/**
|
|
8
9
|
* Used to identify an individual button to be able to highlight the selected one.
|
|
9
10
|
*/
|
|
10
|
-
id:
|
|
11
|
+
id: TSelectedId;
|
|
11
12
|
/**
|
|
12
13
|
* Tooltip's fallback and button's text content.
|
|
13
14
|
*/
|
|
@@ -18,8 +19,8 @@ export interface BasicToggleGroupListProps {
|
|
|
18
19
|
iconName?: IconName;
|
|
19
20
|
/**
|
|
20
21
|
* Due to size of the text, one might need to truncate a button's content or another.
|
|
21
|
-
* This
|
|
22
|
-
* For a button that
|
|
22
|
+
* This behavior is individual for each button.
|
|
23
|
+
* For a button that use this feature, the full text can be read on hover.
|
|
23
24
|
* Truncation should be avoided if possible.
|
|
24
25
|
*/
|
|
25
26
|
text?: {
|
|
@@ -37,14 +38,12 @@ export interface BasicToggleGroupListProps {
|
|
|
37
38
|
};
|
|
38
39
|
dataTestId?: string;
|
|
39
40
|
}
|
|
40
|
-
export
|
|
41
|
-
list: BasicToggleGroupListProps[];
|
|
42
|
-
selected: string;
|
|
43
|
-
setSelected: React.Dispatch<React.SetStateAction<string>>;
|
|
41
|
+
export type ToggleGroupProps<TSelectedId extends string = string> = CommonProps & Omit<VariantProps<typeof cvaToggleGroup>, "className"> & {
|
|
42
|
+
list: readonly BasicToggleGroupListProps<TSelectedId>[];
|
|
44
43
|
/**
|
|
45
|
-
*
|
|
44
|
+
* Instead of onClick, we now use onChange to return the selected value
|
|
46
45
|
*/
|
|
47
|
-
|
|
46
|
+
onChange?: (selectedId: TSelectedId) => void;
|
|
48
47
|
disabled?: boolean;
|
|
49
48
|
/**
|
|
50
49
|
* ToggleGroup buttons can be one of two sizes
|
|
@@ -54,15 +53,17 @@ export interface ToggleGroupProps extends CommonProps, Omit<VariantProps<typeof
|
|
|
54
53
|
* Enable to use toggle buttons with icons only and a tooltip on hover
|
|
55
54
|
*/
|
|
56
55
|
isIconOnly?: boolean;
|
|
57
|
-
|
|
56
|
+
selected: TSelectedId;
|
|
57
|
+
setSelected: React.Dispatch<React.SetStateAction<TSelectedId>>;
|
|
58
|
+
};
|
|
58
59
|
/**
|
|
59
60
|
* Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
|
|
60
61
|
*
|
|
61
|
-
* @param {ToggleGroupProps} props - The props for the
|
|
62
|
-
* @returns {JSX.Element}
|
|
62
|
+
* @param {ToggleGroupProps} props - The props for the ToggleGroup component
|
|
63
|
+
* @returns {JSX.Element} ToggleGroup component
|
|
63
64
|
*/
|
|
64
|
-
export declare const ToggleGroup: ({ list, selected, setSelected,
|
|
65
|
-
export interface ToggleItemProps extends CommonProps,
|
|
65
|
+
export declare const ToggleGroup: <TSelectedId extends string = string>({ list, selected, setSelected, onChange, disabled, size, isIconOnly, className, dataTestId, }: ToggleGroupProps<TSelectedId>) => import("react/jsx-runtime").JSX.Element;
|
|
66
|
+
export interface ToggleItemProps extends CommonProps, MappedOmit<BasicToggleGroupListProps<string>, "id"> {
|
|
66
67
|
onClick: () => void;
|
|
67
68
|
disabled: boolean;
|
|
68
69
|
isIconOnly: boolean;
|