@manakind/ui-core 0.36.0 → 0.37.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/radio-group/radio-group.css +54 -0
- package/dist/radio-group/radio-group.d.ts +22 -4
- package/dist/radio-group/radio-group.d.ts.map +1 -1
- package/dist/radio-group/radio-group.js +10 -5
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/tooltip/tooltip.d.ts +17 -1
- package/dist/tooltip/tooltip.d.ts.map +1 -1
- package/dist/tooltip/tooltip.js +33 -2
- package/dist/tooltip/tooltip.js.map +1 -1
- package/package.json +2 -2
|
@@ -67,4 +67,58 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* Cards: the label above a grid of choices that fills the width and wraps.
|
|
73
|
+
* Each card is the whole click target; the hidden radio inside it carries
|
|
74
|
+
* the state and the keyboard. Chosen, the card's border thickens into a
|
|
75
|
+
* ring in the checked colour, so the choice reads by weight as well as
|
|
76
|
+
* colour; keyboard focus is the focus ring drawn outside it.
|
|
77
|
+
*/
|
|
78
|
+
.ds-radio-group--cards {
|
|
79
|
+
align-items: stretch;
|
|
80
|
+
|
|
81
|
+
& .ds-radio-group__cards {
|
|
82
|
+
display: grid;
|
|
83
|
+
grid-template-columns: repeat(auto-fill, minmax(var(--ds-radio-group-card-min-width), 1fr));
|
|
84
|
+
gap: var(--ds-radio-group-card-gap);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
& .ds-radio-group__item {
|
|
88
|
+
box-sizing: border-box;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
gap: var(--ds-radio-group-card-gap);
|
|
92
|
+
padding: var(--ds-radio-group-card-padding);
|
|
93
|
+
border: 1px solid var(--ds-radio-group-card-border);
|
|
94
|
+
border-radius: var(--ds-radio-group-card-radius);
|
|
95
|
+
background-color: var(--ds-radio-group-card-bg);
|
|
96
|
+
text-align: center;
|
|
97
|
+
transition: border-color 150ms cubic-bezier(0, 0, 0.2, 1);
|
|
98
|
+
|
|
99
|
+
&[data-hover]:not([data-disabled], [data-state="checked"]) {
|
|
100
|
+
border-color: var(--ds-radio-group-card-border-hover);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* The border thickens inward: the padding gives back what it takes, so nothing shifts. */
|
|
104
|
+
&[data-state="checked"] {
|
|
105
|
+
padding: calc(var(--ds-radio-group-card-padding) - 1px);
|
|
106
|
+
border: 2px solid var(--ds-radio-group-card-border-checked);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&[data-focus-visible] {
|
|
110
|
+
outline: 2px solid var(--ds-radio-group-focus-ring);
|
|
111
|
+
outline-offset: 2px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&[data-disabled] {
|
|
115
|
+
opacity: var(--ds-opacity-disabled);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
& .ds-radio-group__visual {
|
|
120
|
+
display: flex;
|
|
121
|
+
justify-content: center;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
70
124
|
}
|
|
@@ -7,7 +7,15 @@ export interface RadioGroupItem {
|
|
|
7
7
|
label: string;
|
|
8
8
|
/** Individually disable this choice without removing it. */
|
|
9
9
|
disabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A picture of the choice, above its label on a `cards` group: a swatch,
|
|
12
|
+
* a badge, a preview. Decorative: the label names the choice. A `list`
|
|
13
|
+
* group ignores it.
|
|
14
|
+
*/
|
|
15
|
+
visual?: ReactNode;
|
|
10
16
|
}
|
|
17
|
+
/** `list` (default) sets radios one under the other; `cards` sets each choice on a card in a wrapping grid. */
|
|
18
|
+
export type RadioGroupAppearance = 'list' | 'cards';
|
|
11
19
|
/**
|
|
12
20
|
* A radio group has to have a name, expressed as a union so an unnamed group
|
|
13
21
|
* is a compile error rather than an axe finding, as `SegmentGroup` does.
|
|
@@ -26,8 +34,16 @@ type RadioGroupName = {
|
|
|
26
34
|
'aria-label': string;
|
|
27
35
|
};
|
|
28
36
|
export type RadioGroupProps = RadioGroupName & {
|
|
29
|
-
/** The choices, in order
|
|
37
|
+
/** The choices, in order. */
|
|
30
38
|
items: RadioGroupItem[];
|
|
39
|
+
/**
|
|
40
|
+
* `list` (default) sets a radio beside each label, one under the other.
|
|
41
|
+
* `cards` sets each choice on a card, its `visual` above its label, in a
|
|
42
|
+
* grid that fills the width and wraps; the chosen card carries a heavier
|
|
43
|
+
* ring instead of a radio. For choices told apart by how they look, such
|
|
44
|
+
* as colours or themes.
|
|
45
|
+
*/
|
|
46
|
+
appearance?: RadioGroupAppearance;
|
|
31
47
|
/**
|
|
32
48
|
* Controlled value. `null` is controlled with nothing chosen; `undefined`
|
|
33
49
|
* leaves the component to own its value from `defaultValue` onward.
|
|
@@ -66,9 +82,11 @@ export type RadioGroupProps = RadioGroupName & {
|
|
|
66
82
|
* />
|
|
67
83
|
* ```
|
|
68
84
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
85
|
+
* Choices told apart by how they look (a colour, a theme) take
|
|
86
|
+
* `appearance="cards"`, each with a `visual`. A few short choices seen at
|
|
87
|
+
* once in a row are a `SegmentGroup`; a long list, or one in a form row, is
|
|
88
|
+
* a `Select`.
|
|
71
89
|
*/
|
|
72
|
-
export declare function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
90
|
+
export declare function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance, className, 'aria-label': ariaLabel, }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
73
91
|
export {};
|
|
74
92
|
//# sourceMappingURL=radio-group.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio-group.d.ts","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":"AAC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EN,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C,6BAA6B;IAC7B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,UAAmB,EACnB,SAAS,EACT,YAAY,EAAE,SAAS,GACxB,EAAE,eAAe,2CAuDjB"}
|
|
@@ -26,10 +26,13 @@ import { cx } from '../cx';
|
|
|
26
26
|
* />
|
|
27
27
|
* ```
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Choices told apart by how they look (a colour, a theme) take
|
|
30
|
+
* `appearance="cards"`, each with a `visual`. A few short choices seen at
|
|
31
|
+
* once in a row are a `SegmentGroup`; a long list, or one in a form row, is
|
|
32
|
+
* a `Select`.
|
|
31
33
|
*/
|
|
32
|
-
export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, className, 'aria-label': ariaLabel, }) {
|
|
34
|
+
export function RadioGroup({ label, items, value, defaultValue, onValueChange, disabled, name, appearance = 'list', className, 'aria-label': ariaLabel, }) {
|
|
35
|
+
const cards = appearance === 'cards';
|
|
33
36
|
const rootRef = useRef(null);
|
|
34
37
|
const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);
|
|
35
38
|
const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {
|
|
@@ -37,7 +40,9 @@ export function RadioGroup({ label, items, value, defaultValue, onValueChange, d
|
|
|
37
40
|
ariaLabel,
|
|
38
41
|
className: 'ds-radio-group__label',
|
|
39
42
|
});
|
|
40
|
-
const
|
|
41
|
-
|
|
43
|
+
const marker = (item) => cards ? (_jsx("span", { className: "ds-radio-group__visual", "aria-hidden": true, children: item.visual })) : (_jsx(ArkRadioGroup.ItemControl, { className: "ds-radio-group__control" }));
|
|
44
|
+
const renderItem = (item) => (_jsxs(ArkRadioGroup.Item, { value: item.value, disabled: item.disabled, className: "ds-radio-group__item", children: [marker(item), _jsx(ArkRadioGroup.ItemText, { className: "ds-radio-group__text", children: item.label }), _jsx(ArkRadioGroup.ItemHiddenInput, {})] }, item.value));
|
|
45
|
+
const choices = cards ? (_jsx("div", { className: "ds-radio-group__cards", children: items.map(renderItem) })) : (items.map(renderItem));
|
|
46
|
+
return (_jsxs(ArkRadioGroup.Root, { ref: rootRef, className: cx('ds-radio-group', cards && 'ds-radio-group--cards', className), value: value, defaultValue: defaultValue, onValueChange: handleValueChange, disabled: disabled, name: name, orientation: "vertical", "aria-label": ariaLabel, children: [visibleLabel, choices] }));
|
|
42
47
|
}
|
|
43
48
|
//# sourceMappingURL=radio-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radio-group.js","sourceRoot":"","sources":["../../src/radio-group/radio-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,EAAE,EAAE,MAA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AE,IAAI,CAAC,KAAK,EACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,SAAS,EAAC,sBAAsB,aAE/B,MAAM,CAAC,IAAI,CAAC,EACb,KAAC,aAAa,CAAC,QAAQ,IAAC,SAAS,EAAC,sBAAsB,YAAE,IAAI,CAAC,KAAK,GAA0B,EAC9F,KAAC,aAAa,CAAC,eAAe,KAAG,KAP5B,IAAI,CAAC,KAAK,CAQI,CACtB,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CACtB,cAAK,SAAS,EAAC,uBAAuB,YAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAO,CACrE,CAAC,CAAC,CAAC,CACF,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CACtB,CAAC;IAEF,OAAO,CACL,MAAC,aAAa,CAAC,IAAI,IACjB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,uBAAuB,EAAE,SAAS,CAAC,EAC5E,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,UAAU,gBACV,SAAS,aAEpB,YAAY,EACZ,OAAO,IACW,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import { RadioGroup as ArkRadioGroup } from '@ark-ui/react/radio-group';\nimport { type ReactNode, useRef } from 'react';\nimport './radio-group.css';\nimport { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport interface RadioGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text beside the radio. The whole row is its click target. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n /**\n * A picture of the choice, above its label on a `cards` group: a swatch,\n * a badge, a preview. Decorative: the label names the choice. A `list`\n * group ignores it.\n */\n visual?: ReactNode;\n}\n\n/** `list` (default) sets radios one under the other; `cards` sets each choice on a card in a wrapping grid. */\nexport type RadioGroupAppearance = 'list' | 'cards';\n\n/**\n * A radio group has to have a name, expressed as a union so an unnamed group\n * is a compile error rather than an axe finding, as `SegmentGroup` does.\n */\ntype RadioGroupName =\n | {\n /** Visible label, above the choices, naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when a heading or a section title around it already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type RadioGroupProps = RadioGroupName & {\n /** The choices, in order. */\n items: RadioGroupItem[];\n /**\n * `list` (default) sets a radio beside each label, one under the other.\n * `cards` sets each choice on a card, its `visual` above its label, in a\n * grid that fills the width and wraps; the chosen card carries a heavier\n * ring instead of a radio. For choices told apart by how they look, such\n * as colours or themes.\n */\n appearance?: RadioGroupAppearance;\n /**\n * Controlled value. `null` is controlled with nothing chosen; `undefined`\n * leaves the component to own its value from `defaultValue` onward.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /** Fired with the newly chosen value. Choosing the chosen one again does nothing. */\n onValueChange?: (value: string) => void;\n /** Disable every choice. The chosen one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the radio inputs. */\n name?: string;\n /** Extra class names appended after `ds-radio-group`. */\n className?: string;\n};\n\n/**\n * One choice among several, as a column of radios, built on Ark UI's\n * RadioGroup: a filter's period, a setting with a handful of options whose\n * labels are worth reading side by side.\n *\n * Ark owns the behaviour: native radio inputs carry the state, the arrow keys\n * move the choice and Tab leaves the group in one step. This wrapper\n * contributes `ds-` classes, the `--ds-radio-group-*` bindings and a flat\n * `items` API.\n *\n * ```tsx\n * <RadioGroup\n * aria-label=\"Scheduled in\"\n * items={[\n * { value: 'any', label: 'Any time' },\n * { value: 'this-week', label: 'This week' },\n * ]}\n * value={when}\n * onValueChange={setWhen}\n * />\n * ```\n *\n * Choices told apart by how they look (a colour, a theme) take\n * `appearance=\"cards\"`, each with a `visual`. A few short choices seen at\n * once in a row are a `SegmentGroup`; a long list, or one in a form row, is\n * a `Select`.\n */\nexport function RadioGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n disabled,\n name,\n appearance = 'list',\n className,\n 'aria-label': ariaLabel,\n}: RadioGroupProps) {\n const cards = appearance === 'cards';\n const rootRef = useRef<HTMLDivElement>(null);\n\n const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);\n\n const visibleLabel = renderVisibleLabel(ArkRadioGroup.Label, {\n label,\n ariaLabel,\n className: 'ds-radio-group__label',\n });\n\n const marker = (item: RadioGroupItem) =>\n cards ? (\n <span className=\"ds-radio-group__visual\" aria-hidden>\n {item.visual}\n </span>\n ) : (\n <ArkRadioGroup.ItemControl className=\"ds-radio-group__control\" />\n );\n const renderItem = (item: RadioGroupItem) => (\n <ArkRadioGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-radio-group__item\"\n >\n {marker(item)}\n <ArkRadioGroup.ItemText className=\"ds-radio-group__text\">{item.label}</ArkRadioGroup.ItemText>\n <ArkRadioGroup.ItemHiddenInput />\n </ArkRadioGroup.Item>\n );\n\n const choices = cards ? (\n <div className=\"ds-radio-group__cards\">{items.map(renderItem)}</div>\n ) : (\n items.map(renderItem)\n );\n\n return (\n <ArkRadioGroup.Root\n ref={rootRef}\n className={cx('ds-radio-group', cards && 'ds-radio-group--cards', className)}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"vertical\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n {choices}\n </ArkRadioGroup.Root>\n );\n}\n"]}
|
|
@@ -4,9 +4,15 @@ export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';
|
|
|
4
4
|
export interface TooltipProps {
|
|
5
5
|
/** The caption: a few words, never a control. */
|
|
6
6
|
content: ReactNode;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The element it captions. It keeps its own accessible name. A disabled
|
|
9
|
+
* one (`disabled` set) is captioned too, and described for good; see the
|
|
10
|
+
* component's description.
|
|
11
|
+
*/
|
|
8
12
|
children: ReactElement<{
|
|
9
13
|
id?: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
'aria-describedby'?: string;
|
|
10
16
|
}>;
|
|
11
17
|
/**
|
|
12
18
|
* What the caption is to assistive tech. `description` (default) adds it
|
|
@@ -33,6 +39,16 @@ export interface TooltipProps {
|
|
|
33
39
|
* for another control whose meaning its glyph alone does not say. Anything
|
|
34
40
|
* a user must read to act belongs on the page, not in a tooltip: touch
|
|
35
41
|
* screens never show one.
|
|
42
|
+
*
|
|
43
|
+
* A disabled control can carry the reason it is disabled ("Month planning
|
|
44
|
+
* is coming later"): the pointer still shows the caption, and since nothing
|
|
45
|
+
* can focus the control, its description holds the same words for good, for
|
|
46
|
+
* assistive technology, which still reads a disabled control. When the
|
|
47
|
+
* control is another part's trigger that finds itself by id (a tab), give it
|
|
48
|
+
* that id and the part the same one through its `ids`, as `CategoryTabs`
|
|
49
|
+
* does; the caption's trigger id otherwise replaces it. The keyboard skips a
|
|
50
|
+
* disabled control, so a sighted keyboard user never sees the caption: put
|
|
51
|
+
* anything they need on the page.
|
|
36
52
|
*/
|
|
37
53
|
export declare function Tooltip({ content, children, kind, placement, }: TooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
38
54
|
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,eAAe,CAAC;AAMvB,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,OAAO,EAAE,SAAS,CAAC;IACnB;;;;OAIG;IACH,QAAQ,EAAE,YAAY,CAAC;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzF;;;;;OAKG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IAC/B,uEAAuE;IACvE,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,CAAC,EACtB,OAAO,EACP,QAAQ,EACR,IAAoB,EACpB,SAAiB,GAClB,EAAE,YAAY,2CAiFd"}
|
package/dist/tooltip/tooltip.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Portal } from '@ark-ui/react/portal';
|
|
3
3
|
import { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';
|
|
4
|
-
import { useContext, useEffect, useState } from 'react';
|
|
4
|
+
import { cloneElement, useContext, useEffect, useId, useState, useSyncExternalStore, } from 'react';
|
|
5
5
|
import { PortalContainerContext } from '../portal-container';
|
|
6
|
+
import { VisuallyHidden } from '../visually-hidden/visually-hidden';
|
|
6
7
|
import './tooltip.css';
|
|
8
|
+
const neverChanges = () => () => { };
|
|
9
|
+
const isClient = () => true;
|
|
10
|
+
const isServer = () => false;
|
|
7
11
|
/**
|
|
8
12
|
* A caption that shows while the pointer rests on its trigger or the
|
|
9
13
|
* keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide
|
|
@@ -19,6 +23,16 @@ import './tooltip.css';
|
|
|
19
23
|
* for another control whose meaning its glyph alone does not say. Anything
|
|
20
24
|
* a user must read to act belongs on the page, not in a tooltip: touch
|
|
21
25
|
* screens never show one.
|
|
26
|
+
*
|
|
27
|
+
* A disabled control can carry the reason it is disabled ("Month planning
|
|
28
|
+
* is coming later"): the pointer still shows the caption, and since nothing
|
|
29
|
+
* can focus the control, its description holds the same words for good, for
|
|
30
|
+
* assistive technology, which still reads a disabled control. When the
|
|
31
|
+
* control is another part's trigger that finds itself by id (a tab), give it
|
|
32
|
+
* that id and the part the same one through its `ids`, as `CategoryTabs`
|
|
33
|
+
* does; the caption's trigger id otherwise replaces it. The keyboard skips a
|
|
34
|
+
* disabled control, so a sighted keyboard user never sees the caption: put
|
|
35
|
+
* anything they need on the page.
|
|
22
36
|
*/
|
|
23
37
|
export function Tooltip({ content, children, kind = 'description', placement = 'top', }) {
|
|
24
38
|
const portalContainer = useContext(PortalContainerContext);
|
|
@@ -28,6 +42,7 @@ export function Tooltip({ content, children, kind = 'description', placement = '
|
|
|
28
42
|
* one. A description the trigger sets itself still wins.
|
|
29
43
|
*/
|
|
30
44
|
const triggerDescription = kind === 'label' ? '' : undefined;
|
|
45
|
+
const describesDisabled = children.props.disabled === true && kind === 'description';
|
|
31
46
|
/*
|
|
32
47
|
* A trigger that is itself another part's asChild trigger (a Menu's, a
|
|
33
48
|
* Dialog's close button, a Calendar arrow) takes that part's id, and the
|
|
@@ -36,7 +51,23 @@ export function Tooltip({ content, children, kind = 'description', placement = '
|
|
|
36
51
|
* with keeps the lookup on the real element.
|
|
37
52
|
*/
|
|
38
53
|
const triggerId = children.props.id;
|
|
54
|
+
const descriptionId = useId();
|
|
39
55
|
const [open, setOpen] = useState(false);
|
|
56
|
+
const description = [children.props['aria-describedby'], descriptionId].filter(Boolean).join(' ');
|
|
57
|
+
/*
|
|
58
|
+
* A disabled control's description holds the caption for good, since
|
|
59
|
+
* nothing can focus the control to show it. The words live at the end of
|
|
60
|
+
* the page, not beside the control: a list that may hold only its items (a
|
|
61
|
+
* tablist, a menu) would otherwise hold a stray text.
|
|
62
|
+
*/
|
|
63
|
+
const trigger = describesDisabled
|
|
64
|
+
? cloneElement(children, { 'aria-describedby': description })
|
|
65
|
+
: children;
|
|
66
|
+
/*
|
|
67
|
+
* A portal renders in place on the server and while hydrating, which would
|
|
68
|
+
* put the words inside the list after all, so they wait for the client.
|
|
69
|
+
*/
|
|
70
|
+
const onClient = useSyncExternalStore(neverChanges, isClient, isServer);
|
|
40
71
|
/*
|
|
41
72
|
* Escape hides the caption and goes on to whatever else it means: Zag's
|
|
42
73
|
* own Escape handling stops the key at the document, so a keyboard drag
|
|
@@ -53,6 +84,6 @@ export function Tooltip({ content, children, kind = 'description', placement = '
|
|
|
53
84
|
document.addEventListener('keydown', hide);
|
|
54
85
|
return () => document.removeEventListener('keydown', hide);
|
|
55
86
|
}, [open]);
|
|
56
|
-
return (_jsxs(ArkTooltip.Root, { lazyMount: true, unmountOnExit: true, positioning: { placement, gutter: 6 }, ids: triggerId ? { trigger: triggerId } : undefined, open: open, onOpenChange: (details) => setOpen(details.open), closeOnEscape: false, children: [_jsx(ArkTooltip.Trigger, { asChild: true, "aria-describedby": triggerDescription, children: children }), _jsx(Portal, { container: portalContainer, children: _jsx(ArkTooltip.Positioner, { children: _jsx(ArkTooltip.Content, { className: "ds-tooltip__content", "aria-hidden": kind === 'label' ? true : undefined, children: content }) }) })] }));
|
|
87
|
+
return (_jsxs(ArkTooltip.Root, { lazyMount: true, unmountOnExit: true, positioning: { placement, gutter: 6 }, ids: triggerId ? { trigger: triggerId } : undefined, open: open, onOpenChange: (details) => setOpen(details.open), closeOnEscape: false, children: [_jsx(ArkTooltip.Trigger, { asChild: true, "aria-describedby": triggerDescription, children: trigger }), describesDisabled && onClient && (_jsx(Portal, { container: portalContainer, children: _jsx(VisuallyHidden, { id: descriptionId, children: content }) })), _jsx(Portal, { container: portalContainer, children: _jsx(ArkTooltip.Positioner, { children: _jsx(ArkTooltip.Content, { className: "ds-tooltip__content", "aria-hidden": kind === 'label' ? true : undefined, children: content }) }) })] }));
|
|
57
88
|
}
|
|
58
89
|
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,YAAY,EAGZ,UAAU,EACV,SAAS,EACT,KAAK,EACL,QAAQ,EACR,oBAAoB,GACrB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,eAAe,CAAC;AAEvB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AACpC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAC5B,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;AAwB7B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,OAAO,CAAC,EACtB,OAAO,EACP,QAAQ,EACR,IAAI,GAAG,aAAa,EACpB,SAAS,GAAG,KAAK,GACJ;IACb,MAAM,eAAe,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAC3D;;;;OAIG;IACH,MAAM,kBAAkB,GAAG,IAAI,KAAK,OAAO,CAAC,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AAI,IACd,SAAS,QACT,aAAa,QACb,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EACrC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,EACnD,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAChD,aAAa,EAAE,KAAK,aAEpB,KAAC,UAAU,CAAC,OAAO,IAAC,OAAO,4BAAmB,kBAAkB,YAC7D,OAAO,GACW,EACpB,iBAAiB,IAAI,QAAQ,IAAI,CAChC,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,cAAc,IAAC,EAAE,EAAE,aAAa,YAAG,OAAO,GAAkB,GACtD,CACV,EACD,KAAC,MAAM,IAAC,SAAS,EAAE,eAAe,YAChC,KAAC,UAAU,CAAC,UAAU,cACpB,KAAC,UAAU,CAAC,OAAO,IACjB,SAAS,EAAC,qBAAqB,iBAClB,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,YAE/C,OAAO,GACW,GACC,GACjB,IACO,CACnB,CAAC;AACJ,CAAC","sourcesContent":["import { Portal } from '@ark-ui/react/portal';\nimport { Tooltip as ArkTooltip } from '@ark-ui/react/tooltip';\nimport {\n cloneElement,\n type ReactElement,\n type ReactNode,\n useContext,\n useEffect,\n useId,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { PortalContainerContext } from '../portal-container';\nimport { VisuallyHidden } from '../visually-hidden/visually-hidden';\nimport './tooltip.css';\n\nconst neverChanges = () => () => {};\nconst isClient = () => true;\nconst isServer = () => false;\n\nexport type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right';\n\nexport interface TooltipProps {\n /** The caption: a few words, never a control. */\n content: ReactNode;\n /**\n * The element it captions. It keeps its own accessible name. A disabled\n * one (`disabled` set) is captioned too, and described for good; see the\n * component's description.\n */\n children: ReactElement<{ id?: string; disabled?: boolean; 'aria-describedby'?: string }>;\n /**\n * What the caption is to assistive tech. `description` (default) adds it\n * to the trigger's description while it shows. `label` says it repeats the\n * trigger's accessible name, as an icon-only button's caption does, so it\n * is left out and the name is announced once.\n */\n kind?: 'description' | 'label';\n /** Side of the trigger it opens on, flipping when there is no room. */\n placement?: TooltipPlacement;\n}\n\n/**\n * A caption that shows while the pointer rests on its trigger or the\n * keyboard focuses it, built on Ark UI's Tooltip. Esc and moving away hide\n * it; it never takes focus and holds nothing to click.\n *\n * ```tsx\n * <Tooltip content=\"Archive\">\n * <button type=\"button\" aria-label=\"Archive Run 10k\">…</button>\n * </Tooltip>\n * ```\n *\n * `IconButton` shows one with its label by default. Reach for it directly\n * for another control whose meaning its glyph alone does not say. Anything\n * a user must read to act belongs on the page, not in a tooltip: touch\n * screens never show one.\n *\n * A disabled control can carry the reason it is disabled (\"Month planning\n * is coming later\"): the pointer still shows the caption, and since nothing\n * can focus the control, its description holds the same words for good, for\n * assistive technology, which still reads a disabled control. When the\n * control is another part's trigger that finds itself by id (a tab), give it\n * that id and the part the same one through its `ids`, as `CategoryTabs`\n * does; the caption's trigger id otherwise replaces it. The keyboard skips a\n * disabled control, so a sighted keyboard user never sees the caption: put\n * anything they need on the page.\n */\nexport function Tooltip({\n content,\n children,\n kind = 'description',\n placement = 'top',\n}: TooltipProps) {\n const portalContainer = useContext(PortalContainerContext);\n /*\n * Zag points the trigger's description at the caption while it shows, and\n * only a defined value overrides it, so a label caption passes an empty\n * one. A description the trigger sets itself still wins.\n */\n const triggerDescription = kind === 'label' ? '' : undefined;\n const describesDisabled = children.props.disabled === true && kind === 'description';\n /*\n * A trigger that is itself another part's asChild trigger (a Menu's, a\n * Dialog's close button, a Calendar arrow) takes that part's id, and the\n * child's props win the merge, so Zag would look for its own id and find\n * nothing to place the caption against. Naming the id the trigger ends up\n * with keeps the lookup on the real element.\n */\n const triggerId = children.props.id;\n const descriptionId = useId();\n const [open, setOpen] = useState(false);\n\n const description = [children.props['aria-describedby'], descriptionId].filter(Boolean).join(' ');\n /*\n * A disabled control's description holds the caption for good, since\n * nothing can focus the control to show it. The words live at the end of\n * the page, not beside the control: a list that may hold only its items (a\n * tablist, a menu) would otherwise hold a stray text.\n */\n const trigger = describesDisabled\n ? cloneElement(children, { 'aria-describedby': description })\n : children;\n /*\n * A portal renders in place on the server and while hydrating, which would\n * put the words inside the list after all, so they wait for the client.\n */\n const onClient = useSyncExternalStore(neverChanges, isClient, isServer);\n\n /*\n * Escape hides the caption and goes on to whatever else it means: Zag's\n * own Escape handling stops the key at the document, so a keyboard drag\n * could not be cancelled and a dialog would not close while a caption\n * showed.\n */\n useEffect(() => {\n if (!open) return;\n const hide = (event: KeyboardEvent) => {\n if (event.key === 'Escape') setOpen(false);\n };\n document.addEventListener('keydown', hide);\n return () => document.removeEventListener('keydown', hide);\n }, [open]);\n\n return (\n <ArkTooltip.Root\n lazyMount\n unmountOnExit\n positioning={{ placement, gutter: 6 }}\n ids={triggerId ? { trigger: triggerId } : undefined}\n open={open}\n onOpenChange={(details) => setOpen(details.open)}\n closeOnEscape={false}\n >\n <ArkTooltip.Trigger asChild aria-describedby={triggerDescription}>\n {trigger}\n </ArkTooltip.Trigger>\n {describesDisabled && onClient && (\n <Portal container={portalContainer}>\n <VisuallyHidden id={descriptionId}>{content}</VisuallyHidden>\n </Portal>\n )}\n <Portal container={portalContainer}>\n <ArkTooltip.Positioner>\n <ArkTooltip.Content\n className=\"ds-tooltip__content\"\n aria-hidden={kind === 'label' ? true : undefined}\n >\n {content}\n </ArkTooltip.Content>\n </ArkTooltip.Positioner>\n </Portal>\n </ArkTooltip.Root>\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manakind/ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -412,7 +412,7 @@
|
|
|
412
412
|
},
|
|
413
413
|
"devDependencies": {
|
|
414
414
|
"@manakind/ds-config": "*",
|
|
415
|
-
"@manakind/manuia-tokens": "0.
|
|
415
|
+
"@manakind/manuia-tokens": "0.35.0",
|
|
416
416
|
"@testing-library/jest-dom": "^6.9.1",
|
|
417
417
|
"@testing-library/react": "^16.3.2",
|
|
418
418
|
"@testing-library/user-event": "^14.6.1",
|