@scaleflex/ui-tw 0.0.28 → 0.0.30
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/button/button.component.js +4 -3
- package/button/button.constants.d.ts +1 -0
- package/button/button.constants.js +1 -0
- package/combobox/combobox-multi-inline/combobox-multi-inline.component.d.ts +3 -0
- package/combobox/combobox-multi-inline/combobox-multi-inline.component.js +68 -0
- package/combobox/combobox-multi-tag/combobox-multi-tag.component.d.ts +3 -0
- package/combobox/combobox-multi-tag/combobox-multi-tag.component.js +117 -0
- package/combobox/combobox-single/combobox-single.component.d.ts +3 -0
- package/combobox/combobox-single/combobox-single.component.js +61 -0
- package/combobox/combobox.component.d.ts +4 -0
- package/combobox/combobox.component.js +137 -0
- package/combobox/combobox.constants.d.ts +15 -0
- package/combobox/combobox.constants.js +5 -0
- package/combobox/combobox.types.d.ts +65 -0
- package/combobox/combobox.types.js +1 -0
- package/combobox/combobox.utils.d.ts +7 -0
- package/combobox/combobox.utils.js +28 -0
- package/combobox/index.d.ts +5 -0
- package/combobox/index.js +5 -0
- package/command/command.component.d.ts +18 -0
- package/command/command.component.js +150 -0
- package/command/command.utils.d.ts +5 -0
- package/command/command.utils.js +3 -0
- package/command/index.d.ts +1 -0
- package/command/index.js +1 -0
- package/dialog/dialog.component.d.ts +22 -0
- package/dialog/dialog.component.js +192 -0
- package/dialog/index.d.ts +1 -0
- package/dialog/index.js +1 -0
- package/form/components/form-combobox-single-field.component.d.ts +5 -0
- package/form/components/form-combobox-single-field.component.js +57 -0
- package/form/components/form-input-field.component.js +1 -1
- package/form/components/form-select-field.component.d.ts +1 -1
- package/form/components/form-select-field.component.js +23 -52
- package/form/form.types.d.ts +2 -0
- package/package.json +4 -2
- package/pill/pill.types.d.ts +2 -2
- package/popover/index.d.ts +1 -0
- package/popover/index.js +1 -0
- package/popover/popover.component.d.ts +7 -0
- package/popover/popover.component.js +40 -0
- package/select/components/select-icon.js +4 -2
- package/select/components/selector.d.ts +3 -0
- package/select/components/selector.js +66 -0
- package/select/index.d.ts +1 -0
- package/select/index.js +2 -1
- package/select/select.component.d.ts +3 -0
- package/select/select.component.js +9 -8
- package/select/select.constants.d.ts +5 -3
- package/select/select.constants.js +5 -1
- package/select/select.types.d.ts +15 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
4
|
var _excluded = ["className", "children", "size", "startIcon", "endIcon", "variant", "loading", "asChild", "disabled"];
|
|
4
5
|
import { Slot } from '@radix-ui/react-slot';
|
|
@@ -7,7 +8,7 @@ import { focusRingClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
|
7
8
|
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
8
9
|
import { cva } from 'class-variance-authority';
|
|
9
10
|
import React, { useImperativeHandle, useRef } from 'react';
|
|
10
|
-
import { ButtonSize, ButtonVariant, buttonSizeOptions, buttonVariantOptions } from './button.constants';
|
|
11
|
+
import { ButtonSize, ButtonVariant, buttonBaseClassNames, buttonSizeOptions, buttonVariantOptions } from './button.constants';
|
|
11
12
|
import { createRipple, isIconSize } from './button.utils';
|
|
12
13
|
import { EndIcon } from './components/end-icon';
|
|
13
14
|
import { StartIcon, startIconVariants } from './components/start-icon';
|
|
@@ -51,11 +52,11 @@ var Button = /*#__PURE__*/React.forwardRef(function Button(_ref, ref) {
|
|
|
51
52
|
return /*#__PURE__*/React.createElement(Comp, _extends({
|
|
52
53
|
ref: localRef,
|
|
53
54
|
"data-slot": "button",
|
|
54
|
-
className: cn(
|
|
55
|
+
className: cn.apply(void 0, _toConsumableArray(buttonBaseClassNames).concat([focusRingClassNames, buttonVariants({
|
|
55
56
|
variant: variant,
|
|
56
57
|
size: size,
|
|
57
58
|
className: className
|
|
58
|
-
}), loading && 'pointer-events-none opacity-30'),
|
|
59
|
+
}), loading && 'pointer-events-none opacity-30'])),
|
|
59
60
|
disabled: disabled,
|
|
60
61
|
onMouseDown: handleClick
|
|
61
62
|
}, rest), startIcon || endIcon || loading ? /*#__PURE__*/React.createElement("span", {
|
|
@@ -47,6 +47,7 @@ export declare const ButtonVariant: {
|
|
|
47
47
|
readonly Error: "error-primary";
|
|
48
48
|
readonly Warning: "warning-primary";
|
|
49
49
|
};
|
|
50
|
+
export declare const buttonBaseClassNames: readonly ["group/button relative inline-flex shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-md font-medium whitespace-nowrap transition-all outline-none", "disabled:pointer-events-none disabled:opacity-40", "[&_svg]:pointer-events-none [&_svg]:shrink-0"];
|
|
50
51
|
export declare const iconVariantOptions: {
|
|
51
52
|
readonly primary: "";
|
|
52
53
|
readonly secondary: "";
|
|
@@ -21,6 +21,7 @@ export var ButtonVariant = {
|
|
|
21
21
|
Error: 'error-primary',
|
|
22
22
|
Warning: 'warning-primary'
|
|
23
23
|
};
|
|
24
|
+
export var buttonBaseClassNames = ['group/button relative inline-flex shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-md font-medium whitespace-nowrap transition-all outline-none', 'disabled:pointer-events-none disabled:opacity-40', '[&_svg]:pointer-events-none [&_svg]:shrink-0'];
|
|
24
25
|
export var iconVariantOptions = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ButtonVariant.Primary, ''), ButtonVariant.Secondary, ''), ButtonVariant.Outline, 'text-muted-foreground group-hover/button:text-muted-foreground/80'), ButtonVariant.GhostPrimary, ''), ButtonVariant.GhostSecondary, 'text-muted-foreground group-hover/button:text-muted-foreground/80'), ButtonVariant.Error, ''), ButtonVariant.Warning, '');
|
|
25
26
|
export var buttonVariantOptions = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ButtonVariant.Primary, 'bg-primary text-primary-foreground shadow-xs hover:bg-primary/80'), ButtonVariant.Secondary, 'border bg-background shadow-xs text-primary border-primary hover:bg-accent hover:border-primary/80'), ButtonVariant.Outline, 'border bg-background text-secondary-foreground shadow-xs border-input hover:bg-secondary hover:border-input/80'), ButtonVariant.GhostPrimary, 'text-primary hover:bg-accent'), ButtonVariant.GhostSecondary, 'text-secondary-foreground hover:bg-secondary'), ButtonVariant.Error, 'bg-destructive text-primary-foreground shadow-xs hover:bg-destructive/80'), ButtonVariant.Warning, 'bg-warning text-primary-foreground shadow-xs hover:bg-warning/80');
|
|
26
27
|
export var iconSizes = [ButtonSize.IconXs, ButtonSize.IconSm, ButtonSize.IconMd, ButtonSize.IconLg];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComboboxMultiInlineProps } from '../combobox.types';
|
|
3
|
+
export declare function ComboboxMultiInline({ options, value, onChange, placeholder, className, disabled, size, readOnly, showClear, popoverClassName, }: ComboboxMultiInlineProps): React.JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import { Popover } from '@scaleflex/ui-tw/popover';
|
|
4
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useMemo, useState } from 'react';
|
|
7
|
+
import { ComboboxContent, ComboboxTrigger, flattenOptions } from '../';
|
|
8
|
+
export function ComboboxMultiInline(_ref) {
|
|
9
|
+
var _ref$options = _ref.options,
|
|
10
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
11
|
+
value = _ref.value,
|
|
12
|
+
onChange = _ref.onChange,
|
|
13
|
+
_ref$placeholder = _ref.placeholder,
|
|
14
|
+
placeholder = _ref$placeholder === void 0 ? 'Select options...' : _ref$placeholder,
|
|
15
|
+
className = _ref.className,
|
|
16
|
+
_ref$disabled = _ref.disabled,
|
|
17
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
18
|
+
_ref$size = _ref.size,
|
|
19
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
20
|
+
_ref$readOnly = _ref.readOnly,
|
|
21
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
22
|
+
_ref$showClear = _ref.showClear,
|
|
23
|
+
showClear = _ref$showClear === void 0 ? true : _ref$showClear,
|
|
24
|
+
popoverClassName = _ref.popoverClassName;
|
|
25
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
open = _useState2[0],
|
|
28
|
+
setOpen = _useState2[1];
|
|
29
|
+
var selectedLabels = useMemo(function () {
|
|
30
|
+
return flattenOptions(options).filter(function (option) {
|
|
31
|
+
return value.includes(option.value);
|
|
32
|
+
}).map(function (option) {
|
|
33
|
+
return option.label;
|
|
34
|
+
});
|
|
35
|
+
}, [options, value]);
|
|
36
|
+
var displayValue = selectedLabels.length > 0 ? selectedLabels.join(', ') : placeholder;
|
|
37
|
+
var toggleValue = function toggleValue(v) {
|
|
38
|
+
if (value.includes(v)) {
|
|
39
|
+
onChange(value.filter(function (val) {
|
|
40
|
+
return val !== v;
|
|
41
|
+
}));
|
|
42
|
+
} else {
|
|
43
|
+
onChange([].concat(_toConsumableArray(value), [v]));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
47
|
+
open: open,
|
|
48
|
+
onOpenChange: setOpen
|
|
49
|
+
}, /*#__PURE__*/React.createElement(ComboboxTrigger, {
|
|
50
|
+
open: open,
|
|
51
|
+
disabled: disabled,
|
|
52
|
+
className: className,
|
|
53
|
+
size: size,
|
|
54
|
+
readOnly: readOnly,
|
|
55
|
+
showClear: showClear,
|
|
56
|
+
selected: selectedLabels.length > 0,
|
|
57
|
+
onClearAll: function onClearAll() {
|
|
58
|
+
return onChange([]);
|
|
59
|
+
}
|
|
60
|
+
}, displayValue), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
61
|
+
className: popoverClassName,
|
|
62
|
+
options: options,
|
|
63
|
+
value: value,
|
|
64
|
+
onSelect: toggleValue,
|
|
65
|
+
size: size,
|
|
66
|
+
multiple: true
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComboboxMultiTagProps } from '../combobox.types';
|
|
3
|
+
export declare function ComboboxMultiTag({ options, value, onChange, placeholder, className, disabled, size, readOnly, popoverClassName, ...rest }: ComboboxMultiTagProps): React.JSX.Element;
|
|
@@ -0,0 +1,117 @@
|
|
|
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", "value", "onChange", "placeholder", "className", "disabled", "size", "readOnly", "popoverClassName"];
|
|
5
|
+
import { ButtonVariant, buttonVariants } from '@scaleflex/ui-tw/button';
|
|
6
|
+
import { buttonBaseClassNames } from '@scaleflex/ui-tw/button/button.constants';
|
|
7
|
+
import { createClearHandlers } from '@scaleflex/ui-tw/combobox/combobox.utils';
|
|
8
|
+
import { Pill } from '@scaleflex/ui-tw/pill';
|
|
9
|
+
import { Popover, PopoverTrigger } from '@scaleflex/ui-tw/popover';
|
|
10
|
+
import { focusRingClassNames, getBaseInputClasses, readOnlyClassNames, selectionHighlightClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
11
|
+
import { textareaVariants } from '@scaleflex/ui-tw/textarea';
|
|
12
|
+
import { getToolbarSizes } from '@scaleflex/ui-tw/textarea/textarea.utils';
|
|
13
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
14
|
+
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
15
|
+
import { ChevronsUpDownIcon } from 'lucide-react';
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import { useState } from 'react';
|
|
18
|
+
import { ComboboxContent, flattenOptions } from '../';
|
|
19
|
+
import { comboboxMultiTagsDefaultSizeOptions, iconSizeInTriggerOptions } from '../combobox.constants';
|
|
20
|
+
export function ComboboxMultiTag(_ref) {
|
|
21
|
+
var options = _ref.options,
|
|
22
|
+
value = _ref.value,
|
|
23
|
+
onChange = _ref.onChange,
|
|
24
|
+
_ref$placeholder = _ref.placeholder,
|
|
25
|
+
placeholder = _ref$placeholder === void 0 ? 'Select options...' : _ref$placeholder,
|
|
26
|
+
className = _ref.className,
|
|
27
|
+
_ref$disabled = _ref.disabled,
|
|
28
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
29
|
+
_ref$size = _ref.size,
|
|
30
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
31
|
+
_ref$readOnly = _ref.readOnly,
|
|
32
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
33
|
+
popoverClassName = _ref.popoverClassName,
|
|
34
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var _getToolbarSizes = getToolbarSizes(size),
|
|
36
|
+
buttonSize = _getToolbarSizes.buttonSize;
|
|
37
|
+
var _useState = useState(false),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
open = _useState2[0],
|
|
40
|
+
setOpen = _useState2[1];
|
|
41
|
+
var selectedOptions = flattenOptions(options).filter(function (option) {
|
|
42
|
+
return value.includes(option.value);
|
|
43
|
+
});
|
|
44
|
+
var isSelected = selectedOptions.length > 0;
|
|
45
|
+
var toggleValue = function toggleValue(v) {
|
|
46
|
+
if (value.includes(v)) {
|
|
47
|
+
onChange(value.filter(function (val) {
|
|
48
|
+
return val !== v;
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
onChange([].concat(_toConsumableArray(value), [v]));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var onClearAll = function onClearAll() {
|
|
55
|
+
onChange([]);
|
|
56
|
+
setOpen(false);
|
|
57
|
+
};
|
|
58
|
+
var _createClearHandlers = createClearHandlers(onClearAll),
|
|
59
|
+
handleOnTriggerClick = _createClearHandlers.onClick,
|
|
60
|
+
handleOnTriggerKeyDown = _createClearHandlers.onKeyDown;
|
|
61
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
62
|
+
open: open,
|
|
63
|
+
onOpenChange: setOpen
|
|
64
|
+
}, /*#__PURE__*/React.createElement(PopoverTrigger, {
|
|
65
|
+
asChild: true
|
|
66
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
67
|
+
role: "combobox",
|
|
68
|
+
"aria-expanded": open,
|
|
69
|
+
"area-invalid": rest['aria-invalid'],
|
|
70
|
+
className: cn.apply(void 0, ['flex w-full', isSelected ? 'flex-col' : 'items-center'].concat(_toConsumableArray(getBaseInputClasses()), [readOnly && readOnlyClassNames, selectionHighlightClassNames, focusRingClassNames, !isSelected && textareaVariants({
|
|
71
|
+
size: size
|
|
72
|
+
}), !isSelected && comboboxMultiTagsDefaultSizeOptions[size], className])),
|
|
73
|
+
disabled: disabled,
|
|
74
|
+
onClick: handleOnTriggerClick,
|
|
75
|
+
onKeyDown: handleOnTriggerKeyDown
|
|
76
|
+
}, !isSelected ? /*#__PURE__*/React.createElement("span", {
|
|
77
|
+
className: "text-muted-foreground"
|
|
78
|
+
}, placeholder) : /*#__PURE__*/React.createElement("div", {
|
|
79
|
+
className: cn('flex w-full flex-wrap justify-start gap-2', textareaVariants({
|
|
80
|
+
size: size
|
|
81
|
+
}), 'min-h-auto')
|
|
82
|
+
}, selectedOptions.map(function (option) {
|
|
83
|
+
return /*#__PURE__*/React.createElement(Pill, {
|
|
84
|
+
key: option.value,
|
|
85
|
+
size: size,
|
|
86
|
+
variant: "default",
|
|
87
|
+
removable: true,
|
|
88
|
+
onRemove: function onRemove(event) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
toggleValue(option.value);
|
|
92
|
+
}
|
|
93
|
+
}, option.label);
|
|
94
|
+
})), isSelected ? /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: "flex w-full items-center justify-between px-1.5 pb-1.5"
|
|
96
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
97
|
+
role: "button",
|
|
98
|
+
tabIndex: 0,
|
|
99
|
+
"data-clear-icon": "true",
|
|
100
|
+
"aria-label": "Clear all",
|
|
101
|
+
className: cn.apply(void 0, _toConsumableArray(buttonBaseClassNames).concat([focusRingClassNames, buttonVariants({
|
|
102
|
+
size: buttonSize,
|
|
103
|
+
variant: ButtonVariant.GhostSecondary
|
|
104
|
+
})]))
|
|
105
|
+
}, "Clear all"), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
106
|
+
className: cn('mr-1.5 ml-auto shrink-0 opacity-50', iconSizeInTriggerOptions[size])
|
|
107
|
+
})) : /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
108
|
+
className: cn('my-auto ml-auto shrink-0 opacity-50', iconSizeInTriggerOptions[size])
|
|
109
|
+
}))), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
110
|
+
options: options,
|
|
111
|
+
value: value,
|
|
112
|
+
onSelect: toggleValue,
|
|
113
|
+
size: size,
|
|
114
|
+
multiple: true,
|
|
115
|
+
className: popoverClassName
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComboboxSingleProps } from '../combobox.types';
|
|
3
|
+
export declare function ComboboxSingle({ options, value, onChange, placeholder, className, disabled, popoverClassName, size, readOnly, showClear, ...rest }: ComboboxSingleProps): React.JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "popoverClassName", "size", "readOnly", "showClear"];
|
|
4
|
+
import { Popover } from '@scaleflex/ui-tw/popover';
|
|
5
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { ComboboxContent, ComboboxTrigger } from '../combobox.component';
|
|
9
|
+
import { flattenOptions } from '../combobox.utils';
|
|
10
|
+
export function ComboboxSingle(_ref) {
|
|
11
|
+
var _flattenOptions$find;
|
|
12
|
+
var _ref$options = _ref.options,
|
|
13
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
14
|
+
value = _ref.value,
|
|
15
|
+
onChange = _ref.onChange,
|
|
16
|
+
_ref$placeholder = _ref.placeholder,
|
|
17
|
+
placeholder = _ref$placeholder === void 0 ? 'Select an option...' : _ref$placeholder,
|
|
18
|
+
className = _ref.className,
|
|
19
|
+
_ref$disabled = _ref.disabled,
|
|
20
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
21
|
+
popoverClassName = _ref.popoverClassName,
|
|
22
|
+
_ref$size = _ref.size,
|
|
23
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
24
|
+
_ref$readOnly = _ref.readOnly,
|
|
25
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
26
|
+
_ref$showClear = _ref.showClear,
|
|
27
|
+
showClear = _ref$showClear === void 0 ? true : _ref$showClear,
|
|
28
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
+
var _useState = useState(false),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
open = _useState2[0],
|
|
32
|
+
setOpen = _useState2[1];
|
|
33
|
+
var selectedLabel = (_flattenOptions$find = flattenOptions(options).find(function (opt) {
|
|
34
|
+
return opt.value === value;
|
|
35
|
+
})) === null || _flattenOptions$find === void 0 ? void 0 : _flattenOptions$find.label;
|
|
36
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
37
|
+
open: open,
|
|
38
|
+
onOpenChange: setOpen
|
|
39
|
+
}, /*#__PURE__*/React.createElement(ComboboxTrigger, {
|
|
40
|
+
open: open,
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
className: className,
|
|
43
|
+
size: size,
|
|
44
|
+
readOnly: readOnly,
|
|
45
|
+
onClearAll: function onClearAll() {
|
|
46
|
+
return onChange('');
|
|
47
|
+
},
|
|
48
|
+
selected: !!selectedLabel,
|
|
49
|
+
showClear: showClear,
|
|
50
|
+
"aria-invalid": rest['aria-invalid']
|
|
51
|
+
}, selectedLabel || placeholder), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
52
|
+
className: popoverClassName,
|
|
53
|
+
options: options,
|
|
54
|
+
value: value,
|
|
55
|
+
onSelect: function onSelect(currentValue) {
|
|
56
|
+
onChange(currentValue === value ? '' : currentValue);
|
|
57
|
+
setOpen(false);
|
|
58
|
+
},
|
|
59
|
+
size: size
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComboboxContentProps, ComboboxTriggerProps } from './combobox.types';
|
|
3
|
+
export declare function ComboboxTrigger({ children, open, disabled, readOnly, size, className, selected, showClear, onClearAll, ...rest }: ComboboxTriggerProps): React.JSX.Element;
|
|
4
|
+
export declare function ComboboxContent({ options, value: selectedValue, onSelect, size, multiple, className, }: ComboboxContentProps): React.JSX.Element;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "open", "disabled", "readOnly", "size", "className", "selected", "showClear", "onClearAll"];
|
|
4
|
+
import { buttonVariants } from '@scaleflex/ui-tw/button';
|
|
5
|
+
import { ButtonVariant, buttonBaseClassNames } from '@scaleflex/ui-tw/button/button.constants';
|
|
6
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@scaleflex/ui-tw/command';
|
|
7
|
+
import { isOptionGroup } from '@scaleflex/ui-tw/form';
|
|
8
|
+
import { PopoverContent, PopoverTrigger } from '@scaleflex/ui-tw/popover';
|
|
9
|
+
import { selectTriggerVariants } from '@scaleflex/ui-tw/select/select.component';
|
|
10
|
+
import { getBaseSelectClassNames, selectReadOnlyClassNames } from '@scaleflex/ui-tw/select/select.constants';
|
|
11
|
+
import { Separator } from '@scaleflex/ui-tw/separator';
|
|
12
|
+
import { focusRingClassNames, getBaseInputClasses } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
13
|
+
import { getToolbarSizes } from '@scaleflex/ui-tw/textarea/textarea.utils';
|
|
14
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
15
|
+
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
16
|
+
import { ChevronsUpDownIcon, XIcon } from 'lucide-react';
|
|
17
|
+
import * as React from 'react';
|
|
18
|
+
import { iconSizeInTriggerOptions, verticalSeparatorNextToChevronOptions } from './combobox.constants';
|
|
19
|
+
import { createClearHandlers } from './combobox.utils';
|
|
20
|
+
export function ComboboxTrigger(_ref) {
|
|
21
|
+
var children = _ref.children,
|
|
22
|
+
open = _ref.open,
|
|
23
|
+
_ref$disabled = _ref.disabled,
|
|
24
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
25
|
+
_ref$readOnly = _ref.readOnly,
|
|
26
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
27
|
+
_ref$size = _ref.size,
|
|
28
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
29
|
+
className = _ref.className,
|
|
30
|
+
_ref$selected = _ref.selected,
|
|
31
|
+
selected = _ref$selected === void 0 ? false : _ref$selected,
|
|
32
|
+
_ref$showClear = _ref.showClear,
|
|
33
|
+
showClear = _ref$showClear === void 0 ? false : _ref$showClear,
|
|
34
|
+
onClearAll = _ref.onClearAll,
|
|
35
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
|
+
var _getToolbarSizes = getToolbarSizes(size),
|
|
37
|
+
iconSize = _getToolbarSizes.iconSize;
|
|
38
|
+
var _createClearHandlers = createClearHandlers(onClearAll),
|
|
39
|
+
handleOnTriggerClick = _createClearHandlers.onClick,
|
|
40
|
+
handleOnTriggerKeyDown = _createClearHandlers.onKeyDown;
|
|
41
|
+
return /*#__PURE__*/React.createElement(PopoverTrigger, {
|
|
42
|
+
asChild: true
|
|
43
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
44
|
+
role: "combobox",
|
|
45
|
+
"aria-expanded": open,
|
|
46
|
+
"aria-invalid": rest['aria-invalid'],
|
|
47
|
+
disabled: disabled,
|
|
48
|
+
className: cn.apply(void 0, _toConsumableArray(getBaseSelectClassNames()).concat(_toConsumableArray(getBaseInputClasses()), [selectTriggerVariants({
|
|
49
|
+
size: size
|
|
50
|
+
}), !selected && 'text-muted-foreground/80 hover:border-secondary-foreground/50', readOnly && selectReadOnlyClassNames, className])),
|
|
51
|
+
onClick: handleOnTriggerClick,
|
|
52
|
+
onKeyDown: handleOnTriggerKeyDown
|
|
53
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
54
|
+
className: "truncate"
|
|
55
|
+
}, children), /*#__PURE__*/React.createElement("div", {
|
|
56
|
+
className: "ml-2 flex items-center gap-1 pl-1"
|
|
57
|
+
}, showClear && !!onClearAll && selected && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
58
|
+
role: "button",
|
|
59
|
+
tabIndex: 0,
|
|
60
|
+
"data-clear-icon": "true",
|
|
61
|
+
"aria-label": "Clear all",
|
|
62
|
+
className: cn.apply(void 0, _toConsumableArray(buttonBaseClassNames).concat([focusRingClassNames, buttonVariants({
|
|
63
|
+
size: iconSize,
|
|
64
|
+
variant: ButtonVariant.GhostSecondary
|
|
65
|
+
})]))
|
|
66
|
+
}, /*#__PURE__*/React.createElement(XIcon, {
|
|
67
|
+
"data-clear-icon": true,
|
|
68
|
+
className: cn('shrink-0 hover:opacity-80', iconSizeInTriggerOptions[size])
|
|
69
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: cn(verticalSeparatorNextToChevronOptions[size])
|
|
71
|
+
}, /*#__PURE__*/React.createElement(Separator, {
|
|
72
|
+
orientation: "vertical"
|
|
73
|
+
}))), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
74
|
+
className: cn('ml-1 shrink-0 opacity-50', iconSizeInTriggerOptions[size])
|
|
75
|
+
}))));
|
|
76
|
+
}
|
|
77
|
+
export function ComboboxContent(_ref2) {
|
|
78
|
+
var options = _ref2.options,
|
|
79
|
+
selectedValue = _ref2.value,
|
|
80
|
+
_onSelect = _ref2.onSelect,
|
|
81
|
+
_ref2$size = _ref2.size,
|
|
82
|
+
size = _ref2$size === void 0 ? 'md' : _ref2$size,
|
|
83
|
+
_ref2$multiple = _ref2.multiple,
|
|
84
|
+
multiple = _ref2$multiple === void 0 ? false : _ref2$multiple,
|
|
85
|
+
className = _ref2.className;
|
|
86
|
+
return /*#__PURE__*/React.createElement(PopoverContent, {
|
|
87
|
+
className: cn('p-0', className)
|
|
88
|
+
}, /*#__PURE__*/React.createElement(Command, null, /*#__PURE__*/React.createElement(CommandInput, {
|
|
89
|
+
size: size,
|
|
90
|
+
placeholder: "Search..."
|
|
91
|
+
}), /*#__PURE__*/React.createElement(CommandList, null, /*#__PURE__*/React.createElement(CommandEmpty, {
|
|
92
|
+
className: "text-muted-foreground"
|
|
93
|
+
}, "No results found."), options === null || options === void 0 ? void 0 : options.map(function (option, groupIndex) {
|
|
94
|
+
if (isOptionGroup(option)) {
|
|
95
|
+
return /*#__PURE__*/React.createElement(CommandGroup, {
|
|
96
|
+
key: groupIndex,
|
|
97
|
+
heading: option.label,
|
|
98
|
+
size: size
|
|
99
|
+
}, option.options.map(function (_ref3) {
|
|
100
|
+
var label = _ref3.label,
|
|
101
|
+
value = _ref3.value,
|
|
102
|
+
disabled = _ref3.disabled,
|
|
103
|
+
icon = _ref3.icon,
|
|
104
|
+
tooltip = _ref3.tooltip;
|
|
105
|
+
return /*#__PURE__*/React.createElement(CommandItem, {
|
|
106
|
+
size: size,
|
|
107
|
+
multiple: multiple,
|
|
108
|
+
disabled: disabled,
|
|
109
|
+
key: value,
|
|
110
|
+
icon: icon,
|
|
111
|
+
value: value,
|
|
112
|
+
tooltip: tooltip,
|
|
113
|
+
isGroup: !!option.label,
|
|
114
|
+
selectedValue: selectedValue,
|
|
115
|
+
onSelect: function onSelect() {
|
|
116
|
+
return _onSelect(value);
|
|
117
|
+
}
|
|
118
|
+
}, label);
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
return /*#__PURE__*/React.createElement(CommandGroup, {
|
|
122
|
+
key: "default"
|
|
123
|
+
}, /*#__PURE__*/React.createElement(CommandItem, {
|
|
124
|
+
size: size,
|
|
125
|
+
multiple: multiple,
|
|
126
|
+
disabled: option.disabled,
|
|
127
|
+
key: option.value,
|
|
128
|
+
icon: option.icon,
|
|
129
|
+
value: option.value,
|
|
130
|
+
tooltip: option.tooltip,
|
|
131
|
+
selectedValue: selectedValue,
|
|
132
|
+
onSelect: function onSelect() {
|
|
133
|
+
return _onSelect(option.value);
|
|
134
|
+
}
|
|
135
|
+
}, option.label));
|
|
136
|
+
}))));
|
|
137
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const verticalSeparatorNextToChevronOptions: {
|
|
2
|
+
readonly sm: "h-4";
|
|
3
|
+
readonly md: "h-5";
|
|
4
|
+
readonly lg: "h-6";
|
|
5
|
+
};
|
|
6
|
+
export declare const iconSizeInTriggerOptions: {
|
|
7
|
+
sm: string;
|
|
8
|
+
md: string;
|
|
9
|
+
lg: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const comboboxMultiTagsDefaultSizeOptions: {
|
|
12
|
+
readonly sm: "min-h-8 h-8";
|
|
13
|
+
readonly md: "min-h-10 h-10";
|
|
14
|
+
readonly lg: "min-h-12 h-12";
|
|
15
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
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-3'), FormSize.Md, 'size-4'), FormSize.Lg, 'size-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');
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { SelectOption } from '@scaleflex/ui-tw/form';
|
|
2
|
+
import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
import { Command as CommandPrimitive } from 'cmdk';
|
|
4
|
+
import { ComponentProps, KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
5
|
+
export type ClearEvent = MouseEvent | KeyboardEvent;
|
|
6
|
+
export type ComboboxTriggerProps = {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
open: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
size?: FormSizeType;
|
|
12
|
+
className?: string;
|
|
13
|
+
selected?: boolean;
|
|
14
|
+
showClear?: boolean;
|
|
15
|
+
'aria-invalid'?: boolean;
|
|
16
|
+
onClearAll?: () => void;
|
|
17
|
+
};
|
|
18
|
+
export type ComboboxContentProps = {
|
|
19
|
+
options: SelectOption[];
|
|
20
|
+
value: string | string[];
|
|
21
|
+
onSelect: (value: string) => void;
|
|
22
|
+
size?: FormSizeType;
|
|
23
|
+
multiple?: boolean;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
export interface CommandInputProps extends Omit<ComponentProps<typeof CommandPrimitive.Input>, 'size'> {
|
|
27
|
+
size?: FormSizeType;
|
|
28
|
+
}
|
|
29
|
+
export interface CommandGroupProps extends ComponentProps<typeof CommandPrimitive.Group> {
|
|
30
|
+
size?: FormSizeType;
|
|
31
|
+
}
|
|
32
|
+
export interface CommandItemProps extends ComponentProps<typeof CommandPrimitive.Item> {
|
|
33
|
+
icon?: ReactElement;
|
|
34
|
+
size?: FormSizeType;
|
|
35
|
+
tooltip?: ReactElement | string;
|
|
36
|
+
isGroup?: boolean;
|
|
37
|
+
shortcut?: ReactElement | string;
|
|
38
|
+
selectedValue?: string | string[];
|
|
39
|
+
multiple?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface ComboboxCommonProps {
|
|
42
|
+
options: SelectOption[];
|
|
43
|
+
placeholder?: string;
|
|
44
|
+
className?: string;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
readOnly?: boolean;
|
|
47
|
+
size?: FormSizeType;
|
|
48
|
+
popoverClassName?: string;
|
|
49
|
+
'aria-invalid'?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface ComboboxSingleProps extends ComboboxCommonProps {
|
|
52
|
+
value: string;
|
|
53
|
+
onChange: (value: string) => void;
|
|
54
|
+
showClear?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ComboboxMultiInlineProps extends ComboboxCommonProps {
|
|
57
|
+
value: string[];
|
|
58
|
+
onChange: (value: string[]) => void;
|
|
59
|
+
showClear?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface ComboboxMultiTagProps extends ComboboxCommonProps {
|
|
62
|
+
value: string[];
|
|
63
|
+
onChange: (value: string[]) => void;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FlatOption, SelectOption } from '@scaleflex/ui-tw/form';
|
|
2
|
+
import { KeyboardEvent, MouseEvent } from 'react';
|
|
3
|
+
export declare const flattenOptions: (options: SelectOption[]) => FlatOption[];
|
|
4
|
+
export declare const createClearHandlers: (onClearAll?: () => void) => {
|
|
5
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
6
|
+
onKeyDown: (e: KeyboardEvent<HTMLButtonElement>) => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isOptionGroup } from '@scaleflex/ui-tw/form';
|
|
2
|
+
export var flattenOptions = function flattenOptions(options) {
|
|
3
|
+
return options.flatMap(function (option) {
|
|
4
|
+
return isOptionGroup(option) ? option.options : [option];
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
function isClearIconEvent(event) {
|
|
8
|
+
var target = event.type === 'keydown' ? document.activeElement : event.target;
|
|
9
|
+
return !!target.closest('[data-clear-icon]');
|
|
10
|
+
}
|
|
11
|
+
export var createClearHandlers = function createClearHandlers(onClearAll) {
|
|
12
|
+
return {
|
|
13
|
+
onClick: function onClick(e) {
|
|
14
|
+
if (isClearIconEvent(e)) {
|
|
15
|
+
e.stopPropagation();
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
onClearAll === null || onClearAll === void 0 || onClearAll();
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
onKeyDown: function onKeyDown(e) {
|
|
21
|
+
if (isClearIconEvent(e) && (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar')) {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
onClearAll === null || onClearAll === void 0 || onClearAll();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ComboboxTrigger, ComboboxContent } from './combobox.component';
|
|
2
|
+
export { ComboboxSingle } from './combobox-single/combobox-single.component';
|
|
3
|
+
export { ComboboxMultiInline } from './combobox-multi-inline/combobox-multi-inline.component';
|
|
4
|
+
export { ComboboxMultiTag } from './combobox-multi-tag/combobox-multi-tag.component';
|
|
5
|
+
export { flattenOptions } from './combobox.utils';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ComboboxTrigger, ComboboxContent } from './combobox.component';
|
|
2
|
+
export { ComboboxSingle } from './combobox-single/combobox-single.component';
|
|
3
|
+
export { ComboboxMultiInline } from './combobox-multi-inline/combobox-multi-inline.component';
|
|
4
|
+
export { ComboboxMultiTag } from './combobox-multi-tag/combobox-multi-tag.component';
|
|
5
|
+
export { flattenOptions } from './combobox.utils';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CommandGroupProps, CommandInputProps, CommandItemProps } from '@scaleflex/ui-tw/combobox/combobox.types';
|
|
2
|
+
import { Dialog } from '@scaleflex/ui-tw/dialog';
|
|
3
|
+
import { Command as CommandPrimitive } from 'cmdk';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { ComponentProps } from 'react';
|
|
6
|
+
declare function Command({ className, ...props }: ComponentProps<typeof CommandPrimitive>): React.JSX.Element;
|
|
7
|
+
declare function CommandDialog({ title, description, children, ...props }: ComponentProps<typeof Dialog> & {
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
}): React.JSX.Element;
|
|
11
|
+
declare function CommandInput({ className, size, ...props }: CommandInputProps): React.JSX.Element;
|
|
12
|
+
declare function CommandList({ className, ...props }: ComponentProps<typeof CommandPrimitive.List>): React.JSX.Element;
|
|
13
|
+
declare function CommandEmpty({ className, ...rest }: ComponentProps<typeof CommandPrimitive.Empty>): React.JSX.Element;
|
|
14
|
+
declare function CommandGroup({ className, size, ...props }: CommandGroupProps): React.JSX.Element;
|
|
15
|
+
declare function CommandSeparator({ className, ...props }: ComponentProps<typeof CommandPrimitive.Separator>): React.JSX.Element;
|
|
16
|
+
declare function CommandItem({ className, size, isGroup, icon, tooltip, children, selectedValue, multiple, value, shortcut, ...props }: CommandItemProps): React.JSX.Element;
|
|
17
|
+
declare function CommandShortcut({ className, ...props }: ComponentProps<'span'>): React.JSX.Element;
|
|
18
|
+
export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator, };
|