@trackunit/react-filter-components 0.0.44 → 0.0.45-alpha-0b53b6cf53.0

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.
Files changed (2) hide show
  1. package/index.cjs +149 -0
  2. package/package.json +3 -3
package/index.cjs ADDED
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var reactComponents = require('@trackunit/react-components');
7
+ var tailwindStyledComponents = require('@trackunit/tailwind-styled-components');
8
+ var React = require('react');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
+
14
+ /******************************************************************************
15
+ Copyright (c) Microsoft Corporation.
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
+ PERFORMANCE OF THIS SOFTWARE.
27
+ ***************************************************************************** */
28
+
29
+ function __rest(s, e) {
30
+ var t = {};
31
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
32
+ t[p] = s[p];
33
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
34
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
35
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
36
+ t[p[i]] = s[p[i]];
37
+ }
38
+ return t;
39
+ }
40
+
41
+ /**
42
+ * The Filter component is the base component used in the manager to filter data.
43
+ *
44
+ * - This component in generic and does not have any connection to the data.
45
+ * - The base props extends button props, and any button props such as prefix and suffix can be used.
46
+ * - Color and size has special default values in this component, but can be overridden if needed.
47
+ *
48
+ * To add items to the popover list use the children prop, this is where you build all the filter items and connected logic.
49
+ *
50
+ * @param {FilterProps} props - The props for the Filter component
51
+ * @returns {JSX.Element} Filter component
52
+ */
53
+ const Filter = (_a) => {
54
+ var { title, children, popoverProps, isActive, activeLabel, menuListProps, className, dataTestId, withStickyHeader = false, readOnly } = _a, rest = __rest(_a, ["title", "children", "popoverProps", "isActive", "activeLabel", "menuListProps", "className", "dataTestId", "withStickyHeader", "readOnly"]);
55
+ const buttonProps = Object.assign({}, rest);
56
+ return (jsxRuntime.jsx(reactComponents.Popover, Object.assign({ dataTestId: dataTestId && `${dataTestId}-popover`, placement: "bottom-start" }, popoverProps, { render: () => (jsxRuntime.jsx(CustomMenuList, Object.assign({ withStickyHeader: withStickyHeader, dataTestId: dataTestId && `${dataTestId}-menulist` }, menuListProps, { children: children }))) }, { children: jsxRuntime.jsxs(CustomButton, Object.assign({ color: "tertiary", size: "small", dataTestId: dataTestId, disabled: readOnly }, buttonProps, { "$isActive": isActive, className: className }, { children: [title, " ", isActive && jsxRuntime.jsx(ActiveLabel, { children: activeLabel })] })) })));
57
+ };
58
+ const CustomButton = tailwindStyledComponents.twx(reactComponents.Button) `
59
+ ${({ $isActive }) => ($isActive ? tailwindStyledComponents.tws `!border-primary-600` : "")}
60
+ `;
61
+ const CustomMenuList = tailwindStyledComponents.twx(reactComponents.MenuList) `
62
+ overflow-x-hidden
63
+ overflow-y-auto
64
+ relative
65
+ `;
66
+ const ActiveLabel = tailwindStyledComponents.tw.span `
67
+ text-primary-600
68
+ `;
69
+
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.
73
+ *
74
+ * @param {FilterItemProps} props - The props for the FilterItem component
75
+ * @returns {JSX.Element} FilterItem component
76
+ */
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
+ };
87
+
88
+ /**
89
+ * The FilterHeader component is used to display the title of the filter and a reset button.
90
+ * IT is intended for use in the Filter component.
91
+ * The reset button will only be visible if the showReset prop is set to true.
92
+ *
93
+ * @param {FilterHeaderProps} props - The props for the FilterHeader component
94
+ * @returns {JSX.Element} FilterHeader component
95
+ */
96
+ const FilterHeader = (_a) => {
97
+ 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] })));
99
+ };
100
+ const HeadingContainer = tailwindStyledComponents.tw.div `
101
+ flex
102
+ items-center
103
+ pl-1
104
+ justify-between
105
+ font-medium
106
+ text-sm
107
+ text-slate-600
108
+ uppercase
109
+ `;
110
+ const HiddenButton = tailwindStyledComponents.twx(reactComponents.Button) `
111
+ ${props => (props.$isVisible ? tailwindStyledComponents.tws `visible` : tailwindStyledComponents.tws `invisible`)}
112
+ `;
113
+ const Root$1 = tailwindStyledComponents.tw.div `
114
+ grid
115
+ gap-1
116
+ p-1
117
+ `;
118
+
119
+ /**
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.
123
+ *
124
+ * @param {FilterBodyProps} props - The props for the FilterBody component
125
+ * @returns {JSX.Element} FilterBody component
126
+ */
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
+ `;
145
+
146
+ exports.Filter = Filter;
147
+ exports.FilterBody = FilterBody;
148
+ exports.FilterHeader = FilterHeader;
149
+ exports.FilterItem = FilterItem;
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@trackunit/react-filter-components",
3
- "version": "0.0.44",
3
+ "version": "0.0.45-alpha-0b53b6cf53.0",
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.64",
7
+ "@trackunit/react-components": "0.1.65-alpha-0b53b6cf53.0",
8
8
  "react": "18.2.0",
9
9
  "@trackunit/tailwind-styled-components": "0.0.54",
10
10
  "jest-canvas-mock": "2.4.0"
11
11
  },
12
12
  "module": "./index.js",
13
- "main": "./index.js",
13
+ "main": "./index.cjs",
14
14
  "type": "module",
15
15
  "types": "./src/index.d.ts",
16
16
  "peerDependencies": {}