@pallasoft/ps-input-components 1.0.0 → 1.1.1
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-combobox-input.js +3 -2
- package/dist/components/ps-file-picker.d.ts +12 -0
- package/dist/components/ps-file-picker.js +31 -0
- package/dist/components/ps-select-input.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/services/ps-combobox-input-service.d.ts +4 -0
- package/dist/services/ps-combobox-input-service.js +10 -0
- package/dist/services/ps-select-input-service.d.ts +4 -0
- package/dist/services/ps-select-input-service.js +12 -0
- package/package.json +6 -3
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PsComboboxInput = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
6
5
|
const ps_core_components_1 = require("@pallasoft/ps-core-components");
|
|
6
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
7
7
|
const react_aria_components_1 = require("react-aria-components");
|
|
8
|
+
const ps_combobox_input_service_1 = require("../services/ps-combobox-input-service");
|
|
8
9
|
const PsComboboxInput = ({ className, getItemKey, getItemLabel, isLoading = false, items, label, onInputChange, onSelectionChange, placeholder, renderItem, }) => {
|
|
9
10
|
const itemsByKey = new Map(items.map((item) => [getItemKey(item), item]));
|
|
10
|
-
return ((0, jsx_runtime_1.jsxs)(react_aria_components_1.ComboBox, { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), defaultFilter: () => true, items: items, onInputChange: onInputChange, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : (itemsByKey
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)(react_aria_components_1.ComboBox, { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), defaultFilter: () => true, items: items, onInputChange: onInputChange, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : ps_combobox_input_service_1.PsComboboxInputService.getItem(itemsByKey, key)), children: [label ? (0, jsx_runtime_1.jsx)(react_aria_components_1.Label, { className: 'ps-input-label', children: label }) : null, (0, jsx_runtime_1.jsx)("span", { className: 'relative mt-2 block', children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { className: 'ps-input-control ps-focus-ring min-h-11 w-full text-sm font-semibold', placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'w-[--trigger-width] rounded-2xl border border-line bg-white/95 p-1.5 shadow-lg dark:border-white/10 dark:bg-slate-900/95', children: isLoading ? ((0, jsx_runtime_1.jsx)("div", { className: 'flex items-center justify-center py-4', children: (0, jsx_runtime_1.jsx)(ps_core_components_1.PsSpinner, { label: 'Loading results', size: 'small' }) })) : ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBox, { className: 'max-h-72 overflow-y-auto outline-none', items: items, children: (item) => ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBoxItem, { className: 'ps-focus-ring cursor-pointer rounded-xl px-3 py-2 text-sm font-semibold text-ink selected:bg-primary-soft selected:text-primary hover:bg-slate-50 dark:hover:bg-white/6', id: getItemKey(item), textValue: getItemLabel(item), children: renderItem ? renderItem(item) : getItemLabel(item) })) })) })] }));
|
|
11
12
|
};
|
|
12
13
|
exports.PsComboboxInput = PsComboboxInput;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface PsFilePickerProps {
|
|
2
|
+
accept: string[];
|
|
3
|
+
acceptLabel: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
dropLabel: string;
|
|
7
|
+
maxSizeBytes?: number;
|
|
8
|
+
maxSizeLabel?: string;
|
|
9
|
+
onError?: (message: string) => void;
|
|
10
|
+
onFileLoad: (file: File) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const PsFilePicker: ({ accept, acceptLabel, className, disabled, dropLabel, maxSizeBytes, maxSizeLabel, onError, onFileLoad, }: PsFilePickerProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsFilePicker = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
7
|
+
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
8
|
+
const PsFilePicker = ({ accept, acceptLabel, className, disabled, dropLabel, maxSizeBytes, maxSizeLabel, onError, onFileLoad, }) => {
|
|
9
|
+
const acceptAttr = (0, react_1.useMemo)(() => accept.join(','), [accept]);
|
|
10
|
+
const isAccepted = (candidate) => accept.some((entry) => entry.startsWith('.')
|
|
11
|
+
? candidate.name.toLowerCase().endsWith(entry.toLowerCase())
|
|
12
|
+
: entry === candidate.type);
|
|
13
|
+
const onFileChange = (event) => {
|
|
14
|
+
const newFile = event.target.files?.[0];
|
|
15
|
+
if (!newFile || disabled)
|
|
16
|
+
return;
|
|
17
|
+
if (!isAccepted(newFile)) {
|
|
18
|
+
onError?.('Invalid file type. Please select a supported file.');
|
|
19
|
+
event.target.value = '';
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (maxSizeBytes && newFile.size > maxSizeBytes) {
|
|
23
|
+
onError?.(maxSizeLabel ? `File is too large. ${maxSizeLabel}.` : 'File is too large.');
|
|
24
|
+
event.target.value = '';
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
onFileLoad(newFile);
|
|
28
|
+
};
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: ps_design_system_1.PallasoftClassNameService.merge('relative flex h-48 w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-line p-4 transition-all hover:border-primary/50 hover:bg-primary/5 sm:h-64', className), children: [(0, jsx_runtime_1.jsxs)("div", { className: 'flex flex-col items-center gap-3 text-center', children: [(0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { iconKey: 'upload', className: 'h-8 w-8 text-primary' }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { className: 'text-body-2 font-medium text-ink sm:text-body-1', children: dropLabel }), (0, jsx_runtime_1.jsx)("p", { className: 'mt-1 text-body-3 text-ink/60 sm:text-body-2', children: "or click to browse your files" }), maxSizeLabel ? (0, jsx_runtime_1.jsx)("p", { className: 'mt-3 text-body-3 text-ink/60', children: maxSizeLabel }) : null, (0, jsx_runtime_1.jsxs)("p", { className: 'text-body-3 text-ink/60', children: ["Accepted formats: ", acceptLabel] })] })] }), (0, jsx_runtime_1.jsx)("input", { type: 'file', accept: acceptAttr, className: 'absolute inset-0 h-full w-full cursor-pointer opacity-0', "aria-label": 'File upload', onChange: onFileChange, disabled: disabled, "aria-disabled": disabled })] }));
|
|
30
|
+
};
|
|
31
|
+
exports.PsFilePicker = PsFilePicker;
|
|
@@ -3,5 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PsSelectInput = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
6
|
-
const
|
|
6
|
+
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
7
|
+
const ps_select_input_service_1 = require("../services/ps-select-input-service");
|
|
8
|
+
const PsSelectInput = ({ className, defaultValue, disabled, helperText, label, name, onChange, options, placeholder = 'Select an option', required, value, }) => ((0, jsx_runtime_1.jsxs)("label", { className: ps_design_system_1.PallasoftClassNameService.merge('block', className), children: [(0, jsx_runtime_1.jsx)("span", { className: 'ps-input-label', children: label }), (0, jsx_runtime_1.jsxs)("span", { className: 'relative mt-2 block', children: [(0, jsx_runtime_1.jsxs)("select", { className: 'ps-input-control ps-focus-ring min-h-11 w-full appearance-none pr-10 text-left font-semibold disabled:cursor-not-allowed disabled:opacity-60', defaultValue: value === undefined
|
|
9
|
+
? ps_select_input_service_1.PsSelectInputService.getDefaultValue(defaultValue, options)
|
|
10
|
+
: undefined, disabled: disabled, name: name, onChange: (event) => onChange?.(event.target.value), required: required, value: value, children: [options.length === 0 || !defaultValue ? ((0, jsx_runtime_1.jsx)("option", { disabled: true, value: '', children: placeholder })) : null, options.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.value)))] }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', iconKey: ps_icons_1.PsIconKey.Chevron, className: 'pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-primary' })] }), helperText ? (0, jsx_runtime_1.jsx)("span", { className: 'ps-input-helper', children: helperText }) : null] }));
|
|
7
11
|
exports.PsSelectInput = PsSelectInput;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './components/ps-combobox-input';
|
|
2
2
|
export * from './components/ps-date-input';
|
|
3
3
|
export * from './components/ps-dropdown';
|
|
4
|
+
export * from './components/ps-file-picker';
|
|
4
5
|
export * from './components/ps-form-control';
|
|
5
6
|
export * from './components/ps-multi-select-input';
|
|
6
7
|
export * from './components/ps-select-input';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./components/ps-combobox-input"), exports);
|
|
18
18
|
__exportStar(require("./components/ps-date-input"), exports);
|
|
19
19
|
__exportStar(require("./components/ps-dropdown"), exports);
|
|
20
|
+
__exportStar(require("./components/ps-file-picker"), exports);
|
|
20
21
|
__exportStar(require("./components/ps-form-control"), exports);
|
|
21
22
|
__exportStar(require("./components/ps-multi-select-input"), exports);
|
|
22
23
|
__exportStar(require("./components/ps-select-input"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsComboboxInputService = void 0;
|
|
4
|
+
class PsComboboxInputService {
|
|
5
|
+
static getItem(itemsByKey, key) {
|
|
6
|
+
const item = itemsByKey.get(String(key));
|
|
7
|
+
return item !== null && item !== undefined ? item : null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PsComboboxInputService = PsComboboxInputService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsSelectInputService = void 0;
|
|
4
|
+
class PsSelectInputService {
|
|
5
|
+
static getDefaultValue(defaultValue, options) {
|
|
6
|
+
if (defaultValue !== null && defaultValue !== undefined)
|
|
7
|
+
return defaultValue;
|
|
8
|
+
const firstValue = options[0]?.value;
|
|
9
|
+
return firstValue !== null && firstValue !== undefined ? firstValue : '';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.PsSelectInputService = PsSelectInputService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-input-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@internationalized/date": "^3.12.2",
|
|
32
|
-
"@pallasoft/ps-core-components": "^
|
|
33
|
-
"@pallasoft/ps-design-system": "^1.
|
|
32
|
+
"@pallasoft/ps-core-components": "^2.0.0",
|
|
33
|
+
"@pallasoft/ps-design-system": "^1.1.0",
|
|
34
|
+
"@pallasoft/ps-icons": "^1.1.0",
|
|
34
35
|
"react-aria-components": "^1.19.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
@@ -61,6 +62,8 @@
|
|
|
61
62
|
"husky": "^9.1.7",
|
|
62
63
|
"lint-staged": "^16.2.7",
|
|
63
64
|
"prettier": "^3.6.2",
|
|
65
|
+
"react": "^19.3.0",
|
|
66
|
+
"react-dom": "^19.3.0",
|
|
64
67
|
"semantic-release": "^24.2.0",
|
|
65
68
|
"ts-node": "^10.9.2",
|
|
66
69
|
"typescript": "^5.9.3"
|