@allxsmith/bestax-bulma 5.57.4 → 5.58.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/Avatars.js +2 -2
- package/dist/esm/components/Avatars.js.map +1 -1
- package/dist/esm/components/Badge.js +2 -2
- package/dist/esm/components/Badge.js.map +1 -1
- package/dist/esm/components/Pagination.js +2 -2
- package/dist/esm/components/Pagination.js.map +1 -1
- package/dist/esm/components/Steps.js +2 -2
- package/dist/esm/components/Steps.js.map +1 -1
- package/dist/esm/components/TreeView.js +7 -5
- package/dist/esm/components/TreeView.js.map +1 -1
- package/dist/esm/components/useDataTable.js +2 -2
- package/dist/esm/components/useDataTable.js.map +1 -1
- package/dist/esm/elements/NumberFormatter.js +42 -0
- package/dist/esm/elements/NumberFormatter.js.map +1 -0
- package/dist/esm/elements/RingProgress.js +2 -2
- package/dist/esm/elements/RingProgress.js.map +1 -1
- package/dist/esm/form/Dropzone.js +2 -2
- package/dist/esm/form/Dropzone.js.map +1 -1
- package/dist/esm/form/File.js +2 -2
- package/dist/esm/form/File.js.map +1 -1
- package/dist/esm/form/Rate.js +2 -2
- package/dist/esm/form/Rate.js.map +1 -1
- package/dist/esm/form/Slider.js +2 -2
- package/dist/esm/form/Slider.js.map +1 -1
- package/dist/esm/form/Taginput.js +2 -2
- package/dist/esm/form/Taginput.js.map +1 -1
- package/dist/esm/form/_colorInternals/pickerState.js +2 -2
- package/dist/esm/form/_colorInternals/pickerState.js.map +1 -1
- package/dist/esm/helpers/LocaleProvider.js +13 -6
- package/dist/esm/helpers/LocaleProvider.js.map +1 -1
- package/dist/esm/helpers/localeFormat.js +196 -36
- package/dist/esm/helpers/localeFormat.js.map +1 -1
- package/dist/esm/helpers/useTreeView.js +54 -20
- package/dist/esm/helpers/useTreeView.js.map +1 -1
- package/dist/extras.css +1 -1
- package/dist/extras.css.map +1 -1
- package/dist/index.cjs +312 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/types/components/TreeView.d.ts +20 -11
- package/dist/types/elements/NumberFormatter.d.ts +62 -0
- package/dist/types/helpers/LocaleProvider.d.ts +7 -0
- package/dist/types/helpers/localeFormat.d.ts +30 -8
- package/dist/types/helpers/useTreeView.d.ts +12 -6
- package/dist/types/index.d.ts +3 -0
- package/dist/types-cjs/components/TreeView.d.ts +20 -11
- package/dist/types-cjs/elements/NumberFormatter.d.ts +62 -0
- package/dist/types-cjs/helpers/LocaleProvider.d.ts +7 -0
- package/dist/types-cjs/helpers/localeFormat.d.ts +30 -8
- package/dist/types-cjs/helpers/useTreeView.d.ts +12 -6
- package/dist/types-cjs/index.d.ts +3 -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/form/_field.scss +40 -0
- package/src/scss/form/_index.scss +1 -0
package/dist/index.esm.js
CHANGED
|
@@ -56,6 +56,7 @@ export { Link } from './esm/elements/Link.js';
|
|
|
56
56
|
export { ListItem } from './esm/elements/ListItem.js';
|
|
57
57
|
export { Loader } from './esm/elements/Loader.js';
|
|
58
58
|
export { Notification, NotificationContainer, notification } from './esm/elements/Notification.js';
|
|
59
|
+
export { NumberFormatter } from './esm/elements/NumberFormatter.js';
|
|
59
60
|
export { OrderedList } from './esm/elements/OrderedList.js';
|
|
60
61
|
export { Paragraph } from './esm/elements/Paragraph.js';
|
|
61
62
|
export { Pre } from './esm/elements/Pre.js';
|
|
@@ -124,6 +125,7 @@ export { ClientOnly } from './esm/helpers/ClientOnly.js';
|
|
|
124
125
|
export { useIsHydrated } from './esm/helpers/useIsHydrated.js';
|
|
125
126
|
export { Portal } from './esm/helpers/portal.js';
|
|
126
127
|
export { LocaleProvider, useLocale } from './esm/helpers/LocaleProvider.js';
|
|
128
|
+
export { useNumberFormat } from './esm/helpers/localeFormat.js';
|
|
127
129
|
export { useFocusTrap } from './esm/helpers/useFocusTrap.js';
|
|
128
130
|
export { Container } from './esm/layout/Container.js';
|
|
129
131
|
export { Footer } from './esm/layout/Footer.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,9 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { BulmaClassesProps } from '../helpers/useBulmaClasses.js';
|
|
3
3
|
/**
|
|
4
4
|
* How items are picked: `none`, nothing is; `single`, one item at a time;
|
|
5
|
-
* `checkbox`, any number, with a box on every item and mixed parents
|
|
5
|
+
* `checkbox`, any number, with a box on every item and mixed parents;
|
|
6
|
+
* `checkbox-independent`, any number, with a box on every item that checks
|
|
7
|
+
* that item alone.
|
|
6
8
|
*/
|
|
7
|
-
export type TreeViewSelectionMode = 'none' | 'single' | 'checkbox';
|
|
9
|
+
export type TreeViewSelectionMode = 'none' | 'single' | 'checkbox' | 'checkbox-independent';
|
|
8
10
|
/**
|
|
9
11
|
* Props for the TreeView component. The helper props, the other attributes
|
|
10
12
|
* and the `ref` land on the `<ul role="tree">`.
|
|
@@ -25,6 +27,9 @@ export interface TreeViewProps extends Omit<React.HTMLAttributes<HTMLUListElemen
|
|
|
25
27
|
* `single`: one item, picked with Enter, Space or a click.
|
|
26
28
|
* `checkbox`: any number, checked with Space or a click. A check reaches
|
|
27
29
|
* every enabled item under it, and a parent with some of them checked is mixed.
|
|
30
|
+
* `checkbox-independent`: any number, checked with Space or a click, each
|
|
31
|
+
* box for its own item. A check reaches nothing under it, and no parent is
|
|
32
|
+
* mixed (Mantine's and Ant Design's `checkStrictly`).
|
|
28
33
|
*/
|
|
29
34
|
selectionMode?: TreeViewSelectionMode;
|
|
30
35
|
/**
|
|
@@ -42,18 +47,22 @@ export interface TreeViewProps extends Omit<React.HTMLAttributes<HTMLUListElemen
|
|
|
42
47
|
onSelectedChange?: (value: string) => void;
|
|
43
48
|
/**
|
|
44
49
|
* The checked items' values when you hold the state. Read with `checkbox`
|
|
45
|
-
* only. A value checks its item
|
|
46
|
-
* when any item above it is in the
|
|
47
|
-
*
|
|
50
|
+
* and `checkbox-independent` only. A value checks its item. In `checkbox`,
|
|
51
|
+
* an enabled item also counts as checked when any item above it is in the
|
|
52
|
+
* list, so a parent's value stands for its whole branch, loaded or not, and
|
|
53
|
+
* a disabled item is checked only by its own value. In
|
|
54
|
+
* `checkbox-independent`, a value checks its own item and nothing else.
|
|
48
55
|
*/
|
|
49
56
|
checked?: string[];
|
|
50
|
-
/** The values checked to begin with, when the tree holds its own state. Read with `checkbox` only. */
|
|
57
|
+
/** The values checked to begin with, when the tree holds its own state. Read with `checkbox` and `checkbox-independent` only. */
|
|
51
58
|
defaultChecked?: string[];
|
|
52
59
|
/**
|
|
53
|
-
* Called after a check or an uncheck with every item that
|
|
54
|
-
* checked, parents included, plus any earlier value that matches
|
|
55
|
-
* the tree knows, left as it was
|
|
56
|
-
* `
|
|
60
|
+
* Called after a check or an uncheck. In `checkbox`, with every item that
|
|
61
|
+
* now shows checked, parents included, plus any earlier value that matches
|
|
62
|
+
* no item the tree knows, left as it was, and the order means nothing. In
|
|
63
|
+
* `checkbox-independent`, with the list as it was, the item's value added
|
|
64
|
+
* at the end or every copy of it taken out, and everything else in the
|
|
65
|
+
* same order. Passed back as `checked`, the list shows the same boxes.
|
|
57
66
|
*/
|
|
58
67
|
onCheckedChange?: (checked: string[]) => void;
|
|
59
68
|
/**
|
|
@@ -103,7 +112,7 @@ export interface TreeViewItemProps extends Omit<React.LiHTMLAttributes<HTMLLIEle
|
|
|
103
112
|
icon?: React.ReactNode;
|
|
104
113
|
/**
|
|
105
114
|
* `TreeView.Item`s under this one. Render them whenever you have them,
|
|
106
|
-
* open or not: the tree hides them while it's closed, and a checkbox tree
|
|
115
|
+
* open or not: the tree hides them while it's closed, and a `checkbox` tree
|
|
107
116
|
* needs them to know what a check reaches.
|
|
108
117
|
*/
|
|
109
118
|
children?: React.ReactNode;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BulmaClassesProps, validColors } from '../helpers/useBulmaClasses.js';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the NumberFormatter component. The helper props, the other
|
|
5
|
+
* attributes and the `ref` land on the `<data>`.
|
|
6
|
+
*
|
|
7
|
+
* @extraProp {React.Ref<HTMLDataElement>} [ref] - Ref forwarded to the `<data>`.
|
|
8
|
+
*/
|
|
9
|
+
export interface NumberFormatterProps extends Omit<React.DataHTMLAttributes<HTMLDataElement>, 'value' | 'color' | 'children'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
10
|
+
/** Additional CSS classes to apply. */
|
|
11
|
+
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The number. The text is what `Intl.NumberFormat` writes for it, `NaN`
|
|
14
|
+
* and `Infinity` included. The `<data>` element's `value` attribute holds
|
|
15
|
+
* it as `String()` writes it, except that `-0` keeps its sign, so
|
|
16
|
+
* `Number()` reads it back: `1234.5`, `1e+21` for a very large one and
|
|
17
|
+
* `1e-7` for a very small one, `NaN`, `Infinity` and `-0`.
|
|
18
|
+
*/
|
|
19
|
+
value: number;
|
|
20
|
+
/**
|
|
21
|
+
* `Intl.NumberFormat` options: a currency, a percentage, a unit, compact
|
|
22
|
+
* notation, the fraction digits, the sign. Options `Intl` refuses, such as
|
|
23
|
+
* `style: 'currency'` with no `currency`, throw its error.
|
|
24
|
+
*/
|
|
25
|
+
format?: Intl.NumberFormatOptions;
|
|
26
|
+
/**
|
|
27
|
+
* BCP 47 locale tag. Unset, it's the `locale` of a `LocaleProvider` around
|
|
28
|
+
* it, and with neither, the runtime's own. On a server render that's the
|
|
29
|
+
* server's, so give it a locale, here or through a `LocaleProvider`, where
|
|
30
|
+
* the server's and the browser's can differ. A tag `Intl` refuses, such as
|
|
31
|
+
* `"en_US"`, is ignored, with a warning in development, as
|
|
32
|
+
* `LocaleProvider` ignores one.
|
|
33
|
+
*/
|
|
34
|
+
locale?: string;
|
|
35
|
+
/** Text color helper. */
|
|
36
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
37
|
+
/** Background color helper. */
|
|
38
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The `NumberFormatter` component writes a number the way a locale writes it, such as a price, a percentage or a count, in a `<data>` element that keeps the number itself in its `value`.
|
|
42
|
+
*
|
|
43
|
+
* It formats with `Intl.NumberFormat`, in its own `locale`, else the
|
|
44
|
+
* `LocaleProvider`'s around it, else the runtime's, with `format` as the
|
|
45
|
+
* options. The `<data>` has no role and no class of its own, so a screen
|
|
46
|
+
* reader reads the formatted text and it takes the look of the text around
|
|
47
|
+
* it. For text outside JSX, such as an `aria-label`, `useNumberFormat`
|
|
48
|
+
* gives the same formatting as a function.
|
|
49
|
+
*
|
|
50
|
+
* @function
|
|
51
|
+
* @param {NumberFormatterProps} props - Props for the NumberFormatter component.
|
|
52
|
+
* @param {React.Ref<HTMLDataElement>} ref - Forwarded ref to the `<data>`.
|
|
53
|
+
* @returns {JSX.Element} The rendered number.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* <NumberFormatter
|
|
57
|
+
* value={8456.4}
|
|
58
|
+
* format={{ style: 'currency', currency: 'USD' }}
|
|
59
|
+
* />
|
|
60
|
+
*/
|
|
61
|
+
export declare const NumberFormatter: React.ForwardRefExoticComponent<NumberFormatterProps & React.RefAttributes<HTMLDataElement>>;
|
|
62
|
+
export default NumberFormatter;
|
|
@@ -36,6 +36,13 @@ export interface LocaleProviderProps extends Omit<React.HTMLAttributes<HTMLDivEl
|
|
|
36
36
|
/** The part of the app it covers. */
|
|
37
37
|
children?: React.ReactNode;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* INTERNAL, deliberately not exported from `src/index.ts`. A tag in
|
|
41
|
+
* canonical form, or `undefined` for an empty or missing one and for one
|
|
42
|
+
* `Intl` refuses, which `refused` reports: by default the provider's own
|
|
43
|
+
* development warning, once per tag.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validLocale(tag: string | undefined, refused?: (tag: string) => void): string | undefined;
|
|
39
46
|
/**
|
|
40
47
|
* Sets the language and writing direction for the part of the app inside it, on a wrapper `<div>` and on what the library portals out of it.
|
|
41
48
|
*
|
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
/** Formats a number for display, with `Intl.NumberFormat` options. */
|
|
2
|
-
export type
|
|
2
|
+
export type NumberFormatFunction = (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
3
3
|
/** Whether `text` contains `query`, as the locale compares letters. */
|
|
4
4
|
export type TextMatcher = (text: string, query: string) => boolean;
|
|
5
5
|
/**
|
|
6
|
-
* A
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* expensive part
|
|
6
|
+
* A function that writes numbers for display in a locale: `locale` when given, else the `LocaleProvider`'s around the component, else the runtime's.
|
|
7
|
+
*
|
|
8
|
+
* Formatters are kept per locale and set of options, since building one is
|
|
9
|
+
* the expensive part, and shared, so many numbers written the same way build
|
|
10
|
+
* one. The function is the same from one render to the next for the same
|
|
11
|
+
* locale, so it's safe in a dependency array. Use it for text outside JSX,
|
|
12
|
+
* such as an `aria-label`, a `placeholder` or a chart's axis; in JSX,
|
|
13
|
+
* `NumberFormatter` also marks the number up. On a server render the
|
|
14
|
+
* runtime's locale is the server's, so give it a locale, here or through a
|
|
15
|
+
* `LocaleProvider`, where the server's and the browser's can differ. A tag
|
|
16
|
+
* `Intl` refuses is ignored, with a warning in development, as
|
|
17
|
+
* `LocaleProvider` ignores one. Options `Intl` refuses throw its error when
|
|
18
|
+
* the function is called.
|
|
19
|
+
*
|
|
20
|
+
* @function
|
|
21
|
+
* @param locale - A BCP 47 locale tag, which wins over the provider's.
|
|
22
|
+
* @returns {NumberFormatFunction} Writes `value` with `Intl.NumberFormat` options.
|
|
10
23
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
24
|
+
* @example
|
|
25
|
+
* const format = useNumberFormat();
|
|
26
|
+
* const placeholder = format(1500, { style: 'currency', currency: 'EUR' });
|
|
27
|
+
*/
|
|
28
|
+
export declare function useNumberFormat(locale?: string): NumberFormatFunction;
|
|
29
|
+
/**
|
|
30
|
+
* INTERNAL, deliberately not exported from `src/index.ts`. Number formatting
|
|
31
|
+
* for a component that shows a number in passing, as `useNumberFormat`
|
|
32
|
+
* writes it in the `LocaleProvider`'s locale, or `null` outside a provider
|
|
33
|
+
* and inside one that gives no locale, as a provider with only a `dir`
|
|
34
|
+
* doesn't, where the component keeps the formatting it has always had.
|
|
13
35
|
*/
|
|
14
|
-
export declare function
|
|
36
|
+
export declare function useScopedNumberFormat(): NumberFormatFunction | null;
|
|
15
37
|
/**
|
|
16
38
|
* A matcher for filtering a list by what was typed, in the locale of the
|
|
17
39
|
* `LocaleProvider` around the component, or `null` outside one that gives a
|
|
@@ -30,7 +30,8 @@ export interface TreeViewPosition {
|
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* What an item shows of the selection: `selected` in a `single` tree,
|
|
33
|
-
* `checked` in a `checkbox` tree, and neither with
|
|
33
|
+
* `checked` in a `checkbox` or `checkbox-independent` tree, and neither with
|
|
34
|
+
* `none`.
|
|
34
35
|
*/
|
|
35
36
|
export interface TreeViewItemState {
|
|
36
37
|
selected?: boolean;
|
|
@@ -55,9 +56,12 @@ export interface TreeViewEngine {
|
|
|
55
56
|
treeRef: React.MutableRefObject<HTMLUListElement | null>;
|
|
56
57
|
/**
|
|
57
58
|
* Whether a closed item still renders its children, drawing nothing, so a
|
|
58
|
-
* check knows everything under it. Only a checkbox tree needs to
|
|
59
|
+
* check knows everything under it. Only a `checkbox` tree needs to: a check
|
|
60
|
+
* in a `checkbox-independent` tree reaches nothing under it.
|
|
59
61
|
*/
|
|
60
62
|
rendersClosed: boolean;
|
|
63
|
+
/** Whether any number of items can be checked, in either checkbox mode. */
|
|
64
|
+
multiselectable: boolean;
|
|
61
65
|
/** The item that holds `tabIndex={0}`. */
|
|
62
66
|
tabStop: string | null;
|
|
63
67
|
isOpen: (value: string) => boolean;
|
|
@@ -97,10 +101,12 @@ export interface TreeViewEngine {
|
|
|
97
101
|
* browser (#1171), read off the page once the tree has mounted.
|
|
98
102
|
*
|
|
99
103
|
* Every item registers its value, its parent and whether it's disabled from
|
|
100
|
-
* a layout effect. In a checkbox tree a closed item's children still
|
|
101
|
-
* and register while drawing nothing, so the registry knows every item
|
|
102
|
-
* check reaches all of them.
|
|
103
|
-
*
|
|
104
|
+
* a layout effect. In a `checkbox` tree a closed item's children still
|
|
105
|
+
* render and register while drawing nothing, so the registry knows every item
|
|
106
|
+
* and a check reaches all of them. A `checkbox-independent` tree reads each
|
|
107
|
+
* box off the checked list alone, so a check adds or takes out its own value
|
|
108
|
+
* and nothing else. The keys read the items on the page, in document order,
|
|
109
|
+
* each time they need them.
|
|
104
110
|
*
|
|
105
111
|
* @function useTreeView
|
|
106
112
|
* @param options - The TreeView's props.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export * from './elements/Link.js';
|
|
|
55
55
|
export * from './elements/ListItem.js';
|
|
56
56
|
export * from './elements/Loader.js';
|
|
57
57
|
export * from './elements/Notification.js';
|
|
58
|
+
export * from './elements/NumberFormatter.js';
|
|
58
59
|
export * from './elements/OrderedList.js';
|
|
59
60
|
export * from './elements/Paragraph.js';
|
|
60
61
|
export * from './elements/Pre.js';
|
|
@@ -144,6 +145,8 @@ export { Portal } from './helpers/portal.js';
|
|
|
144
145
|
export type { PortalProps } from './helpers/portal.js';
|
|
145
146
|
export { LocaleProvider, useLocale } from './helpers/LocaleProvider.js';
|
|
146
147
|
export type { LocaleContextValue, LocaleProviderProps, TextDirection, } from './helpers/LocaleProvider.js';
|
|
148
|
+
export { useNumberFormat } from './helpers/localeFormat.js';
|
|
149
|
+
export type { NumberFormatFunction } from './helpers/localeFormat.js';
|
|
147
150
|
export { useFocusTrap } from './helpers/useFocusTrap.js';
|
|
148
151
|
export type { UseFocusTrapOptions } from './helpers/useFocusTrap.js';
|
|
149
152
|
export * from './layout/Container.js';
|
|
@@ -2,9 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { BulmaClassesProps } from '../helpers/useBulmaClasses.js';
|
|
3
3
|
/**
|
|
4
4
|
* How items are picked: `none`, nothing is; `single`, one item at a time;
|
|
5
|
-
* `checkbox`, any number, with a box on every item and mixed parents
|
|
5
|
+
* `checkbox`, any number, with a box on every item and mixed parents;
|
|
6
|
+
* `checkbox-independent`, any number, with a box on every item that checks
|
|
7
|
+
* that item alone.
|
|
6
8
|
*/
|
|
7
|
-
export type TreeViewSelectionMode = 'none' | 'single' | 'checkbox';
|
|
9
|
+
export type TreeViewSelectionMode = 'none' | 'single' | 'checkbox' | 'checkbox-independent';
|
|
8
10
|
/**
|
|
9
11
|
* Props for the TreeView component. The helper props, the other attributes
|
|
10
12
|
* and the `ref` land on the `<ul role="tree">`.
|
|
@@ -25,6 +27,9 @@ export interface TreeViewProps extends Omit<React.HTMLAttributes<HTMLUListElemen
|
|
|
25
27
|
* `single`: one item, picked with Enter, Space or a click.
|
|
26
28
|
* `checkbox`: any number, checked with Space or a click. A check reaches
|
|
27
29
|
* every enabled item under it, and a parent with some of them checked is mixed.
|
|
30
|
+
* `checkbox-independent`: any number, checked with Space or a click, each
|
|
31
|
+
* box for its own item. A check reaches nothing under it, and no parent is
|
|
32
|
+
* mixed (Mantine's and Ant Design's `checkStrictly`).
|
|
28
33
|
*/
|
|
29
34
|
selectionMode?: TreeViewSelectionMode;
|
|
30
35
|
/**
|
|
@@ -42,18 +47,22 @@ export interface TreeViewProps extends Omit<React.HTMLAttributes<HTMLUListElemen
|
|
|
42
47
|
onSelectedChange?: (value: string) => void;
|
|
43
48
|
/**
|
|
44
49
|
* The checked items' values when you hold the state. Read with `checkbox`
|
|
45
|
-
* only. A value checks its item
|
|
46
|
-
* when any item above it is in the
|
|
47
|
-
*
|
|
50
|
+
* and `checkbox-independent` only. A value checks its item. In `checkbox`,
|
|
51
|
+
* an enabled item also counts as checked when any item above it is in the
|
|
52
|
+
* list, so a parent's value stands for its whole branch, loaded or not, and
|
|
53
|
+
* a disabled item is checked only by its own value. In
|
|
54
|
+
* `checkbox-independent`, a value checks its own item and nothing else.
|
|
48
55
|
*/
|
|
49
56
|
checked?: string[];
|
|
50
|
-
/** The values checked to begin with, when the tree holds its own state. Read with `checkbox` only. */
|
|
57
|
+
/** The values checked to begin with, when the tree holds its own state. Read with `checkbox` and `checkbox-independent` only. */
|
|
51
58
|
defaultChecked?: string[];
|
|
52
59
|
/**
|
|
53
|
-
* Called after a check or an uncheck with every item that
|
|
54
|
-
* checked, parents included, plus any earlier value that matches
|
|
55
|
-
* the tree knows, left as it was
|
|
56
|
-
* `
|
|
60
|
+
* Called after a check or an uncheck. In `checkbox`, with every item that
|
|
61
|
+
* now shows checked, parents included, plus any earlier value that matches
|
|
62
|
+
* no item the tree knows, left as it was, and the order means nothing. In
|
|
63
|
+
* `checkbox-independent`, with the list as it was, the item's value added
|
|
64
|
+
* at the end or every copy of it taken out, and everything else in the
|
|
65
|
+
* same order. Passed back as `checked`, the list shows the same boxes.
|
|
57
66
|
*/
|
|
58
67
|
onCheckedChange?: (checked: string[]) => void;
|
|
59
68
|
/**
|
|
@@ -103,7 +112,7 @@ export interface TreeViewItemProps extends Omit<React.LiHTMLAttributes<HTMLLIEle
|
|
|
103
112
|
icon?: React.ReactNode;
|
|
104
113
|
/**
|
|
105
114
|
* `TreeView.Item`s under this one. Render them whenever you have them,
|
|
106
|
-
* open or not: the tree hides them while it's closed, and a checkbox tree
|
|
115
|
+
* open or not: the tree hides them while it's closed, and a `checkbox` tree
|
|
107
116
|
* needs them to know what a check reaches.
|
|
108
117
|
*/
|
|
109
118
|
children?: React.ReactNode;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BulmaClassesProps, validColors } from '../helpers/useBulmaClasses.js';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the NumberFormatter component. The helper props, the other
|
|
5
|
+
* attributes and the `ref` land on the `<data>`.
|
|
6
|
+
*
|
|
7
|
+
* @extraProp {React.Ref<HTMLDataElement>} [ref] - Ref forwarded to the `<data>`.
|
|
8
|
+
*/
|
|
9
|
+
export interface NumberFormatterProps extends Omit<React.DataHTMLAttributes<HTMLDataElement>, 'value' | 'color' | 'children'>, Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {
|
|
10
|
+
/** Additional CSS classes to apply. */
|
|
11
|
+
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The number. The text is what `Intl.NumberFormat` writes for it, `NaN`
|
|
14
|
+
* and `Infinity` included. The `<data>` element's `value` attribute holds
|
|
15
|
+
* it as `String()` writes it, except that `-0` keeps its sign, so
|
|
16
|
+
* `Number()` reads it back: `1234.5`, `1e+21` for a very large one and
|
|
17
|
+
* `1e-7` for a very small one, `NaN`, `Infinity` and `-0`.
|
|
18
|
+
*/
|
|
19
|
+
value: number;
|
|
20
|
+
/**
|
|
21
|
+
* `Intl.NumberFormat` options: a currency, a percentage, a unit, compact
|
|
22
|
+
* notation, the fraction digits, the sign. Options `Intl` refuses, such as
|
|
23
|
+
* `style: 'currency'` with no `currency`, throw its error.
|
|
24
|
+
*/
|
|
25
|
+
format?: Intl.NumberFormatOptions;
|
|
26
|
+
/**
|
|
27
|
+
* BCP 47 locale tag. Unset, it's the `locale` of a `LocaleProvider` around
|
|
28
|
+
* it, and with neither, the runtime's own. On a server render that's the
|
|
29
|
+
* server's, so give it a locale, here or through a `LocaleProvider`, where
|
|
30
|
+
* the server's and the browser's can differ. A tag `Intl` refuses, such as
|
|
31
|
+
* `"en_US"`, is ignored, with a warning in development, as
|
|
32
|
+
* `LocaleProvider` ignores one.
|
|
33
|
+
*/
|
|
34
|
+
locale?: string;
|
|
35
|
+
/** Text color helper. */
|
|
36
|
+
textColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
37
|
+
/** Background color helper. */
|
|
38
|
+
bgColor?: (typeof validColors)[number] | 'inherit' | 'current';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The `NumberFormatter` component writes a number the way a locale writes it, such as a price, a percentage or a count, in a `<data>` element that keeps the number itself in its `value`.
|
|
42
|
+
*
|
|
43
|
+
* It formats with `Intl.NumberFormat`, in its own `locale`, else the
|
|
44
|
+
* `LocaleProvider`'s around it, else the runtime's, with `format` as the
|
|
45
|
+
* options. The `<data>` has no role and no class of its own, so a screen
|
|
46
|
+
* reader reads the formatted text and it takes the look of the text around
|
|
47
|
+
* it. For text outside JSX, such as an `aria-label`, `useNumberFormat`
|
|
48
|
+
* gives the same formatting as a function.
|
|
49
|
+
*
|
|
50
|
+
* @function
|
|
51
|
+
* @param {NumberFormatterProps} props - Props for the NumberFormatter component.
|
|
52
|
+
* @param {React.Ref<HTMLDataElement>} ref - Forwarded ref to the `<data>`.
|
|
53
|
+
* @returns {JSX.Element} The rendered number.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* <NumberFormatter
|
|
57
|
+
* value={8456.4}
|
|
58
|
+
* format={{ style: 'currency', currency: 'USD' }}
|
|
59
|
+
* />
|
|
60
|
+
*/
|
|
61
|
+
export declare const NumberFormatter: React.ForwardRefExoticComponent<NumberFormatterProps & React.RefAttributes<HTMLDataElement>>;
|
|
62
|
+
export default NumberFormatter;
|
|
@@ -36,6 +36,13 @@ export interface LocaleProviderProps extends Omit<React.HTMLAttributes<HTMLDivEl
|
|
|
36
36
|
/** The part of the app it covers. */
|
|
37
37
|
children?: React.ReactNode;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* INTERNAL, deliberately not exported from `src/index.ts`. A tag in
|
|
41
|
+
* canonical form, or `undefined` for an empty or missing one and for one
|
|
42
|
+
* `Intl` refuses, which `refused` reports: by default the provider's own
|
|
43
|
+
* development warning, once per tag.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validLocale(tag: string | undefined, refused?: (tag: string) => void): string | undefined;
|
|
39
46
|
/**
|
|
40
47
|
* Sets the language and writing direction for the part of the app inside it, on a wrapper `<div>` and on what the library portals out of it.
|
|
41
48
|
*
|
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
/** Formats a number for display, with `Intl.NumberFormat` options. */
|
|
2
|
-
export type
|
|
2
|
+
export type NumberFormatFunction = (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
3
3
|
/** Whether `text` contains `query`, as the locale compares letters. */
|
|
4
4
|
export type TextMatcher = (text: string, query: string) => boolean;
|
|
5
5
|
/**
|
|
6
|
-
* A
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* expensive part
|
|
6
|
+
* A function that writes numbers for display in a locale: `locale` when given, else the `LocaleProvider`'s around the component, else the runtime's.
|
|
7
|
+
*
|
|
8
|
+
* Formatters are kept per locale and set of options, since building one is
|
|
9
|
+
* the expensive part, and shared, so many numbers written the same way build
|
|
10
|
+
* one. The function is the same from one render to the next for the same
|
|
11
|
+
* locale, so it's safe in a dependency array. Use it for text outside JSX,
|
|
12
|
+
* such as an `aria-label`, a `placeholder` or a chart's axis; in JSX,
|
|
13
|
+
* `NumberFormatter` also marks the number up. On a server render the
|
|
14
|
+
* runtime's locale is the server's, so give it a locale, here or through a
|
|
15
|
+
* `LocaleProvider`, where the server's and the browser's can differ. A tag
|
|
16
|
+
* `Intl` refuses is ignored, with a warning in development, as
|
|
17
|
+
* `LocaleProvider` ignores one. Options `Intl` refuses throw its error when
|
|
18
|
+
* the function is called.
|
|
19
|
+
*
|
|
20
|
+
* @function
|
|
21
|
+
* @param locale - A BCP 47 locale tag, which wins over the provider's.
|
|
22
|
+
* @returns {NumberFormatFunction} Writes `value` with `Intl.NumberFormat` options.
|
|
10
23
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
24
|
+
* @example
|
|
25
|
+
* const format = useNumberFormat();
|
|
26
|
+
* const placeholder = format(1500, { style: 'currency', currency: 'EUR' });
|
|
27
|
+
*/
|
|
28
|
+
export declare function useNumberFormat(locale?: string): NumberFormatFunction;
|
|
29
|
+
/**
|
|
30
|
+
* INTERNAL, deliberately not exported from `src/index.ts`. Number formatting
|
|
31
|
+
* for a component that shows a number in passing, as `useNumberFormat`
|
|
32
|
+
* writes it in the `LocaleProvider`'s locale, or `null` outside a provider
|
|
33
|
+
* and inside one that gives no locale, as a provider with only a `dir`
|
|
34
|
+
* doesn't, where the component keeps the formatting it has always had.
|
|
13
35
|
*/
|
|
14
|
-
export declare function
|
|
36
|
+
export declare function useScopedNumberFormat(): NumberFormatFunction | null;
|
|
15
37
|
/**
|
|
16
38
|
* A matcher for filtering a list by what was typed, in the locale of the
|
|
17
39
|
* `LocaleProvider` around the component, or `null` outside one that gives a
|
|
@@ -30,7 +30,8 @@ export interface TreeViewPosition {
|
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* What an item shows of the selection: `selected` in a `single` tree,
|
|
33
|
-
* `checked` in a `checkbox` tree, and neither with
|
|
33
|
+
* `checked` in a `checkbox` or `checkbox-independent` tree, and neither with
|
|
34
|
+
* `none`.
|
|
34
35
|
*/
|
|
35
36
|
export interface TreeViewItemState {
|
|
36
37
|
selected?: boolean;
|
|
@@ -55,9 +56,12 @@ export interface TreeViewEngine {
|
|
|
55
56
|
treeRef: React.MutableRefObject<HTMLUListElement | null>;
|
|
56
57
|
/**
|
|
57
58
|
* Whether a closed item still renders its children, drawing nothing, so a
|
|
58
|
-
* check knows everything under it. Only a checkbox tree needs to
|
|
59
|
+
* check knows everything under it. Only a `checkbox` tree needs to: a check
|
|
60
|
+
* in a `checkbox-independent` tree reaches nothing under it.
|
|
59
61
|
*/
|
|
60
62
|
rendersClosed: boolean;
|
|
63
|
+
/** Whether any number of items can be checked, in either checkbox mode. */
|
|
64
|
+
multiselectable: boolean;
|
|
61
65
|
/** The item that holds `tabIndex={0}`. */
|
|
62
66
|
tabStop: string | null;
|
|
63
67
|
isOpen: (value: string) => boolean;
|
|
@@ -97,10 +101,12 @@ export interface TreeViewEngine {
|
|
|
97
101
|
* browser (#1171), read off the page once the tree has mounted.
|
|
98
102
|
*
|
|
99
103
|
* Every item registers its value, its parent and whether it's disabled from
|
|
100
|
-
* a layout effect. In a checkbox tree a closed item's children still
|
|
101
|
-
* and register while drawing nothing, so the registry knows every item
|
|
102
|
-
* check reaches all of them.
|
|
103
|
-
*
|
|
104
|
+
* a layout effect. In a `checkbox` tree a closed item's children still
|
|
105
|
+
* render and register while drawing nothing, so the registry knows every item
|
|
106
|
+
* and a check reaches all of them. A `checkbox-independent` tree reads each
|
|
107
|
+
* box off the checked list alone, so a check adds or takes out its own value
|
|
108
|
+
* and nothing else. The keys read the items on the page, in document order,
|
|
109
|
+
* each time they need them.
|
|
104
110
|
*
|
|
105
111
|
* @function useTreeView
|
|
106
112
|
* @param options - The TreeView's props.
|
|
@@ -55,6 +55,7 @@ export * from './elements/Link.js';
|
|
|
55
55
|
export * from './elements/ListItem.js';
|
|
56
56
|
export * from './elements/Loader.js';
|
|
57
57
|
export * from './elements/Notification.js';
|
|
58
|
+
export * from './elements/NumberFormatter.js';
|
|
58
59
|
export * from './elements/OrderedList.js';
|
|
59
60
|
export * from './elements/Paragraph.js';
|
|
60
61
|
export * from './elements/Pre.js';
|
|
@@ -144,6 +145,8 @@ export { Portal } from './helpers/portal.js';
|
|
|
144
145
|
export type { PortalProps } from './helpers/portal.js';
|
|
145
146
|
export { LocaleProvider, useLocale } from './helpers/LocaleProvider.js';
|
|
146
147
|
export type { LocaleContextValue, LocaleProviderProps, TextDirection, } from './helpers/LocaleProvider.js';
|
|
148
|
+
export { useNumberFormat } from './helpers/localeFormat.js';
|
|
149
|
+
export type { NumberFormatFunction } from './helpers/localeFormat.js';
|
|
147
150
|
export { useFocusTrap } from './helpers/useFocusTrap.js';
|
|
148
151
|
export type { UseFocusTrapOptions } from './helpers/useFocusTrap.js';
|
|
149
152
|
export * from './layout/Container.js';
|