@pallasoft/ps-input-components 1.0.0 → 1.1.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,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,28 @@
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 onFileChange = (event) => {
11
+ const newFile = event.target.files?.[0];
12
+ if (!newFile || disabled)
13
+ return;
14
+ if (!accept.includes(newFile.type)) {
15
+ onError?.('Invalid file type. Please select a supported file.');
16
+ event.target.value = '';
17
+ return;
18
+ }
19
+ if (maxSizeBytes && newFile.size > maxSizeBytes) {
20
+ onError?.(maxSizeLabel ? `File is too large. ${maxSizeLabel}.` : 'File is too large.');
21
+ event.target.value = '';
22
+ return;
23
+ }
24
+ onFileLoad(newFile);
25
+ };
26
+ 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 })] }));
27
+ };
28
+ exports.PsFilePicker = PsFilePicker;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-input-components",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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": "^1.0.0",
33
- "@pallasoft/ps-design-system": "^1.0.0",
32
+ "@pallasoft/ps-core-components": "^1.4.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": {