@scaleflex/ui-tw 0.0.62 → 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/combobox/combobox-multi-checkbox/combobox-multi-checkbox.component.js +12 -1
- package/combobox/combobox.component.d.ts +1 -1
- package/combobox/combobox.component.js +6 -5
- package/combobox/combobox.constants.js +1 -1
- package/combobox/combobox.types.d.ts +1 -0
- package/combobox/combobox.utils.d.ts +1 -1
- package/combobox/combobox.utils.js +15 -1
- package/package.json +2 -2
|
@@ -156,6 +156,16 @@ export function ComboboxMultiCheckbox(_ref) {
|
|
|
156
156
|
onChange([]);
|
|
157
157
|
}
|
|
158
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
|
+
};
|
|
159
169
|
return /*#__PURE__*/React.createElement(Popover, {
|
|
160
170
|
open: open,
|
|
161
171
|
defaultOpen: defaultOpen,
|
|
@@ -178,7 +188,8 @@ export function ComboboxMultiCheckbox(_ref) {
|
|
|
178
188
|
optionsLength: options.length,
|
|
179
189
|
displayCount: displayCount,
|
|
180
190
|
selectedLength: selectedLabels.length,
|
|
181
|
-
onCheckboxClick: handleCheckboxClick
|
|
191
|
+
onCheckboxClick: handleCheckboxClick,
|
|
192
|
+
toggleFirstOption: toggleFirstOption
|
|
182
193
|
}, displayValue), /*#__PURE__*/React.createElement(ComboboxCheckboxContent, {
|
|
183
194
|
showGroupSeparator: showGroupSeparator,
|
|
184
195
|
searchPlaceholder: searchPlaceholder,
|
|
@@ -2,6 +2,6 @@ import * as React from 'react';
|
|
|
2
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, displayCount, ...rest }: ComboboxCheckboxTriggerProps): 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;
|
|
6
6
|
export declare function ComboboxContent({ options, value: selectedValue, onSelect, size, multiple, className, showGroupSeparator, popoverContentProps, searchPlaceholder, noGroupSelection, actions, fixedActions, }: ComboboxContentProps): React.JSX.Element;
|
|
7
7
|
export declare function ComboboxCheckboxContent({ options, value: selectedValue, onSelect, size, className, showGroupSeparator, popoverContentProps, searchPlaceholder, actions, fixedActions, }: ComboboxContentProps): React.JSX.Element;
|
|
@@ -2,7 +2,7 @@ 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
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", "displayCount"];
|
|
5
|
+
_excluded2 = ["children", "open", "label", "disabled", "readOnly", "size", "className", "selected", "showClear", "onClearAll", "formItemId", "triggerProps", "icon", "iconClassName", "optionsLength", "selectedLength", "onCheckboxClick", "toggleFirstOption", "displayCount"];
|
|
6
6
|
import { buttonVariants } from '@scaleflex/ui-tw/button';
|
|
7
7
|
import { ButtonVariant, buttonBaseClassNames } from '@scaleflex/ui-tw/button/button.constants';
|
|
8
8
|
import { VisualCheckbox } from '@scaleflex/ui-tw/checkbox/checkbox.component';
|
|
@@ -125,12 +125,13 @@ export function ComboboxCheckboxTrigger(_ref3) {
|
|
|
125
125
|
optionsLength = _ref3.optionsLength,
|
|
126
126
|
selectedLength = _ref3.selectedLength,
|
|
127
127
|
onCheckboxClick = _ref3.onCheckboxClick,
|
|
128
|
+
toggleFirstOption = _ref3.toggleFirstOption,
|
|
128
129
|
_ref3$displayCount = _ref3.displayCount,
|
|
129
130
|
displayCount = _ref3$displayCount === void 0 ? false : _ref3$displayCount,
|
|
130
131
|
rest = _objectWithoutProperties(_ref3, _excluded2);
|
|
131
132
|
var _getToolbarSizes2 = getToolbarSizes(size),
|
|
132
133
|
iconSize = _getToolbarSizes2.iconSize;
|
|
133
|
-
var _createClearHandlers2 = createClearHandlers(onClearAll),
|
|
134
|
+
var _createClearHandlers2 = createClearHandlers(onClearAll, optionsLength, toggleFirstOption),
|
|
134
135
|
handleOnTriggerClick = _createClearHandlers2.onClick,
|
|
135
136
|
handleOnTriggerKeyDown = _createClearHandlers2.onKeyDown;
|
|
136
137
|
var handleCheckboxKeyDown = function handleCheckboxKeyDown(event) {
|
|
@@ -178,15 +179,15 @@ export function ComboboxCheckboxTrigger(_ref3) {
|
|
|
178
179
|
className: cn.apply(void 0, _toConsumableArray(buttonBaseClassNames).concat([focusRingClassNames, buttonVariants({
|
|
179
180
|
size: iconSize,
|
|
180
181
|
variant: ButtonVariant.GhostSecondary
|
|
181
|
-
})]))
|
|
182
|
+
}), optionsLength === 1 && '-mr-2']))
|
|
182
183
|
}, /*#__PURE__*/React.createElement(XIcon, {
|
|
183
184
|
"data-clear-icon": true,
|
|
184
185
|
className: cn('text-muted-foreground/70 hover:text-muted-foreground shrink-0', iconSizeInTriggerOptions[size])
|
|
185
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
186
|
+
})), optionsLength !== 1 && /*#__PURE__*/React.createElement("div", {
|
|
186
187
|
className: cn(verticalSeparatorNextToChevronOptions[size])
|
|
187
188
|
}, /*#__PURE__*/React.createElement(Separator, {
|
|
188
189
|
orientation: "vertical"
|
|
189
|
-
}))), /*#__PURE__*/React.createElement(ChevronDown, {
|
|
190
|
+
}))), optionsLength !== 1 && /*#__PURE__*/React.createElement(ChevronDown, {
|
|
190
191
|
className: cn('text-muted-foreground/70 ml-1 shrink-0', iconSizeInTriggerOptions[size])
|
|
191
192
|
}))));
|
|
192
193
|
}
|
|
@@ -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');
|
|
@@ -29,6 +29,7 @@ export type ComboboxCheckboxTriggerProps = ComboboxTriggerProps & {
|
|
|
29
29
|
icon?: ElementType;
|
|
30
30
|
iconClassName?: string;
|
|
31
31
|
onCheckboxClick?: (event: MouseEvent<HTMLDivElement> | KeyboardEvent<HTMLDivElement>) => void;
|
|
32
|
+
toggleFirstOption?: () => void;
|
|
32
33
|
};
|
|
33
34
|
export type ComboboxContentProps = {
|
|
34
35
|
options: SelectOption[];
|
|
@@ -2,7 +2,7 @@ import { FlatOption, SelectOption } from '@scaleflex/ui-tw/form';
|
|
|
2
2
|
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
3
3
|
import { KeyboardEvent, MouseEvent } from 'react';
|
|
4
4
|
export declare const flattenOptions: (options: SelectOption[]) => FlatOption[];
|
|
5
|
-
export declare const createClearHandlers: (onClearAll?: () => void) => {
|
|
5
|
+
export declare const createClearHandlers: (onClearAll?: () => void, optionsLength?: number, toggleFirstOption?: () => void) => {
|
|
6
6
|
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
7
7
|
onKeyDown: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
8
8
|
};
|
|
@@ -9,13 +9,19 @@ function isClearIconEvent(event) {
|
|
|
9
9
|
var target = event.type === 'keydown' ? document.activeElement : event.target;
|
|
10
10
|
return !!target.closest('[data-clear-icon]');
|
|
11
11
|
}
|
|
12
|
-
export var createClearHandlers = function createClearHandlers(onClearAll) {
|
|
12
|
+
export var createClearHandlers = function createClearHandlers(onClearAll, optionsLength, toggleFirstOption) {
|
|
13
13
|
return {
|
|
14
14
|
onClick: function onClick(e) {
|
|
15
15
|
if (isClearIconEvent(e)) {
|
|
16
16
|
e.stopPropagation();
|
|
17
17
|
e.preventDefault();
|
|
18
18
|
onClearAll === null || onClearAll === void 0 || onClearAll();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (optionsLength === 1 && toggleFirstOption) {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
toggleFirstOption();
|
|
19
25
|
}
|
|
20
26
|
},
|
|
21
27
|
onKeyDown: function onKeyDown(e) {
|
|
@@ -23,6 +29,14 @@ export var createClearHandlers = function createClearHandlers(onClearAll) {
|
|
|
23
29
|
e.stopPropagation();
|
|
24
30
|
e.preventDefault();
|
|
25
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
|
+
}
|
|
26
40
|
}
|
|
27
41
|
}
|
|
28
42
|
};
|
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",
|