@trackunit/react-filter-components 0.0.47 → 0.0.48

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 CHANGED
@@ -68,22 +68,32 @@ const ActiveLabel = tailwindStyledComponents.tw.span `
68
68
  `;
69
69
 
70
70
  /**
71
- * The FilterItem component is the base component used in the manager to FilterItem data.
72
- * This component in generic and does not have any connection to the data.
71
+ * The FilterBody component is used to display the title of the filter and a reset button.
72
+ * IT is intended for use in the Filter component.
73
+ * The reset button will only be visible if the showReset prop is set to true.
73
74
  *
74
- * @param {FilterItemProps} props - The props for the FilterItem component
75
- * @returns {JSX.Element} FilterItem component
75
+ * @param {FilterBodyProps} props - The props for the FilterBody component
76
+ * @returns {JSX.Element} FilterBody component
76
77
  */
77
- const FilterItem = (_a) => {
78
- var { itemCount, className, prefix, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["itemCount", "className", "prefix", "dataTestId", "menuItemProps"]);
79
- const checkboxProps = Object.assign({}, rest);
80
- const checkboxRef = React.useRef(null);
81
- return (jsxRuntime.jsx(reactComponents.MenuItem, Object.assign({ onClick: e => {
82
- var _a;
83
- e.preventDefault();
84
- (_a = checkboxRef.current) === null || _a === void 0 ? void 0 : _a.click();
85
- }, selected: checkboxProps.checked, disabled: checkboxProps.disabled, className: className, dataTestId: dataTestId, prefix: prefix }, menuItemProps, { suffix: jsxRuntime.jsx("small", { children: itemCount }) }, { children: jsxRuntime.jsx(reactComponents.Checkbox, Object.assign({ ref: checkboxRef }, checkboxProps, { dataTestId: dataTestId && `${dataTestId}-checkbox`, className: "flex-grow cursor-pointer" })) })));
86
- };
78
+ const FilterBody = React__default["default"].forwardRef((_a, ref) => {
79
+ var { children, dataTestId, limitSize = false } = _a, rest = __rest(_a, ["children", "dataTestId", "limitSize"]);
80
+ return (jsxRuntime.jsx(Root$1, Object.assign({ "$limitSize": limitSize, ref: ref }, rest, { "data-testid": dataTestId }, { children: children })));
81
+ });
82
+ const Root$1 = tailwindStyledComponents.tw.div `
83
+ grid
84
+ gap-1
85
+ p-1
86
+ rounded
87
+ w-full
88
+ ${props => props.$limitSize
89
+ ? tailwindStyledComponents.tws `
90
+ overflow-hidden
91
+ max-h-80
92
+ max-w-sm
93
+ overflow-y-auto
94
+ `
95
+ : ""}
96
+ `;
87
97
 
88
98
  /**
89
99
  * The FilterHeader component is used to display the title of the filter and a reset button.
@@ -95,7 +105,7 @@ const FilterItem = (_a) => {
95
105
  */
96
106
  const FilterHeader = (_a) => {
97
107
  var { title, resetLabel, showReset, dataTestId, onReset, loading, children } = _a, rest = __rest(_a, ["title", "resetLabel", "showReset", "dataTestId", "onReset", "loading", "children"]);
98
- return (jsxRuntime.jsxs(Root$1, Object.assign({}, rest, { "data-testid": dataTestId }, { children: [jsxRuntime.jsxs(HeadingContainer, { children: [jsxRuntime.jsx("h4", { children: title }), loading ? (jsxRuntime.jsx(reactComponents.Spinner, { size: "small" })) : (jsxRuntime.jsx(HiddenButton, Object.assign({ "$isVisible": Boolean(showReset), size: "small", variant: "transparent", color: "danger", onClick: onReset }, { children: resetLabel })))] }), children] })));
108
+ return (jsxRuntime.jsxs(Root, Object.assign({}, rest, { "data-testid": dataTestId }, { children: [jsxRuntime.jsxs(HeadingContainer, { children: [jsxRuntime.jsx("h4", { children: title }), loading ? (jsxRuntime.jsx(reactComponents.Spinner, { size: "small" })) : (jsxRuntime.jsx(HiddenButton, Object.assign({ "$isVisible": Boolean(showReset), size: "small", variant: "transparent", color: "danger", onClick: onReset }, { children: resetLabel })))] }), children] })));
99
109
  };
100
110
  const HeadingContainer = tailwindStyledComponents.tw.div `
101
111
  flex
@@ -110,40 +120,44 @@ const HeadingContainer = tailwindStyledComponents.tw.div `
110
120
  const HiddenButton = tailwindStyledComponents.twx(reactComponents.Button) `
111
121
  ${props => (props.$isVisible ? tailwindStyledComponents.tws `visible` : tailwindStyledComponents.tws `invisible`)}
112
122
  `;
113
- const Root$1 = tailwindStyledComponents.tw.div `
123
+ const Root = tailwindStyledComponents.tw.div `
114
124
  grid
115
125
  gap-1
116
126
  p-1
117
127
  `;
118
128
 
119
129
  /**
120
- * The FilterBody component is used to display the title of the filter and a reset button.
121
- * IT is intended for use in the Filter component.
122
- * The reset button will only be visible if the showReset prop is set to true.
130
+ * The CheckBoxFilterItem component is the base component used in the manager to FilterItem data.
131
+ * This component in generic and does not have any connection to the data.
123
132
  *
124
- * @param {FilterBodyProps} props - The props for the FilterBody component
125
- * @returns {JSX.Element} FilterBody component
133
+ * @param {CheckBoxFilterItemProps} props - The props for the FilterItem component
134
+ * @returns {JSX.Element} FilterItem component
126
135
  */
127
- const FilterBody = React__default["default"].forwardRef((_a, ref) => {
128
- var { children, dataTestId, limitSize = false } = _a, rest = __rest(_a, ["children", "dataTestId", "limitSize"]);
129
- return (jsxRuntime.jsx(Root, Object.assign({ "$limitSize": limitSize, ref: ref }, rest, { "data-testid": dataTestId }, { children: children })));
130
- });
131
- const Root = tailwindStyledComponents.tw.div `
132
- grid
133
- gap-1
134
- p-1
135
- rounded
136
- ${props => props.$limitSize
137
- ? tailwindStyledComponents.tws `
138
- overflow-hidden
139
- max-h-80
140
- max-w-sm
141
- overflow-y-auto
142
- `
143
- : ""}
144
- `;
136
+ const CheckBoxFilterItem = (_a) => {
137
+ var { itemCount, className, prefix, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["itemCount", "className", "prefix", "dataTestId", "menuItemProps"]);
138
+ const checkboxProps = Object.assign({}, rest);
139
+ const checkboxRef = React.useRef(null);
140
+ return (jsxRuntime.jsx(reactComponents.MenuItem, Object.assign({ onClick: e => {
141
+ var _a;
142
+ e.preventDefault();
143
+ (_a = checkboxRef.current) === null || _a === void 0 ? void 0 : _a.click();
144
+ }, selected: checkboxProps.checked, disabled: checkboxProps.disabled, className: className, dataTestId: dataTestId, prefix: prefix }, menuItemProps, { suffix: jsxRuntime.jsx("small", { children: itemCount }) }, { children: jsxRuntime.jsx(reactComponents.Checkbox, Object.assign({ ref: checkboxRef }, checkboxProps, { dataTestId: dataTestId && `${dataTestId}-checkbox`, className: "flex-grow cursor-pointer" })) })));
145
+ };
146
+
147
+ /**
148
+ * The RadioFilterItem component is the base component used in the manager to FilterItem data.
149
+ * This component in generic and does not have any connection to the data.
150
+ *
151
+ * @param {RadioFilterItemProps} props - The props for the FilterItem component
152
+ * @returns {JSX.Element} FilterItem component
153
+ */
154
+ const RadioFilterItem = (_a) => {
155
+ var { value, label, itemCount, selected, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["value", "label", "itemCount", "selected", "dataTestId", "menuItemProps"]);
156
+ return (jsxRuntime.jsx(reactComponents.MenuItem, Object.assign({ selected: selected, dataTestId: dataTestId, className: "flex justify-between cursor-default p-0 my-[2px]", suffix: jsxRuntime.jsx("small", Object.assign({ className: "pl-1 pr-3" }, { children: itemCount })) }, menuItemProps, { children: jsxRuntime.jsx(reactComponents.RadioItem, Object.assign({}, rest, { value: value, className: "flex items-center w-full py-2 pl-2", dataTestId: dataTestId && `${dataTestId}-radio`, label: jsxRuntime.jsx(reactComponents.Text, Object.assign({ className: "cursor-pointer", type: "span" }, { children: label })) })) })));
157
+ };
145
158
 
159
+ exports.CheckBoxFilterItem = CheckBoxFilterItem;
146
160
  exports.Filter = Filter;
147
161
  exports.FilterBody = FilterBody;
148
162
  exports.FilterHeader = FilterHeader;
149
- exports.FilterItem = FilterItem;
163
+ exports.RadioFilterItem = RadioFilterItem;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { Button, MenuList, Popover, PopoverTrigger, PopoverContent, MenuItem, Checkbox, Spinner } from '@trackunit/react-components';
2
+ import { Button, MenuList, Popover, PopoverTrigger, PopoverContent, Spinner, MenuItem, Checkbox, RadioItem, Text } from '@trackunit/react-components';
3
3
  import { twx, tws, tw } from '@trackunit/tailwind-styled-components';
4
4
  import React, { useRef } from 'react';
5
5
 
@@ -60,22 +60,32 @@ const ActiveLabel = tw.span `
60
60
  `;
61
61
 
62
62
  /**
63
- * The FilterItem component is the base component used in the manager to FilterItem data.
64
- * This component in generic and does not have any connection to the data.
63
+ * The FilterBody component is used to display the title of the filter and a reset button.
64
+ * IT is intended for use in the Filter component.
65
+ * The reset button will only be visible if the showReset prop is set to true.
65
66
  *
66
- * @param {FilterItemProps} props - The props for the FilterItem component
67
- * @returns {JSX.Element} FilterItem component
67
+ * @param {FilterBodyProps} props - The props for the FilterBody component
68
+ * @returns {JSX.Element} FilterBody component
68
69
  */
69
- const FilterItem = (_a) => {
70
- var { itemCount, className, prefix, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["itemCount", "className", "prefix", "dataTestId", "menuItemProps"]);
71
- const checkboxProps = Object.assign({}, rest);
72
- const checkboxRef = useRef(null);
73
- return (jsx(MenuItem, Object.assign({ onClick: e => {
74
- var _a;
75
- e.preventDefault();
76
- (_a = checkboxRef.current) === null || _a === void 0 ? void 0 : _a.click();
77
- }, selected: checkboxProps.checked, disabled: checkboxProps.disabled, className: className, dataTestId: dataTestId, prefix: prefix }, menuItemProps, { suffix: jsx("small", { children: itemCount }) }, { children: jsx(Checkbox, Object.assign({ ref: checkboxRef }, checkboxProps, { dataTestId: dataTestId && `${dataTestId}-checkbox`, className: "flex-grow cursor-pointer" })) })));
78
- };
70
+ const FilterBody = React.forwardRef((_a, ref) => {
71
+ var { children, dataTestId, limitSize = false } = _a, rest = __rest(_a, ["children", "dataTestId", "limitSize"]);
72
+ return (jsx(Root$1, Object.assign({ "$limitSize": limitSize, ref: ref }, rest, { "data-testid": dataTestId }, { children: children })));
73
+ });
74
+ const Root$1 = tw.div `
75
+ grid
76
+ gap-1
77
+ p-1
78
+ rounded
79
+ w-full
80
+ ${props => props.$limitSize
81
+ ? tws `
82
+ overflow-hidden
83
+ max-h-80
84
+ max-w-sm
85
+ overflow-y-auto
86
+ `
87
+ : ""}
88
+ `;
79
89
 
80
90
  /**
81
91
  * The FilterHeader component is used to display the title of the filter and a reset button.
@@ -87,7 +97,7 @@ const FilterItem = (_a) => {
87
97
  */
88
98
  const FilterHeader = (_a) => {
89
99
  var { title, resetLabel, showReset, dataTestId, onReset, loading, children } = _a, rest = __rest(_a, ["title", "resetLabel", "showReset", "dataTestId", "onReset", "loading", "children"]);
90
- return (jsxs(Root$1, Object.assign({}, rest, { "data-testid": dataTestId }, { children: [jsxs(HeadingContainer, { children: [jsx("h4", { children: title }), loading ? (jsx(Spinner, { size: "small" })) : (jsx(HiddenButton, Object.assign({ "$isVisible": Boolean(showReset), size: "small", variant: "transparent", color: "danger", onClick: onReset }, { children: resetLabel })))] }), children] })));
100
+ return (jsxs(Root, Object.assign({}, rest, { "data-testid": dataTestId }, { children: [jsxs(HeadingContainer, { children: [jsx("h4", { children: title }), loading ? (jsx(Spinner, { size: "small" })) : (jsx(HiddenButton, Object.assign({ "$isVisible": Boolean(showReset), size: "small", variant: "transparent", color: "danger", onClick: onReset }, { children: resetLabel })))] }), children] })));
91
101
  };
92
102
  const HeadingContainer = tw.div `
93
103
  flex
@@ -102,37 +112,40 @@ const HeadingContainer = tw.div `
102
112
  const HiddenButton = twx(Button) `
103
113
  ${props => (props.$isVisible ? tws `visible` : tws `invisible`)}
104
114
  `;
105
- const Root$1 = tw.div `
115
+ const Root = tw.div `
106
116
  grid
107
117
  gap-1
108
118
  p-1
109
119
  `;
110
120
 
111
121
  /**
112
- * The FilterBody component is used to display the title of the filter and a reset button.
113
- * IT is intended for use in the Filter component.
114
- * The reset button will only be visible if the showReset prop is set to true.
122
+ * The CheckBoxFilterItem component is the base component used in the manager to FilterItem data.
123
+ * This component in generic and does not have any connection to the data.
115
124
  *
116
- * @param {FilterBodyProps} props - The props for the FilterBody component
117
- * @returns {JSX.Element} FilterBody component
125
+ * @param {CheckBoxFilterItemProps} props - The props for the FilterItem component
126
+ * @returns {JSX.Element} FilterItem component
118
127
  */
119
- const FilterBody = React.forwardRef((_a, ref) => {
120
- var { children, dataTestId, limitSize = false } = _a, rest = __rest(_a, ["children", "dataTestId", "limitSize"]);
121
- return (jsx(Root, Object.assign({ "$limitSize": limitSize, ref: ref }, rest, { "data-testid": dataTestId }, { children: children })));
122
- });
123
- const Root = tw.div `
124
- grid
125
- gap-1
126
- p-1
127
- rounded
128
- ${props => props.$limitSize
129
- ? tws `
130
- overflow-hidden
131
- max-h-80
132
- max-w-sm
133
- overflow-y-auto
134
- `
135
- : ""}
136
- `;
128
+ const CheckBoxFilterItem = (_a) => {
129
+ var { itemCount, className, prefix, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["itemCount", "className", "prefix", "dataTestId", "menuItemProps"]);
130
+ const checkboxProps = Object.assign({}, rest);
131
+ const checkboxRef = useRef(null);
132
+ return (jsx(MenuItem, Object.assign({ onClick: e => {
133
+ var _a;
134
+ e.preventDefault();
135
+ (_a = checkboxRef.current) === null || _a === void 0 ? void 0 : _a.click();
136
+ }, selected: checkboxProps.checked, disabled: checkboxProps.disabled, className: className, dataTestId: dataTestId, prefix: prefix }, menuItemProps, { suffix: jsx("small", { children: itemCount }) }, { children: jsx(Checkbox, Object.assign({ ref: checkboxRef }, checkboxProps, { dataTestId: dataTestId && `${dataTestId}-checkbox`, className: "flex-grow cursor-pointer" })) })));
137
+ };
138
+
139
+ /**
140
+ * The RadioFilterItem component is the base component used in the manager to FilterItem data.
141
+ * This component in generic and does not have any connection to the data.
142
+ *
143
+ * @param {RadioFilterItemProps} props - The props for the FilterItem component
144
+ * @returns {JSX.Element} FilterItem component
145
+ */
146
+ const RadioFilterItem = (_a) => {
147
+ var { value, label, itemCount, selected, dataTestId, menuItemProps } = _a, rest = __rest(_a, ["value", "label", "itemCount", "selected", "dataTestId", "menuItemProps"]);
148
+ return (jsx(MenuItem, Object.assign({ selected: selected, dataTestId: dataTestId, className: "flex justify-between cursor-default p-0 my-[2px]", suffix: jsx("small", Object.assign({ className: "pl-1 pr-3" }, { children: itemCount })) }, menuItemProps, { children: jsx(RadioItem, Object.assign({}, rest, { value: value, className: "flex items-center w-full py-2 pl-2", dataTestId: dataTestId && `${dataTestId}-radio`, label: jsx(Text, Object.assign({ className: "cursor-pointer", type: "span" }, { children: label })) })) })));
149
+ };
137
150
 
138
- export { Filter, FilterBody, FilterHeader, FilterItem };
151
+ export { CheckBoxFilterItem, Filter, FilterBody, FilterHeader, RadioFilterItem };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@trackunit/react-filter-components",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
- "@trackunit/react-components": "0.1.67",
7
+ "@trackunit/react-components": "0.1.68",
8
8
  "react": "18.2.0",
9
9
  "@trackunit/tailwind-styled-components": "0.0.54",
10
10
  "jest-canvas-mock": "2.4.0"
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { CheckBoxFilterItemProps } from "../types";
3
+ /**
4
+ * The CheckBoxFilterItem component is the base component used in the manager to FilterItem data.
5
+ * This component in generic and does not have any connection to the data.
6
+ *
7
+ * @param {CheckBoxFilterItemProps} props - The props for the FilterItem component
8
+ * @returns {JSX.Element} FilterItem component
9
+ */
10
+ export declare const CheckBoxFilterItem: ({ itemCount, className, prefix, dataTestId, menuItemProps, ...rest }: CheckBoxFilterItemProps) => JSX.Element;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { RadioFilterItemProps } from "../types";
3
+ /**
4
+ * The RadioFilterItem component is the base component used in the manager to FilterItem data.
5
+ * This component in generic and does not have any connection to the data.
6
+ *
7
+ * @param {RadioFilterItemProps} props - The props for the FilterItem component
8
+ * @returns {JSX.Element} FilterItem component
9
+ */
10
+ export declare const RadioFilterItem: ({ value, label, itemCount, selected, dataTestId, menuItemProps, ...rest }: RadioFilterItemProps) => JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { CheckboxProps, MenuItemProps, RadioItemProps } from "@trackunit/react-components";
2
+ export interface CheckBoxFilterItemProps extends Omit<CheckboxProps, "prefix" | "suffix">, BaseFilterItemProps {
3
+ }
4
+ export interface RadioFilterItemProps extends RadioItemProps, BaseFilterItemProps {
5
+ /**
6
+ * An boolean flag to set checkbox to checked state
7
+ */
8
+ selected?: boolean;
9
+ }
10
+ interface BaseFilterItemProps {
11
+ /**
12
+ * The number of results for the filter item.
13
+ * This displays the number next to the label.
14
+ */
15
+ itemCount?: number;
16
+ /**
17
+ * Properties to be passed to the MenuItem component.
18
+ */
19
+ menuItemProps?: MenuItemProps;
20
+ prefix?: MenuItemProps["prefix"];
21
+ }
22
+ export {};
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./Filter/Filter";
2
- export * from "./FilterItem/FilterItem";
3
- export * from "./FilterHeader/FilterHeader";
4
2
  export * from "./FilterBody/FilterBody";
3
+ export * from "./FilterHeader/FilterHeader";
4
+ export * from "./FilterItem/CheckBoxFilter/CheckBoxFilterItem";
5
+ export * from "./FilterItem/RadioFilter/RadioFilterItem";
@@ -1,30 +0,0 @@
1
- /// <reference types="react" />
2
- import { CheckboxProps, MenuItemProps } from "@trackunit/react-components";
3
- export interface FilterItemProps extends Omit<CheckboxProps, "prefix" | "suffix"> {
4
- /**
5
- * The number of results for the filter item.
6
- * This displays the number next to the label.
7
- */
8
- itemCount?: number;
9
- /**
10
- * An boolean flag to set checkbox to checked state.
11
- */
12
- checked?: boolean;
13
- /**
14
- * An boolean flag to set checkbox to disabled state.
15
- */
16
- disabled?: boolean;
17
- /**
18
- * Properties to be passed to the MenuItem component.
19
- */
20
- menuItemProps?: MenuItemProps;
21
- prefix?: MenuItemProps["prefix"];
22
- }
23
- /**
24
- * The FilterItem component is the base component used in the manager to FilterItem data.
25
- * This component in generic and does not have any connection to the data.
26
- *
27
- * @param {FilterItemProps} props - The props for the FilterItem component
28
- * @returns {JSX.Element} FilterItem component
29
- */
30
- export declare const FilterItem: ({ itemCount, className, prefix, dataTestId, menuItemProps, ...rest }: FilterItemProps) => JSX.Element;