@milktop/react-ui 0.3.6 → 0.3.8
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);
|
package/dist/button/Button.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A button. Other attributes (onClick,
|
|
2
|
+
* A button, or a link that looks like one. Other attributes (onClick,
|
|
3
|
+
* aria-label, form…) go on the <button> or link.
|
|
3
4
|
*
|
|
4
5
|
* <Button variant="primary" icon="lucide:save" loading={saving}>Save</Button>
|
|
6
|
+
* <Button href="/students">Students</Button>
|
|
7
|
+
* <Button variant="link" link={<Link to="/students" />}>Students</Button>
|
|
5
8
|
*
|
|
6
9
|
* - `variant`: 'default', 'primary', 'danger', 'soft', 'ghost' or 'link'
|
|
10
|
+
* - `href`: where it goes, as an <a>; a disabled or loading one stays a <button>,
|
|
11
|
+
* as a link can't be disabled
|
|
12
|
+
* - `link`: your router's link element in place of the <a> (`<Link to="…" />`);
|
|
13
|
+
* it gets the button's props and content
|
|
7
14
|
* - `size`: 'sm', 'md' (matching the inputs' height) or 'lg'
|
|
8
15
|
* - `icon`, `iconEnd`: Iconify names; with no text it is an icon button, so give it an aria-label
|
|
9
16
|
* - `loading`: a spinner in place of the icon; also disables it
|
|
@@ -17,7 +24,7 @@
|
|
|
17
24
|
* - `countLabel`: what the count is, for assistive tech ('new': "Inbox, 3 new")
|
|
18
25
|
* - `type`: 'button' by default (pass 'submit' for forms)
|
|
19
26
|
*/
|
|
20
|
-
import type
|
|
27
|
+
import { type ComponentProps, type ReactElement } from 'react';
|
|
21
28
|
import '../icons.js';
|
|
22
29
|
import { type Classes } from '../utils.js';
|
|
23
30
|
import '../theme.css';
|
|
@@ -25,6 +32,8 @@ import './button.css';
|
|
|
25
32
|
export type ButtonProps = ComponentProps<'button'> & {
|
|
26
33
|
variant?: 'default' | 'primary' | 'danger' | 'soft' | 'ghost' | 'link';
|
|
27
34
|
size?: 'sm' | 'md' | 'lg';
|
|
35
|
+
href?: string | null;
|
|
36
|
+
link?: ReactElement | null;
|
|
28
37
|
icon?: string | null;
|
|
29
38
|
iconEnd?: string | null;
|
|
30
39
|
loading?: boolean;
|
|
@@ -38,4 +47,4 @@ export type ButtonProps = ComponentProps<'button'> & {
|
|
|
38
47
|
countLabel?: string;
|
|
39
48
|
classes?: Classes<'root' | 'spinner' | 'icon' | 'badge' | 'spoken'>;
|
|
40
49
|
};
|
|
41
|
-
export declare function Button({ variant, size, icon, iconEnd, loading, round, block, count, max, dot, pulse, countColor, countLabel: countLabelProp, type, disabled, className, classes, children, ...rest }: ButtonProps): import("react").JSX.Element;
|
|
50
|
+
export declare function Button({ variant, size, href, link, icon, iconEnd, loading, round, block, count, max, dot, pulse, countColor, countLabel: countLabelProp, type, disabled, className, classes, children, ...rest }: ButtonProps): import("react").JSX.Element;
|
package/dist/button/Button.js
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A button, or a link that looks like one. Other attributes (onClick,
|
|
4
|
+
* aria-label, form…) go on the <button> or link.
|
|
5
|
+
*
|
|
6
|
+
* <Button variant="primary" icon="lucide:save" loading={saving}>Save</Button>
|
|
7
|
+
* <Button href="/students">Students</Button>
|
|
8
|
+
* <Button variant="link" link={<Link to="/students" />}>Students</Button>
|
|
9
|
+
*
|
|
10
|
+
* - `variant`: 'default', 'primary', 'danger', 'soft', 'ghost' or 'link'
|
|
11
|
+
* - `href`: where it goes, as an <a>; a disabled or loading one stays a <button>,
|
|
12
|
+
* as a link can't be disabled
|
|
13
|
+
* - `link`: your router's link element in place of the <a> (`<Link to="…" />`);
|
|
14
|
+
* it gets the button's props and content
|
|
15
|
+
* - `size`: 'sm', 'md' (matching the inputs' height) or 'lg'
|
|
16
|
+
* - `icon`, `iconEnd`: Iconify names; with no text it is an icon button, so give it an aria-label
|
|
17
|
+
* - `loading`: a spinner in place of the icon; also disables it
|
|
18
|
+
* - `round`: a circle for icon buttons, a pill with text
|
|
19
|
+
* - `block`: full width
|
|
20
|
+
* - `count`: a badge on the corner (hidden at 0 or null), "99+" past `max`
|
|
21
|
+
* - `dot`: a small dot there instead, for "something new"
|
|
22
|
+
* - `pulse`: a ring ripples out from the badge or dot (not when the system asks for less motion)
|
|
23
|
+
* - `countColor`: 'danger', 'accent', 'success', 'warning' or 'neutral', for the
|
|
24
|
+
* dot too; or set `--ui-button-count-bg` and `--ui-button-count-text` in CSS for any other
|
|
25
|
+
* - `countLabel`: what the count is, for assistive tech ('new': "Inbox, 3 new")
|
|
26
|
+
* - `type`: 'button' by default (pass 'submit' for forms)
|
|
27
|
+
*/
|
|
28
|
+
import { cloneElement } from 'react';
|
|
2
29
|
import '../icons.js';
|
|
3
30
|
import { cx, partsOf } from '../utils.js';
|
|
4
31
|
import { useMessages } from '../format/LocaleProvider.js';
|
|
5
32
|
import '../theme.css';
|
|
6
33
|
import './button.css';
|
|
7
|
-
export function Button({ variant = 'default', size = 'md', icon = null, iconEnd = null, loading = false, round = false, block = false, count = null, max = 99, dot = false, pulse = false, countColor = 'danger', countLabel: countLabelProp, type = 'button', disabled = false, className, classes, children, ...rest }) {
|
|
34
|
+
export function Button({ variant = 'default', size = 'md', href = null, link = null, icon = null, iconEnd = null, loading = false, round = false, block = false, count = null, max = 99, dot = false, pulse = false, countColor = 'danger', countLabel: countLabelProp, type = 'button', disabled = false, className, classes, children, ...rest }) {
|
|
8
35
|
const t = useMessages();
|
|
9
36
|
const countLabel = countLabelProp ?? t.button.countLabel;
|
|
10
37
|
const part = partsOf('button', classes);
|
|
@@ -13,7 +40,20 @@ export function Button({ variant = 'default', size = 'md', icon = null, iconEnd
|
|
|
13
40
|
const spoken = count && count > 0 ? `${count} ${countLabel}` : dot ? countLabel : '';
|
|
14
41
|
// An aria-label hides the button's text from assistive tech, so the count joins the label.
|
|
15
42
|
const label = rest['aria-label'] && spoken ? `${rest['aria-label']}, ${spoken}` : rest['aria-label'];
|
|
16
|
-
|
|
43
|
+
const props = {
|
|
44
|
+
...rest, ...part('root'), className: cx(className, classes?.root),
|
|
45
|
+
'aria-label': label, 'aria-busy': loading || undefined,
|
|
46
|
+
'data-variant': variant, 'data-size': size, 'data-round': round || undefined, 'data-block': block || undefined,
|
|
47
|
+
'data-loading': loading || undefined, 'data-icon-only': (children == null && !(icon && iconEnd)) || undefined,
|
|
48
|
+
};
|
|
49
|
+
const content = _jsxs(_Fragment, { children: [loading
|
|
17
50
|
? _jsx("span", { ...part('spinner'), "aria-hidden": "true" })
|
|
18
|
-
: icon && _jsx("iconify-icon", { ...part('icon'), icon: icon, "aria-hidden": "true" }), children, iconEnd && _jsx("iconify-icon", { ...part('icon'), icon: iconEnd, "aria-hidden": "true" }), badge != null && _jsxs(_Fragment, { children: [_jsx("span", { ...part('badge'), "aria-hidden": "true", "data-dot": badge === '' || undefined, "data-pulse": pulse || undefined, "data-color": countColor, children: badge }), !rest['aria-label'] && _jsxs("span", { ...part('spoken'), children: [", ", spoken] })] })] })
|
|
51
|
+
: icon && _jsx("iconify-icon", { ...part('icon'), icon: icon, "aria-hidden": "true" }), children, iconEnd && _jsx("iconify-icon", { ...part('icon'), icon: iconEnd, "aria-hidden": "true" }), badge != null && _jsxs(_Fragment, { children: [_jsx("span", { ...part('badge'), "aria-hidden": "true", "data-dot": badge === '' || undefined, "data-pulse": pulse || undefined, "data-color": countColor, children: badge }), !rest['aria-label'] && _jsxs("span", { ...part('spoken'), children: [", ", spoken] })] })] });
|
|
52
|
+
if (!disabled && !loading) {
|
|
53
|
+
if (link)
|
|
54
|
+
return cloneElement(link, props, content);
|
|
55
|
+
if (href)
|
|
56
|
+
return _jsx("a", { ...props, href: href, children: content });
|
|
57
|
+
}
|
|
58
|
+
return _jsx("button", { ...props, type: type, disabled: disabled || loading, children: content });
|
|
19
59
|
}
|
package/dist/button/button.css
CHANGED
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
&:hover { filter: brightness(0.97); } }
|
|
22
22
|
&[data-variant=ghost] { background: transparent; border-color: transparent;
|
|
23
23
|
&:hover { background: var(--ui-hover); } }
|
|
24
|
-
/*
|
|
24
|
+
/* Reads as part of the text around it, so it wraps and takes that text's type. */
|
|
25
25
|
&[data-variant=link] { height: auto; padding: 0; background: transparent; border-color: transparent; color: var(--ui-accent);
|
|
26
|
+
font-size: inherit; font-weight: inherit; line-height: inherit; white-space: normal; text-align: start;
|
|
26
27
|
&:hover { background: transparent; text-decoration: underline; }
|
|
27
28
|
&:active { translate: none; } }
|
|
28
29
|
|