@milktop/react-ui 0.3.7 → 0.3.9
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.
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* `persist` (a localStorage key) their choice is remembered
|
|
14
14
|
* - `columns`: the most tiles per row in the grid; fewer when tiles would get
|
|
15
15
|
* too small (without it, as many as fit)
|
|
16
|
+
* - `onOpen`: gets the item when it's clicked; return true to say you've shown
|
|
17
|
+
* it yourself (a PDF in your own viewer), or nothing to leave it to the default
|
|
16
18
|
* - `removable`: a remove button on each; `onRemove` gets the item
|
|
17
19
|
* - `addable`: an "Add files" tile that opens the file picker, and files can
|
|
18
20
|
* be dropped onto the attachments; `onAdd` gets the Files
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
* the saved ones no longer there.
|
|
35
37
|
*
|
|
36
38
|
* Clicking an image opens it large; other files open their `url`, if any, in
|
|
37
|
-
* a new tab. Files with a `url` get a download button.
|
|
39
|
+
* a new tab (see `onOpen`). Files with a `url` get a download button.
|
|
38
40
|
*/
|
|
39
41
|
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
40
42
|
import '../icons.js';
|
|
@@ -71,6 +73,7 @@ export type AttachmentsProps = Omit<HTMLAttributes<HTMLDivElement>, 'onDrop'> &
|
|
|
71
73
|
maxFileSize?: number | null;
|
|
72
74
|
addLabel?: ReactNode;
|
|
73
75
|
emptyText?: ReactNode;
|
|
76
|
+
onOpen?: (item: Attachment) => boolean | void;
|
|
74
77
|
onRemove?: (item: Attachment) => void;
|
|
75
78
|
onAdd?: (files: File[]) => void;
|
|
76
79
|
onReject?: (rejected: AttachmentRejection[]) => void;
|
|
@@ -81,4 +84,4 @@ export type AttachmentsProps = Omit<HTMLAttributes<HTMLDivElement>, 'onDrop'> &
|
|
|
81
84
|
classes?: Classes<'root' | 'header' | 'label' | 'switch' | 'empty' | 'files' | 'file' | 'open' | 'thumb' | 'icon' | 'ext' | 'meta' | 'name' | 'size' | 'actions' | 'action' | 'addTile' | 'addInput' | 'addIcon' | 'addText' | 'addLabel' | 'limit' | 'rejected' | 'dropHint' | 'preview' | 'downloadLink'>;
|
|
82
85
|
};
|
|
83
86
|
export declare const formatSize: (bytes: number, locale?: string) => string;
|
|
84
|
-
export declare function Attachments({ items: itemsProp, defaultItems, onItemsChange, layout: layoutProp, defaultLayout, onLayoutChange, switchable, persist, columns, removable, addable, accept, maxFiles, maxFileSize, addLabel: addLabelProp, emptyText, onRemove, onAdd, onReject, label, name, keptName, disabled: disabledProp, className, classes, style, ...rest }: AttachmentsProps): import("react").JSX.Element;
|
|
87
|
+
export declare function Attachments({ items: itemsProp, defaultItems, onItemsChange, layout: layoutProp, defaultLayout, onLayoutChange, switchable, persist, columns, removable, addable, accept, maxFiles, maxFileSize, addLabel: addLabelProp, emptyText, onOpen, onRemove, onAdd, onReject, label, name, keptName, disabled: disabledProp, className, classes, style, ...rest }: AttachmentsProps): import("react").JSX.Element;
|
|
@@ -14,6 +14,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
14
14
|
* `persist` (a localStorage key) their choice is remembered
|
|
15
15
|
* - `columns`: the most tiles per row in the grid; fewer when tiles would get
|
|
16
16
|
* too small (without it, as many as fit)
|
|
17
|
+
* - `onOpen`: gets the item when it's clicked; return true to say you've shown
|
|
18
|
+
* it yourself (a PDF in your own viewer), or nothing to leave it to the default
|
|
17
19
|
* - `removable`: a remove button on each; `onRemove` gets the item
|
|
18
20
|
* - `addable`: an "Add files" tile that opens the file picker, and files can
|
|
19
21
|
* be dropped onto the attachments; `onAdd` gets the Files
|
|
@@ -35,7 +37,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
35
37
|
* the saved ones no longer there.
|
|
36
38
|
*
|
|
37
39
|
* Clicking an image opens it large; other files open their `url`, if any, in
|
|
38
|
-
* a new tab. Files with a `url` get a download button.
|
|
40
|
+
* a new tab (see `onOpen`). Files with a `url` get a download button.
|
|
39
41
|
*/
|
|
40
42
|
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
41
43
|
import { createFileTypeValidator, getAcceptAttrString, getFileKey } from '@zag-js/file-utils';
|
|
@@ -104,7 +106,7 @@ const typeChecker = (accept) => {
|
|
|
104
106
|
const fits = createFileTypeValidator(getAcceptAttrString(accept ?? undefined));
|
|
105
107
|
return (file) => !accept || fits(file)[0];
|
|
106
108
|
};
|
|
107
|
-
export function Attachments({ items: itemsProp, defaultItems = [], onItemsChange, layout: layoutProp, defaultLayout = 'grid', onLayoutChange, switchable = false, persist = null, columns = null, removable = false, addable = false, accept = null, maxFiles = null, maxFileSize = null, addLabel: addLabelProp, emptyText = null, onRemove, onAdd, onReject, label = null, name, keptName, disabled: disabledProp = false, className, classes, style, ...rest }) {
|
|
109
|
+
export function Attachments({ items: itemsProp, defaultItems = [], onItemsChange, layout: layoutProp, defaultLayout = 'grid', onLayoutChange, switchable = false, persist = null, columns = null, removable = false, addable = false, accept = null, maxFiles = null, maxFileSize = null, addLabel: addLabelProp, emptyText = null, onOpen, onRemove, onAdd, onReject, label = null, name, keptName, disabled: disabledProp = false, className, classes, style, ...rest }) {
|
|
108
110
|
const t = useMessages();
|
|
109
111
|
const addLabel = addLabelProp ?? t.attachments.add;
|
|
110
112
|
const layouts = [{ value: 'grid', label: t.attachments.grid, icon: 'lucide:layout-grid' }, { value: 'list', label: t.attachments.list, icon: 'lucide:list' }];
|
|
@@ -224,6 +226,8 @@ export function Attachments({ items: itemsProp, defaultItems = [], onItemsChange
|
|
|
224
226
|
const [previewing, setPreviewing] = useState(null);
|
|
225
227
|
const [previewOpen, setPreviewOpen] = useState(false);
|
|
226
228
|
function open(entry) {
|
|
229
|
+
if (onOpen?.(entry.item))
|
|
230
|
+
return;
|
|
227
231
|
if (entry.image && entry.url) {
|
|
228
232
|
setPreviewing(entry);
|
|
229
233
|
setPreviewOpen(true);
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
[data-scope=number-input][data-part=root] { display: inline-block; min-width: 10rem; color: var(--ui-text); font-family: var(--ui-font); }
|
|
3
3
|
[data-scope=number-input][data-part=label] { display: block; font-size: 14px; font-weight: 500; margin-bottom: 0.375rem; }
|
|
4
4
|
[data-scope=number-input][data-part=control] { display: flex; align-items: center; gap: 0.5rem; height: var(--ui-control-height);
|
|
5
|
-
padding: 0 0.
|
|
5
|
+
padding: 0 0.75rem; box-sizing: border-box; background: var(--ui-field-bg);
|
|
6
6
|
border: 1px solid var(--ui-field-border); border-radius: var(--ui-radius); font-size: 14px;
|
|
7
|
+
&:has([data-part=increment-trigger]) { padding-right: 0.25rem; }
|
|
7
8
|
&:hover { border-color: var(--ui-field-border-hover); }
|
|
8
9
|
&:focus-within { border-color: var(--ui-ring); outline: 2px solid var(--ui-ring-soft); }
|
|
9
10
|
&:has(input:autofill) { background: var(--ui-field-autofill-bg); }
|