@pallasoft/ps-input-components 1.18.1 → 1.19.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.
@@ -4,6 +4,8 @@ export interface PsCalendarHeaderProps extends ReactDatePickerCustomHeaderProps
4
4
  maxDate?: Date;
5
5
  minDate?: Date;
6
6
  onViewChange: (view: PsCalendarView) => void;
7
+ onYearPick?: (year: number) => void;
8
+ selectedYear?: number;
7
9
  view: PsCalendarView;
8
10
  }
9
- export declare const PsCalendarHeader: ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, prevMonthButtonDisabled, view, }: PsCalendarHeaderProps) => import("react").JSX.Element;
11
+ export declare const PsCalendarHeader: ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, onYearPick, prevMonthButtonDisabled, selectedYear, view, }: PsCalendarHeaderProps) => import("react").JSX.Element;
@@ -12,8 +12,8 @@ const navigationButtonClassName = 'ps-focus-ring flex h-8 w-8 items-center justi
12
12
  const titleButtonClassName = 'ps-focus-ring flex items-center gap-1 rounded-lg px-2 py-1 text-sm font-semibold text-ink transition-colors hover:bg-primary/10';
13
13
  const cellClassName = 'ps-focus-ring flex h-10 items-center justify-center rounded-[0.625rem] text-sm font-medium text-ink transition-colors hover:bg-primary/10 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent';
14
14
  const selectedCellClassName = 'bg-primary font-bold text-[var(--ps-color-primary-contrast)] hover:bg-primary';
15
- const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, prevMonthButtonDisabled, view, }) => {
16
- const year = monthDate.getFullYear();
15
+ const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, onYearPick, prevMonthButtonDisabled, selectedYear, view, }) => {
16
+ const year = selectedYear === undefined ? monthDate.getFullYear() : selectedYear;
17
17
  const [pageYear, setPageYear] = (0, react_1.useState)(year);
18
18
  const years = ps_date_input_service_1.PsDateInputService.yearPage(pageYear);
19
19
  const navigation = {
@@ -51,13 +51,17 @@ const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, increaseMont
51
51
  titleView: ps_calendar_view_1.PsCalendarView.day,
52
52
  },
53
53
  }[view];
54
- return ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-col gap-2', children: [(0, jsx_runtime_1.jsxs)("div", { className: 'flex items-center justify-between gap-2 px-1', children: [(0, jsx_runtime_1.jsx)("button", { "aria-label": navigation.previousLabel, className: navigationButtonClassName, disabled: navigation.isPreviousDisabled, onClick: navigation.previous, type: 'button', children: (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-180', iconKey: ps_icons_1.PsIconKey.ChevronRight }) }), (0, jsx_runtime_1.jsxs)("button", { "aria-label": navigation.titleLabel, "aria-live": 'polite', className: titleButtonClassName, onClick: () => {
54
+ return ((0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-col gap-2', children: [(0, jsx_runtime_1.jsxs)("div", { className: 'flex items-center justify-between gap-2 px-1', children: [(0, jsx_runtime_1.jsx)("button", { "aria-label": navigation.previousLabel, className: navigationButtonClassName, disabled: navigation.isPreviousDisabled, onClick: navigation.previous, type: 'button', children: (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-180', iconKey: ps_icons_1.PsIconKey.ChevronRight }) }), onYearPick === undefined ? ((0, jsx_runtime_1.jsxs)("button", { "aria-label": navigation.titleLabel, "aria-live": 'polite', className: titleButtonClassName, onClick: () => {
55
55
  setPageYear(year);
56
56
  onViewChange(navigation.titleView);
57
- }, type: 'button', children: [navigation.title, (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-3.5 w-3.5 rotate-90 text-ink/50', iconKey: ps_icons_1.PsIconKey.ChevronRight })] }), (0, jsx_runtime_1.jsx)("button", { "aria-label": navigation.nextLabel, className: navigationButtonClassName, disabled: navigation.isNextDisabled, onClick: navigation.next, type: 'button', children: (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.ChevronRight }) })] }), view === ps_calendar_view_1.PsCalendarView.month ? ((0, jsx_runtime_1.jsx)("div", { className: 'grid grid-cols-3 gap-1', children: ps_date_input_service_1.PsDateInputService.monthNames().map((name, month) => ((0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge(cellClassName, month === monthDate.getMonth() ? selectedCellClassName : undefined), disabled: ps_date_input_service_1.PsDateInputService.isMonthOutOfRange(year, month, minDate, maxDate), onClick: () => {
57
+ }, type: 'button', children: [navigation.title, (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-3.5 w-3.5 rotate-90 text-ink/50', iconKey: ps_icons_1.PsIconKey.ChevronRight })] })) : ((0, jsx_runtime_1.jsx)("p", { "aria-live": 'polite', className: 'text-sm font-semibold text-ink', children: navigation.title })), (0, jsx_runtime_1.jsx)("button", { "aria-label": navigation.nextLabel, className: navigationButtonClassName, disabled: navigation.isNextDisabled, onClick: navigation.next, type: 'button', children: (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.ChevronRight }) })] }), view === ps_calendar_view_1.PsCalendarView.month ? ((0, jsx_runtime_1.jsx)("div", { className: 'grid grid-cols-3 gap-1', children: ps_date_input_service_1.PsDateInputService.monthNames().map((name, month) => ((0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge(cellClassName, month === monthDate.getMonth() ? selectedCellClassName : undefined), disabled: ps_date_input_service_1.PsDateInputService.isMonthOutOfRange(year, month, minDate, maxDate), onClick: () => {
58
58
  changeMonth(month);
59
59
  onViewChange(ps_calendar_view_1.PsCalendarView.day);
60
60
  }, type: 'button', children: name }, name))) })) : null, view === ps_calendar_view_1.PsCalendarView.year ? ((0, jsx_runtime_1.jsx)("div", { className: 'grid grid-cols-3 gap-1', children: years.map((candidate) => ((0, jsx_runtime_1.jsx)("button", { className: ps_design_system_1.PallasoftClassNameService.merge(cellClassName, candidate === year ? selectedCellClassName : undefined), disabled: ps_date_input_service_1.PsDateInputService.isYearOutOfRange(candidate, minDate, maxDate), onClick: () => {
61
+ if (onYearPick !== undefined) {
62
+ onYearPick(candidate);
63
+ return;
64
+ }
61
65
  changeYear(candidate);
62
66
  onViewChange(ps_calendar_view_1.PsCalendarView.month);
63
67
  }, type: 'button', children: candidate }, candidate))) })) : null] }));
@@ -0,0 +1,6 @@
1
+ import { type PsSelectInputProps } from './ps-select-input';
2
+ export interface PsCurrencyInputProps extends Omit<PsSelectInputProps, 'options'> {
3
+ currencies: string[];
4
+ locale?: string;
5
+ }
6
+ export declare const PsCurrencyInput: ({ currencies, locale, ...props }: PsCurrencyInputProps) => import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInput = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const ps_currency_input_service_1 = require("../services/ps-currency-input-service");
6
+ const ps_select_input_1 = require("./ps-select-input");
7
+ const PsCurrencyInput = ({ currencies, locale, ...props }) => ((0, jsx_runtime_1.jsx)(ps_select_input_1.PsSelectInput, { ...props, options: ps_currency_input_service_1.PsCurrencyInputService.options(currencies, locale) }));
8
+ exports.PsCurrencyInput = PsCurrencyInput;
@@ -10,9 +10,11 @@ const ps_core_components_1 = require("@pallasoft/ps-core-components");
10
10
  const ps_design_system_1 = require("@pallasoft/ps-design-system");
11
11
  const ps_icons_1 = require("@pallasoft/ps-icons");
12
12
  const react_datepicker_1 = __importDefault(require("react-datepicker"));
13
+ const ps_calendar_view_1 = require("../constants/ps-calendar-view");
13
14
  const ps_date_input_config_1 = require("../constants/ps-date-input-config");
14
15
  const ps_year_input_config_1 = require("../constants/ps-year-input-config");
15
16
  const ps_year_input_service_1 = require("../services/ps-year-input-service");
17
+ const ps_calendar_header_1 = require("./ps-calendar-header");
16
18
  const ps_field_skeleton_1 = require("./ps-field-skeleton");
17
19
  const ps_required_mark_1 = require("./ps-required-mark");
18
20
  const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel, isLoading = false, label, maxYear, minYear, name, onChange, placeholder = ps_year_input_config_1.PsYearInputConfig.placeholder, required, value, }) => {
@@ -23,6 +25,10 @@ const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel,
23
25
  const zIndex = (0, ps_core_components_1.usePsLayerZIndex)(ps_design_system_1.PallasoftZIndex.Dropdown);
24
26
  const [uncontrolledValue, setUncontrolledValue] = (0, react_1.useState)(defaultValue === undefined ? '' : defaultValue);
25
27
  const currentValue = value === undefined ? uncontrolledValue : value;
28
+ const pickerRef = (0, react_1.useRef)(null);
29
+ const selected = ps_year_input_service_1.PsYearInputService.parse(currentValue);
30
+ const minDate = ps_year_input_service_1.PsYearInputService.bound(minYear);
31
+ const maxDate = ps_year_input_service_1.PsYearInputService.bound(maxYear);
26
32
  (0, react_1.useEffect)(() => {
27
33
  const existing = document.getElementById(portalId);
28
34
  const container = existing ? existing : document.createElement('div');
@@ -40,6 +46,9 @@ const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel,
40
46
  setUncontrolledValue(nextValue);
41
47
  onChange?.(nextValue);
42
48
  };
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] }));
49
+ 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 ${ps_date_input_config_1.PsDateInputConfig.pickingClassName}`, 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: maxDate, minDate: minDate, onChange: handleChange, placeholderText: placeholder, popperClassName: 'ps-datepicker-popper', popperPlacement: 'bottom-start', popperProps: { strategy: 'fixed' }, portalId: portalId, ref: pickerRef, renderCustomHeader: (headerProps) => ((0, jsx_runtime_1.jsx)(ps_calendar_header_1.PsCalendarHeader, { ...headerProps, maxDate: maxDate, minDate: minDate, onViewChange: () => undefined, onYearPick: (year) => {
50
+ handleChange(new Date(year, 0, 1));
51
+ pickerRef.current?.setOpen(false);
52
+ }, selectedYear: selected === null ? undefined : selected.getFullYear(), view: ps_calendar_view_1.PsCalendarView.year })), required: required, selected: selected, showPopperArrow: false, wrapperClassName: 'block w-full' }), (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
53
  };
45
54
  exports.PsYearInput = PsYearInput;
@@ -0,0 +1,5 @@
1
+ export declare const PsCurrencyInputConfig: {
2
+ readonly locale: "en";
3
+ readonly separator: " · ";
4
+ readonly displayType: "currency";
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInputConfig = void 0;
4
+ exports.PsCurrencyInputConfig = {
5
+ locale: 'en',
6
+ separator: ' · ',
7
+ displayType: 'currency',
8
+ };
@@ -1,5 +1,4 @@
1
1
  export declare const PsYearInputConfig: {
2
2
  readonly format: "yyyy";
3
3
  readonly placeholder: "Select a year";
4
- readonly yearsPerPage: 12;
5
4
  };
@@ -4,5 +4,4 @@ exports.PsYearInputConfig = void 0;
4
4
  exports.PsYearInputConfig = {
5
5
  format: 'yyyy',
6
6
  placeholder: 'Select a year',
7
- yearsPerPage: 12,
8
7
  };
@@ -9,8 +9,8 @@ const navigationButtonClassName = 'ps-focus-ring flex h-8 w-8 items-center justi
9
9
  const titleButtonClassName = 'ps-focus-ring flex items-center gap-1 rounded-lg px-2 py-1 text-sm font-semibold text-ink transition-colors hover:bg-primary/10';
10
10
  const cellClassName = 'ps-focus-ring flex h-10 items-center justify-center rounded-[0.625rem] text-sm font-medium text-ink transition-colors hover:bg-primary/10 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent';
11
11
  const selectedCellClassName = 'bg-primary font-bold text-[var(--ps-color-primary-contrast)] hover:bg-primary';
12
- export const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, prevMonthButtonDisabled, view, }) => {
13
- const year = monthDate.getFullYear();
12
+ export const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, increaseMonth, maxDate, minDate, monthDate, nextMonthButtonDisabled, onViewChange, onYearPick, prevMonthButtonDisabled, selectedYear, view, }) => {
13
+ const year = selectedYear === undefined ? monthDate.getFullYear() : selectedYear;
14
14
  const [pageYear, setPageYear] = useState(year);
15
15
  const years = PsDateInputService.yearPage(pageYear);
16
16
  const navigation = {
@@ -48,13 +48,17 @@ export const PsCalendarHeader = ({ changeMonth, changeYear, decreaseMonth, incre
48
48
  titleView: PsCalendarView.day,
49
49
  },
50
50
  }[view];
51
- return (_jsxs("div", { className: 'flex flex-col gap-2', children: [_jsxs("div", { className: 'flex items-center justify-between gap-2 px-1', children: [_jsx("button", { "aria-label": navigation.previousLabel, className: navigationButtonClassName, disabled: navigation.isPreviousDisabled, onClick: navigation.previous, type: 'button', children: _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-180', iconKey: PsIconKey.ChevronRight }) }), _jsxs("button", { "aria-label": navigation.titleLabel, "aria-live": 'polite', className: titleButtonClassName, onClick: () => {
51
+ return (_jsxs("div", { className: 'flex flex-col gap-2', children: [_jsxs("div", { className: 'flex items-center justify-between gap-2 px-1', children: [_jsx("button", { "aria-label": navigation.previousLabel, className: navigationButtonClassName, disabled: navigation.isPreviousDisabled, onClick: navigation.previous, type: 'button', children: _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4 rotate-180', iconKey: PsIconKey.ChevronRight }) }), onYearPick === undefined ? (_jsxs("button", { "aria-label": navigation.titleLabel, "aria-live": 'polite', className: titleButtonClassName, onClick: () => {
52
52
  setPageYear(year);
53
53
  onViewChange(navigation.titleView);
54
- }, type: 'button', children: [navigation.title, _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-3.5 w-3.5 rotate-90 text-ink/50', iconKey: PsIconKey.ChevronRight })] }), _jsx("button", { "aria-label": navigation.nextLabel, className: navigationButtonClassName, disabled: navigation.isNextDisabled, onClick: navigation.next, type: 'button', children: _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: PsIconKey.ChevronRight }) })] }), view === PsCalendarView.month ? (_jsx("div", { className: 'grid grid-cols-3 gap-1', children: PsDateInputService.monthNames().map((name, month) => (_jsx("button", { className: PallasoftClassNameService.merge(cellClassName, month === monthDate.getMonth() ? selectedCellClassName : undefined), disabled: PsDateInputService.isMonthOutOfRange(year, month, minDate, maxDate), onClick: () => {
54
+ }, type: 'button', children: [navigation.title, _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-3.5 w-3.5 rotate-90 text-ink/50', iconKey: PsIconKey.ChevronRight })] })) : (_jsx("p", { "aria-live": 'polite', className: 'text-sm font-semibold text-ink', children: navigation.title })), _jsx("button", { "aria-label": navigation.nextLabel, className: navigationButtonClassName, disabled: navigation.isNextDisabled, onClick: navigation.next, type: 'button', children: _jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: PsIconKey.ChevronRight }) })] }), view === PsCalendarView.month ? (_jsx("div", { className: 'grid grid-cols-3 gap-1', children: PsDateInputService.monthNames().map((name, month) => (_jsx("button", { className: PallasoftClassNameService.merge(cellClassName, month === monthDate.getMonth() ? selectedCellClassName : undefined), disabled: PsDateInputService.isMonthOutOfRange(year, month, minDate, maxDate), onClick: () => {
55
55
  changeMonth(month);
56
56
  onViewChange(PsCalendarView.day);
57
57
  }, type: 'button', children: name }, name))) })) : null, view === PsCalendarView.year ? (_jsx("div", { className: 'grid grid-cols-3 gap-1', children: years.map((candidate) => (_jsx("button", { className: PallasoftClassNameService.merge(cellClassName, candidate === year ? selectedCellClassName : undefined), disabled: PsDateInputService.isYearOutOfRange(candidate, minDate, maxDate), onClick: () => {
58
+ if (onYearPick !== undefined) {
59
+ onYearPick(candidate);
60
+ return;
61
+ }
58
62
  changeYear(candidate);
59
63
  onViewChange(PsCalendarView.month);
60
64
  }, type: 'button', children: candidate }, candidate))) })) : null] }));
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PsCurrencyInputService } from '../services/ps-currency-input-service';
3
+ import { PsSelectInput } from './ps-select-input';
4
+ export const PsCurrencyInput = ({ currencies, locale, ...props }) => (_jsx(PsSelectInput, { ...props, options: PsCurrencyInputService.options(currencies, locale) }));
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useId, useState } from 'react';
2
+ import { useEffect, useId, useRef, useState } from 'react';
3
3
  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 DatePicker from 'react-datepicker';
7
+ import { PsCalendarView } from '../constants/ps-calendar-view';
7
8
  import { PsDateInputConfig } from '../constants/ps-date-input-config';
8
9
  import { PsYearInputConfig } from '../constants/ps-year-input-config';
9
10
  import { PsYearInputService } from '../services/ps-year-input-service';
11
+ import { PsCalendarHeader } from './ps-calendar-header';
10
12
  import { PsFieldSkeleton } from './ps-field-skeleton';
11
13
  import { PsRequiredMark } from './ps-required-mark';
12
14
  export const PsYearInput = ({ className, defaultValue, disabled, helperText, hideLabel, isLoading = false, label, maxYear, minYear, name, onChange, placeholder = PsYearInputConfig.placeholder, required, value, }) => {
@@ -17,6 +19,10 @@ export const PsYearInput = ({ className, defaultValue, disabled, helperText, hid
17
19
  const zIndex = usePsLayerZIndex(PallasoftZIndex.Dropdown);
18
20
  const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue === undefined ? '' : defaultValue);
19
21
  const currentValue = value === undefined ? uncontrolledValue : value;
22
+ const pickerRef = useRef(null);
23
+ const selected = PsYearInputService.parse(currentValue);
24
+ const minDate = PsYearInputService.bound(minYear);
25
+ const maxDate = PsYearInputService.bound(maxYear);
20
26
  useEffect(() => {
21
27
  const existing = document.getElementById(portalId);
22
28
  const container = existing ? existing : document.createElement('div');
@@ -34,5 +40,8 @@ export const PsYearInput = ({ className, defaultValue, disabled, helperText, hid
34
40
  setUncontrolledValue(nextValue);
35
41
  onChange?.(nextValue);
36
42
  };
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] }));
43
+ 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 ${PsDateInputConfig.pickingClassName}`, 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: maxDate, minDate: minDate, onChange: handleChange, placeholderText: placeholder, popperClassName: 'ps-datepicker-popper', popperPlacement: 'bottom-start', popperProps: { strategy: 'fixed' }, portalId: portalId, ref: pickerRef, renderCustomHeader: (headerProps) => (_jsx(PsCalendarHeader, { ...headerProps, maxDate: maxDate, minDate: minDate, onViewChange: () => undefined, onYearPick: (year) => {
44
+ handleChange(new Date(year, 0, 1));
45
+ pickerRef.current?.setOpen(false);
46
+ }, selectedYear: selected === null ? undefined : selected.getFullYear(), view: PsCalendarView.year })), required: required, selected: selected, showPopperArrow: false, wrapperClassName: 'block w-full' }), _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
47
  };
@@ -0,0 +1,5 @@
1
+ export const PsCurrencyInputConfig = {
2
+ locale: 'en',
3
+ separator: ' · ',
4
+ displayType: 'currency',
5
+ };
@@ -1,5 +1,4 @@
1
1
  export const PsYearInputConfig = {
2
2
  format: 'yyyy',
3
3
  placeholder: 'Select a year',
4
- yearsPerPage: 12,
5
4
  };
package/dist/esm/index.js CHANGED
@@ -37,3 +37,6 @@ export * from './components/ps-year-input';
37
37
  export * from './constants/ps-year-input-config';
38
38
  export * from './services/ps-year-input-service';
39
39
  export * from './constants/ps-cascader-config';
40
+ export * from './components/ps-currency-input';
41
+ export * from './constants/ps-currency-input-config';
42
+ export * from './services/ps-currency-input-service';
@@ -1,25 +1,9 @@
1
- import { PsAmountInputConfig } from '../constants/ps-amount-input-config';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  export class PsAmountInputService {
3
3
  static normalise(raw) {
4
- const trimmed = raw.trim();
5
- const isBracketed = trimmed.startsWith(PsAmountInputConfig.openBracket) &&
6
- trimmed.endsWith(PsAmountInputConfig.closeBracket);
7
- const isNegative = isBracketed || trimmed.startsWith(PsAmountInputConfig.minus);
8
- const kept = trimmed.replace(PsAmountInputConfig.disallowed, '');
9
- const pointIndex = kept.indexOf(PsAmountInputConfig.point);
10
- const digits = pointIndex === -1
11
- ? kept
12
- : `${kept.slice(0, pointIndex + 1)}${kept
13
- .slice(pointIndex + 1)
14
- .split(PsAmountInputConfig.point)
15
- .join('')}`;
16
- if (digits === '')
17
- return isNegative && !isBracketed ? PsAmountInputConfig.minus : '';
18
- return isNegative ? `${PsAmountInputConfig.minus}${digits}` : digits;
4
+ return Common.AmountService.normalise(raw);
19
5
  }
20
6
  static toNumber(raw) {
21
- const normalised = PsAmountInputService.normalise(raw);
22
- const parsed = Number(normalised);
23
- return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
7
+ return Common.AmountService.toNumber(raw);
24
8
  }
25
9
  }
@@ -0,0 +1,10 @@
1
+ import { PsCurrencyInputConfig } from '../constants/ps-currency-input-config';
2
+ export class PsCurrencyInputService {
3
+ static options(currencies, locale = PsCurrencyInputConfig.locale) {
4
+ const names = new Intl.DisplayNames([locale], { type: PsCurrencyInputConfig.displayType });
5
+ return [...new Set(currencies.map((code) => code.toUpperCase()))].map((code) => ({
6
+ label: `${code}${PsCurrencyInputConfig.separator}${names.of(code) ?? code}`,
7
+ value: code,
8
+ }));
9
+ }
10
+ }
@@ -1,56 +1,27 @@
1
- import { AsYouType, getCountries, getCountryCallingCode, parsePhoneNumberFromString, } from 'libphonenumber-js';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  import { PsPhoneInputConfig } from '../constants/ps-phone-input-config';
3
3
  export class PsPhoneInputService {
4
4
  static isCountry(code) {
5
- return getCountries().includes(code);
5
+ return Common.PhoneService.isCountry(code);
6
6
  }
7
7
  static countries(preferred) {
8
- const names = new Intl.DisplayNames([PsPhoneInputConfig.locale], {
9
- type: PsPhoneInputConfig.displayNamesType,
10
- });
11
- const options = getCountries().map((code) => {
12
- const name = names.of(code);
13
- return {
14
- callingCode: getCountryCallingCode(code),
15
- code,
16
- label: name !== undefined ? name : code,
17
- };
18
- });
19
- return options.sort((left, right) => {
20
- if (left.code === preferred)
21
- return -1;
22
- if (right.code === preferred)
23
- return 1;
24
- return left.label.localeCompare(right.label);
25
- });
8
+ return Common.PhoneService.countries(preferred, PsPhoneInputConfig.locale);
26
9
  }
27
10
  static display(value, fallbackCountry) {
28
- const parsed = value.startsWith(PsPhoneInputConfig.plus)
29
- ? parsePhoneNumberFromString(value)
30
- : undefined;
31
- if (parsed !== undefined && parsed.country !== undefined)
32
- return { country: parsed.country, national: parsed.formatNational() };
33
- return { country: fallbackCountry, national: value };
11
+ return Common.PhoneService.display(value, fallbackCountry);
34
12
  }
35
13
  static format(national, country) {
36
- if (!PsPhoneInputService.isCountry(country))
37
- return national;
38
- return new AsYouType(country).input(national);
14
+ return Common.PhoneService.format(national, country);
39
15
  }
40
16
  static toStored(national, country) {
41
- const trimmed = national.trim();
42
- if (trimmed === '' || !PsPhoneInputService.isCountry(country))
43
- return trimmed;
44
- const parsed = parsePhoneNumberFromString(trimmed, country);
45
- return parsed !== undefined ? parsed.number : trimmed;
17
+ return Common.PhoneService.toStored(national, country);
46
18
  }
47
19
  static isValid(national, country) {
48
20
  if (national.trim() === '')
49
21
  return true;
50
22
  if (!PsPhoneInputService.isCountry(country))
51
23
  return false;
52
- const parsed = parsePhoneNumberFromString(national, country);
53
- return parsed !== undefined && parsed.isValid();
24
+ return Common.PhoneService.isValid(national, country);
54
25
  }
55
26
  static search(options, query) {
56
27
  const term = query.trim().toLowerCase().replace(PsPhoneInputConfig.plus, '');
@@ -72,6 +43,6 @@ export class PsPhoneInputService {
72
43
  ].filter((part) => part.text !== '');
73
44
  }
74
45
  static callingCode(country) {
75
- return PsPhoneInputService.isCountry(country) ? getCountryCallingCode(country) : '';
46
+ return Common.PhoneService.callingCode(country);
76
47
  }
77
48
  }
@@ -1,28 +1,9 @@
1
- import { PsPostalCodeConfig, PsPostalCodeFormats } from '../constants/ps-postal-code-formats';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  export class PsPostalCodeService {
3
3
  static format(raw, country) {
4
- const upper = raw.toUpperCase();
5
- const format = PsPostalCodeFormats[country];
6
- if (format === undefined)
7
- return upper.replace(PsPostalCodeConfig.fallbackAllowed, '');
8
- const compact = upper.replace(format.allowed, '');
9
- if (format.groups.length === 0)
10
- return upper.replace(PsPostalCodeConfig.fallbackAllowed, '');
11
- const parts = [];
12
- let cursor = 0;
13
- for (const size of format.groups) {
14
- if (cursor >= compact.length)
15
- break;
16
- parts.push(compact.slice(cursor, cursor + size));
17
- cursor += size;
18
- }
19
- return parts.join(format.separator);
4
+ return Common.PostalCodeService.format(raw, country);
20
5
  }
21
6
  static maxLength(country) {
22
- const format = PsPostalCodeFormats[country];
23
- if (format === undefined || format.groups.length === 0)
24
- return undefined;
25
- return (format.groups.reduce((sum, size) => sum + size, 0) +
26
- format.separator.length * (format.groups.length - 1));
7
+ return Common.PostalCodeService.maxLength(country);
27
8
  }
28
9
  }
package/dist/index.d.ts CHANGED
@@ -37,3 +37,6 @@ export * from './components/ps-year-input';
37
37
  export * from './constants/ps-year-input-config';
38
38
  export * from './services/ps-year-input-service';
39
39
  export * from './constants/ps-cascader-config';
40
+ export * from './components/ps-currency-input';
41
+ export * from './constants/ps-currency-input-config';
42
+ export * from './services/ps-currency-input-service';
package/dist/index.js CHANGED
@@ -53,3 +53,6 @@ __exportStar(require("./components/ps-year-input"), exports);
53
53
  __exportStar(require("./constants/ps-year-input-config"), exports);
54
54
  __exportStar(require("./services/ps-year-input-service"), exports);
55
55
  __exportStar(require("./constants/ps-cascader-config"), exports);
56
+ __exportStar(require("./components/ps-currency-input"), exports);
57
+ __exportStar(require("./constants/ps-currency-input-config"), exports);
58
+ __exportStar(require("./services/ps-currency-input-service"), exports);
@@ -1,29 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsAmountInputService = void 0;
4
- const ps_amount_input_config_1 = require("../constants/ps-amount-input-config");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  class PsAmountInputService {
6
6
  static normalise(raw) {
7
- const trimmed = raw.trim();
8
- const isBracketed = trimmed.startsWith(ps_amount_input_config_1.PsAmountInputConfig.openBracket) &&
9
- trimmed.endsWith(ps_amount_input_config_1.PsAmountInputConfig.closeBracket);
10
- const isNegative = isBracketed || trimmed.startsWith(ps_amount_input_config_1.PsAmountInputConfig.minus);
11
- const kept = trimmed.replace(ps_amount_input_config_1.PsAmountInputConfig.disallowed, '');
12
- const pointIndex = kept.indexOf(ps_amount_input_config_1.PsAmountInputConfig.point);
13
- const digits = pointIndex === -1
14
- ? kept
15
- : `${kept.slice(0, pointIndex + 1)}${kept
16
- .slice(pointIndex + 1)
17
- .split(ps_amount_input_config_1.PsAmountInputConfig.point)
18
- .join('')}`;
19
- if (digits === '')
20
- return isNegative && !isBracketed ? ps_amount_input_config_1.PsAmountInputConfig.minus : '';
21
- return isNegative ? `${ps_amount_input_config_1.PsAmountInputConfig.minus}${digits}` : digits;
7
+ return ps_utilities_1.Common.AmountService.normalise(raw);
22
8
  }
23
9
  static toNumber(raw) {
24
- const normalised = PsAmountInputService.normalise(raw);
25
- const parsed = Number(normalised);
26
- return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
10
+ return ps_utilities_1.Common.AmountService.toNumber(raw);
27
11
  }
28
12
  }
29
13
  exports.PsAmountInputService = PsAmountInputService;
@@ -0,0 +1,4 @@
1
+ import type { PsSelectOption } from '../components/ps-select-input';
2
+ export declare class PsCurrencyInputService {
3
+ static options(currencies: string[], locale?: string): PsSelectOption[];
4
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInputService = void 0;
4
+ const ps_currency_input_config_1 = require("../constants/ps-currency-input-config");
5
+ class PsCurrencyInputService {
6
+ static options(currencies, locale = ps_currency_input_config_1.PsCurrencyInputConfig.locale) {
7
+ const names = new Intl.DisplayNames([locale], { type: ps_currency_input_config_1.PsCurrencyInputConfig.displayType });
8
+ return [...new Set(currencies.map((code) => code.toUpperCase()))].map((code) => ({
9
+ label: `${code}${ps_currency_input_config_1.PsCurrencyInputConfig.separator}${names.of(code) ?? code}`,
10
+ value: code,
11
+ }));
12
+ }
13
+ }
14
+ exports.PsCurrencyInputService = PsCurrencyInputService;
@@ -1,59 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsPhoneInputService = void 0;
4
- const libphonenumber_js_1 = require("libphonenumber-js");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  const ps_phone_input_config_1 = require("../constants/ps-phone-input-config");
6
6
  class PsPhoneInputService {
7
7
  static isCountry(code) {
8
- return (0, libphonenumber_js_1.getCountries)().includes(code);
8
+ return ps_utilities_1.Common.PhoneService.isCountry(code);
9
9
  }
10
10
  static countries(preferred) {
11
- const names = new Intl.DisplayNames([ps_phone_input_config_1.PsPhoneInputConfig.locale], {
12
- type: ps_phone_input_config_1.PsPhoneInputConfig.displayNamesType,
13
- });
14
- const options = (0, libphonenumber_js_1.getCountries)().map((code) => {
15
- const name = names.of(code);
16
- return {
17
- callingCode: (0, libphonenumber_js_1.getCountryCallingCode)(code),
18
- code,
19
- label: name !== undefined ? name : code,
20
- };
21
- });
22
- return options.sort((left, right) => {
23
- if (left.code === preferred)
24
- return -1;
25
- if (right.code === preferred)
26
- return 1;
27
- return left.label.localeCompare(right.label);
28
- });
11
+ return ps_utilities_1.Common.PhoneService.countries(preferred, ps_phone_input_config_1.PsPhoneInputConfig.locale);
29
12
  }
30
13
  static display(value, fallbackCountry) {
31
- const parsed = value.startsWith(ps_phone_input_config_1.PsPhoneInputConfig.plus)
32
- ? (0, libphonenumber_js_1.parsePhoneNumberFromString)(value)
33
- : undefined;
34
- if (parsed !== undefined && parsed.country !== undefined)
35
- return { country: parsed.country, national: parsed.formatNational() };
36
- return { country: fallbackCountry, national: value };
14
+ return ps_utilities_1.Common.PhoneService.display(value, fallbackCountry);
37
15
  }
38
16
  static format(national, country) {
39
- if (!PsPhoneInputService.isCountry(country))
40
- return national;
41
- return new libphonenumber_js_1.AsYouType(country).input(national);
17
+ return ps_utilities_1.Common.PhoneService.format(national, country);
42
18
  }
43
19
  static toStored(national, country) {
44
- const trimmed = national.trim();
45
- if (trimmed === '' || !PsPhoneInputService.isCountry(country))
46
- return trimmed;
47
- const parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(trimmed, country);
48
- return parsed !== undefined ? parsed.number : trimmed;
20
+ return ps_utilities_1.Common.PhoneService.toStored(national, country);
49
21
  }
50
22
  static isValid(national, country) {
51
23
  if (national.trim() === '')
52
24
  return true;
53
25
  if (!PsPhoneInputService.isCountry(country))
54
26
  return false;
55
- const parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(national, country);
56
- return parsed !== undefined && parsed.isValid();
27
+ return ps_utilities_1.Common.PhoneService.isValid(national, country);
57
28
  }
58
29
  static search(options, query) {
59
30
  const term = query.trim().toLowerCase().replace(ps_phone_input_config_1.PsPhoneInputConfig.plus, '');
@@ -75,7 +46,7 @@ class PsPhoneInputService {
75
46
  ].filter((part) => part.text !== '');
76
47
  }
77
48
  static callingCode(country) {
78
- return PsPhoneInputService.isCountry(country) ? (0, libphonenumber_js_1.getCountryCallingCode)(country) : '';
49
+ return ps_utilities_1.Common.PhoneService.callingCode(country);
79
50
  }
80
51
  }
81
52
  exports.PsPhoneInputService = PsPhoneInputService;
@@ -1,32 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsPostalCodeService = void 0;
4
- const ps_postal_code_formats_1 = require("../constants/ps-postal-code-formats");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  class PsPostalCodeService {
6
6
  static format(raw, country) {
7
- const upper = raw.toUpperCase();
8
- const format = ps_postal_code_formats_1.PsPostalCodeFormats[country];
9
- if (format === undefined)
10
- return upper.replace(ps_postal_code_formats_1.PsPostalCodeConfig.fallbackAllowed, '');
11
- const compact = upper.replace(format.allowed, '');
12
- if (format.groups.length === 0)
13
- return upper.replace(ps_postal_code_formats_1.PsPostalCodeConfig.fallbackAllowed, '');
14
- const parts = [];
15
- let cursor = 0;
16
- for (const size of format.groups) {
17
- if (cursor >= compact.length)
18
- break;
19
- parts.push(compact.slice(cursor, cursor + size));
20
- cursor += size;
21
- }
22
- return parts.join(format.separator);
7
+ return ps_utilities_1.Common.PostalCodeService.format(raw, country);
23
8
  }
24
9
  static maxLength(country) {
25
- const format = ps_postal_code_formats_1.PsPostalCodeFormats[country];
26
- if (format === undefined || format.groups.length === 0)
27
- return undefined;
28
- return (format.groups.reduce((sum, size) => sum + size, 0) +
29
- format.separator.length * (format.groups.length - 1));
10
+ return ps_utilities_1.Common.PostalCodeService.maxLength(country);
30
11
  }
31
12
  }
32
13
  exports.PsPostalCodeService = PsPostalCodeService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-input-components",
3
- "version": "1.18.1",
3
+ "version": "1.19.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -35,7 +35,7 @@
35
35
  "@pallasoft/ps-core-components": "^2.10.0",
36
36
  "@pallasoft/ps-design-system": "^1.5.0",
37
37
  "@pallasoft/ps-icons": "^1.5.4",
38
- "@pallasoft/ps-utilities": "^2.2.0",
38
+ "@pallasoft/ps-utilities": "^2.8.0",
39
39
  "libphonenumber-js": "^1.13.13",
40
40
  "react-aria-components": "^1.19.0",
41
41
  "react-datepicker": "^9.1.0"