@milktop/react-ui 0.3.6 → 0.3.7
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/button/Button.d.ts +12 -3
- package/dist/button/Button.js +43 -3
- package/dist/button/button.css +2 -1
- package/package.json +1 -1
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
|
|