@allxsmith/bestax-bulma 5.62.0 → 5.63.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.
- package/dist/bestax.css +1 -1
- package/dist/bestax.css.map +1 -1
- package/dist/esm/components/EmptyState.js +2 -6
- package/dist/esm/components/EmptyState.js.map +1 -1
- package/dist/esm/components/Timeline.js +5 -9
- package/dist/esm/components/Timeline.js.map +1 -1
- package/dist/esm/components/TreeView.js +3 -7
- package/dist/esm/components/TreeView.js.map +1 -1
- package/dist/esm/elements/Buttons.js +2 -0
- package/dist/esm/elements/Buttons.js.map +1 -1
- package/dist/esm/elements/CopyButton.js +132 -0
- package/dist/esm/elements/CopyButton.js.map +1 -0
- package/dist/esm/elements/DescriptionList.js +1 -5
- package/dist/esm/elements/DescriptionList.js.map +1 -1
- package/dist/esm/elements/Stat.js +196 -0
- package/dist/esm/elements/Stat.js.map +1 -0
- package/dist/esm/elements/Stats.js +48 -0
- package/dist/esm/elements/Stats.js.map +1 -0
- package/dist/esm/elements/statContext.js +10 -0
- package/dist/esm/elements/statContext.js.map +1 -0
- package/dist/esm/form/Combobox.js +2 -1
- package/dist/esm/form/Combobox.js.map +1 -1
- package/dist/esm/helpers/checkIcon.js +20 -0
- package/dist/esm/helpers/checkIcon.js.map +1 -0
- package/dist/esm/helpers/isGiven.js +13 -0
- package/dist/esm/helpers/isGiven.js.map +1 -0
- package/dist/esm/helpers/statusRegion.js +3 -3
- package/dist/esm/helpers/useClipboard.js +176 -0
- package/dist/esm/helpers/useClipboard.js.map +1 -0
- package/dist/extras.css +1 -1
- package/dist/extras.css.map +1 -1
- package/dist/index.cjs +4946 -4428
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +4 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/types/elements/Buttons.d.ts +1 -0
- package/dist/types/elements/CopyButton.d.ts +105 -0
- package/dist/types/elements/Stat.d.ts +242 -0
- package/dist/types/elements/Stats.d.ts +40 -0
- package/dist/types/elements/statContext.d.ts +18 -0
- package/dist/types/helpers/checkIcon.d.ts +10 -0
- package/dist/types/helpers/isGiven.d.ts +7 -0
- package/dist/types/helpers/useClipboard.d.ts +65 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types-cjs/elements/Buttons.d.ts +1 -0
- package/dist/types-cjs/elements/CopyButton.d.ts +105 -0
- package/dist/types-cjs/elements/Stat.d.ts +242 -0
- package/dist/types-cjs/elements/Stats.d.ts +40 -0
- package/dist/types-cjs/elements/statContext.d.ts +18 -0
- package/dist/types-cjs/helpers/checkIcon.d.ts +10 -0
- package/dist/types-cjs/helpers/isGiven.d.ts +7 -0
- package/dist/types-cjs/helpers/useClipboard.d.ts +65 -0
- package/dist/types-cjs/index.d.ts +5 -0
- package/dist/versions/bestax-no-dark-mode.css +1 -1
- package/dist/versions/bestax-no-dark-mode.css.map +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
- package/dist/versions/bestax-no-helpers.css +1 -1
- package/dist/versions/bestax-no-helpers.css.map +1 -1
- package/dist/versions/bestax-prefixed.css +1 -1
- package/dist/versions/bestax-prefixed.css.map +1 -1
- package/package.json +1 -1
- package/src/scss/elements/_index.scss +1 -0
- package/src/scss/elements/_stat.scss +153 -0
package/dist/index.esm.js
CHANGED
|
@@ -44,6 +44,7 @@ export { ToggleButton } from './esm/elements/ToggleButton.js';
|
|
|
44
44
|
export { Code } from './esm/elements/Code.js';
|
|
45
45
|
export { ColorSwatch } from './esm/elements/ColorSwatch.js';
|
|
46
46
|
export { Content } from './esm/elements/Content.js';
|
|
47
|
+
export { CopyButton } from './esm/elements/CopyButton.js';
|
|
47
48
|
export { Delete } from './esm/elements/Delete.js';
|
|
48
49
|
export { DescriptionList, DescriptionListItem, DescriptionListLabel, DescriptionListValue } from './esm/elements/DescriptionList.js';
|
|
49
50
|
export { Divider } from './esm/elements/Divider.js';
|
|
@@ -66,6 +67,8 @@ export { Progress } from './esm/elements/Progress.js';
|
|
|
66
67
|
export { RingProgress } from './esm/elements/RingProgress.js';
|
|
67
68
|
export { Skeleton } from './esm/elements/Skeleton.js';
|
|
68
69
|
export { Span } from './esm/elements/Span.js';
|
|
70
|
+
export { Stat, StatChange, StatDescription, StatLabel, StatValue } from './esm/elements/Stat.js';
|
|
71
|
+
export { Stats } from './esm/elements/Stats.js';
|
|
69
72
|
export { Strong } from './esm/elements/Strong.js';
|
|
70
73
|
export { SubTitle } from './esm/elements/SubTitle.js';
|
|
71
74
|
export { Table } from './esm/elements/Table.js';
|
|
@@ -130,6 +133,7 @@ export { Portal } from './esm/helpers/portal.js';
|
|
|
130
133
|
export { LocaleProvider, useLocale } from './esm/helpers/LocaleProvider.js';
|
|
131
134
|
export { useNumberFormat } from './esm/helpers/localeFormat.js';
|
|
132
135
|
export { useFocusTrap } from './esm/helpers/useFocusTrap.js';
|
|
136
|
+
export { useClipboard } from './esm/helpers/useClipboard.js';
|
|
133
137
|
export { AppFrame, AppFrameAside, AppFrameBurger, AppFrameFooter, AppFrameHeader, AppFrameMain, AppFrameNav, useAppFrame } from './esm/layout/AppFrame.js';
|
|
134
138
|
export { Center } from './esm/layout/Center.js';
|
|
135
139
|
export { Container } from './esm/layout/Container.js';
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -38,5 +38,6 @@ export declare const Buttons: React.FC<ButtonsProps> & {
|
|
|
38
38
|
LinkButton: import("../index.js").PolymorphicComponent<import("./LinkButton.js").LinkButtonOwnProps, "button", never>;
|
|
39
39
|
ToggleButton: React.ForwardRefExoticComponent<import("./ToggleButton.js").ToggleButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
40
40
|
IconButton: import("../index.js").PolymorphicComponent<import("./IconButton.js").IconButtonOwnProps & import("./IconButton.js").IconButtonName, "button", never>;
|
|
41
|
+
CopyButton: React.ForwardRefExoticComponent<import("./CopyButton.js").CopyButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
41
42
|
};
|
|
42
43
|
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ButtonOwnProps } from './Button.js';
|
|
3
|
+
/**
|
|
4
|
+
* The strings CopyButton shows and announces, each with an English default. A
|
|
5
|
+
* key left out, or set to an empty string, keeps its default.
|
|
6
|
+
*/
|
|
7
|
+
export interface CopyButtonLabels {
|
|
8
|
+
/**
|
|
9
|
+
* The button's label, and so its name, until a copy. With `showLabel` off
|
|
10
|
+
* it's the name in both states, given as `aria-label`.
|
|
11
|
+
* @defaultValue 'Copy'
|
|
12
|
+
*/
|
|
13
|
+
copy?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The label shown for `duration` after a copy, and so the name meanwhile.
|
|
16
|
+
* Not used with `showLabel` off, where only the glyph changes.
|
|
17
|
+
* @defaultValue 'Copied'
|
|
18
|
+
*/
|
|
19
|
+
copied?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Announced after a copy.
|
|
22
|
+
* @defaultValue 'Copied to the clipboard'
|
|
23
|
+
*/
|
|
24
|
+
copiedStatus?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Announced when the copy fails.
|
|
27
|
+
* @defaultValue "Couldn't copy to the clipboard"
|
|
28
|
+
*/
|
|
29
|
+
failedStatus?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Props for the CopyButton component. The helper props, the other button
|
|
33
|
+
* attributes and the `ref` land on the `<button>`.
|
|
34
|
+
*
|
|
35
|
+
* @extraProp {'button' | 'submit' | 'reset'} [type=button] - `button` unless you pass `submit` or `reset`.
|
|
36
|
+
* @extraProp {React.MouseEventHandler<HTMLButtonElement>} [onClick] - Runs before the copy. An `onClick` that calls `preventDefault()` stops the copy, and neither `onCopiedChange` nor `onCopyError` fires.
|
|
37
|
+
* @extraProp {React.Ref<HTMLButtonElement>} [ref] - Ref forwarded to the `<button>`.
|
|
38
|
+
*/
|
|
39
|
+
export interface CopyButtonProps extends Omit<ButtonOwnProps, 'children'>, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonOwnProps | 'value'> {
|
|
40
|
+
/**
|
|
41
|
+
* The text it copies. This is not the `<button>`'s form value, which it
|
|
42
|
+
* doesn't render.
|
|
43
|
+
*/
|
|
44
|
+
value: string;
|
|
45
|
+
/**
|
|
46
|
+
* How long the "Copied" label stays, in milliseconds. Another copy
|
|
47
|
+
* restarts it. `0` turns the reset off, as Toast's `0` turns off its
|
|
48
|
+
* auto-close, so "Copied" stays until a later copy fails. A missing or `NaN`
|
|
49
|
+
* value uses the default, a negative one ends it at once, and `Infinity`,
|
|
50
|
+
* or anything longer than the longest delay `setTimeout` takes (about 24.8
|
|
51
|
+
* days), is that longest delay.
|
|
52
|
+
* @defaultValue 2000
|
|
53
|
+
*/
|
|
54
|
+
duration?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Shows the label beside the icon, which is then the button's name: it
|
|
57
|
+
* carries no `aria-label`, so the name reads "Copy" and then "Copied" as
|
|
58
|
+
* the words on it do. Turned off, it's a square icon-only button named by
|
|
59
|
+
* `labels.copy` through `aria-label` in both states, and only the glyph
|
|
60
|
+
* changes. An `aria-label` you pass yourself names it in either form.
|
|
61
|
+
* @defaultValue true
|
|
62
|
+
*/
|
|
63
|
+
showLabel?: boolean;
|
|
64
|
+
/** Translations for the label and the announcements. */
|
|
65
|
+
labels?: CopyButtonLabels;
|
|
66
|
+
/**
|
|
67
|
+
* Called with `true` after each copy that worked, a repeat included, and
|
|
68
|
+
* with `false` when `duration` runs out or a later copy fails.
|
|
69
|
+
*/
|
|
70
|
+
onCopiedChange?: (copied: boolean) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Called when neither the Clipboard API nor the fallback could write. A
|
|
73
|
+
* copy field can select its text from here, so the reader can copy it
|
|
74
|
+
* themselves.
|
|
75
|
+
*/
|
|
76
|
+
onCopyError?: (error: Error) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The `CopyButton` component renders a button that copies a piece of text to the clipboard, says "Copied" for a moment, and announces the result.
|
|
80
|
+
*
|
|
81
|
+
* It's a `Button` with a copy icon and "Copy", and takes everything `Button`
|
|
82
|
+
* takes. A click writes `value` through the Clipboard API, or through the
|
|
83
|
+
* older copy command where that's missing or refused, and reports a failure
|
|
84
|
+
* rather than showing "Copied". Each outcome is announced through a polite
|
|
85
|
+
* status region portaled out of the button's place, so it stays the last
|
|
86
|
+
* child of a `Control` or `Buttons`: into the open modal dialog the button is
|
|
87
|
+
* in, otherwise where `Portal` puts portaled content (the `ConfigProvider`'s
|
|
88
|
+
* `portalContainer`, or the end of the page). With `showLabel={false}` it's an
|
|
89
|
+
* `IconButton`. For a trigger of your own, use `useClipboard`, which it's
|
|
90
|
+
* built on.
|
|
91
|
+
*
|
|
92
|
+
* @function
|
|
93
|
+
* @param {CopyButtonProps} props - Props for the CopyButton component.
|
|
94
|
+
* @param {React.Ref<HTMLButtonElement>} ref - Forwarded ref to the `<button>`.
|
|
95
|
+
* @returns {JSX.Element} The rendered button.
|
|
96
|
+
* @see {@link https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html | WCAG 4.1.3 Status Messages}
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* <CopyButton value="https://bestax.io" />
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* <CopyButton value={apiKey} showLabel={false} size="small" />
|
|
103
|
+
*/
|
|
104
|
+
export declare const CopyButton: React.ForwardRefExoticComponent<CopyButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
105
|
+
export default CopyButton;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BulmaClassesProps, validColors } from '../helpers/useBulmaClasses.js';
|
|
3
|
+
/** The colors a Stat's change can take, the union `messageColor` takes. */
|
|
4
|
+
export type StatChangeColor = 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';
|
|
5
|
+
/**
|
|
6
|
+
* Props for the Stat component. The helper props, the other attributes and
|
|
7
|
+
* the `ref` land on its root: a `<div>` inside `Stats`, or its own `<dl>` on
|
|
8
|
+
* its own.
|
|
9
|
+
*
|
|
10
|
+
* @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the root, a `<div>` inside `Stats` or a `<dl>` on its own.
|
|
11
|
+
*/
|
|
12
|
+
export interface StatProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
13
|
+
/** Additional CSS classes to apply. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/**
|
|
16
|
+
* What the figure is ("Revenue"), as a `Stat.Label` before the children.
|
|
17
|
+
* A Stat needs one, here or as a `Stat.Label` child: it's the figure's
|
|
18
|
+
* name for assistive tech, and a definition list's values belong to a
|
|
19
|
+
* term. A Stat with neither a `label` nor a `Stat.Label` child warns in
|
|
20
|
+
* development.
|
|
21
|
+
*/
|
|
22
|
+
label?: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* The figure, as a `Stat.Value` after the children. A number is written by
|
|
25
|
+
* `NumberFormatter` with `format` and `locale`; anything else, such as
|
|
26
|
+
* "N/A", renders as given, and `0` renders. `undefined`, `null`, a boolean
|
|
27
|
+
* and `''` leave it empty, and its `<dd>` still renders, one line of the
|
|
28
|
+
* figure tall, while the Stat has a label, so the label keeps its
|
|
29
|
+
* definition while the figure is missing. A `Stat.Value` child takes its
|
|
30
|
+
* place: with one, `value` and its `<dd>` are left out.
|
|
31
|
+
*/
|
|
32
|
+
value?: React.ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* `Intl.NumberFormat` options for a number `value`, as NumberFormatter's
|
|
35
|
+
* `format`. A `value` that isn't a number ignores it.
|
|
36
|
+
*/
|
|
37
|
+
format?: Intl.NumberFormatOptions;
|
|
38
|
+
/**
|
|
39
|
+
* The locale for `value` and `change`, as NumberFormatter's `locale`.
|
|
40
|
+
* Unset, it's the `LocaleProvider`'s around it, and with neither, the
|
|
41
|
+
* runtime's own, so give one, here or through a `LocaleProvider`, on a
|
|
42
|
+
* page rendered on the server.
|
|
43
|
+
*/
|
|
44
|
+
locale?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The change, as a `Stat.Change` after the value. With the default format
|
|
47
|
+
* it's a fraction (`0.12` for 12%); with your own `changeFormat`, it's in
|
|
48
|
+
* that format's terms. It's written with its sign, so the direction is in
|
|
49
|
+
* the text.
|
|
50
|
+
*/
|
|
51
|
+
change?: number;
|
|
52
|
+
/**
|
|
53
|
+
* `Intl.NumberFormat` options for `change`. Yours replace the default, and
|
|
54
|
+
* `signDisplay: 'exceptZero'` is added unless you set a `signDisplay`. With
|
|
55
|
+
* `signDisplay: 'never'`, or `'negative'` on a rise, the text carries no
|
|
56
|
+
* direction: the arrow is hidden from assistive tech and the tone is color
|
|
57
|
+
* alone, so keep a sign, or say the direction in `description`.
|
|
58
|
+
* @defaultValue { style: 'percent', signDisplay: 'exceptZero', maximumFractionDigits: 1 }
|
|
59
|
+
*/
|
|
60
|
+
changeFormat?: Intl.NumberFormatOptions;
|
|
61
|
+
/**
|
|
62
|
+
* The change's color. Unset, it's the sign's: `success` up, `danger` down,
|
|
63
|
+
* and none at zero. Set it where up is bad news, such as a cost or an
|
|
64
|
+
* error rate.
|
|
65
|
+
*/
|
|
66
|
+
changeColor?: StatChangeColor;
|
|
67
|
+
/** A note under the figure ("since last month"), as a `Stat.Description` last. */
|
|
68
|
+
description?: React.ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* The figure's size, a step of Bulma's size scale. The label, the change
|
|
71
|
+
* and the note stay small.
|
|
72
|
+
*/
|
|
73
|
+
size?: 'small' | 'medium' | 'large';
|
|
74
|
+
/**
|
|
75
|
+
* Shows a `Skeleton` in place of `value`, one line of the figure tall,
|
|
76
|
+
* and sets `aria-busy` on the Stat. The label, the change and the note
|
|
77
|
+
* render as given. With a `Stat.Value` child, it only sets `aria-busy`:
|
|
78
|
+
* the child renders as given, so put a `Skeleton` in it yourself.
|
|
79
|
+
*/
|
|
80
|
+
loading?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* `Stat.Label`, `Stat.Value`, `Stat.Change` and `Stat.Description`, for
|
|
83
|
+
* anything the props don't cover, such as a unit or an info tip. They
|
|
84
|
+
* render between `label` and `value`. They're this Stat's own parts, so
|
|
85
|
+
* not another Stat: that would be a list inside this one's. The Stat finds
|
|
86
|
+
* a `Stat.Label` or `Stat.Value` among them by type, so one rendered from
|
|
87
|
+
* inside a component of your own isn't seen.
|
|
88
|
+
*/
|
|
89
|
+
children?: React.ReactNode;
|
|
90
|
+
/**
|
|
91
|
+
* Text color helper. It colors the figure; the label, the change and the
|
|
92
|
+
* note keep their own colors. Inside `Stats`, a Stat without one takes the
|
|
93
|
+
* row's.
|
|
94
|
+
*/
|
|
95
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
96
|
+
/** Background color helper. */
|
|
97
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Props for Stat.Label, what the figure is. The helper props, the other
|
|
101
|
+
* attributes and the `ref` land on its `<dt>`.
|
|
102
|
+
*
|
|
103
|
+
* @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the `<dt>`.
|
|
104
|
+
*/
|
|
105
|
+
export interface StatLabelProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
106
|
+
/** Additional CSS classes to apply. */
|
|
107
|
+
className?: string;
|
|
108
|
+
/**
|
|
109
|
+
* The label. A button may sit in it, such as one that opens a `Popover`
|
|
110
|
+
* about the figure, but not a heading, which HTML doesn't allow here.
|
|
111
|
+
*/
|
|
112
|
+
children?: React.ReactNode;
|
|
113
|
+
/** Text color helper. */
|
|
114
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
115
|
+
/** Background color helper. */
|
|
116
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Props for Stat.Value, the figure. The helper props, the other attributes
|
|
120
|
+
* and the `ref` land on its `<dd>`.
|
|
121
|
+
*
|
|
122
|
+
* @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the `<dd>`.
|
|
123
|
+
*/
|
|
124
|
+
export interface StatValueProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
125
|
+
/** Additional CSS classes to apply. */
|
|
126
|
+
className?: string;
|
|
127
|
+
/**
|
|
128
|
+
* The figure, written as you give it, so write a number with
|
|
129
|
+
* `NumberFormatter`.
|
|
130
|
+
*/
|
|
131
|
+
children?: React.ReactNode;
|
|
132
|
+
/** Text color helper. */
|
|
133
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
134
|
+
/** Background color helper. */
|
|
135
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Props for Stat.Description, a note under the figure. The helper props, the
|
|
139
|
+
* other attributes and the `ref` land on its `<dd>`.
|
|
140
|
+
*
|
|
141
|
+
* @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the `<dd>`.
|
|
142
|
+
*/
|
|
143
|
+
export interface StatDescriptionProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
144
|
+
/** Additional CSS classes to apply. */
|
|
145
|
+
className?: string;
|
|
146
|
+
/** The note, such as "since last month". */
|
|
147
|
+
children?: React.ReactNode;
|
|
148
|
+
/** Text color helper. */
|
|
149
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
150
|
+
/** Background color helper. */
|
|
151
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Props for Stat.Change, a change written with its sign. The helper props,
|
|
155
|
+
* the other attributes and the `ref` land on its `<dd>`.
|
|
156
|
+
*
|
|
157
|
+
* @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the `<dd>`.
|
|
158
|
+
*/
|
|
159
|
+
export interface StatChangeProps extends Omit<React.HTMLAttributes<HTMLElement>, 'color' | 'children'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
160
|
+
/** Additional CSS classes to apply. */
|
|
161
|
+
className?: string;
|
|
162
|
+
/**
|
|
163
|
+
* The change, as Stat's `change`. One that rounds to zero in its format,
|
|
164
|
+
* such as `0.0004` at one decimal place of a percentage, reads as zero, so
|
|
165
|
+
* it gets no arrow and no color of its own.
|
|
166
|
+
*/
|
|
167
|
+
value: number;
|
|
168
|
+
/**
|
|
169
|
+
* As Stat's `changeFormat`: yours replace the default, and
|
|
170
|
+
* `signDisplay: 'exceptZero'` is added unless you set a `signDisplay`.
|
|
171
|
+
* @defaultValue { style: 'percent', signDisplay: 'exceptZero', maximumFractionDigits: 1 }
|
|
172
|
+
*/
|
|
173
|
+
format?: Intl.NumberFormatOptions;
|
|
174
|
+
/** As Stat's `locale`. Unset, the Stat's. */
|
|
175
|
+
locale?: string;
|
|
176
|
+
/**
|
|
177
|
+
* As Stat's `changeColor`. Unset, it's the sign's: `success` up, `danger`
|
|
178
|
+
* down, and none at zero. Set, it applies at zero too.
|
|
179
|
+
*/
|
|
180
|
+
color?: StatChangeColor;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* What the figure is: a `<dt>`, small and in the weaker text color.
|
|
184
|
+
*
|
|
185
|
+
* @function
|
|
186
|
+
* @param {StatLabelProps} props - Props for Stat.Label.
|
|
187
|
+
* @param {React.Ref<HTMLElement>} ref - Forwarded ref to the `<dt>`.
|
|
188
|
+
* @returns {JSX.Element} The rendered label.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* <Stat.Label>Revenue</Stat.Label>
|
|
192
|
+
*/
|
|
193
|
+
export declare const StatLabel: React.ForwardRefExoticComponent<StatLabelProps & React.RefAttributes<HTMLElement>>;
|
|
194
|
+
/**
|
|
195
|
+
* The figure: a `<dd>`, large, in the Stat's color, with digits of one width so a figure that updates doesn't shift.
|
|
196
|
+
*
|
|
197
|
+
* @function
|
|
198
|
+
* @param {StatValueProps} props - Props for Stat.Value.
|
|
199
|
+
* @param {React.Ref<HTMLElement>} ref - Forwarded ref to the `<dd>`.
|
|
200
|
+
* @returns {JSX.Element} The rendered figure.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* <Stat.Value>
|
|
204
|
+
* <NumberFormatter value={182} format={{ style: 'unit', unit: 'millisecond' }} />
|
|
205
|
+
* </Stat.Value>
|
|
206
|
+
*/
|
|
207
|
+
export declare const StatValue: React.ForwardRefExoticComponent<StatValueProps & React.RefAttributes<HTMLElement>>;
|
|
208
|
+
/**
|
|
209
|
+
* A note under the figure: a `<dd>`, small and in the weaker text color.
|
|
210
|
+
*
|
|
211
|
+
* @function
|
|
212
|
+
* @param {StatDescriptionProps} props - Props for Stat.Description.
|
|
213
|
+
* @param {React.Ref<HTMLElement>} ref - Forwarded ref to the `<dd>`.
|
|
214
|
+
* @returns {JSX.Element} The rendered note.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* <Stat.Description>since last month</Stat.Description>
|
|
218
|
+
*/
|
|
219
|
+
export declare const StatDescription: React.ForwardRefExoticComponent<StatDescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
220
|
+
/**
|
|
221
|
+
* A change written with its sign, such as "+12%", after an arrow that repeats the direction: a `<dd>`, green when it's up and red when it's down unless `color` says otherwise.
|
|
222
|
+
*
|
|
223
|
+
* The sign is in the text, written by `Intl` for the locale, so a screen
|
|
224
|
+
* reader hears the direction; the arrow is hidden from assistive tech, and
|
|
225
|
+
* the color repeats the direction for sighted readers rather than carry it.
|
|
226
|
+
*
|
|
227
|
+
* @function
|
|
228
|
+
* @param {StatChangeProps} props - Props for Stat.Change.
|
|
229
|
+
* @param {React.Ref<HTMLElement>} ref - Forwarded ref to the `<dd>`.
|
|
230
|
+
* @returns {JSX.Element} The rendered change.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* <Stat.Change value={-0.08} color="success" />
|
|
234
|
+
*/
|
|
235
|
+
export declare const StatChange: React.ForwardRefExoticComponent<StatChangeProps & React.RefAttributes<HTMLElement>>;
|
|
236
|
+
export declare const Stat: React.ForwardRefExoticComponent<StatProps & React.RefAttributes<HTMLElement>> & {
|
|
237
|
+
Label: React.ForwardRefExoticComponent<StatLabelProps & React.RefAttributes<HTMLElement>>;
|
|
238
|
+
Value: React.ForwardRefExoticComponent<StatValueProps & React.RefAttributes<HTMLElement>>;
|
|
239
|
+
Change: React.ForwardRefExoticComponent<StatChangeProps & React.RefAttributes<HTMLElement>>;
|
|
240
|
+
Description: React.ForwardRefExoticComponent<StatDescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
241
|
+
};
|
|
242
|
+
export default Stat;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BulmaClassesProps, validColors } from '../helpers/useBulmaClasses.js';
|
|
3
|
+
import type { BulmaMinColValue } from '../grid/Grid.js';
|
|
4
|
+
/**
|
|
5
|
+
* Props for the Stats component, a row of Stats on Bulma's smart grid. The
|
|
6
|
+
* helper props, the other attributes and the `ref` land on its `<dl>`.
|
|
7
|
+
*
|
|
8
|
+
* @extraProp {React.Ref<HTMLDListElement>} [ref] - Ref forwarded to the `<dl>`.
|
|
9
|
+
* @extraProp {BulmaGapStep} [gap] - The space between tiles (`is-gap-*`), the helper prop with the values Grid's `gap` takes.
|
|
10
|
+
* @extraProp {string} [aria-labelledby] - The id of the heading above the row, which names it.
|
|
11
|
+
*/
|
|
12
|
+
export interface StatsProps extends Omit<React.HTMLAttributes<HTMLDListElement>, 'color'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
13
|
+
/** Additional CSS classes to apply. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** `Stat`s, one per figure, and nothing else: they're the groups of its `<dl>`. */
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* The narrowest a tile gets before the row wraps (`is-col-min-*`), as
|
|
19
|
+
* Grid's `minCol`: 1.5rem a step. Unset, it's Bulma's 9rem.
|
|
20
|
+
*/
|
|
21
|
+
minCol?: BulmaMinColValue;
|
|
22
|
+
/**
|
|
23
|
+
* Text color helper: `has-text-*` on the `<dl>`, as on Buttons. Each Stat
|
|
24
|
+
* in the row without a `textColor` of its own takes it too, which colors
|
|
25
|
+
* its figure, since a Stat sets its own color. The labels, the changes and
|
|
26
|
+
* the notes keep theirs.
|
|
27
|
+
*/
|
|
28
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
29
|
+
/** Background color helper. */
|
|
30
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
31
|
+
}
|
|
32
|
+
export declare const Stats: React.ForwardRefExoticComponent<StatsProps & React.RefAttributes<HTMLDListElement>> & {
|
|
33
|
+
Stat: React.ForwardRefExoticComponent<import("./Stat.js").StatProps & React.RefAttributes<HTMLElement>> & {
|
|
34
|
+
Label: React.ForwardRefExoticComponent<import("./Stat.js").StatLabelProps & React.RefAttributes<HTMLElement>>;
|
|
35
|
+
Value: React.ForwardRefExoticComponent<import("./Stat.js").StatValueProps & React.RefAttributes<HTMLElement>>;
|
|
36
|
+
Change: React.ForwardRefExoticComponent<import("./Stat.js").StatChangeProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
+
Description: React.ForwardRefExoticComponent<import("./Stat.js").StatDescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default Stats;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { validColors } from '../helpers/useBulmaClasses.js';
|
|
2
|
+
export interface StatScope {
|
|
3
|
+
/**
|
|
4
|
+
* Whether this is inside a `Stats` row, where a Stat is a `<div>` in the
|
|
5
|
+
* row's `<dl>` rather than a `<dl>` of its own. A Stat sets it back to
|
|
6
|
+
* `false` for its children. Those are meant to be its parts, so a Stat
|
|
7
|
+
* inside a part sits in a `<dd>`, where a `<dl>` of its own is valid. A
|
|
8
|
+
* Stat written straight among another's children isn't handled: it renders
|
|
9
|
+
* a `<dl>` inside the other's list, which HTML doesn't allow, and Stat's
|
|
10
|
+
* `children` TSDoc says not to.
|
|
11
|
+
*/
|
|
12
|
+
row: boolean;
|
|
13
|
+
/** The row's `textColor`, which each Stat in it takes unless it has its own. */
|
|
14
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
15
|
+
/** The Stat's `locale`, which a `Stat.Change` in it takes unless it has its own. */
|
|
16
|
+
locale?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const StatScopeContext: import("react").Context<StatScope>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A check mark, 1em square and drawn in `currentColor`, so it takes the text
|
|
3
|
+
* color around it, the system's in forced colors included. Combobox draws it
|
|
4
|
+
* beside a chosen item, and CopyButton after a copy. It's decorative: put it
|
|
5
|
+
* inside something `aria-hidden`.
|
|
6
|
+
*
|
|
7
|
+
* @function CheckIcon
|
|
8
|
+
* @returns The check mark's `<svg>`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function CheckIcon(): import("react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* INTERNAL, deliberately not exported from `src/index.ts`. Whether a prop
|
|
4
|
+
* was given something to render: `undefined`, `null`, a boolean and `''`
|
|
5
|
+
* weren't, and `0` was, since React renders it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isGiven: (node: ReactNode) => boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Options for useClipboard. */
|
|
2
|
+
export interface UseClipboardOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How long `copied` stays `true` after a copy, in milliseconds. Another
|
|
5
|
+
* copy restarts it. `0` turns the timer off, as Toast's `0` does, so
|
|
6
|
+
* `copied` stays `true` until a later copy fails. A missing or `NaN` value
|
|
7
|
+
* uses the default, a negative one ends it at once, and `Infinity`, or
|
|
8
|
+
* anything longer than the longest delay `setTimeout` takes (2147483647 ms,
|
|
9
|
+
* about 24.8 days), is that longest delay.
|
|
10
|
+
* @defaultValue 2000
|
|
11
|
+
*/
|
|
12
|
+
duration?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Called with `true` after each copy that worked, a repeat included, and
|
|
15
|
+
* with `false` when `duration` runs out or a later copy fails.
|
|
16
|
+
*/
|
|
17
|
+
onCopiedChange?: (copied: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Called when neither the Clipboard API nor the copy command could write,
|
|
20
|
+
* with the Clipboard API's own error when it refused, or an `Error` saying
|
|
21
|
+
* neither could.
|
|
22
|
+
*/
|
|
23
|
+
onCopyError?: (error: Error) => void;
|
|
24
|
+
}
|
|
25
|
+
/** What useClipboard returns. */
|
|
26
|
+
export interface UseClipboardResult {
|
|
27
|
+
/**
|
|
28
|
+
* Writes `text` to the clipboard, and resolves `true` once it's written or
|
|
29
|
+
* `false` when it couldn't be. It never rejects. Call it from a click or a
|
|
30
|
+
* key press, with no `await` before it: browsers only allow a write
|
|
31
|
+
* shortly after one. A call that a later one overtakes leaves `copied`,
|
|
32
|
+
* `error` and the callbacks to the later one, and doesn't fall back to the
|
|
33
|
+
* copy command once the later one has started.
|
|
34
|
+
*/
|
|
35
|
+
copy: (text: string) => Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* `true` for `duration` after a copy that worked, or, with a `duration` of
|
|
38
|
+
* `0`, until a later copy fails.
|
|
39
|
+
*/
|
|
40
|
+
copied: boolean;
|
|
41
|
+
/** Why the last copy failed, or `null` after one that worked. */
|
|
42
|
+
error: Error | null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Copies text to the clipboard through the Clipboard API, falling back to the copy command where that's missing or refused, and keeps a `copied` flag for `duration` after a copy.
|
|
46
|
+
*
|
|
47
|
+
* It announces nothing. A trigger of your own says "Copied" in a
|
|
48
|
+
* `role="status"` region that's in the page before the click; `CopyButton`
|
|
49
|
+
* is this hook with the button, the label and the announcement built in.
|
|
50
|
+
*
|
|
51
|
+
* A failed copy sets `error`, calls `onCopyError`, and ends `copied` if a
|
|
52
|
+
* copy before it had set it. When copies overlap, only the latest one's
|
|
53
|
+
* outcome sets the state and fires the callbacks, whichever finishes first.
|
|
54
|
+
* Nothing changes and no callback fires once the component using it has
|
|
55
|
+
* unmounted, though a write already under way still finishes.
|
|
56
|
+
*
|
|
57
|
+
* @function useClipboard
|
|
58
|
+
* @param options - How long `copied` lasts, and the callbacks.
|
|
59
|
+
* @returns `copy`, which writes, and the `copied` and `error` state.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const { copy, copied } = useClipboard();
|
|
63
|
+
* <Button onClick={() => copy(url)}>{copied ? 'Copied' : 'Copy link'}</Button>
|
|
64
|
+
*/
|
|
65
|
+
export declare function useClipboard(options?: UseClipboardOptions): UseClipboardResult;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export * from './elements/ToggleButton.js';
|
|
|
43
43
|
export * from './elements/Code.js';
|
|
44
44
|
export * from './elements/ColorSwatch.js';
|
|
45
45
|
export * from './elements/Content.js';
|
|
46
|
+
export * from './elements/CopyButton.js';
|
|
46
47
|
export * from './elements/Delete.js';
|
|
47
48
|
export * from './elements/DescriptionList.js';
|
|
48
49
|
export * from './elements/Divider.js';
|
|
@@ -65,6 +66,8 @@ export * from './elements/Progress.js';
|
|
|
65
66
|
export * from './elements/RingProgress.js';
|
|
66
67
|
export * from './elements/Skeleton.js';
|
|
67
68
|
export * from './elements/Span.js';
|
|
69
|
+
export * from './elements/Stat.js';
|
|
70
|
+
export * from './elements/Stats.js';
|
|
68
71
|
export * from './elements/Strong.js';
|
|
69
72
|
export * from './elements/SubTitle.js';
|
|
70
73
|
export * from './elements/Table.js';
|
|
@@ -152,6 +155,8 @@ export { useNumberFormat } from './helpers/localeFormat.js';
|
|
|
152
155
|
export type { NumberFormatFunction } from './helpers/localeFormat.js';
|
|
153
156
|
export { useFocusTrap } from './helpers/useFocusTrap.js';
|
|
154
157
|
export type { UseFocusTrapOptions } from './helpers/useFocusTrap.js';
|
|
158
|
+
export { useClipboard } from './helpers/useClipboard.js';
|
|
159
|
+
export type { UseClipboardOptions, UseClipboardResult, } from './helpers/useClipboard.js';
|
|
155
160
|
export * from './layout/AppFrame.js';
|
|
156
161
|
export * from './layout/Center.js';
|
|
157
162
|
export * from './layout/Container.js';
|
|
@@ -38,5 +38,6 @@ export declare const Buttons: React.FC<ButtonsProps> & {
|
|
|
38
38
|
LinkButton: import("../index.js").PolymorphicComponent<import("./LinkButton.js").LinkButtonOwnProps, "button", never>;
|
|
39
39
|
ToggleButton: React.ForwardRefExoticComponent<import("./ToggleButton.js").ToggleButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
40
40
|
IconButton: import("../index.js").PolymorphicComponent<import("./IconButton.js").IconButtonOwnProps & import("./IconButton.js").IconButtonName, "button", never>;
|
|
41
|
+
CopyButton: React.ForwardRefExoticComponent<import("./CopyButton.js").CopyButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
41
42
|
};
|
|
42
43
|
export {};
|