@pallasoft/ps-input-components 1.13.0 → 1.15.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.js +6 -5
- package/dist/components/ps-year-input.d.ts +17 -0
- package/dist/components/ps-year-input.js +45 -0
- package/dist/constants/ps-cascader-config.d.ts +5 -0
- package/dist/constants/ps-cascader-config.js +8 -0
- package/dist/constants/ps-year-input-config.d.ts +5 -0
- package/dist/constants/ps-year-input-config.js +8 -0
- package/dist/esm/components/ps-cascader-input.js +6 -5
- package/dist/esm/components/ps-year-input.js +38 -0
- package/dist/esm/constants/ps-cascader-config.js +5 -0
- package/dist/esm/constants/ps-year-input-config.js +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/services/ps-year-input-service.js +15 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/services/ps-year-input-service.d.ts +5 -0
- package/dist/services/ps-year-input-service.js +19 -0
- package/package.json +5 -5
|
@@ -7,6 +7,7 @@ const ps_core_components_1 = require("@pallasoft/ps-core-components");
|
|
|
7
7
|
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
8
8
|
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
9
9
|
const react_aria_components_1 = require("react-aria-components");
|
|
10
|
+
const ps_cascader_config_1 = require("../constants/ps-cascader-config");
|
|
10
11
|
const ps_cascader_service_1 = require("../services/ps-cascader-service");
|
|
11
12
|
const ps_field_skeleton_1 = require("./ps-field-skeleton");
|
|
12
13
|
const ps_required_mark_1 = require("./ps-required-mark");
|
|
@@ -43,10 +44,10 @@ const PsCascaderInput = ({ className, disabled, groups, helperText, hideLabel, i
|
|
|
43
44
|
const renderOption = (option, groupLabel, close) => ((0, jsx_runtime_1.jsxs)("button", { "aria-selected": option.value === value, className: ps_design_system_1.PallasoftClassNameService.merge('ps-focus-ring flex w-full items-start gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-medium transition-colors', option.value === value
|
|
44
45
|
? 'bg-primary/10 text-ink'
|
|
45
46
|
: 'text-ink/80 hover:bg-mist/60 hover:text-ink'), 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 truncate', children: option.label }), groupLabel ? ((0, jsx_runtime_1.jsx)("span", { className: 'mt-0.5 block truncate text-xs font-normal text-ink/50', children: groupLabel })) : null, option.description ? ((0, jsx_runtime_1.jsx)("span", { className: 'mt-0.5 block truncate text-xs font-normal text-ink/55', children: option.description })) : null] })] }, option.value));
|
|
46
|
-
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 min-h-11 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.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-focus-ring h-10 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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
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 min-h-11 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-focus-ring h-10 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
|
|
48
|
+
? 'bg-mist text-ink'
|
|
49
|
+
: '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
|
|
50
|
+
? activeGroup.options.map((option) => renderOption(option, null, close))
|
|
51
|
+
: null] })] })) : ((0, jsx_runtime_1.jsx)("div", { className: 'ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5', role: 'listbox', children: matches.length === 0 ? ((0, jsx_runtime_1.jsx)("p", { className: 'px-3 py-6 text-center text-sm text-ink/55', children: ps_cascader_config_1.PsCascaderConfig.noMatchesLabel })) : (matches.map((match) => renderOption(match.option, match.group.label, close))) }))] })) })) }) })] }), helperText ? (0, jsx_runtime_1.jsx)("span", { className: 'ps-input-helper mt-2 block', children: helperText }) : null] }));
|
|
51
52
|
};
|
|
52
53
|
exports.PsCascaderInput = PsCascaderInput;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PsYearInputProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
helperText?: string;
|
|
6
|
+
hideLabel?: boolean;
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
label: string;
|
|
9
|
+
maxYear?: number;
|
|
10
|
+
minYear?: number;
|
|
11
|
+
name?: string;
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
value?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const PsYearInput: ({ className, defaultValue, disabled, helperText, hideLabel, isLoading, label, maxYear, minYear, name, onChange, placeholder, required, value, }: PsYearInputProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PsYearInput = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const ps_core_components_1 = require("@pallasoft/ps-core-components");
|
|
10
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
11
|
+
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
12
|
+
const react_datepicker_1 = __importDefault(require("react-datepicker"));
|
|
13
|
+
const ps_date_input_config_1 = require("../constants/ps-date-input-config");
|
|
14
|
+
const ps_year_input_config_1 = require("../constants/ps-year-input-config");
|
|
15
|
+
const ps_year_input_service_1 = require("../services/ps-year-input-service");
|
|
16
|
+
const ps_field_skeleton_1 = require("./ps-field-skeleton");
|
|
17
|
+
const ps_required_mark_1 = require("./ps-required-mark");
|
|
18
|
+
const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel, isLoading = false, label, maxYear, minYear, name, onChange, placeholder = ps_year_input_config_1.PsYearInputConfig.placeholder, required, value, }) => {
|
|
19
|
+
if (isLoading)
|
|
20
|
+
return (0, jsx_runtime_1.jsx)(ps_field_skeleton_1.PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
21
|
+
const inputId = (0, react_1.useId)();
|
|
22
|
+
const portalId = `${ps_date_input_config_1.PsDateInputConfig.portalId}-${inputId.replace(/:/g, '')}`;
|
|
23
|
+
const zIndex = (0, ps_core_components_1.usePsLayerZIndex)(ps_design_system_1.PallasoftZIndex.Dropdown);
|
|
24
|
+
const [uncontrolledValue, setUncontrolledValue] = (0, react_1.useState)(defaultValue === undefined ? '' : defaultValue);
|
|
25
|
+
const currentValue = value === undefined ? uncontrolledValue : value;
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
const existing = document.getElementById(portalId);
|
|
28
|
+
const container = existing ? existing : document.createElement('div');
|
|
29
|
+
container.id = portalId;
|
|
30
|
+
container.setAttribute(ps_date_input_config_1.PsDateInputConfig.topLayerAttribute, 'true');
|
|
31
|
+
container.style.position = 'relative';
|
|
32
|
+
container.style.zIndex = String(zIndex);
|
|
33
|
+
if (!existing)
|
|
34
|
+
document.body.appendChild(container);
|
|
35
|
+
return () => container.remove();
|
|
36
|
+
}, [portalId, zIndex]);
|
|
37
|
+
const handleChange = (date) => {
|
|
38
|
+
const nextValue = ps_year_input_service_1.PsYearInputService.format(date);
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
setUncontrolledValue(nextValue);
|
|
41
|
+
onChange?.(nextValue);
|
|
42
|
+
};
|
|
43
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), children: [(0, jsx_runtime_1.jsxs)("label", { className: hideLabel ? 'sr-only' : 'ps-input-label block', htmlFor: inputId, children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] }), (0, jsx_runtime_1.jsxs)("div", { className: hideLabel ? 'relative' : 'relative mt-2', children: [(0, jsx_runtime_1.jsx)(react_datepicker_1.default, { autoComplete: 'off', calendarClassName: 'ps-floating-panel ps-datepicker', className: 'ps-input-control ps-focus-ring min-h-11 w-full pr-10 text-sm font-semibold', dateFormat: ps_year_input_config_1.PsYearInputConfig.format, disabled: disabled, id: inputId, maxDate: ps_year_input_service_1.PsYearInputService.bound(maxYear), minDate: ps_year_input_service_1.PsYearInputService.bound(minYear), onChange: handleChange, placeholderText: placeholder, popperClassName: 'ps-datepicker-popper', popperPlacement: 'bottom-start', popperProps: { strategy: 'fixed' }, portalId: portalId, required: required, selected: ps_year_input_service_1.PsYearInputService.parse(currentValue), showPopperArrow: false, showYearPicker: true, wrapperClassName: 'block w-full', yearItemNumber: ps_year_input_config_1.PsYearInputConfig.yearsPerPage }), (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-ink/50', iconKey: ps_icons_1.PsIconKey.Calendar }), name ? (0, jsx_runtime_1.jsx)("input", { name: name, type: 'hidden', value: currentValue }) : null] }), helperText ? (0, jsx_runtime_1.jsx)("span", { className: 'ps-input-helper', children: helperText }) : null] }));
|
|
44
|
+
};
|
|
45
|
+
exports.PsYearInput = PsYearInput;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsCascaderConfig = void 0;
|
|
4
|
+
exports.PsCascaderConfig = {
|
|
5
|
+
emptyDescription: 'Add one first and it will show up here.',
|
|
6
|
+
emptyLabel: 'Nothing to choose from yet',
|
|
7
|
+
noMatchesLabel: 'No matches.',
|
|
8
|
+
};
|
|
@@ -4,6 +4,7 @@ import { usePsLayerZIndex } from '@pallasoft/ps-core-components';
|
|
|
4
4
|
import { PallasoftClassNameService, PallasoftZIndex } from '@pallasoft/ps-design-system';
|
|
5
5
|
import { PsIcon, PsIconKey } from '@pallasoft/ps-icons';
|
|
6
6
|
import { Button, Dialog, DialogTrigger, Popover } from 'react-aria-components';
|
|
7
|
+
import { PsCascaderConfig } from '../constants/ps-cascader-config';
|
|
7
8
|
import { PsCascaderService } from '../services/ps-cascader-service';
|
|
8
9
|
import { PsFieldSkeleton } from './ps-field-skeleton';
|
|
9
10
|
import { PsRequiredMark } from './ps-required-mark';
|
|
@@ -40,9 +41,9 @@ export const PsCascaderInput = ({ className, disabled, groups, helperText, hideL
|
|
|
40
41
|
const renderOption = (option, groupLabel, close) => (_jsxs("button", { "aria-selected": option.value === value, className: PallasoftClassNameService.merge('ps-focus-ring flex w-full items-start gap-2 rounded-ps-control px-3 py-2.5 text-left text-sm font-medium transition-colors', option.value === value
|
|
41
42
|
? 'bg-primary/10 text-ink'
|
|
42
43
|
: 'text-ink/80 hover:bg-mist/60 hover:text-ink'), 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 truncate', children: option.label }), groupLabel ? (_jsx("span", { className: 'mt-0.5 block truncate text-xs font-normal text-ink/50', children: groupLabel })) : null, option.description ? (_jsx("span", { className: 'mt-0.5 block truncate text-xs font-normal text-ink/55', children: option.description })) : null] })] }, option.value));
|
|
43
|
-
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 min-h-11 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 }) => (_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-focus-ring h-10 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
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
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 min-h-11 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-focus-ring h-10 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
|
|
45
|
+
? 'bg-mist text-ink'
|
|
46
|
+
: '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
|
|
47
|
+
? activeGroup.options.map((option) => renderOption(option, null, close))
|
|
48
|
+
: null] })] })) : (_jsx("div", { className: 'ps-scrollbar-hidden max-h-72 overflow-y-auto p-1.5', role: 'listbox', children: matches.length === 0 ? (_jsx("p", { className: 'px-3 py-6 text-center text-sm text-ink/55', children: PsCascaderConfig.noMatchesLabel })) : (matches.map((match) => renderOption(match.option, match.group.label, close))) }))] })) })) }) })] }), helperText ? _jsx("span", { className: 'ps-input-helper mt-2 block', children: helperText }) : null] }));
|
|
48
49
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useState } from 'react';
|
|
3
|
+
import { usePsLayerZIndex } from '@pallasoft/ps-core-components';
|
|
4
|
+
import { PallasoftClassNameService, PallasoftZIndex } from '@pallasoft/ps-design-system';
|
|
5
|
+
import { PsIcon, PsIconKey } from '@pallasoft/ps-icons';
|
|
6
|
+
import DatePicker from 'react-datepicker';
|
|
7
|
+
import { PsDateInputConfig } from '../constants/ps-date-input-config';
|
|
8
|
+
import { PsYearInputConfig } from '../constants/ps-year-input-config';
|
|
9
|
+
import { PsYearInputService } from '../services/ps-year-input-service';
|
|
10
|
+
import { PsFieldSkeleton } from './ps-field-skeleton';
|
|
11
|
+
import { PsRequiredMark } from './ps-required-mark';
|
|
12
|
+
export const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel, isLoading = false, label, maxYear, minYear, name, onChange, placeholder = PsYearInputConfig.placeholder, required, value, }) => {
|
|
13
|
+
if (isLoading)
|
|
14
|
+
return _jsx(PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
|
|
15
|
+
const inputId = useId();
|
|
16
|
+
const portalId = `${PsDateInputConfig.portalId}-${inputId.replace(/:/g, '')}`;
|
|
17
|
+
const zIndex = usePsLayerZIndex(PallasoftZIndex.Dropdown);
|
|
18
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue === undefined ? '' : defaultValue);
|
|
19
|
+
const currentValue = value === undefined ? uncontrolledValue : value;
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const existing = document.getElementById(portalId);
|
|
22
|
+
const container = existing ? existing : document.createElement('div');
|
|
23
|
+
container.id = portalId;
|
|
24
|
+
container.setAttribute(PsDateInputConfig.topLayerAttribute, 'true');
|
|
25
|
+
container.style.position = 'relative';
|
|
26
|
+
container.style.zIndex = String(zIndex);
|
|
27
|
+
if (!existing)
|
|
28
|
+
document.body.appendChild(container);
|
|
29
|
+
return () => container.remove();
|
|
30
|
+
}, [portalId, zIndex]);
|
|
31
|
+
const handleChange = (date) => {
|
|
32
|
+
const nextValue = PsYearInputService.format(date);
|
|
33
|
+
if (value === undefined)
|
|
34
|
+
setUncontrolledValue(nextValue);
|
|
35
|
+
onChange?.(nextValue);
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs("div", { className: PallasoftClassNameService.merge('block', className), children: [_jsxs("label", { className: hideLabel ? 'sr-only' : 'ps-input-label block', htmlFor: inputId, children: [label, _jsx(PsRequiredMark, { isRequired: required })] }), _jsxs("div", { className: hideLabel ? 'relative' : 'relative mt-2', children: [_jsx(DatePicker, { autoComplete: 'off', calendarClassName: 'ps-floating-panel ps-datepicker', className: 'ps-input-control ps-focus-ring min-h-11 w-full pr-10 text-sm font-semibold', dateFormat: PsYearInputConfig.format, disabled: disabled, id: inputId, maxDate: PsYearInputService.bound(maxYear), minDate: PsYearInputService.bound(minYear), onChange: handleChange, placeholderText: placeholder, popperClassName: 'ps-datepicker-popper', popperPlacement: 'bottom-start', popperProps: { strategy: 'fixed' }, portalId: portalId, required: required, selected: PsYearInputService.parse(currentValue), showPopperArrow: false, showYearPicker: true, wrapperClassName: 'block w-full', yearItemNumber: PsYearInputConfig.yearsPerPage }), _jsx(PsIcon, { "aria-hidden": 'true', className: 'pointer-events-none absolute top-1/2 right-3 h-4 w-4 -translate-y-1/2 text-ink/50', iconKey: PsIconKey.Calendar }), name ? _jsx("input", { name: name, type: 'hidden', value: currentValue }) : null] }), helperText ? _jsx("span", { className: 'ps-input-helper', children: helperText }) : null] }));
|
|
38
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -33,3 +33,7 @@ export * from './services/ps-phone-input-service';
|
|
|
33
33
|
export * from './services/ps-postal-code-service';
|
|
34
34
|
export * from './services/ps-text-format-service';
|
|
35
35
|
export * from './components/ps-required-mark';
|
|
36
|
+
export * from './components/ps-year-input';
|
|
37
|
+
export * from './constants/ps-year-input-config';
|
|
38
|
+
export * from './services/ps-year-input-service';
|
|
39
|
+
export * from './constants/ps-cascader-config';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class PsYearInputService {
|
|
2
|
+
static parse(value) {
|
|
3
|
+
if (value === undefined || !/^\d{4}$/.test(value))
|
|
4
|
+
return null;
|
|
5
|
+
return new Date(Number(value), 0, 1);
|
|
6
|
+
}
|
|
7
|
+
static format(date) {
|
|
8
|
+
return date === null ? '' : String(date.getFullYear());
|
|
9
|
+
}
|
|
10
|
+
static bound(year) {
|
|
11
|
+
if (year === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
return new Date(year, 0, 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -33,3 +33,7 @@ export * from './services/ps-phone-input-service';
|
|
|
33
33
|
export * from './services/ps-postal-code-service';
|
|
34
34
|
export * from './services/ps-text-format-service';
|
|
35
35
|
export * from './components/ps-required-mark';
|
|
36
|
+
export * from './components/ps-year-input';
|
|
37
|
+
export * from './constants/ps-year-input-config';
|
|
38
|
+
export * from './services/ps-year-input-service';
|
|
39
|
+
export * from './constants/ps-cascader-config';
|
package/dist/index.js
CHANGED
|
@@ -49,3 +49,7 @@ __exportStar(require("./services/ps-phone-input-service"), exports);
|
|
|
49
49
|
__exportStar(require("./services/ps-postal-code-service"), exports);
|
|
50
50
|
__exportStar(require("./services/ps-text-format-service"), exports);
|
|
51
51
|
__exportStar(require("./components/ps-required-mark"), exports);
|
|
52
|
+
__exportStar(require("./components/ps-year-input"), exports);
|
|
53
|
+
__exportStar(require("./constants/ps-year-input-config"), exports);
|
|
54
|
+
__exportStar(require("./services/ps-year-input-service"), exports);
|
|
55
|
+
__exportStar(require("./constants/ps-cascader-config"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsYearInputService = void 0;
|
|
4
|
+
class PsYearInputService {
|
|
5
|
+
static parse(value) {
|
|
6
|
+
if (value === undefined || !/^\d{4}$/.test(value))
|
|
7
|
+
return null;
|
|
8
|
+
return new Date(Number(value), 0, 1);
|
|
9
|
+
}
|
|
10
|
+
static format(date) {
|
|
11
|
+
return date === null ? '' : String(date.getFullYear());
|
|
12
|
+
}
|
|
13
|
+
static bound(year) {
|
|
14
|
+
if (year === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
return new Date(year, 0, 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.PsYearInputService = PsYearInputService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-input-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@internationalized/date": "^3.12.2",
|
|
35
|
-
"@pallasoft/ps-core-components": "^2.
|
|
36
|
-
"@pallasoft/ps-design-system": "^1.
|
|
37
|
-
"@pallasoft/ps-icons": "^1.
|
|
38
|
-
"@pallasoft/ps-utilities": "^2.
|
|
35
|
+
"@pallasoft/ps-core-components": "^2.10.0",
|
|
36
|
+
"@pallasoft/ps-design-system": "^1.5.0",
|
|
37
|
+
"@pallasoft/ps-icons": "^1.5.4",
|
|
38
|
+
"@pallasoft/ps-utilities": "^2.2.0",
|
|
39
39
|
"libphonenumber-js": "^1.13.13",
|
|
40
40
|
"react-aria-components": "^1.19.0",
|
|
41
41
|
"react-datepicker": "^9.1.0"
|