@pallasoft/ps-input-components 3.5.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ps-cascader-input.d.ts +2 -1
- package/dist/components/ps-cascader-input.js +2 -2
- package/dist/components/ps-tag-input.d.ts +17 -0
- package/dist/components/ps-tag-input.js +43 -0
- package/dist/constants/ps-tag-input-config.d.ts +5 -0
- package/dist/constants/ps-tag-input-config.js +8 -0
- package/dist/esm/components/ps-cascader-input.js +2 -2
- package/dist/esm/components/ps-tag-input.js +39 -0
- package/dist/esm/constants/ps-tag-input-config.js +5 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/services/ps-grouped-switcher-service.js +1 -1
- package/dist/esm/services/ps-tag-input-service.js +27 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/services/ps-grouped-switcher-service.js +1 -1
- package/dist/services/ps-tag-input-service.d.ts +6 -0
- package/dist/services/ps-tag-input-service.js +31 -0
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ export interface PsCascaderInputProps {
|
|
|
16
16
|
helperText?: string;
|
|
17
17
|
hideLabel?: boolean;
|
|
18
18
|
isLoading?: boolean;
|
|
19
|
+
isSuggested?: boolean;
|
|
19
20
|
label: string;
|
|
20
21
|
onChange: (value: string) => void;
|
|
21
22
|
placeholder?: string;
|
|
@@ -24,4 +25,4 @@ export interface PsCascaderInputProps {
|
|
|
24
25
|
searchPlaceholder?: string;
|
|
25
26
|
value: string;
|
|
26
27
|
}
|
|
27
|
-
export declare const PsCascaderInput: ({ className, disabled, groups, helperText, hideLabel, isLoading, label, onChange, placeholder, preferredGroupKey, required, searchPlaceholder, value, }: PsCascaderInputProps) => import("react").JSX.Element;
|
|
28
|
+
export declare const PsCascaderInput: ({ className, disabled, groups, helperText, hideLabel, isLoading, isSuggested, label, onChange, placeholder, preferredGroupKey, required, searchPlaceholder, value, }: PsCascaderInputProps) => import("react").JSX.Element;
|
|
@@ -11,7 +11,7 @@ const ps_cascader_config_1 = require("../constants/ps-cascader-config");
|
|
|
11
11
|
const ps_cascader_service_1 = require("../services/ps-cascader-service");
|
|
12
12
|
const ps_field_skeleton_1 = require("./ps-field-skeleton");
|
|
13
13
|
const ps_required_mark_1 = require("./ps-required-mark");
|
|
14
|
-
const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, isLoading = false, label, onChange, placeholder = 'Select an option', preferredGroupKey, required, searchPlaceholder = 'Search', value, }) => {
|
|
14
|
+
const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, isLoading = false, isSuggested = false, label, onChange, placeholder = 'Select an option', preferredGroupKey, required, searchPlaceholder = 'Search', value, }) => {
|
|
15
15
|
if (isLoading)
|
|
16
16
|
return (0, jsx_runtime_1.jsx)(ps_field_skeleton_1.PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
17
17
|
const zIndex = (0, ps_core_components_1.usePsLayerZIndex)(ps_design_system_1.PallasoftZIndex.Dropdown);
|
|
@@ -51,7 +51,7 @@ const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, i
|
|
|
51
51
|
: option.value === value
|
|
52
52
|
? 'bg-primary/10 text-ink'
|
|
53
53
|
: 'text-ink/80 hover:bg-mist/60 hover:text-ink'), disabled: option.isDisabled, onClick: () => select(option.value, close), role: 'option', type: 'button', children: [(0, jsx_runtime_1.jsx)("span", { className: 'flex h-5 w-4 shrink-0 items-center justify-center text-primary', children: option.value === value ? ((0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.Check })) : null }), (0, jsx_runtime_1.jsxs)("span", { className: 'min-w-0 flex-1', children: [(0, jsx_runtime_1.jsx)("span", { className: 'block break-words', children: option.label }), groupLabel ? ((0, jsx_runtime_1.jsx)("span", { className: 'mt-0.5 block break-words text-xs font-normal text-ink/50', children: groupLabel })) : null, option.description ? ((0, jsx_runtime_1.jsx)("span", { className: 'mt-0.5 block break-words text-xs font-normal text-ink/55', children: option.description })) : null] })] }, option.value));
|
|
54
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), children: [hideLabel ? null : ((0, jsx_runtime_1.jsxs)("span", { className: 'ps-input-label block', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] })), (0, jsx_runtime_1.jsxs)(react_aria_components_1.DialogTrigger, { isOpen: isOpen, onOpenChange: open, children: [(0, jsx_runtime_1.jsxs)(react_aria_components_1.Button, { "aria-label": hideLabel ? label : undefined, className: ps_design_system_1.PallasoftClassNameService.merge('ps-input-control ps-focus-ring relative flex w-full items-center pr-10 text-left text-sm font-semibold disabled:cursor-not-allowed disabled:opacity-60', hideLabel ? '' : 'mt-2'), isDisabled: disabled, children: [(0, jsx_runtime_1.jsx)("span", { className: 'min-w-0 flex-1 truncate', children: selected ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: 'truncate', children: selected.option.label }), (0, jsx_runtime_1.jsx)("span", { className: 'ml-2 text-xs font-medium text-ink/45', children: selected.group.label })] })) : ((0, jsx_runtime_1.jsx)("span", { className: 'font-medium text-ink/45', children: placeholder })) }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute top-1/2 right-3 h-4 w-4 -translate-y-1/2 text-primary', iconKey: ps_icons_1.PsIconKey.Chevron })] }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'ps-floating-panel w-[min(calc(100vw-2rem),32rem)] min-w-[var(--trigger-width)] outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Dialog, { "aria-label": label, className: 'flex flex-col outline-none', children: ({ close }) => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: groups.length === 0 ? ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-col gap-1 px-4 py-8 text-center', children: [(0, jsx_runtime_1.jsx)("p", { className: 'text-sm font-semibold text-ink', children: ps_cascader_config_1.PsCascaderConfig.emptyLabel }), (0, jsx_runtime_1.jsx)("p", { className: 'text-xs text-ink/55', children: ps_cascader_config_1.PsCascaderConfig.emptyDescription })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'border-b border-line p-2', children: (0, jsx_runtime_1.jsx)("input", { "aria-label": searchPlaceholder, autoFocus: true, className: 'ps-input-control ps-control-compact ps-focus-ring w-full text-sm', onChange: (event) => setQuery(event.target.value), placeholder: searchPlaceholder, type: 'search', value: query }) }), query.trim() === '' ? ((0, jsx_runtime_1.jsxs)("div", { className: 'grid grid-cols-1 sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]', children: [(0, jsx_runtime_1.jsx)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5 sm:border-r sm:border-line', activeGroupKey && groups.length > 1 ? 'hidden sm:block' : ''), children: groups.map((group) => ((0, jsx_runtime_1.jsxs)("button", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-focus-ring flex w-full items-center gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-semibold transition-colors', activeGroup?.key === group.key
|
|
54
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), children: [hideLabel ? null : ((0, jsx_runtime_1.jsxs)("span", { className: 'ps-input-label block', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] })), (0, jsx_runtime_1.jsxs)(react_aria_components_1.DialogTrigger, { isOpen: isOpen, onOpenChange: open, children: [(0, jsx_runtime_1.jsxs)(react_aria_components_1.Button, { "aria-label": hideLabel ? label : undefined, className: ps_design_system_1.PallasoftClassNameService.merge('ps-input-control ps-focus-ring relative flex w-full items-center pr-10 text-left text-sm font-semibold disabled:cursor-not-allowed disabled:opacity-60', hideLabel ? '' : 'mt-2', isSuggested ? 'border-dashed border-primary/60 bg-primary/5' : ''), isDisabled: disabled, children: [(0, jsx_runtime_1.jsx)("span", { className: 'min-w-0 flex-1 truncate', children: selected ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: 'truncate', children: selected.option.label }), (0, jsx_runtime_1.jsx)("span", { className: 'ml-2 text-xs font-medium text-ink/45', children: selected.group.label })] })) : ((0, jsx_runtime_1.jsx)("span", { className: 'font-medium text-ink/45', children: placeholder })) }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute top-1/2 right-3 h-4 w-4 -translate-y-1/2 text-primary', iconKey: ps_icons_1.PsIconKey.Chevron })] }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'ps-floating-panel w-[min(calc(100vw-2rem),32rem)] min-w-[var(--trigger-width)] outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Dialog, { "aria-label": label, className: 'flex flex-col outline-none', children: ({ close }) => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: groups.length === 0 ? ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-col gap-1 px-4 py-8 text-center', children: [(0, jsx_runtime_1.jsx)("p", { className: 'text-sm font-semibold text-ink', children: ps_cascader_config_1.PsCascaderConfig.emptyLabel }), (0, jsx_runtime_1.jsx)("p", { className: 'text-xs text-ink/55', children: ps_cascader_config_1.PsCascaderConfig.emptyDescription })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: 'border-b border-line p-2', children: (0, jsx_runtime_1.jsx)("input", { "aria-label": searchPlaceholder, autoFocus: true, className: 'ps-input-control ps-control-compact ps-focus-ring w-full text-sm', onChange: (event) => setQuery(event.target.value), placeholder: searchPlaceholder, type: 'search', value: query }) }), query.trim() === '' ? ((0, jsx_runtime_1.jsxs)("div", { className: 'grid grid-cols-1 sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]', children: [(0, jsx_runtime_1.jsx)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5 sm:border-r sm:border-line', activeGroupKey && groups.length > 1 ? 'hidden sm:block' : ''), children: groups.map((group) => ((0, jsx_runtime_1.jsxs)("button", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-focus-ring flex w-full items-center gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-semibold transition-colors', activeGroup?.key === group.key
|
|
55
55
|
? 'bg-mist text-ink'
|
|
56
56
|
: 'text-ink/70 hover:bg-mist/60 hover:text-ink'), onClick: () => setActiveGroupKey(group.key), type: 'button', children: [(0, jsx_runtime_1.jsx)("span", { className: 'min-w-0 flex-1 truncate', children: group.label }), (0, jsx_runtime_1.jsx)("span", { className: 'text-xs font-medium text-ink/45', children: group.options.length }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 shrink-0 -rotate-90 text-ink/35', iconKey: ps_icons_1.PsIconKey.Chevron })] }, group.key))) }), (0, jsx_runtime_1.jsxs)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5', activeGroupKey && groups.length > 1 ? '' : 'hidden sm:block'), role: 'listbox', children: [groups.length > 1 ? ((0, jsx_runtime_1.jsxs)("button", { className: 'ps-focus-ring mb-1 flex w-full items-center gap-2 rounded-ps-control px-3 py-2 text-left text-xs font-semibold text-ink/60 hover:text-ink sm:hidden', onClick: () => setActiveGroupKey(null), type: 'button', children: [(0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-90', iconKey: ps_icons_1.PsIconKey.Chevron }), "All groups"] })) : null, activeGroup
|
|
57
57
|
? activeGroup.options.map((option) => renderOption(option, null, close))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PsTagInputProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
errorText?: string;
|
|
4
|
+
helperText?: string;
|
|
5
|
+
hideLabel?: boolean;
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
label: string;
|
|
9
|
+
max?: number;
|
|
10
|
+
name?: string;
|
|
11
|
+
onChange: (values: string[]) => void;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
removeLabel: (value: string) => string;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
values: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare const PsTagInput: ({ className, errorText, helperText, hideLabel, isDisabled, isLoading, label, max, name, onChange, placeholder, removeLabel, required, values, }: PsTagInputProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTagInput = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const ps_core_components_1 = require("@pallasoft/ps-core-components");
|
|
7
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
8
|
+
const ps_tag_input_config_1 = require("../constants/ps-tag-input-config");
|
|
9
|
+
const ps_tag_input_service_1 = require("../services/ps-tag-input-service");
|
|
10
|
+
const ps_field_skeleton_1 = require("./ps-field-skeleton");
|
|
11
|
+
const ps_form_control_1 = require("./ps-form-control");
|
|
12
|
+
const ps_required_mark_1 = require("./ps-required-mark");
|
|
13
|
+
const PsTagInput = ({ className, errorText, helperText, hideLabel, isDisabled = false, isLoading = false, label, max, name, onChange, placeholder, removeLabel, required, values, }) => {
|
|
14
|
+
const [draft, setDraft] = (0, react_1.useState)('');
|
|
15
|
+
const isFull = max !== undefined && values.length >= max;
|
|
16
|
+
if (isLoading)
|
|
17
|
+
return (0, jsx_runtime_1.jsx)(ps_field_skeleton_1.PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
18
|
+
const commit = (text) => {
|
|
19
|
+
if (text.trim() !== '')
|
|
20
|
+
onChange(ps_tag_input_service_1.PsTagInputService.add(values, text, max));
|
|
21
|
+
setDraft('');
|
|
22
|
+
};
|
|
23
|
+
const handleKeyDown = (event) => {
|
|
24
|
+
if (event.key === ps_tag_input_config_1.PsTagInputConfig.addKey) {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
commit(draft);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (event.key === ps_tag_input_config_1.PsTagInputConfig.removeKey && draft === '' && values.length > 0)
|
|
30
|
+
onChange(ps_tag_input_service_1.PsTagInputService.removeLast(values));
|
|
31
|
+
};
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)(ps_form_control_1.PsFormControl, { className: className, errorText: errorText, helperText: helperText, children: (0, jsx_runtime_1.jsxs)("label", { className: 'block', children: [(0, jsx_runtime_1.jsxs)("span", { className: hideLabel ? 'sr-only' : 'ps-input-label', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] }), (0, jsx_runtime_1.jsxs)("span", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-input-control flex flex-wrap items-center gap-1.5 py-1.5', hideLabel ? '' : 'mt-2', isDisabled ? 'opacity-60' : ''), children: [values.map((value) => ((0, jsx_runtime_1.jsx)(ps_core_components_1.PsActiveFilterChip, { label: value, onRemove: () => {
|
|
33
|
+
if (!isDisabled)
|
|
34
|
+
onChange(ps_tag_input_service_1.PsTagInputService.remove(values, value));
|
|
35
|
+
}, removeLabel: removeLabel(value) }, value))), (0, jsx_runtime_1.jsx)("input", { "aria-invalid": errorText ? true : undefined, className: 'min-w-24 flex-1 bg-transparent text-sm font-semibold outline-none placeholder:font-medium placeholder:text-ink/45 disabled:cursor-not-allowed', disabled: isDisabled || isFull, name: name, onBlur: () => commit(draft), onChange: (event) => {
|
|
36
|
+
const text = event.target.value;
|
|
37
|
+
if (text.includes(ps_tag_input_config_1.PsTagInputConfig.separator))
|
|
38
|
+
commit(text);
|
|
39
|
+
else
|
|
40
|
+
setDraft(text);
|
|
41
|
+
}, onKeyDown: handleKeyDown, placeholder: values.length === 0 ? placeholder : undefined, value: draft })] })] }) }));
|
|
42
|
+
};
|
|
43
|
+
exports.PsTagInput = PsTagInput;
|
|
@@ -8,7 +8,7 @@ import { PsCascaderConfig } from '../constants/ps-cascader-config';
|
|
|
8
8
|
import { PsCascaderService } from '../services/ps-cascader-service';
|
|
9
9
|
import { PsFieldSkeleton } from './ps-field-skeleton';
|
|
10
10
|
import { PsRequiredMark } from './ps-required-mark';
|
|
11
|
-
export const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, isLoading = false, label, onChange, placeholder = 'Select an option', preferredGroupKey, required, searchPlaceholder = 'Search', value, }) => {
|
|
11
|
+
export const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, isLoading = false, isSuggested = false, label, onChange, placeholder = 'Select an option', preferredGroupKey, required, searchPlaceholder = 'Search', value, }) => {
|
|
12
12
|
if (isLoading)
|
|
13
13
|
return _jsx(PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
14
14
|
const zIndex = usePsLayerZIndex(PallasoftZIndex.Dropdown);
|
|
@@ -48,7 +48,7 @@ export const PsCascaderInput = ({ className, disabled, groups, helperText, hideL
|
|
|
48
48
|
: option.value === value
|
|
49
49
|
? 'bg-primary/10 text-ink'
|
|
50
50
|
: 'text-ink/80 hover:bg-mist/60 hover:text-ink'), disabled: option.isDisabled, onClick: () => select(option.value, close), role: 'option', type: 'button', children: [_jsx("span", { className: 'flex h-5 w-4 shrink-0 items-center justify-center text-primary', children: option.value === value ? (_jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: PsIconKey.Check })) : null }), _jsxs("span", { className: 'min-w-0 flex-1', children: [_jsx("span", { className: 'block break-words', children: option.label }), groupLabel ? (_jsx("span", { className: 'mt-0.5 block break-words text-xs font-normal text-ink/50', children: groupLabel })) : null, option.description ? (_jsx("span", { className: 'mt-0.5 block break-words text-xs font-normal text-ink/55', children: option.description })) : null] })] }, option.value));
|
|
51
|
-
return (_jsxs("div", { className: PallasoftClassNameService.merge('block', className), children: [hideLabel ? null : (_jsxs("span", { className: 'ps-input-label block', children: [label, _jsx(PsRequiredMark, { isRequired: required })] })), _jsxs(DialogTrigger, { isOpen: isOpen, onOpenChange: open, children: [_jsxs(Button, { "aria-label": hideLabel ? label : undefined, className: PallasoftClassNameService.merge('ps-input-control ps-focus-ring relative flex w-full items-center pr-10 text-left text-sm font-semibold disabled:cursor-not-allowed disabled:opacity-60', hideLabel ? '' : 'mt-2'), isDisabled: disabled, children: [_jsx("span", { className: 'min-w-0 flex-1 truncate', children: selected ? (_jsxs(_Fragment, { children: [_jsx("span", { className: 'truncate', children: selected.option.label }), _jsx("span", { className: 'ml-2 text-xs font-medium text-ink/45', children: selected.group.label })] })) : (_jsx("span", { className: 'font-medium text-ink/45', children: placeholder })) }), _jsx(PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute top-1/2 right-3 h-4 w-4 -translate-y-1/2 text-primary', iconKey: PsIconKey.Chevron })] }), _jsx(Popover, { className: 'ps-floating-panel w-[min(calc(100vw-2rem),32rem)] min-w-[var(--trigger-width)] outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: _jsx(Dialog, { "aria-label": label, className: 'flex flex-col outline-none', children: ({ close }) => (_jsx(_Fragment, { children: groups.length === 0 ? (_jsxs("div", { className: 'flex flex-col gap-1 px-4 py-8 text-center', children: [_jsx("p", { className: 'text-sm font-semibold text-ink', children: PsCascaderConfig.emptyLabel }), _jsx("p", { className: 'text-xs text-ink/55', children: PsCascaderConfig.emptyDescription })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: 'border-b border-line p-2', children: _jsx("input", { "aria-label": searchPlaceholder, autoFocus: true, className: 'ps-input-control ps-control-compact ps-focus-ring w-full text-sm', onChange: (event) => setQuery(event.target.value), placeholder: searchPlaceholder, type: 'search', value: query }) }), query.trim() === '' ? (_jsxs("div", { className: 'grid grid-cols-1 sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]', children: [_jsx("div", { className: PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5 sm:border-r sm:border-line', activeGroupKey && groups.length > 1 ? 'hidden sm:block' : ''), children: groups.map((group) => (_jsxs("button", { className: PallasoftClassNameService.merge('ps-focus-ring flex w-full items-center gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-semibold transition-colors', activeGroup?.key === group.key
|
|
51
|
+
return (_jsxs("div", { className: PallasoftClassNameService.merge('block', className), children: [hideLabel ? null : (_jsxs("span", { className: 'ps-input-label block', children: [label, _jsx(PsRequiredMark, { isRequired: required })] })), _jsxs(DialogTrigger, { isOpen: isOpen, onOpenChange: open, children: [_jsxs(Button, { "aria-label": hideLabel ? label : undefined, className: PallasoftClassNameService.merge('ps-input-control ps-focus-ring relative flex w-full items-center pr-10 text-left text-sm font-semibold disabled:cursor-not-allowed disabled:opacity-60', hideLabel ? '' : 'mt-2', isSuggested ? 'border-dashed border-primary/60 bg-primary/5' : ''), isDisabled: disabled, children: [_jsx("span", { className: 'min-w-0 flex-1 truncate', children: selected ? (_jsxs(_Fragment, { children: [_jsx("span", { className: 'truncate', children: selected.option.label }), _jsx("span", { className: 'ml-2 text-xs font-medium text-ink/45', children: selected.group.label })] })) : (_jsx("span", { className: 'font-medium text-ink/45', children: placeholder })) }), _jsx(PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute top-1/2 right-3 h-4 w-4 -translate-y-1/2 text-primary', iconKey: PsIconKey.Chevron })] }), _jsx(Popover, { className: 'ps-floating-panel w-[min(calc(100vw-2rem),32rem)] min-w-[var(--trigger-width)] outline-none', offset: 6, placement: 'bottom start', style: { zIndex }, children: _jsx(Dialog, { "aria-label": label, className: 'flex flex-col outline-none', children: ({ close }) => (_jsx(_Fragment, { children: groups.length === 0 ? (_jsxs("div", { className: 'flex flex-col gap-1 px-4 py-8 text-center', children: [_jsx("p", { className: 'text-sm font-semibold text-ink', children: PsCascaderConfig.emptyLabel }), _jsx("p", { className: 'text-xs text-ink/55', children: PsCascaderConfig.emptyDescription })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: 'border-b border-line p-2', children: _jsx("input", { "aria-label": searchPlaceholder, autoFocus: true, className: 'ps-input-control ps-control-compact ps-focus-ring w-full text-sm', onChange: (event) => setQuery(event.target.value), placeholder: searchPlaceholder, type: 'search', value: query }) }), query.trim() === '' ? (_jsxs("div", { className: 'grid grid-cols-1 sm:grid-cols-[minmax(0,11rem)_minmax(0,1fr)]', children: [_jsx("div", { className: PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5 sm:border-r sm:border-line', activeGroupKey && groups.length > 1 ? 'hidden sm:block' : ''), children: groups.map((group) => (_jsxs("button", { className: PallasoftClassNameService.merge('ps-focus-ring flex w-full items-center gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-semibold transition-colors', activeGroup?.key === group.key
|
|
52
52
|
? 'bg-mist text-ink'
|
|
53
53
|
: 'text-ink/70 hover:bg-mist/60 hover:text-ink'), onClick: () => setActiveGroupKey(group.key), type: 'button', children: [_jsx("span", { className: 'min-w-0 flex-1 truncate', children: group.label }), _jsx("span", { className: 'text-xs font-medium text-ink/45', children: group.options.length }), _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 shrink-0 -rotate-90 text-ink/35', iconKey: PsIconKey.Chevron })] }, group.key))) }), _jsxs("div", { className: PallasoftClassNameService.merge('ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5', activeGroupKey && groups.length > 1 ? '' : 'hidden sm:block'), role: 'listbox', children: [groups.length > 1 ? (_jsxs("button", { className: 'ps-focus-ring mb-1 flex w-full items-center gap-2 rounded-ps-control px-3 py-2 text-left text-xs font-semibold text-ink/60 hover:text-ink sm:hidden', onClick: () => setActiveGroupKey(null), type: 'button', children: [_jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-90', iconKey: PsIconKey.Chevron }), "All groups"] })) : null, activeGroup
|
|
54
54
|
? activeGroup.options.map((option) => renderOption(option, null, close))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { PsActiveFilterChip } from '@pallasoft/ps-core-components';
|
|
4
|
+
import { PallasoftClassNameService } from '@pallasoft/ps-design-system';
|
|
5
|
+
import { PsTagInputConfig } from '../constants/ps-tag-input-config';
|
|
6
|
+
import { PsTagInputService } from '../services/ps-tag-input-service';
|
|
7
|
+
import { PsFieldSkeleton } from './ps-field-skeleton';
|
|
8
|
+
import { PsFormControl } from './ps-form-control';
|
|
9
|
+
import { PsRequiredMark } from './ps-required-mark';
|
|
10
|
+
export const PsTagInput = ({ className, errorText, helperText, hideLabel, isDisabled = false, isLoading = false, label, max, name, onChange, placeholder, removeLabel, required, values, }) => {
|
|
11
|
+
const [draft, setDraft] = useState('');
|
|
12
|
+
const isFull = max !== undefined && values.length >= max;
|
|
13
|
+
if (isLoading)
|
|
14
|
+
return _jsx(PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
15
|
+
const commit = (text) => {
|
|
16
|
+
if (text.trim() !== '')
|
|
17
|
+
onChange(PsTagInputService.add(values, text, max));
|
|
18
|
+
setDraft('');
|
|
19
|
+
};
|
|
20
|
+
const handleKeyDown = (event) => {
|
|
21
|
+
if (event.key === PsTagInputConfig.addKey) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
commit(draft);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (event.key === PsTagInputConfig.removeKey && draft === '' && values.length > 0)
|
|
27
|
+
onChange(PsTagInputService.removeLast(values));
|
|
28
|
+
};
|
|
29
|
+
return (_jsx(PsFormControl, { className: className, errorText: errorText, helperText: helperText, children: _jsxs("label", { className: 'block', children: [_jsxs("span", { className: hideLabel ? 'sr-only' : 'ps-input-label', children: [label, _jsx(PsRequiredMark, { isRequired: required })] }), _jsxs("span", { className: PallasoftClassNameService.merge('ps-input-control flex flex-wrap items-center gap-1.5 py-1.5', hideLabel ? '' : 'mt-2', isDisabled ? 'opacity-60' : ''), children: [values.map((value) => (_jsx(PsActiveFilterChip, { label: value, onRemove: () => {
|
|
30
|
+
if (!isDisabled)
|
|
31
|
+
onChange(PsTagInputService.remove(values, value));
|
|
32
|
+
}, removeLabel: removeLabel(value) }, value))), _jsx("input", { "aria-invalid": errorText ? true : undefined, className: 'min-w-24 flex-1 bg-transparent text-sm font-semibold outline-none placeholder:font-medium placeholder:text-ink/45 disabled:cursor-not-allowed', disabled: isDisabled || isFull, name: name, onBlur: () => commit(draft), onChange: (event) => {
|
|
33
|
+
const text = event.target.value;
|
|
34
|
+
if (text.includes(PsTagInputConfig.separator))
|
|
35
|
+
commit(text);
|
|
36
|
+
else
|
|
37
|
+
setDraft(text);
|
|
38
|
+
}, onKeyDown: handleKeyDown, placeholder: values.length === 0 ? placeholder : undefined, value: draft })] })] }) }));
|
|
39
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -11,6 +11,9 @@ export * from './components/ps-field-skeleton';
|
|
|
11
11
|
export * from './components/ps-form-control';
|
|
12
12
|
export * from './components/ps-multi-select-input';
|
|
13
13
|
export * from './components/ps-select-input';
|
|
14
|
+
export * from './components/ps-tag-input';
|
|
15
|
+
export * from './constants/ps-tag-input-config';
|
|
16
|
+
export * from './services/ps-tag-input-service';
|
|
14
17
|
export * from './components/ps-text-area-input';
|
|
15
18
|
export * from './components/ps-text-input';
|
|
16
19
|
export * from './components/ps-toggle';
|
|
@@ -24,7 +24,7 @@ export class PsGroupedSwitcherService {
|
|
|
24
24
|
const groups = input.groups
|
|
25
25
|
.map((group) => ({
|
|
26
26
|
items: needle === ''
|
|
27
|
-
? group.items
|
|
27
|
+
? group.items.filter((item) => !input.pinnedKeys.includes(input.getItemKey(item)))
|
|
28
28
|
: group.items.filter((item) => {
|
|
29
29
|
const haystack = `${group.label} ${input.getItemSearchText(item)}`.toLowerCase();
|
|
30
30
|
return words.every((word) => haystack.includes(word));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PsTagInputConfig } from '../constants/ps-tag-input-config';
|
|
2
|
+
export class PsTagInputService {
|
|
3
|
+
static parse(text) {
|
|
4
|
+
return text
|
|
5
|
+
.split(PsTagInputConfig.separator)
|
|
6
|
+
.map((entry) => entry.trim())
|
|
7
|
+
.filter((entry) => entry !== '');
|
|
8
|
+
}
|
|
9
|
+
static add(values, text, max) {
|
|
10
|
+
const taken = new Set(values.map((value) => value.toLowerCase()));
|
|
11
|
+
const next = [...values];
|
|
12
|
+
for (const entry of PsTagInputService.parse(text)) {
|
|
13
|
+
const key = entry.toLowerCase();
|
|
14
|
+
if (taken.has(key) || (max !== undefined && next.length >= max))
|
|
15
|
+
continue;
|
|
16
|
+
taken.add(key);
|
|
17
|
+
next.push(entry);
|
|
18
|
+
}
|
|
19
|
+
return next;
|
|
20
|
+
}
|
|
21
|
+
static remove(values, value) {
|
|
22
|
+
return values.filter((entry) => entry !== value);
|
|
23
|
+
}
|
|
24
|
+
static removeLast(values) {
|
|
25
|
+
return values.slice(0, values.length - 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export * from './components/ps-field-skeleton';
|
|
|
11
11
|
export * from './components/ps-form-control';
|
|
12
12
|
export * from './components/ps-multi-select-input';
|
|
13
13
|
export * from './components/ps-select-input';
|
|
14
|
+
export * from './components/ps-tag-input';
|
|
15
|
+
export * from './constants/ps-tag-input-config';
|
|
16
|
+
export * from './services/ps-tag-input-service';
|
|
14
17
|
export * from './components/ps-text-area-input';
|
|
15
18
|
export * from './components/ps-text-input';
|
|
16
19
|
export * from './components/ps-toggle';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,9 @@ __exportStar(require("./components/ps-field-skeleton"), exports);
|
|
|
27
27
|
__exportStar(require("./components/ps-form-control"), exports);
|
|
28
28
|
__exportStar(require("./components/ps-multi-select-input"), exports);
|
|
29
29
|
__exportStar(require("./components/ps-select-input"), exports);
|
|
30
|
+
__exportStar(require("./components/ps-tag-input"), exports);
|
|
31
|
+
__exportStar(require("./constants/ps-tag-input-config"), exports);
|
|
32
|
+
__exportStar(require("./services/ps-tag-input-service"), exports);
|
|
30
33
|
__exportStar(require("./components/ps-text-area-input"), exports);
|
|
31
34
|
__exportStar(require("./components/ps-text-input"), exports);
|
|
32
35
|
__exportStar(require("./components/ps-toggle"), exports);
|
|
@@ -27,7 +27,7 @@ class PsGroupedSwitcherService {
|
|
|
27
27
|
const groups = input.groups
|
|
28
28
|
.map((group) => ({
|
|
29
29
|
items: needle === ''
|
|
30
|
-
? group.items
|
|
30
|
+
? group.items.filter((item) => !input.pinnedKeys.includes(input.getItemKey(item)))
|
|
31
31
|
: group.items.filter((item) => {
|
|
32
32
|
const haystack = `${group.label} ${input.getItemSearchText(item)}`.toLowerCase();
|
|
33
33
|
return words.every((word) => haystack.includes(word));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class PsTagInputService {
|
|
2
|
+
static parse(text: string): string[];
|
|
3
|
+
static add(values: string[], text: string, max: number | undefined): string[];
|
|
4
|
+
static remove(values: string[], value: string): string[];
|
|
5
|
+
static removeLast(values: string[]): string[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTagInputService = void 0;
|
|
4
|
+
const ps_tag_input_config_1 = require("../constants/ps-tag-input-config");
|
|
5
|
+
class PsTagInputService {
|
|
6
|
+
static parse(text) {
|
|
7
|
+
return text
|
|
8
|
+
.split(ps_tag_input_config_1.PsTagInputConfig.separator)
|
|
9
|
+
.map((entry) => entry.trim())
|
|
10
|
+
.filter((entry) => entry !== '');
|
|
11
|
+
}
|
|
12
|
+
static add(values, text, max) {
|
|
13
|
+
const taken = new Set(values.map((value) => value.toLowerCase()));
|
|
14
|
+
const next = [...values];
|
|
15
|
+
for (const entry of PsTagInputService.parse(text)) {
|
|
16
|
+
const key = entry.toLowerCase();
|
|
17
|
+
if (taken.has(key) || (max !== undefined && next.length >= max))
|
|
18
|
+
continue;
|
|
19
|
+
taken.add(key);
|
|
20
|
+
next.push(entry);
|
|
21
|
+
}
|
|
22
|
+
return next;
|
|
23
|
+
}
|
|
24
|
+
static remove(values, value) {
|
|
25
|
+
return values.filter((entry) => entry !== value);
|
|
26
|
+
}
|
|
27
|
+
static removeLast(values) {
|
|
28
|
+
return values.slice(0, values.length - 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.PsTagInputService = PsTagInputService;
|