@pallasoft/ps-input-components 1.13.0 → 1.14.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.
@@ -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,5 @@
1
+ export declare const PsYearInputConfig: {
2
+ readonly format: "yyyy";
3
+ readonly placeholder: "Select a year";
4
+ readonly yearsPerPage: 12;
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsYearInputConfig = void 0;
4
+ exports.PsYearInputConfig = {
5
+ format: 'yyyy',
6
+ placeholder: 'Select a year',
7
+ yearsPerPage: 12,
8
+ };
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ export const PsYearInputConfig = {
2
+ format: 'yyyy',
3
+ placeholder: 'Select a year',
4
+ yearsPerPage: 12,
5
+ };
package/dist/esm/index.js CHANGED
@@ -33,3 +33,6 @@ 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';
@@ -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,6 @@ 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';
package/dist/index.js CHANGED
@@ -49,3 +49,6 @@ __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);
@@ -0,0 +1,5 @@
1
+ export declare class PsYearInputService {
2
+ static parse(value: string | undefined): Date | null;
3
+ static format(date: Date | null): string;
4
+ static bound(year: number | undefined): Date | undefined;
5
+ }
@@ -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.13.0",
3
+ "version": "1.14.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",