@scaleflex/ui-tw 0.0.45 → 0.0.47
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-inline/combobox-multi-inline.component.d.ts +1 -1
- package/combobox/combobox-multi-inline/combobox-multi-inline.component.js +6 -2
- package/combobox/combobox-multi-tag/combobox-multi-tag.component.d.ts +1 -1
- package/combobox/combobox-multi-tag/combobox-multi-tag.component.js +3 -1
- package/combobox/combobox-single/combobox-single.component.d.ts +1 -1
- package/combobox/combobox-single/combobox-single.component.js +3 -1
- package/combobox/combobox.component.d.ts +1 -1
- package/combobox/combobox.component.js +5 -5
- package/combobox/combobox.types.d.ts +2 -0
- package/form/components/form-tags-field.component.d.ts +5 -0
- package/form/components/form-tags-field.component.js +57 -0
- package/form/form.types.d.ts +13 -1
- package/form/index.d.ts +1 -0
- package/form/index.js +2 -1
- package/input-tags/index.d.ts +1 -0
- package/input-tags/index.js +1 -0
- package/input-tags/input-tags.component.d.ts +3 -0
- package/input-tags/input-tags.component.js +216 -0
- package/input-tags/input-tags.types.d.ts +26 -0
- package/input-tags/input-tags.types.js +1 -0
- package/package.json +2 -2
- package/textarea/components/left-toolbar-buttons.js +6 -2
- package/textarea/textarea.types.d.ts +2 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ComboboxMultiInlineProps } from '../combobox.types';
|
|
3
|
-
export declare function ComboboxMultiInline({ options, value, onChange, placeholder, className, disabled, size, readOnly, showClear, popoverClassName, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, ...rest }: ComboboxMultiInlineProps): React.JSX.Element;
|
|
3
|
+
export declare function ComboboxMultiInline({ options, value, onChange, placeholder, className, disabled, size, readOnly, showClear, popoverClassName, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, formItemId, searchPlaceholder, ...rest }: ComboboxMultiInlineProps): React.JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "size", "readOnly", "showClear", "popoverClassName", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps"];
|
|
4
|
+
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "size", "readOnly", "showClear", "popoverClassName", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps", "formItemId", "searchPlaceholder"];
|
|
5
5
|
import { Popover } from '@scaleflex/ui-tw/popover';
|
|
6
6
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
7
7
|
import React from 'react';
|
|
@@ -30,6 +30,8 @@ export function ComboboxMultiInline(_ref) {
|
|
|
30
30
|
_ref$defaultOpen = _ref.defaultOpen,
|
|
31
31
|
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
32
32
|
popoverContentProps = _ref.popoverContentProps,
|
|
33
|
+
formItemId = _ref.formItemId,
|
|
34
|
+
searchPlaceholder = _ref.searchPlaceholder,
|
|
33
35
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
34
36
|
var _useState = useState(defaultOpen),
|
|
35
37
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -76,9 +78,11 @@ export function ComboboxMultiInline(_ref) {
|
|
|
76
78
|
showClear: showClear,
|
|
77
79
|
selected: selectedLabels.length > 0,
|
|
78
80
|
onClearAll: onClearAll,
|
|
79
|
-
"aria-invalid": rest['aria-invalid']
|
|
81
|
+
"aria-invalid": rest['aria-invalid'],
|
|
82
|
+
formItemId: formItemId
|
|
80
83
|
}, displayValue), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
81
84
|
showGroupSeparator: showGroupSeparator,
|
|
85
|
+
searchPlaceholder: searchPlaceholder,
|
|
82
86
|
className: popoverClassName,
|
|
83
87
|
options: options,
|
|
84
88
|
value: value,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ComboboxMultiTagProps } from '../combobox.types';
|
|
3
|
-
export declare function ComboboxMultiTag({ options, value, onChange, placeholder, className, disabled, size, readOnly, popoverClassName, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, ...rest }: ComboboxMultiTagProps): React.JSX.Element;
|
|
3
|
+
export declare function ComboboxMultiTag({ options, value, onChange, placeholder, className, disabled, size, readOnly, popoverClassName, onBlur, showGroupSeparator, defaultOpen, searchPlaceholder, popoverContentProps, ...rest }: ComboboxMultiTagProps): React.JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "size", "readOnly", "popoverClassName", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps"];
|
|
4
|
+
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "size", "readOnly", "popoverClassName", "onBlur", "showGroupSeparator", "defaultOpen", "searchPlaceholder", "popoverContentProps"];
|
|
5
5
|
import { ButtonVariant, buttonVariants } from '@scaleflex/ui-tw/button';
|
|
6
6
|
import { buttonBaseClassNames } from '@scaleflex/ui-tw/button/button.constants';
|
|
7
7
|
import { createClearHandlers } from '@scaleflex/ui-tw/combobox/combobox.utils';
|
|
@@ -36,6 +36,7 @@ export function ComboboxMultiTag(_ref) {
|
|
|
36
36
|
showGroupSeparator = _ref$showGroupSeparat === void 0 ? false : _ref$showGroupSeparat,
|
|
37
37
|
_ref$defaultOpen = _ref.defaultOpen,
|
|
38
38
|
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
39
|
+
searchPlaceholder = _ref.searchPlaceholder,
|
|
39
40
|
popoverContentProps = _ref.popoverContentProps,
|
|
40
41
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
41
42
|
var _getToolbarSizes = getToolbarSizes(size),
|
|
@@ -132,6 +133,7 @@ export function ComboboxMultiTag(_ref) {
|
|
|
132
133
|
size: size,
|
|
133
134
|
multiple: true,
|
|
134
135
|
className: popoverClassName,
|
|
136
|
+
searchPlaceholder: searchPlaceholder,
|
|
135
137
|
showGroupSeparator: showGroupSeparator,
|
|
136
138
|
popoverContentProps: popoverContentProps
|
|
137
139
|
}));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ComboboxSingleProps } from '../combobox.types';
|
|
3
|
-
export declare function ComboboxSingle({ options, value, onChange, placeholder, className, disabled, popoverClassName, size, readOnly, showClear, formItemId, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, ...rest }: ComboboxSingleProps): React.JSX.Element;
|
|
3
|
+
export declare function ComboboxSingle({ options, value, onChange, placeholder, className, disabled, popoverClassName, size, readOnly, showClear, formItemId, onBlur, showGroupSeparator, defaultOpen, popoverContentProps, searchPlaceholder, ...rest }: ComboboxSingleProps): React.JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "popoverClassName", "size", "readOnly", "showClear", "formItemId", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps"];
|
|
3
|
+
var _excluded = ["options", "value", "onChange", "placeholder", "className", "disabled", "popoverClassName", "size", "readOnly", "showClear", "formItemId", "onBlur", "showGroupSeparator", "defaultOpen", "popoverContentProps", "searchPlaceholder"];
|
|
4
4
|
import { Popover } from '@scaleflex/ui-tw/popover';
|
|
5
5
|
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
6
6
|
import * as React from 'react';
|
|
@@ -32,6 +32,7 @@ export function ComboboxSingle(_ref) {
|
|
|
32
32
|
_ref$defaultOpen = _ref.defaultOpen,
|
|
33
33
|
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
34
34
|
popoverContentProps = _ref.popoverContentProps,
|
|
35
|
+
searchPlaceholder = _ref.searchPlaceholder,
|
|
35
36
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
37
|
var _useState = useState(defaultOpen),
|
|
37
38
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -72,6 +73,7 @@ export function ComboboxSingle(_ref) {
|
|
|
72
73
|
"aria-invalid": rest['aria-invalid'],
|
|
73
74
|
formItemId: formItemId
|
|
74
75
|
}, selectedLabel || placeholder), /*#__PURE__*/React.createElement(ComboboxContent, {
|
|
76
|
+
searchPlaceholder: searchPlaceholder,
|
|
75
77
|
className: popoverClassName,
|
|
76
78
|
options: options,
|
|
77
79
|
value: value,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ComboboxContentProps, ComboboxTriggerProps } from './combobox.types';
|
|
3
3
|
export declare function ComboboxTrigger({ children, open, disabled, readOnly, size, className, selected, showClear, onClearAll, formItemId, ...rest }: ComboboxTriggerProps): React.JSX.Element;
|
|
4
|
-
export declare function ComboboxContent({ options, value: selectedValue, onSelect, size, multiple, className, showGroupSeparator, popoverContentProps, }: ComboboxContentProps): React.JSX.Element;
|
|
4
|
+
export declare function ComboboxContent({ options, value: selectedValue, onSelect, size, multiple, className, showGroupSeparator, popoverContentProps, searchPlaceholder, }: ComboboxContentProps): React.JSX.Element;
|
|
@@ -88,15 +88,15 @@ export function ComboboxContent(_ref2) {
|
|
|
88
88
|
className = _ref2.className,
|
|
89
89
|
_ref2$showGroupSepara = _ref2.showGroupSeparator,
|
|
90
90
|
showGroupSeparator = _ref2$showGroupSepara === void 0 ? false : _ref2$showGroupSepara,
|
|
91
|
-
popoverContentProps = _ref2.popoverContentProps
|
|
91
|
+
popoverContentProps = _ref2.popoverContentProps,
|
|
92
|
+
_ref2$searchPlacehold = _ref2.searchPlaceholder,
|
|
93
|
+
searchPlaceholder = _ref2$searchPlacehold === void 0 ? 'Search...' : _ref2$searchPlacehold;
|
|
92
94
|
return /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
93
95
|
className: cn('p-0', className)
|
|
94
96
|
}, popoverContentProps), /*#__PURE__*/React.createElement(Command, null, /*#__PURE__*/React.createElement(CommandInput, {
|
|
95
97
|
size: size,
|
|
96
|
-
placeholder:
|
|
97
|
-
}), /*#__PURE__*/React.createElement(CommandList, null, /*#__PURE__*/React.createElement(CommandEmpty, {
|
|
98
|
-
className: "text-muted-foreground"
|
|
99
|
-
}, "No results found."), options === null || options === void 0 ? void 0 : options.map(function (option, groupIndex) {
|
|
98
|
+
placeholder: searchPlaceholder
|
|
99
|
+
}), /*#__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) {
|
|
100
100
|
if (isOptionGroup(option)) {
|
|
101
101
|
return /*#__PURE__*/React.createElement(CommandGroup, {
|
|
102
102
|
key: groupIndex,
|
|
@@ -27,6 +27,7 @@ export type ComboboxContentProps = {
|
|
|
27
27
|
multiple?: boolean;
|
|
28
28
|
className?: string;
|
|
29
29
|
showGroupSeparator?: boolean;
|
|
30
|
+
searchPlaceholder?: string;
|
|
30
31
|
popoverContentProps?: ComponentProps<typeof PopoverPrimitive.Content>;
|
|
31
32
|
};
|
|
32
33
|
export interface CommandInputProps extends Omit<ComponentProps<typeof CommandPrimitive.Input>, 'size'> {
|
|
@@ -56,6 +57,7 @@ interface ComboboxCommonProps {
|
|
|
56
57
|
'aria-invalid'?: boolean;
|
|
57
58
|
formItemId?: string;
|
|
58
59
|
showGroupSeparator?: boolean;
|
|
60
|
+
searchPlaceholder?: string;
|
|
59
61
|
popoverContentProps?: ComponentProps<typeof PopoverPrimitive.Content>;
|
|
60
62
|
}
|
|
61
63
|
export interface ComboboxSingleProps extends ComboboxCommonProps {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FieldValues, Path } from 'react-hook-form';
|
|
3
|
+
import type { FormTagsFieldProps } from '../form.types';
|
|
4
|
+
declare function FormTagsField<TFieldValues extends FieldValues, TName extends Path<TFieldValues>>({ tagsProps, ...rest }: FormTagsFieldProps<TFieldValues, TName>): React.JSX.Element;
|
|
5
|
+
export { FormTagsField };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["placeholder", "suggestedTags", "allTags", "allowCustomTags", "onGenerateTags"],
|
|
4
|
+
_excluded2 = ["tagsProps"];
|
|
5
|
+
import { useFormField } from '@scaleflex/ui-tw/form';
|
|
6
|
+
import { FormFieldGroup } from '@scaleflex/ui-tw/form';
|
|
7
|
+
import { InputTags } from '@scaleflex/ui-tw/input-tags';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
function FormTagsInner(_ref) {
|
|
10
|
+
var field = _ref.field,
|
|
11
|
+
args = _ref.args,
|
|
12
|
+
tagsProps = _ref.tagsProps,
|
|
13
|
+
readOnly = _ref.readOnly,
|
|
14
|
+
disabled = _ref.disabled,
|
|
15
|
+
className = _ref.className;
|
|
16
|
+
var _useFormField = useFormField(),
|
|
17
|
+
error = _useFormField.error,
|
|
18
|
+
formItemId = _useFormField.formItemId;
|
|
19
|
+
var _ref2 = tagsProps || {},
|
|
20
|
+
placeholder = _ref2.placeholder,
|
|
21
|
+
suggestedTags = _ref2.suggestedTags,
|
|
22
|
+
allTags = _ref2.allTags,
|
|
23
|
+
allowCustomTags = _ref2.allowCustomTags,
|
|
24
|
+
onGenerateTags = _ref2.onGenerateTags,
|
|
25
|
+
restTagsProps = _objectWithoutProperties(_ref2, _excluded);
|
|
26
|
+
return /*#__PURE__*/React.createElement(InputTags, _extends({
|
|
27
|
+
value: field.value,
|
|
28
|
+
onChange: field.onChange,
|
|
29
|
+
placeholder: placeholder,
|
|
30
|
+
suggestedTags: suggestedTags,
|
|
31
|
+
allTags: allTags,
|
|
32
|
+
allowCustomTags: allowCustomTags,
|
|
33
|
+
onGenerateTags: onGenerateTags,
|
|
34
|
+
disabled: disabled,
|
|
35
|
+
readOnly: readOnly,
|
|
36
|
+
formItemId: formItemId,
|
|
37
|
+
size: args === null || args === void 0 ? void 0 : args.size,
|
|
38
|
+
"aria-invalid": !!error,
|
|
39
|
+
className: className
|
|
40
|
+
}, restTagsProps));
|
|
41
|
+
}
|
|
42
|
+
function FormTagsField(_ref3) {
|
|
43
|
+
var tagsProps = _ref3.tagsProps,
|
|
44
|
+
rest = _objectWithoutProperties(_ref3, _excluded2);
|
|
45
|
+
var readOnly = rest.readOnly,
|
|
46
|
+
disabled = rest.disabled;
|
|
47
|
+
return /*#__PURE__*/React.createElement(FormFieldGroup, rest, function (field, args) {
|
|
48
|
+
return /*#__PURE__*/React.createElement(FormTagsInner, {
|
|
49
|
+
field: field,
|
|
50
|
+
args: args,
|
|
51
|
+
tagsProps: tagsProps,
|
|
52
|
+
readOnly: readOnly,
|
|
53
|
+
disabled: disabled
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { FormTagsField };
|
package/form/form.types.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { CheckboxProps } from '@scaleflex/ui-tw/checkbox/checkbox.types';
|
|
|
2
2
|
import type { ComboboxMultiInlineProps, ComboboxMultiTagProps, ComboboxSingleProps } from '@scaleflex/ui-tw/combobox/combobox.types';
|
|
3
3
|
import type { DatePickerProps } from '@scaleflex/ui-tw/date-picker/date-picker.types';
|
|
4
4
|
import type { InputProps } from '@scaleflex/ui-tw/input';
|
|
5
|
+
import { InputTagsProps } from '@scaleflex/ui-tw/input-tags/input-tags.types';
|
|
5
6
|
import type { RadioGroupItemProps } from '@scaleflex/ui-tw/radio-group/radio-group.types';
|
|
6
7
|
import type { SelectProps } from '@scaleflex/ui-tw/select/select.types';
|
|
7
8
|
import type { SwitchProps } from '@scaleflex/ui-tw/switch/switch.types';
|
|
8
9
|
import type { TextareaProps } from '@scaleflex/ui-tw/textarea';
|
|
9
10
|
import type { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
10
11
|
import type { Values } from '@scaleflex/ui-tw/types/values';
|
|
11
|
-
import { ReactElement, ReactNode } from 'react';
|
|
12
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
12
13
|
import { Control, type ControllerRenderProps, type FieldPath, type FieldValues, type Path, type UseControllerProps } from 'react-hook-form';
|
|
13
14
|
import { FormMessageSize, SwitchLayout } from './form.constants';
|
|
14
15
|
export type FormMessageSizeType = Values<typeof FormMessageSize>;
|
|
@@ -127,4 +128,15 @@ export interface FormDatePickerInnerProps<TFieldValues extends FieldValues, TNam
|
|
|
127
128
|
readOnly?: boolean;
|
|
128
129
|
disabled?: boolean;
|
|
129
130
|
}
|
|
131
|
+
export type FormTagsFieldProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> = Omit<FormFieldGroupProps<TFieldValues, TName>, 'children'> & {
|
|
132
|
+
tagsProps?: Partial<InputTagsProps>;
|
|
133
|
+
};
|
|
134
|
+
export interface FormTagsInnerProps<TFieldValues extends FieldValues, TName extends Path<TFieldValues>> {
|
|
135
|
+
field: ControllerRenderProps<TFieldValues, TName>;
|
|
136
|
+
args?: FormFieldArgs;
|
|
137
|
+
tagsProps?: Partial<InputTagsProps>;
|
|
138
|
+
readOnly?: boolean;
|
|
139
|
+
disabled?: boolean;
|
|
140
|
+
className?: string;
|
|
141
|
+
}
|
|
130
142
|
export {};
|
package/form/index.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export { FormCheckboxField } from './components/form-checkbox-field.component';
|
|
|
12
12
|
export { FormCheckboxGroupField } from './components/form-checkbox-group-field.component';
|
|
13
13
|
export { FormRadioGroupField } from './components/form-radio-group-field.component';
|
|
14
14
|
export { FormDatePickerField } from './components/form-date-picker-field.component';
|
|
15
|
+
export { FormTagsField } from './components/form-tags-field.component';
|
package/form/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export { FormComboboxField } from './components/form-combobox-field.component';
|
|
|
10
10
|
export { FormCheckboxField } from './components/form-checkbox-field.component';
|
|
11
11
|
export { FormCheckboxGroupField } from './components/form-checkbox-group-field.component';
|
|
12
12
|
export { FormRadioGroupField } from './components/form-radio-group-field.component';
|
|
13
|
-
export { FormDatePickerField } from './components/form-date-picker-field.component';
|
|
13
|
+
export { FormDatePickerField } from './components/form-date-picker-field.component';
|
|
14
|
+
export { FormTagsField } from './components/form-tags-field.component';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InputTags } from './input-tags.component';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InputTags } from './input-tags.component';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InputTagsProps } from '@scaleflex/ui-tw/input-tags/input-tags.types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export declare function InputTags({ value, onChange, suggestedTags, allTags, placeholder, allowCustomTags, disabled, size, onGenerateTags, popoverClassName, popoverContentProps, formItemId, readOnly, className, clearAllLabel, generateLabel, ...rest }: InputTagsProps): React.JSX.Element;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
var _excluded = ["value", "onChange", "suggestedTags", "allTags", "placeholder", "allowCustomTags", "disabled", "size", "onGenerateTags", "popoverClassName", "popoverContentProps", "formItemId", "readOnly", "className", "clearAllLabel", "generateLabel"];
|
|
6
|
+
import { SparkleIcon } from '@scaleflex/icons-tw/sparkle-icon';
|
|
7
|
+
import { Button } from '@scaleflex/ui-tw/button';
|
|
8
|
+
import { iconSizeInTriggerOptions } from '@scaleflex/ui-tw/combobox/combobox.constants';
|
|
9
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@scaleflex/ui-tw/command';
|
|
10
|
+
import { Pill } from '@scaleflex/ui-tw/pill';
|
|
11
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@scaleflex/ui-tw/popover';
|
|
12
|
+
import { selectReadOnlyClassNames } from '@scaleflex/ui-tw/select/select.constants';
|
|
13
|
+
import { focusRingClassNames, getBaseInputClasses, selectionHighlightClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
|
|
14
|
+
import { textareaSizeOptions } from '@scaleflex/ui-tw/textarea/textarea.constants';
|
|
15
|
+
import { getToolbarSizes } from '@scaleflex/ui-tw/textarea/textarea.utils';
|
|
16
|
+
import { FormSize } from '@scaleflex/ui-tw/types/form-size';
|
|
17
|
+
import { cn } from '@scaleflex/ui-tw/utils/cn';
|
|
18
|
+
import { cva } from 'class-variance-authority';
|
|
19
|
+
import { ChevronsUpDownIcon } from 'lucide-react';
|
|
20
|
+
import * as React from 'react';
|
|
21
|
+
import { useMemo, useState } from 'react';
|
|
22
|
+
var inputTagsVariants = cva('', {
|
|
23
|
+
variants: {
|
|
24
|
+
size: textareaSizeOptions
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
size: FormSize.Md
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
export function InputTags(_ref) {
|
|
31
|
+
var value = _ref.value,
|
|
32
|
+
onChange = _ref.onChange,
|
|
33
|
+
_ref$suggestedTags = _ref.suggestedTags,
|
|
34
|
+
suggestedTags = _ref$suggestedTags === void 0 ? [] : _ref$suggestedTags,
|
|
35
|
+
_ref$allTags = _ref.allTags,
|
|
36
|
+
allTags = _ref$allTags === void 0 ? [] : _ref$allTags,
|
|
37
|
+
_ref$placeholder = _ref.placeholder,
|
|
38
|
+
placeholder = _ref$placeholder === void 0 ? 'Select or create tags...' : _ref$placeholder,
|
|
39
|
+
_ref$allowCustomTags = _ref.allowCustomTags,
|
|
40
|
+
allowCustomTags = _ref$allowCustomTags === void 0 ? true : _ref$allowCustomTags,
|
|
41
|
+
_ref$disabled = _ref.disabled,
|
|
42
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
43
|
+
_ref$size = _ref.size,
|
|
44
|
+
size = _ref$size === void 0 ? FormSize.Md : _ref$size,
|
|
45
|
+
onGenerateTags = _ref.onGenerateTags,
|
|
46
|
+
popoverClassName = _ref.popoverClassName,
|
|
47
|
+
popoverContentProps = _ref.popoverContentProps,
|
|
48
|
+
formItemId = _ref.formItemId,
|
|
49
|
+
readOnly = _ref.readOnly,
|
|
50
|
+
className = _ref.className,
|
|
51
|
+
_ref$clearAllLabel = _ref.clearAllLabel,
|
|
52
|
+
clearAllLabel = _ref$clearAllLabel === void 0 ? 'Clear all' : _ref$clearAllLabel,
|
|
53
|
+
_ref$generateLabel = _ref.generateLabel,
|
|
54
|
+
generateLabel = _ref$generateLabel === void 0 ? 'Generate' : _ref$generateLabel,
|
|
55
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
56
|
+
var _useState = useState(false),
|
|
57
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
58
|
+
open = _useState2[0],
|
|
59
|
+
setOpen = _useState2[1];
|
|
60
|
+
var _useState3 = useState(''),
|
|
61
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
62
|
+
search = _useState4[0],
|
|
63
|
+
setSearch = _useState4[1];
|
|
64
|
+
var tagsList = [].concat(_toConsumableArray(suggestedTags), _toConsumableArray(allTags));
|
|
65
|
+
var _getToolbarSizes = getToolbarSizes(size),
|
|
66
|
+
buttonSize = _getToolbarSizes.buttonSize;
|
|
67
|
+
var searchTrimmed = search.trim().toLowerCase();
|
|
68
|
+
var isSameTag = function isSameTag(a, b) {
|
|
69
|
+
return a.value.trim().toLowerCase() === b.value.trim().toLowerCase();
|
|
70
|
+
};
|
|
71
|
+
var isSelected = function isSelected(tag) {
|
|
72
|
+
return value.some(function (t) {
|
|
73
|
+
return isSameTag(t, tag);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
var normalizeLabel = function normalizeLabel(label) {
|
|
77
|
+
return label.trim().replace(/\s+/g, ' ');
|
|
78
|
+
};
|
|
79
|
+
var normalizeValue = function normalizeValue(label) {
|
|
80
|
+
return normalizeLabel(label).toLowerCase().replace(/\s+/g, '-');
|
|
81
|
+
};
|
|
82
|
+
var createTag = function createTag(label) {
|
|
83
|
+
return {
|
|
84
|
+
label: normalizeLabel(label),
|
|
85
|
+
value: normalizeValue(label)
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
var newTag = createTag(search);
|
|
89
|
+
var canCreate = useMemo(function () {
|
|
90
|
+
if (!allowCustomTags || !searchTrimmed) return false;
|
|
91
|
+
return !value.some(function (v) {
|
|
92
|
+
return isSameTag(v, newTag);
|
|
93
|
+
}) && !tagsList.some(function (t) {
|
|
94
|
+
return isSameTag(t, newTag);
|
|
95
|
+
});
|
|
96
|
+
}, [newTag, value, tagsList, allowCustomTags, searchTrimmed]);
|
|
97
|
+
var handleAddTag = function handleAddTag(tag) {
|
|
98
|
+
if (isSelected(tag)) return;
|
|
99
|
+
onChange([].concat(_toConsumableArray(value), [tag]));
|
|
100
|
+
setSearch('');
|
|
101
|
+
setOpen(true);
|
|
102
|
+
};
|
|
103
|
+
var handleRemoveTag = function handleRemoveTag(tag) {
|
|
104
|
+
onChange(value.filter(function (t) {
|
|
105
|
+
return !isSameTag(t, tag);
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
var handleClearAll = function handleClearAll() {
|
|
109
|
+
onChange([]);
|
|
110
|
+
setSearch('');
|
|
111
|
+
setOpen(false);
|
|
112
|
+
};
|
|
113
|
+
var filteredSuggested = suggestedTags.filter(function (tag) {
|
|
114
|
+
return !isSelected(tag) && tag.label.toLowerCase().includes(searchTrimmed);
|
|
115
|
+
});
|
|
116
|
+
var filteredAll = allTags.filter(function (tag) {
|
|
117
|
+
return !isSelected(tag) && tag.label.toLowerCase().includes(searchTrimmed);
|
|
118
|
+
});
|
|
119
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
120
|
+
open: open,
|
|
121
|
+
onOpenChange: setOpen
|
|
122
|
+
}, /*#__PURE__*/React.createElement(PopoverTrigger, {
|
|
123
|
+
asChild: true
|
|
124
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
125
|
+
id: formItemId,
|
|
126
|
+
role: "combobox-tags",
|
|
127
|
+
"aria-expanded": open,
|
|
128
|
+
"aria-invalid": rest['aria-invalid'],
|
|
129
|
+
disabled: disabled,
|
|
130
|
+
className: cn.apply(void 0, ['relative flex w-full', onGenerateTags || value.length > 0 ? 'flex-col' : 'items-center'].concat(_toConsumableArray(getBaseInputClasses()), [selectionHighlightClassNames, focusRingClassNames, readOnly && selectReadOnlyClassNames, className])),
|
|
131
|
+
onClick: function onClick() {
|
|
132
|
+
return !disabled && setOpen(true);
|
|
133
|
+
}
|
|
134
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
135
|
+
className: cn('flex w-full flex-wrap gap-2', inputTagsVariants({
|
|
136
|
+
size: size
|
|
137
|
+
}), 'min-h-auto')
|
|
138
|
+
}, value.length === 0 ? /*#__PURE__*/React.createElement("span", {
|
|
139
|
+
className: "text-muted-foreground"
|
|
140
|
+
}, placeholder) : value.map(function (tag) {
|
|
141
|
+
return /*#__PURE__*/React.createElement(Pill, {
|
|
142
|
+
key: tag.value,
|
|
143
|
+
size: size,
|
|
144
|
+
removable: true,
|
|
145
|
+
onRemove: function onRemove() {
|
|
146
|
+
return handleRemoveTag(tag);
|
|
147
|
+
}
|
|
148
|
+
}, tag.label);
|
|
149
|
+
})), onGenerateTags || value.length > 0 ? /*#__PURE__*/React.createElement("div", {
|
|
150
|
+
className: "flex w-full items-center justify-between p-1.5 pt-0"
|
|
151
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
152
|
+
className: "flex gap-2"
|
|
153
|
+
}, value.length > 0 && /*#__PURE__*/React.createElement(Button, {
|
|
154
|
+
type: "button",
|
|
155
|
+
variant: "ghost-secondary",
|
|
156
|
+
size: buttonSize,
|
|
157
|
+
"aria-label": "Clear all",
|
|
158
|
+
"data-clear-icon": "true",
|
|
159
|
+
onClick: handleClearAll
|
|
160
|
+
}, clearAllLabel), onGenerateTags && /*#__PURE__*/React.createElement(Button, {
|
|
161
|
+
tabIndex: 0,
|
|
162
|
+
"aria-label": "Generate tags",
|
|
163
|
+
type: "button",
|
|
164
|
+
variant: "ghost-primary",
|
|
165
|
+
size: buttonSize,
|
|
166
|
+
startIcon: /*#__PURE__*/React.createElement(SparkleIcon, {
|
|
167
|
+
className: "size-3.5"
|
|
168
|
+
}),
|
|
169
|
+
onClick: function onClick(e) {
|
|
170
|
+
e.stopPropagation();
|
|
171
|
+
onGenerateTags === null || onGenerateTags === void 0 || onGenerateTags();
|
|
172
|
+
}
|
|
173
|
+
}, generateLabel)), /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
174
|
+
className: cn('mr-1.5 ml-auto shrink-0 opacity-50', iconSizeInTriggerOptions[size])
|
|
175
|
+
})) : /*#__PURE__*/React.createElement(ChevronsUpDownIcon, {
|
|
176
|
+
className: cn('my-auto mr-1.5 ml-auto shrink-0 opacity-50', iconSizeInTriggerOptions[size])
|
|
177
|
+
})))), /*#__PURE__*/React.createElement(PopoverContent, _extends({
|
|
178
|
+
className: cn('w-[--radix-popover-trigger-width] p-0', popoverClassName)
|
|
179
|
+
}, popoverContentProps), /*#__PURE__*/React.createElement(Command, {
|
|
180
|
+
shouldFilter: false
|
|
181
|
+
}, /*#__PURE__*/React.createElement(CommandInput, {
|
|
182
|
+
size: size,
|
|
183
|
+
value: search,
|
|
184
|
+
onValueChange: setSearch,
|
|
185
|
+
placeholder: "Search or create a tag"
|
|
186
|
+
}), /*#__PURE__*/React.createElement(CommandList, null, filteredSuggested.length > 0 && /*#__PURE__*/React.createElement(CommandGroup, {
|
|
187
|
+
size: size,
|
|
188
|
+
heading: "Suggested"
|
|
189
|
+
}, filteredSuggested.map(function (tag) {
|
|
190
|
+
return /*#__PURE__*/React.createElement(CommandItem, {
|
|
191
|
+
key: tag.value,
|
|
192
|
+
size: size,
|
|
193
|
+
onSelect: function onSelect() {
|
|
194
|
+
return handleAddTag(tag);
|
|
195
|
+
},
|
|
196
|
+
isGroup: true
|
|
197
|
+
}, tag.label);
|
|
198
|
+
})), filteredAll.length > 0 && /*#__PURE__*/React.createElement(CommandGroup, {
|
|
199
|
+
size: size,
|
|
200
|
+
heading: "All Tags"
|
|
201
|
+
}, filteredAll.map(function (tag) {
|
|
202
|
+
return /*#__PURE__*/React.createElement(CommandItem, {
|
|
203
|
+
key: tag.value,
|
|
204
|
+
size: size,
|
|
205
|
+
onSelect: function onSelect() {
|
|
206
|
+
return handleAddTag(tag);
|
|
207
|
+
},
|
|
208
|
+
isGroup: true
|
|
209
|
+
}, tag.label);
|
|
210
|
+
})), !canCreate && filteredSuggested.length === 0 && filteredAll.length === 0 && /*#__PURE__*/React.createElement(CommandEmpty, null, "No results found."), canCreate && /*#__PURE__*/React.createElement(CommandItem, {
|
|
211
|
+
size: size,
|
|
212
|
+
onSelect: function onSelect() {
|
|
213
|
+
return handleAddTag(newTag);
|
|
214
|
+
}
|
|
215
|
+
}, "Create \"", search.trim(), "\"")))));
|
|
216
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
2
|
+
import type { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
export interface TagOption {
|
|
5
|
+
label: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
export interface InputTagsProps {
|
|
9
|
+
value: TagOption[];
|
|
10
|
+
onChange: (value: TagOption[]) => void;
|
|
11
|
+
suggestedTags?: TagOption[];
|
|
12
|
+
allTags?: TagOption[];
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
allowCustomTags?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
popoverClassName?: string;
|
|
17
|
+
popoverContentProps?: ComponentProps<typeof PopoverPrimitive.Content>;
|
|
18
|
+
size?: FormSizeType;
|
|
19
|
+
onGenerateTags?: () => void;
|
|
20
|
+
formItemId?: string;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
clearAllLabel?: string;
|
|
24
|
+
generateLabel?: string;
|
|
25
|
+
'aria-invalid'?: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
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.47",
|
|
27
27
|
"@tanstack/react-table": "^8.21.3",
|
|
28
28
|
"@types/lodash.merge": "^4.6.9",
|
|
29
29
|
"class-variance-authority": "^0.7.1",
|
|
@@ -4,6 +4,10 @@ import React from 'react';
|
|
|
4
4
|
import { getToolbarSizes } from '../textarea.utils';
|
|
5
5
|
export var LeftToolbarButtons = function LeftToolbarButtons(props) {
|
|
6
6
|
var size = props.size,
|
|
7
|
+
_props$generateLabel = props.generateLabel,
|
|
8
|
+
generateLabel = _props$generateLabel === void 0 ? 'Generate' : _props$generateLabel,
|
|
9
|
+
_props$clearAllLabel = props.clearAllLabel,
|
|
10
|
+
clearAllLabel = _props$clearAllLabel === void 0 ? 'Clear all' : _props$clearAllLabel,
|
|
7
11
|
onGenerate = props.onGenerate,
|
|
8
12
|
onClearAll = props.onClearAll;
|
|
9
13
|
var _getToolbarSizes = getToolbarSizes(size),
|
|
@@ -16,10 +20,10 @@ export var LeftToolbarButtons = function LeftToolbarButtons(props) {
|
|
|
16
20
|
className: "size-3.5"
|
|
17
21
|
}),
|
|
18
22
|
onClick: onGenerate
|
|
19
|
-
},
|
|
23
|
+
}, generateLabel), onClearAll && /*#__PURE__*/React.createElement(Button, {
|
|
20
24
|
type: "button",
|
|
21
25
|
variant: "ghost-secondary",
|
|
22
26
|
size: buttonSize,
|
|
23
27
|
onClick: onClearAll
|
|
24
|
-
},
|
|
28
|
+
}, clearAllLabel));
|
|
25
29
|
};
|