@scaleflex/ui-tw 0.0.61 → 0.0.63
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/checkbox/checkbox.component.d.ts +4 -3
- package/checkbox/checkbox.component.js +37 -8
- package/checkbox/checkbox.types.d.ts +7 -0
- package/combobox/combobox-multi-checkbox/combobox-multi-checkbox.component.d.ts +3 -0
- package/combobox/combobox-multi-checkbox/combobox-multi-checkbox.component.js +205 -0
- package/combobox/combobox-multi-tag/combobox-multi-tag.component.js +2 -2
- package/combobox/combobox.component.d.ts +3 -1
- package/combobox/combobox.component.js +211 -30
- package/combobox/combobox.constants.js +1 -1
- package/combobox/combobox.types.d.ts +21 -1
- package/combobox/combobox.utils.d.ts +3 -1
- package/combobox/combobox.utils.js +27 -1
- package/combobox/index.d.ts +1 -0
- package/combobox/index.js +1 -0
- package/command/command.component.d.ts +2 -1
- package/command/command.component.js +45 -3
- package/dialog/dialog.component.js +2 -2
- package/input-tags/input-tags.component.js +2 -2
- package/package.json +2 -2
- package/search/search.component.js +1 -1
- package/select/components/select-icon.d.ts +1 -1
- package/select/select.component.js +3 -3
- package/select/select.types.d.ts +4 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
declare function Checkbox({ className, size, ...
|
|
4
|
-
|
|
2
|
+
import { CheckboxProps, VisualCheckboxProps } from './checkbox.types';
|
|
3
|
+
declare function Checkbox({ className, size, partial, ...rest }: CheckboxProps): React.JSX.Element;
|
|
4
|
+
declare function VisualCheckbox({ checked, partial, size, className, ...rest }: VisualCheckboxProps): React.JSX.Element;
|
|
5
|
+
export { Checkbox, VisualCheckbox };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["className", "size"]
|
|
3
|
+
var _excluded = ["className", "size", "partial"],
|
|
4
|
+
_excluded2 = ["checked", "partial", "size", "className"];
|
|
4
5
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
5
6
|
import { ariaInvalidClassNames, focusRingClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
6
7
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
7
8
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
8
9
|
import { cva } from 'class-variance-authority';
|
|
9
|
-
import { CheckIcon } from 'lucide-react';
|
|
10
|
+
import { CheckIcon, MinusIcon } from 'lucide-react';
|
|
10
11
|
import React from 'react';
|
|
11
12
|
import { checkboxIndicatorSizeOptions, checkboxSizeOptions } from './checkbox.constants';
|
|
12
13
|
var checkboxVariants = cva('', {
|
|
@@ -27,20 +28,48 @@ var checkboxIndicatorVariants = cva('', {
|
|
|
27
28
|
});
|
|
28
29
|
function Checkbox(_ref) {
|
|
29
30
|
var className = _ref.className,
|
|
30
|
-
size = _ref.size,
|
|
31
|
-
|
|
31
|
+
_ref$size = _ref.size,
|
|
32
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
33
|
+
partial = _ref.partial,
|
|
34
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
32
35
|
return /*#__PURE__*/React.createElement(CheckboxPrimitive.Root, _extends({
|
|
33
36
|
"data-slot": "checkbox",
|
|
34
37
|
className: cn('peer border-input shrink-0 cursor-pointer rounded-sm border shadow-xs transition-shadow outline-none', 'hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50', 'data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:border-primary', ariaInvalidClassNames, focusRingClassNames, checkboxVariants({
|
|
35
38
|
size: size
|
|
36
39
|
}), className)
|
|
37
|
-
},
|
|
40
|
+
}, rest), /*#__PURE__*/React.createElement(CheckboxPrimitive.Indicator, {
|
|
38
41
|
"data-slot": "checkbox-indicator",
|
|
39
42
|
className: "flex items-center justify-center text-current transition-none"
|
|
40
|
-
}, /*#__PURE__*/React.createElement(
|
|
41
|
-
className: cn(checkboxIndicatorVariants({
|
|
43
|
+
}, partial ? /*#__PURE__*/React.createElement(MinusIcon, {
|
|
44
|
+
className: cn('text-current', checkboxIndicatorVariants({
|
|
45
|
+
size: size
|
|
46
|
+
}))
|
|
47
|
+
}) : /*#__PURE__*/React.createElement(CheckIcon, {
|
|
48
|
+
className: cn('text-current', checkboxIndicatorVariants({
|
|
49
|
+
size: size
|
|
50
|
+
}))
|
|
51
|
+
})));
|
|
52
|
+
}
|
|
53
|
+
function VisualCheckbox(_ref2) {
|
|
54
|
+
var checked = _ref2.checked,
|
|
55
|
+
partial = _ref2.partial,
|
|
56
|
+
_ref2$size = _ref2.size,
|
|
57
|
+
size = _ref2$size === void 0 ? FormSize.Md : _ref2$size,
|
|
58
|
+
className = _ref2.className,
|
|
59
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
60
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
61
|
+
"aria-hidden": "true",
|
|
62
|
+
className: cn('peer border-input shrink-0 cursor-pointer rounded-sm border shadow-xs transition-shadow outline-none', 'hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50', checked && 'bg-primary text-primary-foreground border-primary', ariaInvalidClassNames, focusRingClassNames, checkboxVariants({
|
|
63
|
+
size: size
|
|
64
|
+
}), className)
|
|
65
|
+
}, rest), checked && (partial ? /*#__PURE__*/React.createElement(MinusIcon, {
|
|
66
|
+
className: cn('text-current', checkboxIndicatorVariants({
|
|
67
|
+
size: size
|
|
68
|
+
}))
|
|
69
|
+
}) : /*#__PURE__*/React.createElement(CheckIcon, {
|
|
70
|
+
className: cn('text-current', checkboxIndicatorVariants({
|
|
42
71
|
size: size
|
|
43
72
|
}))
|
|
44
73
|
})));
|
|
45
74
|
}
|
|
46
|
-
export { Checkbox };
|
|
75
|
+
export { Checkbox, VisualCheckbox };
|
|
@@ -3,4 +3,11 @@ import type { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
|
3
3
|
import type { ComponentProps } from 'react';
|
|
4
4
|
export interface CheckboxProps extends ComponentProps<typeof CheckboxPrimitive.Root> {
|
|
5
5
|
size?: FormSizeType;
|
|
6
|
+
partial?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface VisualCheckboxProps extends ComponentProps<'div'> {
|
|
9
|
+
size?: FormSizeType;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
partial?: boolean;
|
|
12
|
+
className?: string;
|
|
6
13
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComboboxMultiCheckboxProps } from '../combobox.types';
|
|
3
|
+
export declare function ComboboxMultiCheckbox({ options, label, icon, value: selectedValue, onChange, className, disabled, size, readOnly, showClear, popoverClassName, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, formItemId, searchPlaceholder, actions, fixedActions, triggerProps, iconClassName, placeholder, displayCount, ...rest }: ComboboxMultiCheckboxProps): React.JSX.Element;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["options", "label", "icon", "value", "onChange", "className", "disabled", "size", "readOnly", "showClear", "popoverClassName", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps", "formItemId", "searchPlaceholder", "actions", "fixedActions", "triggerProps", "iconClassName", "placeholder", "displayCount"];
|
|
5
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
+
import { ComboboxCheckboxContent, ComboboxCheckboxTrigger } from '@scaleflex/ui-tw/combobox/combobox.component';
|
|
9
|
+
import { isOptionGroup } from '@scaleflex/ui-tw/form';
|
|
10
|
+
import { Popover } from '@scaleflex/ui-tw/popover';
|
|
11
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { useMemo, useState } from 'react';
|
|
14
|
+
export function ComboboxMultiCheckbox(_ref) {
|
|
15
|
+
var _ref$options = _ref.options,
|
|
16
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
17
|
+
label = _ref.label,
|
|
18
|
+
icon = _ref.icon,
|
|
19
|
+
selectedValue = _ref.value,
|
|
20
|
+
onChange = _ref.onChange,
|
|
21
|
+
className = _ref.className,
|
|
22
|
+
_ref$disabled = _ref.disabled,
|
|
23
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
24
|
+
_ref$size = _ref.size,
|
|
25
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
26
|
+
_ref$readOnly = _ref.readOnly,
|
|
27
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
28
|
+
_ref$showClear = _ref.showClear,
|
|
29
|
+
showClear = _ref$showClear === void 0 ? true : _ref$showClear,
|
|
30
|
+
popoverClassName = _ref.popoverClassName,
|
|
31
|
+
onBlur = _ref.onBlur,
|
|
32
|
+
_ref$showGroupSeparat = _ref.showGroupSeparator,
|
|
33
|
+
showGroupSeparator = _ref$showGroupSeparat === void 0 ? false : _ref$showGroupSeparat,
|
|
34
|
+
_ref$defaultOpen = _ref.defaultOpen,
|
|
35
|
+
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
36
|
+
popoverContentProps = _ref.popoverContentProps,
|
|
37
|
+
formItemId = _ref.formItemId,
|
|
38
|
+
_ref$searchPlaceholde = _ref.searchPlaceholder,
|
|
39
|
+
searchPlaceholder = _ref$searchPlaceholde === void 0 ? 'Search options...' : _ref$searchPlaceholde,
|
|
40
|
+
actions = _ref.actions,
|
|
41
|
+
fixedActions = _ref.fixedActions,
|
|
42
|
+
triggerProps = _ref.triggerProps,
|
|
43
|
+
iconClassName = _ref.iconClassName,
|
|
44
|
+
placeholder = _ref.placeholder,
|
|
45
|
+
_ref$displayCount = _ref.displayCount,
|
|
46
|
+
displayCount = _ref$displayCount === void 0 ? false : _ref$displayCount,
|
|
47
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
48
|
+
var _useState = useState(defaultOpen),
|
|
49
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
50
|
+
open = _useState2[0],
|
|
51
|
+
setOpen = _useState2[1];
|
|
52
|
+
var selectedLabels = useMemo(function () {
|
|
53
|
+
var labels = [];
|
|
54
|
+
var _iterator = _createForOfIteratorHelper(options),
|
|
55
|
+
_step;
|
|
56
|
+
try {
|
|
57
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
58
|
+
var option = _step.value;
|
|
59
|
+
if (isOptionGroup(option)) {
|
|
60
|
+
if (option.value && selectedValue.includes(option.value)) {
|
|
61
|
+
labels.push(option.label);
|
|
62
|
+
}
|
|
63
|
+
var _iterator2 = _createForOfIteratorHelper(option.options),
|
|
64
|
+
_step2;
|
|
65
|
+
try {
|
|
66
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
67
|
+
var sub = _step2.value;
|
|
68
|
+
if (selectedValue.includes(sub.value)) {
|
|
69
|
+
labels.push(sub.label);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_iterator2.e(err);
|
|
74
|
+
} finally {
|
|
75
|
+
_iterator2.f();
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
if (selectedValue.includes(option.value)) {
|
|
79
|
+
labels.push(option.label);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
_iterator.e(err);
|
|
85
|
+
} finally {
|
|
86
|
+
_iterator.f();
|
|
87
|
+
}
|
|
88
|
+
return labels;
|
|
89
|
+
}, [options, selectedValue]);
|
|
90
|
+
var displayValue = selectedLabels.length > 0 ? selectedLabels.join(', ') : placeholder;
|
|
91
|
+
var toggleValue = function toggleValue(v) {
|
|
92
|
+
var group = options.find(function (opt) {
|
|
93
|
+
return isOptionGroup(opt) && opt.value === v;
|
|
94
|
+
});
|
|
95
|
+
var nextValue;
|
|
96
|
+
if (group && isOptionGroup(group)) {
|
|
97
|
+
var childValues = group.options.map(function (child) {
|
|
98
|
+
return child.value;
|
|
99
|
+
});
|
|
100
|
+
var isGroupSelected = selectedValue.includes(group.value);
|
|
101
|
+
if (isGroupSelected) {
|
|
102
|
+
nextValue = selectedValue.filter(function (val) {
|
|
103
|
+
return val !== group.value;
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
nextValue = [].concat(_toConsumableArray(selectedValue.filter(function (val) {
|
|
107
|
+
return !childValues.includes(val);
|
|
108
|
+
})), [group.value]);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
nextValue = selectedValue.includes(v) ? selectedValue.filter(function (val) {
|
|
112
|
+
return val !== v;
|
|
113
|
+
}) : [].concat(_toConsumableArray(selectedValue), [v]);
|
|
114
|
+
}
|
|
115
|
+
onChange(nextValue);
|
|
116
|
+
};
|
|
117
|
+
var onOpenChange = function onOpenChange(isOpen) {
|
|
118
|
+
if (!isOpen) {
|
|
119
|
+
onBlur === null || onBlur === void 0 || onBlur(selectedValue);
|
|
120
|
+
}
|
|
121
|
+
setOpen(isOpen);
|
|
122
|
+
};
|
|
123
|
+
var onClearAll = function onClearAll() {
|
|
124
|
+
onChange([]);
|
|
125
|
+
onBlur === null || onBlur === void 0 || onBlur([]);
|
|
126
|
+
setOpen(false);
|
|
127
|
+
};
|
|
128
|
+
var handleCheckboxClick = function handleCheckboxClick(event) {
|
|
129
|
+
event.stopPropagation();
|
|
130
|
+
var allValues = [];
|
|
131
|
+
var _iterator3 = _createForOfIteratorHelper(options),
|
|
132
|
+
_step3;
|
|
133
|
+
try {
|
|
134
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
135
|
+
var option = _step3.value;
|
|
136
|
+
if (isOptionGroup(option)) {
|
|
137
|
+
allValues.push(option.value);
|
|
138
|
+
allValues.push.apply(allValues, _toConsumableArray(option.options.map(function (sub) {
|
|
139
|
+
return sub.value;
|
|
140
|
+
})));
|
|
141
|
+
} else {
|
|
142
|
+
allValues.push(option.value);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
_iterator3.e(err);
|
|
147
|
+
} finally {
|
|
148
|
+
_iterator3.f();
|
|
149
|
+
}
|
|
150
|
+
var isNoneSelected = selectedLabels.length === 0;
|
|
151
|
+
var isPartiallySelected = selectedLabels.length > 0 && selectedLabels.length < allValues.length;
|
|
152
|
+
var isAllSelected = selectedLabels.length === allValues.length;
|
|
153
|
+
if (isNoneSelected || isPartiallySelected) {
|
|
154
|
+
onChange(_toConsumableArray(new Set(allValues)));
|
|
155
|
+
} else if (isAllSelected) {
|
|
156
|
+
onChange([]);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var toggleFirstOption = function toggleFirstOption() {
|
|
160
|
+
var _options$;
|
|
161
|
+
if (options.length > 0 && (_options$ = options[0]) !== null && _options$ !== void 0 && _options$.value) {
|
|
162
|
+
var firstOptionValue = options[0].value;
|
|
163
|
+
var isSelected = selectedValue.includes(firstOptionValue);
|
|
164
|
+
onChange(isSelected ? selectedValue.filter(function (val) {
|
|
165
|
+
return val !== firstOptionValue;
|
|
166
|
+
}) : [].concat(_toConsumableArray(selectedValue), [firstOptionValue]));
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
170
|
+
open: open,
|
|
171
|
+
defaultOpen: defaultOpen,
|
|
172
|
+
onOpenChange: onOpenChange
|
|
173
|
+
}, /*#__PURE__*/React.createElement(ComboboxCheckboxTrigger, {
|
|
174
|
+
open: open,
|
|
175
|
+
icon: icon,
|
|
176
|
+
label: label,
|
|
177
|
+
disabled: disabled,
|
|
178
|
+
className: className,
|
|
179
|
+
size: size,
|
|
180
|
+
readOnly: readOnly,
|
|
181
|
+
showClear: showClear,
|
|
182
|
+
selected: selectedLabels.length > 0,
|
|
183
|
+
onClearAll: onClearAll,
|
|
184
|
+
"aria-invalid": rest['aria-invalid'],
|
|
185
|
+
formItemId: formItemId,
|
|
186
|
+
triggerProps: triggerProps,
|
|
187
|
+
iconClassName: iconClassName,
|
|
188
|
+
optionsLength: options.length,
|
|
189
|
+
displayCount: displayCount,
|
|
190
|
+
selectedLength: selectedLabels.length,
|
|
191
|
+
onCheckboxClick: handleCheckboxClick,
|
|
192
|
+
toggleFirstOption: toggleFirstOption
|
|
193
|
+
}, displayValue), /*#__PURE__*/React.createElement(ComboboxCheckboxContent, {
|
|
194
|
+
showGroupSeparator: showGroupSeparator,
|
|
195
|
+
searchPlaceholder: searchPlaceholder,
|
|
196
|
+
className: popoverClassName,
|
|
197
|
+
options: options,
|
|
198
|
+
value: selectedValue,
|
|
199
|
+
onSelect: toggleValue,
|
|
200
|
+
size: size,
|
|
201
|
+
popoverContentProps: popoverContentProps,
|
|
202
|
+
actions: actions,
|
|
203
|
+
fixedActions: fixedActions
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
@@ -128,9 +128,9 @@ export function ComboboxMultiTag(_ref) {
|
|
|
128
128
|
variant: ButtonVariant.GhostSecondary
|
|
129
129
|
})]))
|
|
130
130
|
}, "Clear all"), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
131
|
-
className: cn('mr-1.5 ml-auto shrink-0
|
|
131
|
+
className: cn('text-muted-foreground/70 mr-1.5 ml-auto shrink-0', iconSizeInTriggerOptions[size])
|
|
132
132
|
})) : /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
133
|
-
className: cn('my-auto ml-auto shrink-0
|
|
133
|
+
className: cn('text-muted-foreground/70 my-auto ml-auto shrink-0', iconSizeInTriggerOptions[size])
|
|
134
134
|
}))), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
135
135
|
options: options,
|
|
136
136
|
value: value,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { ComboboxCheckboxTriggerProps, ComboboxContentProps, ComboboxTriggerProps, SelectActionsProps } from './combobox.types';
|
|
3
3
|
export declare function SelectActions({ actions }: SelectActionsProps): React.JSX.Element | null;
|
|
4
4
|
export declare function ComboboxTrigger({ children, open, disabled, readOnly, size, className, selected, showClear, onClearAll, formItemId, triggerProps, ...rest }: ComboboxTriggerProps): React.JSX.Element;
|
|
5
|
+
export declare function ComboboxCheckboxTrigger({ children, open, label, disabled, readOnly, size, className, selected, showClear, onClearAll, formItemId, triggerProps, icon: Icon, iconClassName, optionsLength, selectedLength, onCheckboxClick, toggleFirstOption, displayCount, ...rest }: ComboboxCheckboxTriggerProps): React.JSX.Element;
|
|
5
6
|
export declare function ComboboxContent({ options, value: selectedValue, onSelect, size, multiple, className, showGroupSeparator, popoverContentProps, searchPlaceholder, noGroupSelection, actions, fixedActions, }: ComboboxContentProps): React.JSX.Element;
|
|
7
|
+
export declare function ComboboxCheckboxContent({ options, value: selectedValue, onSelect, size, className, showGroupSeparator, popoverContentProps, searchPlaceholder, actions, fixedActions, }: ComboboxContentProps): React.JSX.Element;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["children", "open", "disabled", "readOnly", "size", "className", "selected", "showClear", "onClearAll", "formItemId", "triggerProps"]
|
|
4
|
+
var _excluded = ["children", "open", "disabled", "readOnly", "size", "className", "selected", "showClear", "onClearAll", "formItemId", "triggerProps"],
|
|
5
|
+
_excluded2 = ["children", "open", "label", "disabled", "readOnly", "size", "className", "selected", "showClear", "onClearAll", "formItemId", "triggerProps", "icon", "iconClassName", "optionsLength", "selectedLength", "onCheckboxClick", "toggleFirstOption", "displayCount"];
|
|
5
6
|
import { buttonVariants } from '@scaleflex/ui-tw/button';
|
|
6
7
|
import { ButtonVariant, buttonBaseClassNames } from '@scaleflex/ui-tw/button/button.constants';
|
|
8
|
+
import { VisualCheckbox } from '@scaleflex/ui-tw/checkbox/checkbox.component';
|
|
7
9
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@scaleflex/ui-tw/command';
|
|
10
|
+
import { CommandCheckboxItem } from '@scaleflex/ui-tw/command/command.component';
|
|
8
11
|
import { isOptionGroup } from '@scaleflex/ui-tw/form';
|
|
9
12
|
import { PopoverContent, PopoverTrigger } from '@scaleflex/ui-tw/popover';
|
|
10
13
|
import { SelectSeparator, selectTriggerVariants } from '@scaleflex/ui-tw/select/select.component';
|
|
@@ -15,11 +18,11 @@ import { getToolbarSizes } from '@scaleflex/ui-tw/textarea/textarea.utils';
|
|
|
15
18
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
16
19
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
17
20
|
import { cva } from 'class-variance-authority';
|
|
18
|
-
import { ChevronsUpDownIcon, XIcon } from 'lucide-react';
|
|
21
|
+
import { ChevronDown, ChevronsUpDownIcon, XIcon } from 'lucide-react';
|
|
19
22
|
import * as React from 'react';
|
|
20
23
|
import { Fragment } from 'react';
|
|
21
24
|
import { iconSizeInTriggerOptions, verticalSeparatorNextToChevronOptions } from './combobox.constants';
|
|
22
|
-
import { createClearHandlers } from './combobox.utils';
|
|
25
|
+
import { createClearHandlers, getIconSize } from './combobox.utils';
|
|
23
26
|
var selectLabelVariants = cva('', {
|
|
24
27
|
variants: {
|
|
25
28
|
size: selectLabelSizeOptions
|
|
@@ -90,34 +93,123 @@ export function ComboboxTrigger(_ref2) {
|
|
|
90
93
|
})]))
|
|
91
94
|
}, /*#__PURE__*/React.createElement(XIcon, {
|
|
92
95
|
"data-clear-icon": true,
|
|
93
|
-
className: cn('
|
|
96
|
+
className: cn('text-muted-foreground/70 hover:text-muted-foreground shrink-0', iconSizeInTriggerOptions[size])
|
|
94
97
|
})), /*#__PURE__*/React.createElement("div", {
|
|
95
98
|
className: cn(verticalSeparatorNextToChevronOptions[size])
|
|
96
99
|
}, /*#__PURE__*/React.createElement(Separator, {
|
|
97
100
|
orientation: "vertical"
|
|
98
101
|
}))), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
99
|
-
className: cn('ml-1 shrink-0
|
|
102
|
+
className: cn('text-muted-foreground/70 ml-1 shrink-0', iconSizeInTriggerOptions[size])
|
|
100
103
|
}))));
|
|
101
104
|
}
|
|
102
|
-
export function
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
export function ComboboxCheckboxTrigger(_ref3) {
|
|
106
|
+
var children = _ref3.children,
|
|
107
|
+
open = _ref3.open,
|
|
108
|
+
label = _ref3.label,
|
|
109
|
+
_ref3$disabled = _ref3.disabled,
|
|
110
|
+
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled,
|
|
111
|
+
_ref3$readOnly = _ref3.readOnly,
|
|
112
|
+
readOnly = _ref3$readOnly === void 0 ? false : _ref3$readOnly,
|
|
106
113
|
_ref3$size = _ref3.size,
|
|
107
|
-
size = _ref3$size === void 0 ?
|
|
108
|
-
_ref3$multiple = _ref3.multiple,
|
|
109
|
-
multiple = _ref3$multiple === void 0 ? false : _ref3$multiple,
|
|
114
|
+
size = _ref3$size === void 0 ? FormSize.Md : _ref3$size,
|
|
110
115
|
className = _ref3.className,
|
|
111
|
-
_ref3$
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
_ref3$
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
_ref3$selected = _ref3.selected,
|
|
117
|
+
selected = _ref3$selected === void 0 ? false : _ref3$selected,
|
|
118
|
+
_ref3$showClear = _ref3.showClear,
|
|
119
|
+
showClear = _ref3$showClear === void 0 ? false : _ref3$showClear,
|
|
120
|
+
onClearAll = _ref3.onClearAll,
|
|
121
|
+
formItemId = _ref3.formItemId,
|
|
122
|
+
triggerProps = _ref3.triggerProps,
|
|
123
|
+
Icon = _ref3.icon,
|
|
124
|
+
iconClassName = _ref3.iconClassName,
|
|
125
|
+
optionsLength = _ref3.optionsLength,
|
|
126
|
+
selectedLength = _ref3.selectedLength,
|
|
127
|
+
onCheckboxClick = _ref3.onCheckboxClick,
|
|
128
|
+
toggleFirstOption = _ref3.toggleFirstOption,
|
|
129
|
+
_ref3$displayCount = _ref3.displayCount,
|
|
130
|
+
displayCount = _ref3$displayCount === void 0 ? false : _ref3$displayCount,
|
|
131
|
+
rest = _objectWithoutProperties(_ref3, _excluded2);
|
|
132
|
+
var _getToolbarSizes2 = getToolbarSizes(size),
|
|
133
|
+
iconSize = _getToolbarSizes2.iconSize;
|
|
134
|
+
var _createClearHandlers2 = createClearHandlers(onClearAll, optionsLength, toggleFirstOption),
|
|
135
|
+
handleOnTriggerClick = _createClearHandlers2.onClick,
|
|
136
|
+
handleOnTriggerKeyDown = _createClearHandlers2.onKeyDown;
|
|
137
|
+
var handleCheckboxKeyDown = function handleCheckboxKeyDown(event) {
|
|
138
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
onCheckboxClick === null || onCheckboxClick === void 0 || onCheckboxClick(event);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return /*#__PURE__*/React.createElement(PopoverTrigger, {
|
|
144
|
+
asChild: true
|
|
145
|
+
}, /*#__PURE__*/React.createElement("button", _extends({
|
|
146
|
+
id: formItemId,
|
|
147
|
+
role: "combobox",
|
|
148
|
+
"aria-expanded": open,
|
|
149
|
+
"aria-invalid": rest['aria-invalid'],
|
|
150
|
+
disabled: disabled,
|
|
151
|
+
className: cn.apply(void 0, _toConsumableArray(getBaseSelectClassNames()).concat(_toConsumableArray(getBaseInputClasses()), [selectTriggerVariants({
|
|
152
|
+
size: size
|
|
153
|
+
}), readOnly && selectReadOnlyClassNames, className, 'min-w-0'])),
|
|
154
|
+
onClick: handleOnTriggerClick,
|
|
155
|
+
onKeyDown: handleOnTriggerKeyDown
|
|
156
|
+
}, triggerProps), /*#__PURE__*/React.createElement(VisualCheckbox, {
|
|
157
|
+
size: size,
|
|
158
|
+
checked: !!selected,
|
|
159
|
+
partial: selectedLength !== optionsLength,
|
|
160
|
+
"aria-hidden": "true",
|
|
161
|
+
tabIndex: 0,
|
|
162
|
+
onClick: onCheckboxClick,
|
|
163
|
+
onKeyDown: handleCheckboxKeyDown
|
|
164
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
165
|
+
className: "flex min-w-0 grow items-center gap-2"
|
|
166
|
+
}, Icon && /*#__PURE__*/React.createElement(Icon, {
|
|
167
|
+
className: cn('text-muted-foreground hover:text-primary shrink-0', getIconSize(size), selected && 'text-primary', disabled && 'opacity-50', iconClassName)
|
|
168
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
169
|
+
className: cn('truncate font-normal', !label && selectedLength === 0 && 'text-muted-foreground')
|
|
170
|
+
}, label || children), displayCount && selectedLength > 0 && optionsLength > 1 && /*#__PURE__*/React.createElement("span", {
|
|
171
|
+
className: "text-muted-foreground text-sm"
|
|
172
|
+
}, selectedLength, "/", optionsLength)), /*#__PURE__*/React.createElement("div", {
|
|
173
|
+
className: "ml-2 flex items-center gap-1 pl-1"
|
|
174
|
+
}, showClear && !!onClearAll && selected && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
175
|
+
role: "button",
|
|
176
|
+
tabIndex: 0,
|
|
177
|
+
"data-clear-icon": "true",
|
|
178
|
+
"aria-label": "Clear all",
|
|
179
|
+
className: cn.apply(void 0, _toConsumableArray(buttonBaseClassNames).concat([focusRingClassNames, buttonVariants({
|
|
180
|
+
size: iconSize,
|
|
181
|
+
variant: ButtonVariant.GhostSecondary
|
|
182
|
+
}), optionsLength === 1 && '-mr-2']))
|
|
183
|
+
}, /*#__PURE__*/React.createElement(XIcon, {
|
|
184
|
+
"data-clear-icon": true,
|
|
185
|
+
className: cn('text-muted-foreground/70 hover:text-muted-foreground shrink-0', iconSizeInTriggerOptions[size])
|
|
186
|
+
})), optionsLength !== 1 && /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
className: cn(verticalSeparatorNextToChevronOptions[size])
|
|
188
|
+
}, /*#__PURE__*/React.createElement(Separator, {
|
|
189
|
+
orientation: "vertical"
|
|
190
|
+
}))), optionsLength !== 1 && /*#__PURE__*/React.createElement(ChevronDown, {
|
|
191
|
+
className: cn('text-muted-foreground/70 ml-1 shrink-0', iconSizeInTriggerOptions[size])
|
|
192
|
+
}))));
|
|
193
|
+
}
|
|
194
|
+
export function ComboboxContent(_ref4) {
|
|
195
|
+
var options = _ref4.options,
|
|
196
|
+
selectedValue = _ref4.value,
|
|
197
|
+
_onSelect = _ref4.onSelect,
|
|
198
|
+
_ref4$size = _ref4.size,
|
|
199
|
+
size = _ref4$size === void 0 ? 'md' : _ref4$size,
|
|
200
|
+
_ref4$multiple = _ref4.multiple,
|
|
201
|
+
multiple = _ref4$multiple === void 0 ? false : _ref4$multiple,
|
|
202
|
+
className = _ref4.className,
|
|
203
|
+
_ref4$showGroupSepara = _ref4.showGroupSeparator,
|
|
204
|
+
showGroupSeparator = _ref4$showGroupSepara === void 0 ? false : _ref4$showGroupSepara,
|
|
205
|
+
popoverContentProps = _ref4.popoverContentProps,
|
|
206
|
+
_ref4$searchPlacehold = _ref4.searchPlaceholder,
|
|
207
|
+
searchPlaceholder = _ref4$searchPlacehold === void 0 ? 'Search...' : _ref4$searchPlacehold,
|
|
208
|
+
_ref4$noGroupSelectio = _ref4.noGroupSelection,
|
|
209
|
+
noGroupSelection = _ref4$noGroupSelectio === void 0 ? false : _ref4$noGroupSelectio,
|
|
210
|
+
actions = _ref4.actions,
|
|
211
|
+
_ref4$fixedActions = _ref4.fixedActions,
|
|
212
|
+
fixedActions = _ref4$fixedActions === void 0 ? false : _ref4$fixedActions;
|
|
121
213
|
return /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
122
214
|
className: cn('p-0', className)
|
|
123
215
|
}, popoverContentProps), /*#__PURE__*/React.createElement(Command, null, /*#__PURE__*/React.createElement(CommandInput, {
|
|
@@ -147,14 +239,14 @@ export function ComboboxContent(_ref3) {
|
|
|
147
239
|
className: cn('text-secondary-foreground', selectLabelVariants({
|
|
148
240
|
size: size
|
|
149
241
|
}))
|
|
150
|
-
}, option.label), option.options.map(function (
|
|
151
|
-
var label =
|
|
152
|
-
optionLabel =
|
|
153
|
-
value =
|
|
154
|
-
disabled =
|
|
155
|
-
icon =
|
|
156
|
-
tooltip =
|
|
157
|
-
disabledTooltip =
|
|
242
|
+
}, option.label), option.options.map(function (_ref5) {
|
|
243
|
+
var label = _ref5.label,
|
|
244
|
+
optionLabel = _ref5.optionLabel,
|
|
245
|
+
value = _ref5.value,
|
|
246
|
+
disabled = _ref5.disabled,
|
|
247
|
+
icon = _ref5.icon,
|
|
248
|
+
tooltip = _ref5.tooltip,
|
|
249
|
+
disabledTooltip = _ref5.disabledTooltip;
|
|
158
250
|
var isGroupSelected = !noGroupSelection && multiple && option.value && Array.isArray(selectedValue) && selectedValue.includes(option.value);
|
|
159
251
|
return /*#__PURE__*/React.createElement(CommandItem, {
|
|
160
252
|
size: size,
|
|
@@ -194,4 +286,93 @@ export function ComboboxContent(_ref3) {
|
|
|
194
286
|
})), fixedActions && /*#__PURE__*/React.createElement(SelectActions, {
|
|
195
287
|
actions: actions
|
|
196
288
|
})));
|
|
289
|
+
}
|
|
290
|
+
export function ComboboxCheckboxContent(_ref6) {
|
|
291
|
+
var options = _ref6.options,
|
|
292
|
+
selectedValue = _ref6.value,
|
|
293
|
+
_onSelect2 = _ref6.onSelect,
|
|
294
|
+
_ref6$size = _ref6.size,
|
|
295
|
+
size = _ref6$size === void 0 ? 'md' : _ref6$size,
|
|
296
|
+
className = _ref6.className,
|
|
297
|
+
_ref6$showGroupSepara = _ref6.showGroupSeparator,
|
|
298
|
+
showGroupSeparator = _ref6$showGroupSepara === void 0 ? false : _ref6$showGroupSepara,
|
|
299
|
+
popoverContentProps = _ref6.popoverContentProps,
|
|
300
|
+
_ref6$searchPlacehold = _ref6.searchPlaceholder,
|
|
301
|
+
searchPlaceholder = _ref6$searchPlacehold === void 0 ? 'Search...' : _ref6$searchPlacehold,
|
|
302
|
+
actions = _ref6.actions,
|
|
303
|
+
_ref6$fixedActions = _ref6.fixedActions,
|
|
304
|
+
fixedActions = _ref6$fixedActions === void 0 ? false : _ref6$fixedActions;
|
|
305
|
+
return /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
306
|
+
className: cn('p-0', className)
|
|
307
|
+
}, popoverContentProps), /*#__PURE__*/React.createElement(Command, null, /*#__PURE__*/React.createElement(CommandInput, {
|
|
308
|
+
size: size,
|
|
309
|
+
placeholder: searchPlaceholder
|
|
310
|
+
}), /*#__PURE__*/React.createElement(CommandList, null, /*#__PURE__*/React.createElement(CommandEmpty, null, "No results found."), options === null || options === void 0 ? void 0 : options.map(function (option, groupIndex) {
|
|
311
|
+
var _option$optionLabel2;
|
|
312
|
+
if (isOptionGroup(option)) {
|
|
313
|
+
return /*#__PURE__*/React.createElement(CommandGroup, {
|
|
314
|
+
key: groupIndex,
|
|
315
|
+
heading: !option.value ? option.label : undefined,
|
|
316
|
+
size: size
|
|
317
|
+
}, option.value && /*#__PURE__*/React.createElement(CommandCheckboxItem, {
|
|
318
|
+
size: size,
|
|
319
|
+
disabled: option.disabled,
|
|
320
|
+
key: option.value,
|
|
321
|
+
icon: option.icon,
|
|
322
|
+
value: option.value,
|
|
323
|
+
tooltip: option.tooltip,
|
|
324
|
+
disabledTooltip: option.disabledTooltip,
|
|
325
|
+
isGroup: true,
|
|
326
|
+
selectedValue: selectedValue,
|
|
327
|
+
onSelect: function onSelect() {
|
|
328
|
+
return _onSelect2(option.value);
|
|
329
|
+
},
|
|
330
|
+
className: cn('text-secondary-foreground', selectLabelVariants({
|
|
331
|
+
size: size
|
|
332
|
+
}))
|
|
333
|
+
}, option.label), option.options.map(function (_ref7) {
|
|
334
|
+
var label = _ref7.label,
|
|
335
|
+
optionLabel = _ref7.optionLabel,
|
|
336
|
+
value = _ref7.value,
|
|
337
|
+
disabled = _ref7.disabled,
|
|
338
|
+
icon = _ref7.icon,
|
|
339
|
+
tooltip = _ref7.tooltip,
|
|
340
|
+
disabledTooltip = _ref7.disabledTooltip;
|
|
341
|
+
var isGroupSelected = option.value && Array.isArray(selectedValue) && selectedValue.includes(option.value);
|
|
342
|
+
return /*#__PURE__*/React.createElement(CommandCheckboxItem, {
|
|
343
|
+
size: size,
|
|
344
|
+
disabled: disabled || !!isGroupSelected,
|
|
345
|
+
key: value,
|
|
346
|
+
icon: icon,
|
|
347
|
+
value: value,
|
|
348
|
+
tooltip: tooltip,
|
|
349
|
+
disabledTooltip: disabledTooltip,
|
|
350
|
+
isGroup: !!option.label,
|
|
351
|
+
selectedValue: selectedValue,
|
|
352
|
+
onSelect: function onSelect() {
|
|
353
|
+
return _onSelect2(value);
|
|
354
|
+
}
|
|
355
|
+
}, optionLabel !== null && optionLabel !== void 0 ? optionLabel : label);
|
|
356
|
+
}), showGroupSeparator && groupIndex !== options.length - 1 && /*#__PURE__*/React.createElement(SelectSeparator, null));
|
|
357
|
+
}
|
|
358
|
+
return /*#__PURE__*/React.createElement(CommandGroup, {
|
|
359
|
+
key: "default"
|
|
360
|
+
}, /*#__PURE__*/React.createElement(CommandCheckboxItem, {
|
|
361
|
+
size: size,
|
|
362
|
+
disabled: option.disabled,
|
|
363
|
+
key: option.value,
|
|
364
|
+
icon: option.icon,
|
|
365
|
+
value: option.value,
|
|
366
|
+
tooltip: option.tooltip,
|
|
367
|
+
disabledTooltip: option.disabledTooltip,
|
|
368
|
+
selectedValue: selectedValue,
|
|
369
|
+
onSelect: function onSelect() {
|
|
370
|
+
return _onSelect2(option.value);
|
|
371
|
+
}
|
|
372
|
+
}, (_option$optionLabel2 = option.optionLabel) !== null && _option$optionLabel2 !== void 0 ? _option$optionLabel2 : option.label));
|
|
373
|
+
}), !fixedActions && /*#__PURE__*/React.createElement(SelectActions, {
|
|
374
|
+
actions: actions
|
|
375
|
+
})), fixedActions && /*#__PURE__*/React.createElement(SelectActions, {
|
|
376
|
+
actions: actions
|
|
377
|
+
})));
|
|
197
378
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
3
3
|
export var verticalSeparatorNextToChevronOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'h-4'), FormSize.Md, 'h-5'), FormSize.Lg, 'h-6');
|
|
4
|
-
export var iconSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'size-
|
|
4
|
+
export var iconSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'size-4'), FormSize.Md, 'size-4'), FormSize.Lg, 'size-5');
|
|
5
5
|
export var comboboxMultiTagsDefaultSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'min-h-8 h-8'), FormSize.Md, 'min-h-10 h-10'), FormSize.Lg, 'min-h-12 h-12');
|
|
@@ -2,7 +2,7 @@ import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
|
2
2
|
import { SelectOption } from '@scaleflex/ui-tw/form';
|
|
3
3
|
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
4
4
|
import { Command as CommandPrimitive } from 'cmdk';
|
|
5
|
-
import type { ButtonHTMLAttributes, ComponentProps, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
5
|
+
import type { ButtonHTMLAttributes, ComponentProps, ElementType, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
6
6
|
export type ClearEvent = MouseEvent | KeyboardEvent;
|
|
7
7
|
export type SelectActionsProps = {
|
|
8
8
|
actions?: ReactNode[];
|
|
@@ -21,6 +21,16 @@ export type ComboboxTriggerProps = {
|
|
|
21
21
|
onClearAll?: () => void;
|
|
22
22
|
triggerProps?: ButtonHTMLAttributes<HTMLButtonElement>;
|
|
23
23
|
};
|
|
24
|
+
export type ComboboxCheckboxTriggerProps = ComboboxTriggerProps & {
|
|
25
|
+
optionsLength: number;
|
|
26
|
+
selectedLength: number;
|
|
27
|
+
label?: ReactNode | string;
|
|
28
|
+
displayCount?: boolean;
|
|
29
|
+
icon?: ElementType;
|
|
30
|
+
iconClassName?: string;
|
|
31
|
+
onCheckboxClick?: (event: MouseEvent<HTMLDivElement> | KeyboardEvent<HTMLDivElement>) => void;
|
|
32
|
+
toggleFirstOption?: () => void;
|
|
33
|
+
};
|
|
24
34
|
export type ComboboxContentProps = {
|
|
25
35
|
options: SelectOption[];
|
|
26
36
|
value: string | string[];
|
|
@@ -83,6 +93,16 @@ export interface ComboboxMultiInlineProps extends ComboboxCommonProps {
|
|
|
83
93
|
onBlur?: (value: string[]) => void;
|
|
84
94
|
showClear?: boolean;
|
|
85
95
|
}
|
|
96
|
+
export interface ComboboxMultiCheckboxProps extends ComboboxCommonProps {
|
|
97
|
+
value: string[];
|
|
98
|
+
onChange: (value: string[]) => void;
|
|
99
|
+
label?: ReactElement | string;
|
|
100
|
+
displayCount?: boolean;
|
|
101
|
+
iconClassName?: string;
|
|
102
|
+
icon?: ElementType;
|
|
103
|
+
onBlur?: (value: string[]) => void;
|
|
104
|
+
showClear?: boolean;
|
|
105
|
+
}
|
|
86
106
|
export interface ComboboxMultiTagProps extends ComboboxCommonProps {
|
|
87
107
|
value: string[];
|
|
88
108
|
onChange: (value: string[]) => void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FlatOption, SelectOption } from '@scaleflex/ui-tw/form';
|
|
2
|
+
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
2
3
|
import { KeyboardEvent, MouseEvent } from 'react';
|
|
3
4
|
export declare const flattenOptions: (options: SelectOption[]) => FlatOption[];
|
|
4
|
-
export declare const createClearHandlers: (onClearAll?: () => void) => {
|
|
5
|
+
export declare const createClearHandlers: (onClearAll?: () => void, optionsLength?: number, toggleFirstOption?: () => void) => {
|
|
5
6
|
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
6
7
|
onKeyDown: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
7
8
|
};
|
|
9
|
+
export declare const getIconSize: (size: FormSizeType) => string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isOptionGroup } from '@scaleflex/ui-tw/form';
|
|
2
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
2
3
|
export var flattenOptions = function flattenOptions(options) {
|
|
3
4
|
return options.flatMap(function (option) {
|
|
4
5
|
return isOptionGroup(option) ? option.options : [option];
|
|
@@ -8,13 +9,19 @@ function isClearIconEvent(event) {
|
|
|
8
9
|
var target = event.type === 'keydown' ? document.activeElement : event.target;
|
|
9
10
|
return !!target.closest('[data-clear-icon]');
|
|
10
11
|
}
|
|
11
|
-
export var createClearHandlers = function createClearHandlers(onClearAll) {
|
|
12
|
+
export var createClearHandlers = function createClearHandlers(onClearAll, optionsLength, toggleFirstOption) {
|
|
12
13
|
return {
|
|
13
14
|
onClick: function onClick(e) {
|
|
14
15
|
if (isClearIconEvent(e)) {
|
|
15
16
|
e.stopPropagation();
|
|
16
17
|
e.preventDefault();
|
|
17
18
|
onClearAll === null || onClearAll === void 0 || onClearAll();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (optionsLength === 1 && toggleFirstOption) {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
toggleFirstOption();
|
|
18
25
|
}
|
|
19
26
|
},
|
|
20
27
|
onKeyDown: function onKeyDown(e) {
|
|
@@ -22,7 +29,26 @@ export var createClearHandlers = function createClearHandlers(onClearAll) {
|
|
|
22
29
|
e.stopPropagation();
|
|
23
30
|
e.preventDefault();
|
|
24
31
|
onClearAll === null || onClearAll === void 0 || onClearAll();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (optionsLength === 1 && toggleFirstOption) {
|
|
35
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
toggleFirstOption();
|
|
39
|
+
}
|
|
25
40
|
}
|
|
26
41
|
}
|
|
27
42
|
};
|
|
43
|
+
};
|
|
44
|
+
export var getIconSize = function getIconSize(size) {
|
|
45
|
+
switch (size) {
|
|
46
|
+
case FormSize.Lg:
|
|
47
|
+
return 'size-6 ml-2';
|
|
48
|
+
case FormSize.Sm:
|
|
49
|
+
return 'size-4 ml-1';
|
|
50
|
+
case FormSize.Md:
|
|
51
|
+
default:
|
|
52
|
+
return 'size-5 ml-1.5';
|
|
53
|
+
}
|
|
28
54
|
};
|
package/combobox/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { ComboboxTrigger, ComboboxContent } from './combobox.component';
|
|
|
2
2
|
export { ComboboxSingle } from './combobox-single/combobox-single.component';
|
|
3
3
|
export { ComboboxMultiInline } from './combobox-multi-inline/combobox-multi-inline.component';
|
|
4
4
|
export { ComboboxMultiTag } from './combobox-multi-tag/combobox-multi-tag.component';
|
|
5
|
+
export { ComboboxMultiCheckbox } from './combobox-multi-checkbox/combobox-multi-checkbox.component';
|
|
5
6
|
export { flattenOptions } from './combobox.utils';
|
package/combobox/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { ComboboxTrigger, ComboboxContent } from './combobox.component';
|
|
|
2
2
|
export { ComboboxSingle } from './combobox-single/combobox-single.component';
|
|
3
3
|
export { ComboboxMultiInline } from './combobox-multi-inline/combobox-multi-inline.component';
|
|
4
4
|
export { ComboboxMultiTag } from './combobox-multi-tag/combobox-multi-tag.component';
|
|
5
|
+
export { ComboboxMultiCheckbox } from './combobox-multi-checkbox/combobox-multi-checkbox.component';
|
|
5
6
|
export { flattenOptions } from './combobox.utils';
|
|
@@ -14,5 +14,6 @@ declare function CommandEmpty({ className, ...rest }: ComponentProps<typeof Comm
|
|
|
14
14
|
declare function CommandGroup({ className, size, ...props }: CommandGroupProps): React.JSX.Element;
|
|
15
15
|
declare function CommandSeparator({ className, ...props }: ComponentProps<typeof CommandPrimitive.Separator>): React.JSX.Element;
|
|
16
16
|
declare function CommandItem({ className, size, isGroup, icon, tooltip, children, selectedValue, multiple, value, shortcut, disabledTooltip, disabled, ...props }: CommandItemProps): React.JSX.Element;
|
|
17
|
+
declare function CommandCheckboxItem({ className, size, isGroup, children, selectedValue, value, icon, disabled, tooltip, disabledTooltip, ...props }: CommandItemProps): React.JSX.Element;
|
|
17
18
|
declare function CommandShortcut({ className, ...props }: ComponentProps<'span'>): React.JSX.Element;
|
|
18
|
-
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator, };
|
|
19
|
+
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandCheckboxItem, CommandShortcut, CommandSeparator, };
|
|
@@ -8,7 +8,9 @@ var _excluded = ["className"],
|
|
|
8
8
|
_excluded6 = ["className", "size"],
|
|
9
9
|
_excluded7 = ["className"],
|
|
10
10
|
_excluded8 = ["className", "size", "isGroup", "icon", "tooltip", "children", "selectedValue", "multiple", "value", "shortcut", "disabledTooltip", "disabled"],
|
|
11
|
-
_excluded9 = ["className"]
|
|
11
|
+
_excluded9 = ["className", "size", "isGroup", "children", "selectedValue", "value", "icon", "disabled", "tooltip", "disabledTooltip"],
|
|
12
|
+
_excluded10 = ["className"];
|
|
13
|
+
import { Checkbox } from '@scaleflex/ui-tw/checkbox';
|
|
12
14
|
import { Dialog, DialogFormDescription, DialogFormHeader, DialogFormTitle, DialogWideContent } from '@scaleflex/ui-tw/dialog';
|
|
13
15
|
import { LabelIcon } from '@scaleflex/ui-tw/label/components/label-icon';
|
|
14
16
|
import { SelectIcon } from '@scaleflex/ui-tw/select/components/select-icon';
|
|
@@ -150,12 +152,52 @@ function CommandItem(_ref8) {
|
|
|
150
152
|
className: cn('text-primary ml-auto h-4 w-4', selected ? 'opacity-100' : 'opacity-0')
|
|
151
153
|
})));
|
|
152
154
|
}
|
|
153
|
-
function
|
|
155
|
+
function CommandCheckboxItem(_ref9) {
|
|
154
156
|
var className = _ref9.className,
|
|
157
|
+
size = _ref9.size,
|
|
158
|
+
isGroup = _ref9.isGroup,
|
|
159
|
+
children = _ref9.children,
|
|
160
|
+
selectedValue = _ref9.selectedValue,
|
|
161
|
+
value = _ref9.value,
|
|
162
|
+
icon = _ref9.icon,
|
|
163
|
+
disabled = _ref9.disabled,
|
|
164
|
+
tooltip = _ref9.tooltip,
|
|
165
|
+
disabledTooltip = _ref9.disabledTooltip,
|
|
155
166
|
props = _objectWithoutProperties(_ref9, _excluded9);
|
|
167
|
+
var selected = value && (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.includes(value));
|
|
168
|
+
return /*#__PURE__*/React.createElement(CommandPrimitive.Item, _extends({
|
|
169
|
+
"data-slot": "command-checkbox-item",
|
|
170
|
+
className: cn('relative flex w-full cursor-pointer items-center gap-3 outline-none select-none', 'data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground', '!opacity-100 data-[disabled=true]:cursor-not-allowed', selectItemVariants({
|
|
171
|
+
size: size
|
|
172
|
+
}), isGroup && getOptionInGroupPaddingLeft(size), className),
|
|
173
|
+
disabled: disabled
|
|
174
|
+
}, props), /*#__PURE__*/React.createElement(Checkbox, {
|
|
175
|
+
size: size,
|
|
176
|
+
checked: !!selected,
|
|
177
|
+
"aria-hidden": "true",
|
|
178
|
+
tabIndex: -1,
|
|
179
|
+
className: "pointer-events-none"
|
|
180
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
className: "flex items-center gap-1 overflow-hidden"
|
|
182
|
+
}, icon && /*#__PURE__*/React.createElement(SelectIcon, {
|
|
183
|
+
size: size,
|
|
184
|
+
icon: icon,
|
|
185
|
+
className: cn('text-muted-foreground hover:text-primary !mr-1 shrink-0', selected && 'text-primary', disabled && 'opacity-50')
|
|
186
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
className: cn('line-clamp-2 overflow-hidden text-left break-words text-ellipsis', disabled && 'opacity-50')
|
|
188
|
+
}, children), (tooltip || disabledTooltip) && /*#__PURE__*/React.createElement("div", {
|
|
189
|
+
className: "flex shrink-0 items-center"
|
|
190
|
+
}, /*#__PURE__*/React.createElement(LabelIcon, {
|
|
191
|
+
size: size,
|
|
192
|
+
tooltip: disabled ? disabledTooltip : tooltip
|
|
193
|
+
}))));
|
|
194
|
+
}
|
|
195
|
+
function CommandShortcut(_ref10) {
|
|
196
|
+
var className = _ref10.className,
|
|
197
|
+
props = _objectWithoutProperties(_ref10, _excluded10);
|
|
156
198
|
return /*#__PURE__*/React.createElement("span", _extends({
|
|
157
199
|
"data-slot": "command-shortcut",
|
|
158
200
|
className: cn('text-muted-foreground ml-auto text-xs tracking-widest', className)
|
|
159
201
|
}, props));
|
|
160
202
|
}
|
|
161
|
-
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator };
|
|
203
|
+
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandCheckboxItem, CommandShortcut, CommandSeparator };
|
|
@@ -66,7 +66,7 @@ function DialogWideContent(_ref6) {
|
|
|
66
66
|
}, props), children, /*#__PURE__*/React.createElement(DialogPrimitive.Close, {
|
|
67
67
|
"data-state": "open",
|
|
68
68
|
asChild: true,
|
|
69
|
-
className: cn('text-muted-foreground absolute top-3 right-3 cursor-pointer rounded-xs
|
|
69
|
+
className: cn('text-muted-foreground/70 hover:text-muted-foreground absolute top-3 right-3 cursor-pointer rounded-xs transition-opacity disabled:pointer-events-none', "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-6", focusRingClassNames)
|
|
70
70
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
71
71
|
variant: "ghost-secondary",
|
|
72
72
|
size: "icon-md"
|
|
@@ -86,7 +86,7 @@ function DialogFormContent(_ref7) {
|
|
|
86
86
|
}, props), children, /*#__PURE__*/React.createElement(DialogPrimitive.Close, {
|
|
87
87
|
"data-state": "open",
|
|
88
88
|
asChild: true,
|
|
89
|
-
className: cn('text-muted-foreground absolute top-3 right-3 cursor-pointer rounded-xs
|
|
89
|
+
className: cn('text-muted-foreground/70 hover:text-muted-foreground absolute top-3 right-3 cursor-pointer rounded-xs transition-opacity disabled:pointer-events-none', "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-6", focusRingClassNames)
|
|
90
90
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
91
91
|
variant: "ghost-secondary",
|
|
92
92
|
size: "icon-md"
|
|
@@ -180,9 +180,9 @@ export function InputTags(_ref) {
|
|
|
180
180
|
onGenerateTags === null || onGenerateTags === void 0 || onGenerateTags();
|
|
181
181
|
}
|
|
182
182
|
}, generateLabel)), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
183
|
-
className: cn('mr-1.5 ml-auto shrink-0
|
|
183
|
+
className: cn('text-muted-foreground/70 mr-1.5 ml-auto shrink-0', iconSizeInTriggerOptions[size])
|
|
184
184
|
})) : /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
185
|
-
className: cn('my-auto mr-1.5 ml-auto shrink-0
|
|
185
|
+
className: cn('text-muted-foreground/70 my-auto mr-1.5 ml-auto shrink-0', iconSizeInTriggerOptions[size])
|
|
186
186
|
})))), /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
187
187
|
className: cn('w-[--radix-popover-trigger-width] p-0', popoverClassName)
|
|
188
188
|
}, popoverContentProps), /*#__PURE__*/React.createElement(Command, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"author": "scaleflex",
|
|
5
5
|
"repository": "github:scaleflex/ui",
|
|
6
6
|
"homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@radix-ui/react-slot": "^1.1.2",
|
|
24
24
|
"@radix-ui/react-switch": "^1.0.1",
|
|
25
25
|
"@radix-ui/react-tooltip": "^1.2.6",
|
|
26
|
-
"@scaleflex/icons-tw": "^0.0.
|
|
26
|
+
"@scaleflex/icons-tw": "^0.0.63",
|
|
27
27
|
"@tanstack/react-table": "^8.21.3",
|
|
28
28
|
"@types/lodash.merge": "^4.6.9",
|
|
29
29
|
"class-variance-authority": "^0.7.1",
|
|
@@ -65,6 +65,6 @@ export function Search(_ref) {
|
|
|
65
65
|
}), 'absolute top-1/2 right-2 -translate-y-1/2']))
|
|
66
66
|
}, /*#__PURE__*/React.createElement(XIcon, {
|
|
67
67
|
"data-clear-icon": true,
|
|
68
|
-
className: cn('
|
|
68
|
+
className: cn('text-muted-foreground/70 hover:text-muted-foreground shrink-0')
|
|
69
69
|
})));
|
|
70
70
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SelectIconProps } from '@scaleflex/ui-tw/select/select.types';
|
|
2
2
|
export declare const SelectIcon: (props: SelectIconProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
@@ -89,7 +89,7 @@ function SelectTrigger(_ref4) {
|
|
|
89
89
|
}, children)), /*#__PURE__*/React.createElement(SelectPrimitive.Icon, {
|
|
90
90
|
asChild: true
|
|
91
91
|
}, /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
92
|
-
className: cn('
|
|
92
|
+
className: cn('text-muted-foreground/70', size === FormSize.Lg ? 'size-5' : 'size-4.5')
|
|
93
93
|
})));
|
|
94
94
|
}
|
|
95
95
|
function SelectContent(_ref5) {
|
|
@@ -165,7 +165,7 @@ function SelectScrollUpButton(_ref9) {
|
|
|
165
165
|
"data-slot": "select-scroll-up-button",
|
|
166
166
|
className: cn('flex cursor-default items-center justify-center py-1', className)
|
|
167
167
|
}, props), /*#__PURE__*/React.createElement(ChevronUpIcon, {
|
|
168
|
-
className: "size-4"
|
|
168
|
+
className: "text-muted-foreground/70 size-4"
|
|
169
169
|
}));
|
|
170
170
|
}
|
|
171
171
|
function SelectScrollDownButton(_ref10) {
|
|
@@ -175,7 +175,7 @@ function SelectScrollDownButton(_ref10) {
|
|
|
175
175
|
"data-slot": "select-scroll-down-button",
|
|
176
176
|
className: cn('flex cursor-default items-center justify-center py-1', className)
|
|
177
177
|
}, props), /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
178
|
-
className: "size-4"
|
|
178
|
+
className: "text-muted-foreground/70 size-4"
|
|
179
179
|
}));
|
|
180
180
|
}
|
|
181
181
|
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue };
|
package/select/select.types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
2
2
|
import { SelectOption } from '@scaleflex/ui-tw/form';
|
|
3
3
|
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
4
|
-
import type { ComponentProps, ReactElement, ReactNode } from 'react';
|
|
4
|
+
import type { ComponentProps, ElementType, ReactElement, ReactNode } from 'react';
|
|
5
5
|
export interface SelectProps extends ComponentProps<typeof SelectPrimitive.Root> {
|
|
6
6
|
}
|
|
7
7
|
export interface SelectTriggerProps extends ComponentProps<typeof SelectPrimitive.Trigger> {
|
|
@@ -22,6 +22,9 @@ export interface SelectLabelProps extends ComponentProps<typeof SelectPrimitive.
|
|
|
22
22
|
}
|
|
23
23
|
export interface SelectIconProps extends ComponentProps<'span'>, Pick<SelectTriggerProps, 'size' | 'icon'> {
|
|
24
24
|
}
|
|
25
|
+
export interface SelectIconElementProps extends ComponentProps<'svg'>, Pick<SelectTriggerProps, 'size'> {
|
|
26
|
+
icon: ElementType;
|
|
27
|
+
}
|
|
25
28
|
export interface SelectorProps extends SelectProps {
|
|
26
29
|
options: SelectOption[];
|
|
27
30
|
value?: string;
|