@galaxy-io/dls 2.12.1 → 2.12.3
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/avatar/Avatar.d.ts +8 -0
- package/dist/avatar/Avatar.js +94 -40
- package/dist/avatar/internal/avatarBadge.d.ts +17 -0
- package/dist/avatar/internal/avatarBadge.js +34 -0
- package/dist/charts/ChartLegend.js +42 -23
- package/dist/charts/constants.d.ts +3 -1
- package/dist/charts/constants.js +4 -2
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/avatar/Avatar.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare enum AvatarSize {
|
|
|
13
13
|
/** 40px (`size.control.xLarge`); initials `body_lg`. */
|
|
14
14
|
X_LARGE = "X_LARGE"
|
|
15
15
|
}
|
|
16
|
+
/** The badge avatar: what it shows and its shape. Its size comes from the avatar it sits on. */
|
|
17
|
+
export type AvatarBadge = Pick<AvatarProps, "name" | "img" | "seed" | "isSquare" | "color" | "hex">;
|
|
16
18
|
export interface AvatarProps extends AriaAttributes {
|
|
17
19
|
/** Name of the person or entity. It gives the initials fallback and the accessible name. */
|
|
18
20
|
name?: string;
|
|
@@ -44,6 +46,12 @@ export interface AvatarProps extends AriaAttributes {
|
|
|
44
46
|
* @default false
|
|
45
47
|
*/
|
|
46
48
|
isLoading?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* A smaller avatar in the bottom-end corner for this one's context: a person on an organization
|
|
51
|
+
* (`isSquare` outside, a round badge) or an organization on a person. Sized from this avatar
|
|
52
|
+
* (8 / 9 / 12 / 13 / 14px on the rungs) and named with it ("Ada Lovelace, Galaxy").
|
|
53
|
+
*/
|
|
54
|
+
badge?: AvatarBadge;
|
|
47
55
|
/** Accessible name, when it should differ from `name` (for example "Ada Lovelace, owner"). Without it and without `name`, the avatar is decorative (`aria-hidden`). */
|
|
48
56
|
ariaLabel?: string;
|
|
49
57
|
/** DOM id on the root `<span>`. */
|
package/dist/avatar/Avatar.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Skeleton, { SkeletonVariant } from "../feedback/Skeleton.js";
|
|
2
2
|
import Text, { TextSize, TextVariant, TextWeight } from "../text/Text.js";
|
|
3
3
|
import { CONTROL_SIZE } from "../theme/tokens/scales.js";
|
|
4
|
+
import { getAvatarAccessibleName, getAvatarBadgeDiameter, getAvatarBadgedInitials } from "./internal/avatarBadge.js";
|
|
4
5
|
/* empty css */
|
|
5
6
|
import { styled } from "@linaria/react";
|
|
6
7
|
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { cx } from "@linaria/core";
|
|
9
10
|
//#region src/avatar/Avatar.tsx
|
|
10
11
|
/**
|
|
@@ -19,6 +20,11 @@ import { cx } from "@linaria/core";
|
|
|
19
20
|
* (`--gx-avatar-tint`, the surface fill and hairline) and `hex` is the `--gx-avatar-hex` custom
|
|
20
21
|
* property, so a theme switch needs no re-render and nothing reads the theme at runtime.
|
|
21
22
|
*
|
|
23
|
+
* A `badge` is a second, smaller avatar in the bottom-end corner for the context of the first: a
|
|
24
|
+
* person's organization, or the person acting in a workspace. It sits inside the avatar's box, and
|
|
25
|
+
* the main avatar is cut away around it by a mask (no ring, no shadow), so the pair reads on any
|
|
26
|
+
* surface. The two are one image with one accessible name.
|
|
27
|
+
*
|
|
22
28
|
* Not a button (wrap it in one), not a stack (`AvatarGroup`), not a name label (put a `Text`
|
|
23
29
|
* beside it), not a generic image container.
|
|
24
30
|
*/
|
|
@@ -51,61 +57,77 @@ var Surface = /*#__PURE__*/ styled("span")({
|
|
|
51
57
|
class: "gx-Avatar-Surface-s3r0r1h",
|
|
52
58
|
propsAsIs: false
|
|
53
59
|
});
|
|
60
|
+
/** The badge's box: the bottom-end corner, inside the avatar's own bounds. */
|
|
61
|
+
var BadgeSlot = /*#__PURE__*/ styled("span")({
|
|
62
|
+
name: "BadgeSlot",
|
|
63
|
+
class: "gx-Avatar-BadgeSlot-b1n32hoy",
|
|
64
|
+
propsAsIs: false
|
|
65
|
+
});
|
|
54
66
|
var Image = /*#__PURE__*/ styled("img")({
|
|
55
67
|
name: "Image",
|
|
56
|
-
class: "gx-Avatar-Image-
|
|
68
|
+
class: "gx-Avatar-Image-i94shpk",
|
|
57
69
|
propsAsIs: false
|
|
58
70
|
});
|
|
59
71
|
/** The generated pattern: one `viewBox` grid that scales to any diameter. Tinted by `hex` or `color`. */
|
|
60
72
|
var Pattern = /*#__PURE__*/ styled("svg")({
|
|
61
73
|
name: "Pattern",
|
|
62
|
-
class: "gx-Avatar-Pattern-
|
|
74
|
+
class: "gx-Avatar-Pattern-pblj6sc",
|
|
63
75
|
propsAsIs: false
|
|
64
76
|
});
|
|
65
77
|
/** Diameter per rung. */
|
|
66
78
|
var AVATAR_SIZE_TO_CSS_MAP = {
|
|
67
|
-
["X_SMALL"]: "gx-Avatar-X_SMALL-
|
|
68
|
-
["SMALL"]: "gx-Avatar-SMALL-
|
|
69
|
-
["MEDIUM"]: "gx-Avatar-MEDIUM-
|
|
70
|
-
["LARGE"]: "gx-Avatar-LARGE-
|
|
71
|
-
["X_LARGE"]: "gx-Avatar-X_LARGE-
|
|
79
|
+
["X_SMALL"]: "gx-Avatar-X_SMALL-x116bpx4",
|
|
80
|
+
["SMALL"]: "gx-Avatar-SMALL-s1ykihtn",
|
|
81
|
+
["MEDIUM"]: "gx-Avatar-MEDIUM-m1vt38m2",
|
|
82
|
+
["LARGE"]: "gx-Avatar-LARGE-ljtmhfq",
|
|
83
|
+
["X_LARGE"]: "gx-Avatar-X_LARGE-xtukwhw"
|
|
72
84
|
};
|
|
73
85
|
/** A px diameter, set as `--gx-avatar-size` in `style` (a continuous value). */
|
|
74
|
-
var PX_SIZE_CSS = "gx-Avatar-PX_SIZE_CSS-
|
|
86
|
+
var PX_SIZE_CSS = "gx-Avatar-PX_SIZE_CSS-pdv3w7l";
|
|
75
87
|
/** `isSquare`: control-radius corners at every size. */
|
|
76
|
-
var SQUARE_CSS = "gx-Avatar-SQUARE_CSS-
|
|
88
|
+
var SQUARE_CSS = "gx-Avatar-SQUARE_CSS-s1c3dn12";
|
|
89
|
+
/** The gap between the badge and the cut-away edge of the avatar under it. */
|
|
90
|
+
/** A round badge: a circular notch centered on the badge, one gap wider. Mirrors under RTL. */
|
|
91
|
+
var ROUND_NOTCH_CSS = "gx-Avatar-ROUND_NOTCH_CSS-r63z1lx";
|
|
92
|
+
/**
|
|
93
|
+
* A square badge: a notch in the corner one gap wider than the badge, square where it meets the
|
|
94
|
+
* avatar's edges and rounded at its inner corner by `radius.md`, the radius of every control. Two
|
|
95
|
+
* rectangles and a quarter circle make the notch; together they are subtracted from the avatar.
|
|
96
|
+
* Mirrors under RTL.
|
|
97
|
+
*/
|
|
98
|
+
var SQUARE_NOTCH_CSS = "gx-Avatar-SQUARE_NOTCH_CSS-s1x7b2uf";
|
|
77
99
|
/** The initials' color, which the `INHERIT` text takes. Tinted by `hex` or `color`. */
|
|
78
|
-
var INITIALS_CSS = "gx-Avatar-INITIALS_CSS-
|
|
100
|
+
var INITIALS_CSS = "gx-Avatar-INITIALS_CSS-iz59h18";
|
|
79
101
|
/** Categorical `color` on the fallback surface: the tint the initials and pattern read, the family's fill and hairline. */
|
|
80
102
|
var AVATAR_COLOR_TO_CSS_MAP = {
|
|
81
|
-
red: "gx-Avatar-red-
|
|
82
|
-
orange: "gx-Avatar-orange-
|
|
83
|
-
amber: "gx-Avatar-amber-
|
|
84
|
-
yellow: "gx-Avatar-yellow-
|
|
85
|
-
lime: "gx-Avatar-lime-
|
|
86
|
-
green: "gx-Avatar-green-
|
|
87
|
-
emerald: "gx-Avatar-emerald-
|
|
88
|
-
teal: "gx-Avatar-teal-
|
|
89
|
-
cyan: "gx-Avatar-cyan-
|
|
90
|
-
sky: "gx-Avatar-sky-
|
|
91
|
-
blue: "gx-Avatar-blue-
|
|
92
|
-
indigo: "gx-Avatar-indigo-
|
|
93
|
-
violet: "gx-Avatar-violet-
|
|
94
|
-
purple: "gx-Avatar-purple-
|
|
95
|
-
fuchsia: "gx-Avatar-fuchsia-
|
|
96
|
-
pink: "gx-Avatar-pink-
|
|
97
|
-
rose: "gx-Avatar-rose-
|
|
103
|
+
red: "gx-Avatar-red-r1y5rsmb",
|
|
104
|
+
orange: "gx-Avatar-orange-ozxsfel",
|
|
105
|
+
amber: "gx-Avatar-amber-a414m3u",
|
|
106
|
+
yellow: "gx-Avatar-yellow-y1uew7pg",
|
|
107
|
+
lime: "gx-Avatar-lime-l6z9q1b",
|
|
108
|
+
green: "gx-Avatar-green-ghef53l",
|
|
109
|
+
emerald: "gx-Avatar-emerald-e1o5jkv9",
|
|
110
|
+
teal: "gx-Avatar-teal-te52zro",
|
|
111
|
+
cyan: "gx-Avatar-cyan-c9qjv1q",
|
|
112
|
+
sky: "gx-Avatar-sky-s6zn1e0",
|
|
113
|
+
blue: "gx-Avatar-blue-bc3yopb",
|
|
114
|
+
indigo: "gx-Avatar-indigo-izee674",
|
|
115
|
+
violet: "gx-Avatar-violet-v1f7v2mb",
|
|
116
|
+
purple: "gx-Avatar-purple-p87xw4u",
|
|
117
|
+
fuchsia: "gx-Avatar-fuchsia-f17r187b",
|
|
118
|
+
pink: "gx-Avatar-pink-p9ksu8k",
|
|
119
|
+
rose: "gx-Avatar-rose-r1ql1bax"
|
|
98
120
|
};
|
|
99
121
|
/**
|
|
100
122
|
* The pattern's five tones of `currentColor`, indexed by the PRNG (a palette index, not an enum
|
|
101
123
|
* axis). They replace the 1.x JS color math: base, lighter, darker, 30% and 15% opaque.
|
|
102
124
|
*/
|
|
103
125
|
var PATTERN_TONE_CSS = [
|
|
104
|
-
"gx-Avatar-PATTERN_TONE_CSS-p17r187b",
|
|
105
|
-
"gx-Avatar-PATTERN_TONE_CSS-p9ksu8k",
|
|
106
|
-
"gx-Avatar-PATTERN_TONE_CSS-p1ql1bax",
|
|
107
126
|
"gx-Avatar-PATTERN_TONE_CSS-p12sxa1c",
|
|
108
|
-
"gx-Avatar-PATTERN_TONE_CSS-pq3238h"
|
|
127
|
+
"gx-Avatar-PATTERN_TONE_CSS-pq3238h",
|
|
128
|
+
"gx-Avatar-PATTERN_TONE_CSS-p826b8b",
|
|
129
|
+
"gx-Avatar-PATTERN_TONE_CSS-p7662vu",
|
|
130
|
+
"gx-Avatar-PATTERN_TONE_CSS-p1j9rxb"
|
|
109
131
|
];
|
|
110
132
|
/** Initials text per rung (Constitution III-A.4): lines 12 / 16 / 16 / 20 / 20px, so whole-pixel offsets. */
|
|
111
133
|
var AVATAR_SIZE_TO_TEXT_SIZE_MAP = {
|
|
@@ -140,6 +162,13 @@ var PATTERN_GRID_MAX = 9;
|
|
|
140
162
|
var PATTERN_DOT_RADIUS = .3;
|
|
141
163
|
/** Number of pattern tones (`PATTERN_TONE_CSS`). */
|
|
142
164
|
var PATTERN_TONE_COUNT = 5;
|
|
165
|
+
/** Initials text steps from smallest to largest, for stepping down under a badge. */
|
|
166
|
+
var AVATAR_TEXT_SIZE_STEPS = AVATAR_PX_TO_TEXT_SIZE_STEPS.map(([, step]) => step).reverse();
|
|
167
|
+
/** One initials step smaller (never below `CAPTION`), so the letters fit beside a badge. */
|
|
168
|
+
function getBadgedTextSize(textSize) {
|
|
169
|
+
const index = AVATAR_TEXT_SIZE_STEPS.indexOf(textSize);
|
|
170
|
+
return AVATAR_TEXT_SIZE_STEPS[Math.max(0, index - 1)] ?? TextSize.CAPTION;
|
|
171
|
+
}
|
|
143
172
|
/** The initials text step for a px diameter. */
|
|
144
173
|
function getTextSizeForPx(px) {
|
|
145
174
|
return AVATAR_PX_TO_TEXT_SIZE_STEPS.find(([min]) => min <= px)?.[1] ?? TextSize.CAPTION;
|
|
@@ -196,7 +225,7 @@ function getInitials(name) {
|
|
|
196
225
|
return `${firstChars[0] ?? ""}${Array.from(last)[0] ?? ""}`.toLocaleUpperCase();
|
|
197
226
|
}
|
|
198
227
|
/** A person or entity: image, initials or generated pattern, round or square. */
|
|
199
|
-
var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSquare = false, color, hex, isLoading = false, ariaLabel, id, className, style, ...rest }, ref) {
|
|
228
|
+
var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSquare = false, color, hex, isLoading = false, badge, ariaLabel, id, className, style, ...rest }, ref) {
|
|
200
229
|
const imageRef = useRef(null);
|
|
201
230
|
const [failedSrc, setFailedSrc] = useState(null);
|
|
202
231
|
useEffect(() => {
|
|
@@ -205,16 +234,18 @@ var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSq
|
|
|
205
234
|
}, [img]);
|
|
206
235
|
const isPx = typeof size === "number";
|
|
207
236
|
const diameter = isPx ? size : AVATAR_SIZE_TO_DIAMETER_PX_MAP[size];
|
|
208
|
-
const
|
|
237
|
+
const baseTextSize = isPx ? getTextSizeForPx(size) : AVATAR_SIZE_TO_TEXT_SIZE_MAP[size];
|
|
238
|
+
const textSize = badge === void 0 ? baseTextSize : getBadgedTextSize(baseTextSize);
|
|
209
239
|
const imageSrc = typeof img === "string" && img.length > 0 && img !== failedSrc ? img : void 0;
|
|
210
240
|
const hasImage = imageSrc !== void 0;
|
|
211
|
-
const
|
|
241
|
+
const nameInitials = getInitials(name);
|
|
242
|
+
const initials = badge === void 0 ? nameInitials : getAvatarBadgedInitials(nameInitials, diameter);
|
|
212
243
|
const isInitials = !hasImage && seed === void 0 && initials.length > 0;
|
|
213
244
|
const tintCss = color !== void 0 && hex === void 0 && !hasImage ? AVATAR_COLOR_TO_CSS_MAP[color] : void 0;
|
|
214
245
|
const seedValue = seed ?? hex ?? "default";
|
|
215
246
|
const grid = getPatternGrid(diameter);
|
|
216
247
|
const cells = useMemo(() => getPatternCells(seedValue, grid), [seedValue, grid]);
|
|
217
|
-
const accessibleName = ariaLabel
|
|
248
|
+
const accessibleName = getAvatarAccessibleName(ariaLabel, name, badge?.name);
|
|
218
249
|
const accessibility = accessibleName !== void 0 && accessibleName.length > 0 ? {
|
|
219
250
|
role: "img",
|
|
220
251
|
"aria-label": accessibleName
|
|
@@ -222,6 +253,9 @@ var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSq
|
|
|
222
253
|
const variables = {};
|
|
223
254
|
if (isPx) variables["--gx-avatar-size"] = `${size}px`;
|
|
224
255
|
if (hex !== void 0) variables["--gx-avatar-hex"] = hex;
|
|
256
|
+
const badgeDiameter = badge === void 0 ? void 0 : getAvatarBadgeDiameter(diameter);
|
|
257
|
+
if (badgeDiameter !== void 0) variables["--gx-avatar-badge-size"] = `${badgeDiameter}px`;
|
|
258
|
+
const notchCss = badge === void 0 ? void 0 : badge.isSquare ? SQUARE_NOTCH_CSS : ROUND_NOTCH_CSS;
|
|
225
259
|
let content;
|
|
226
260
|
if (imageSrc !== void 0) content = /* @__PURE__ */ jsx(Image, {
|
|
227
261
|
ref: imageRef,
|
|
@@ -247,7 +281,7 @@ var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSq
|
|
|
247
281
|
className: PATTERN_TONE_CSS[tone]
|
|
248
282
|
}, key))
|
|
249
283
|
});
|
|
250
|
-
const root = /* @__PURE__ */
|
|
284
|
+
const root = /* @__PURE__ */ jsxs(Root, {
|
|
251
285
|
...accessibility,
|
|
252
286
|
...rest,
|
|
253
287
|
ref,
|
|
@@ -257,10 +291,16 @@ var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSq
|
|
|
257
291
|
...variables,
|
|
258
292
|
...style
|
|
259
293
|
},
|
|
260
|
-
children: /* @__PURE__ */ jsx(Surface, {
|
|
261
|
-
className: cx(tintCss, isInitials && INITIALS_CSS),
|
|
294
|
+
children: [/* @__PURE__ */ jsx(Surface, {
|
|
295
|
+
className: cx(tintCss, isInitials && INITIALS_CSS, notchCss),
|
|
262
296
|
children: content
|
|
263
|
-
})
|
|
297
|
+
}), badge !== void 0 && badgeDiameter !== void 0 && /* @__PURE__ */ jsx(BadgeSlot, {
|
|
298
|
+
className: cx(badge.isSquare && SQUARE_CSS),
|
|
299
|
+
children: /* @__PURE__ */ jsx(AvatarBadgeImage, {
|
|
300
|
+
badge,
|
|
301
|
+
size: badgeDiameter
|
|
302
|
+
})
|
|
303
|
+
})]
|
|
264
304
|
});
|
|
265
305
|
if (!isLoading) return root;
|
|
266
306
|
return /* @__PURE__ */ jsx(Skeleton, {
|
|
@@ -270,5 +310,19 @@ var Avatar = forwardRef(function Avatar({ name, img, seed, size = "MEDIUM", isSq
|
|
|
270
310
|
});
|
|
271
311
|
});
|
|
272
312
|
Avatar.displayName = "Avatar";
|
|
313
|
+
/**
|
|
314
|
+
* The badge, drawn by the exported `Avatar`: inside `Avatar`'s render function that name is the
|
|
315
|
+
* render function itself, which would receive the wrong ref. Decorative, since the badged avatar
|
|
316
|
+
* already names both, so it keeps one initial: two do not fit at badge size.
|
|
317
|
+
*/
|
|
318
|
+
function AvatarBadgeImage({ badge: { name, ...badge }, size }) {
|
|
319
|
+
const initial = Array.from(getInitials(name))[0];
|
|
320
|
+
return /* @__PURE__ */ jsx(Avatar, {
|
|
321
|
+
...badge,
|
|
322
|
+
...initial === void 0 ? {} : { name: initial },
|
|
323
|
+
size,
|
|
324
|
+
"aria-hidden": true
|
|
325
|
+
});
|
|
326
|
+
}
|
|
273
327
|
//#endregion
|
|
274
328
|
export { AvatarSize, Avatar as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The badge's geometry and the badged avatar's accessible name. Kept out of `Avatar.tsx` so the
|
|
3
|
+
* sizing rule and the name rule are tested on their own.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The badge diameter for a main avatar diameter: 36% of it to the nearest px, never below 8px. The
|
|
7
|
+
* 20 / 24 / 32 / 36 / 40px rungs give 8 / 9 / 12 / 13 / 14px.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAvatarBadgeDiameter(diameter: number): number;
|
|
10
|
+
/** The initials drawn beside a badge: the first one alone on avatars of 24px or less. */
|
|
11
|
+
export declare function getAvatarBadgedInitials(initials: string, diameter: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* The accessible name of an avatar and its badge, read as one image: `ariaLabel` when set,
|
|
14
|
+
* otherwise the non-empty names joined by a comma ("Ada Lovelace, Galaxy"), or `undefined` when
|
|
15
|
+
* there is nothing to read (the avatar is then decorative).
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAvatarAccessibleName(ariaLabel: string | undefined, name: string | undefined, badgeName: string | undefined): string | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/avatar/internal/avatarBadge.ts
|
|
2
|
+
/**
|
|
3
|
+
* The badge's geometry and the badged avatar's accessible name. Kept out of `Avatar.tsx` so the
|
|
4
|
+
* sizing rule and the name rule are tested on their own.
|
|
5
|
+
*/
|
|
6
|
+
/** Badge diameter as a share of the avatar it sits on. */
|
|
7
|
+
var AVATAR_BADGE_RATIO = .36;
|
|
8
|
+
/** Smallest badge: below this a face or initials stop reading as anything. */
|
|
9
|
+
var AVATAR_BADGE_MIN_PX = 8;
|
|
10
|
+
/**
|
|
11
|
+
* The badge diameter for a main avatar diameter: 36% of it to the nearest px, never below 8px. The
|
|
12
|
+
* 20 / 24 / 32 / 36 / 40px rungs give 8 / 9 / 12 / 13 / 14px.
|
|
13
|
+
*/
|
|
14
|
+
function getAvatarBadgeDiameter(diameter) {
|
|
15
|
+
return Math.max(AVATAR_BADGE_MIN_PX, Math.round(diameter * AVATAR_BADGE_RATIO));
|
|
16
|
+
}
|
|
17
|
+
/** Largest diameter whose badged initials keep only the first letter: two do not clear the notch. */
|
|
18
|
+
var AVATAR_BADGE_ONE_INITIAL_MAX_PX = 24;
|
|
19
|
+
/** The initials drawn beside a badge: the first one alone on avatars of 24px or less. */
|
|
20
|
+
function getAvatarBadgedInitials(initials, diameter) {
|
|
21
|
+
return diameter <= AVATAR_BADGE_ONE_INITIAL_MAX_PX ? Array.from(initials)[0] ?? "" : initials;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The accessible name of an avatar and its badge, read as one image: `ariaLabel` when set,
|
|
25
|
+
* otherwise the non-empty names joined by a comma ("Ada Lovelace, Galaxy"), or `undefined` when
|
|
26
|
+
* there is nothing to read (the avatar is then decorative).
|
|
27
|
+
*/
|
|
28
|
+
function getAvatarAccessibleName(ariaLabel, name, badgeName) {
|
|
29
|
+
if (ariaLabel !== void 0) return ariaLabel;
|
|
30
|
+
const names = [name, badgeName].filter((value) => value !== void 0 && value.trim().length > 0);
|
|
31
|
+
return names.length > 0 ? names.join(", ") : void 0;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getAvatarAccessibleName, getAvatarBadgeDiameter, getAvatarBadgedInitials };
|
|
@@ -4,6 +4,8 @@ import Text, { TextSize, TextVariant } from "../text/Text.js";
|
|
|
4
4
|
import { t } from "../theme/tokens/t.js";
|
|
5
5
|
import Flex, { AlignItems } from "../layout/Flex.js";
|
|
6
6
|
import Tooltip from "../tooltip/Tooltip.js";
|
|
7
|
+
import Box from "../layout/Box.js";
|
|
8
|
+
import Popover, { PopoverTrigger } from "../overlays/Popover.js";
|
|
7
9
|
import { ChartLegendPlacement, ChartMarkState, ChartPalette, ChartSwatch } from "./types.js";
|
|
8
10
|
import { CHART_MARK_STATE_TO_CSS_MAP } from "./ChartPrimitives.js";
|
|
9
11
|
import "./constants.js";
|
|
@@ -26,8 +28,10 @@ import { cx } from "@linaria/core";
|
|
|
26
28
|
* Entries are list items. Hovering one previews its series (a pointer enhancement; keyboard users
|
|
27
29
|
* hear every series in the announcement). On a filterable chart each entry is also a toggle button
|
|
28
30
|
* (`aria-pressed`): a click pins its series, ⌘ / Ctrl / Shift-click adds or removes it. Entries
|
|
29
|
-
* collapsed behind "+N more"
|
|
30
|
-
*
|
|
31
|
+
* collapsed behind "+N more" always draw at full strength: the list is for reading, and the
|
|
32
|
+
* trigger already carries the isolation. On a filterable chart a click (or Enter) on "+N more"
|
|
33
|
+
* opens a `Popover` whose entries are the same toggles, focus on the first (a tooltip holds no
|
|
34
|
+
* controls, and touch cannot hover); otherwise a `Tooltip` lists them on hover. A
|
|
31
35
|
* filterable chart's legend ends in a slot for its filter chip, right after the last entry (under
|
|
32
36
|
* the column when RIGHT): the slot always keeps its height, and a bottom legend always keeps room
|
|
33
37
|
* for the chip's width, so pinning never moves an entry. Spacing is padding on each entry and on
|
|
@@ -77,7 +81,10 @@ var MEASURE_PLACEMENT_TO_CSS_MAP = {
|
|
|
77
81
|
[ChartLegendPlacement.BOTTOM]: "gx-ChartLegend-ChartLegendPlacement_BOTTOM-cixvbm6",
|
|
78
82
|
[ChartLegendPlacement.RIGHT]: "gx-ChartLegend-ChartLegendPlacement_RIGHT-c1ehakcs"
|
|
79
83
|
};
|
|
80
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* The filter chips' slot: one or two chips, never taller than the row it sets. The fit keeps its
|
|
86
|
+
* minimum free; it shrinks into whatever the entries leave, up to its cap, and the chips truncate.
|
|
87
|
+
*/
|
|
81
88
|
var FilterSlot = /*#__PURE__*/ styled("li")({
|
|
82
89
|
name: "FilterSlot",
|
|
83
90
|
class: "gx-ChartLegend-FilterSlot-fsomlsk",
|
|
@@ -157,7 +164,7 @@ function ChartLegend({ items, placement, swatch, inset, extent = 0, isFixedExten
|
|
|
157
164
|
const rendered = Array.from(measure.children);
|
|
158
165
|
const trigger = rendered.pop();
|
|
159
166
|
if (!trigger) return;
|
|
160
|
-
const available = isVertical ? extent || Number.POSITIVE_INFINITY : list.clientWidth - inset - (hasFilterSlot ?
|
|
167
|
+
const available = isVertical ? extent || Number.POSITIVE_INFINITY : list.clientWidth - inset - (hasFilterSlot ? 120 : 0);
|
|
161
168
|
const sizeOf = (element) => {
|
|
162
169
|
const rect = element.getBoundingClientRect();
|
|
163
170
|
return Math.ceil(isVertical ? rect.height : rect.width);
|
|
@@ -196,6 +203,26 @@ function ChartLegend({ items, placement, swatch, inset, extent = 0, isFixedExten
|
|
|
196
203
|
const inline = items.slice(0, fitCount ?? items.length);
|
|
197
204
|
const overflow = items.slice(inline.length);
|
|
198
205
|
const triggerState = overflow.some((item) => getEntryState(item.key) === ChartMarkState.ACTIVE) ? ChartMarkState.ACTIVE : ChartMarkState.MUTED;
|
|
206
|
+
/** The collapsed entries: toggles on a filterable chart (in a Popover), read-only otherwise. */
|
|
207
|
+
const overflowList = /* @__PURE__ */ jsx(OverflowList, { children: overflow.map((item) => /* @__PURE__ */ jsx(Entry, {
|
|
208
|
+
item,
|
|
209
|
+
swatch,
|
|
210
|
+
isVertical: true,
|
|
211
|
+
state: ChartMarkState.ACTIVE,
|
|
212
|
+
isPinned: isEntryPinned?.(item.key) ?? false,
|
|
213
|
+
onEnter: () => onItemEnter(item.key),
|
|
214
|
+
onLeave: onItemLeave,
|
|
215
|
+
onClick: onItemClick && ((isAdditive) => onItemClick(item.key, isAdditive))
|
|
216
|
+
}, item.key)) });
|
|
217
|
+
const overflowTrigger = /* @__PURE__ */ jsx("button", {
|
|
218
|
+
type: "button",
|
|
219
|
+
className: TRIGGER_CSS,
|
|
220
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
221
|
+
size: TextSize.BODY_SM,
|
|
222
|
+
variant: TextVariant.SECONDARY,
|
|
223
|
+
children: `+${overflow.length} more`
|
|
224
|
+
})
|
|
225
|
+
});
|
|
199
226
|
const variables = {
|
|
200
227
|
"--gx-chart-legend-inset": `${inset}px`,
|
|
201
228
|
...isVertical && extent > 0 && isFixedExtent && { "--gx-chart-legend-extent": `${extent}px` }
|
|
@@ -251,26 +278,18 @@ function ChartLegend({ items, placement, swatch, inset, extent = 0, isFixedExten
|
|
|
251
278
|
0
|
|
252
279
|
],
|
|
253
280
|
className: cx(ENTRY_CSS, CHART_MARK_STATE_TO_CSS_MAP[triggerState]),
|
|
254
|
-
children: /* @__PURE__ */ jsx(
|
|
281
|
+
children: onItemClick ? /* @__PURE__ */ jsx(Popover, {
|
|
282
|
+
trigger: PopoverTrigger.CLICK,
|
|
283
|
+
placement: isVertical ? Placement.RIGHT_START : Placement.TOP_START,
|
|
284
|
+
body: /* @__PURE__ */ jsx(Box, {
|
|
285
|
+
padding: [8, 12],
|
|
286
|
+
children: overflowList
|
|
287
|
+
}),
|
|
288
|
+
children: overflowTrigger
|
|
289
|
+
}) : /* @__PURE__ */ jsx(Tooltip, {
|
|
255
290
|
placement: isVertical ? Placement.RIGHT : Placement.TOP,
|
|
256
|
-
body:
|
|
257
|
-
|
|
258
|
-
swatch,
|
|
259
|
-
isVertical: true,
|
|
260
|
-
state: ChartMarkState.ACTIVE,
|
|
261
|
-
isPinned: isEntryPinned?.(item.key) ?? false,
|
|
262
|
-
onEnter: () => onItemEnter(item.key),
|
|
263
|
-
onLeave: onItemLeave
|
|
264
|
-
}, item.key)) }),
|
|
265
|
-
children: /* @__PURE__ */ jsx("button", {
|
|
266
|
-
type: "button",
|
|
267
|
-
className: TRIGGER_CSS,
|
|
268
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
269
|
-
size: TextSize.BODY_SM,
|
|
270
|
-
variant: TextVariant.SECONDARY,
|
|
271
|
-
children: `+${overflow.length} more`
|
|
272
|
-
})
|
|
273
|
-
})
|
|
291
|
+
body: overflowList,
|
|
292
|
+
children: overflowTrigger
|
|
274
293
|
})
|
|
275
294
|
}),
|
|
276
295
|
hasFilterSlot && /* @__PURE__ */ jsx(FilterSlot, {
|
|
@@ -99,8 +99,10 @@ export declare const CHART_TOOLTIP_MAX_ROWS = 8;
|
|
|
99
99
|
export declare const CHART_LEGEND_SIDE_GAP: number;
|
|
100
100
|
/** @internal Height a side legend gives up to its filter chips: the 8px top padding and a 20px `Chip SMALL`. */
|
|
101
101
|
export declare const CHART_LEGEND_FILTER_EXTENT: number;
|
|
102
|
-
/** @internal Widest the filter chips grow (one or two) before their labels truncate
|
|
102
|
+
/** @internal Widest the filter chips grow (one or two) before their labels truncate. */
|
|
103
103
|
export declare const CHART_LEGEND_FILTER_MAX_WIDTH = 240;
|
|
104
|
+
/** @internal Room a bottom legend always keeps for its filter chips, so pinning never moves an entry; the chips take more, up to the max, when the entries leave it. */
|
|
105
|
+
export declare const CHART_LEGEND_FILTER_MIN_WIDTH = 120;
|
|
104
106
|
/** @internal Height cap of the "+N more" legend list (about eight entries) before it scrolls. */
|
|
105
107
|
export declare const CHART_LEGEND_OVERFLOW_MAX_HEIGHT = 208;
|
|
106
108
|
/** @internal 2:1, the aspect-ratio fallback of cartesian charts and PieChart. */
|
package/dist/charts/constants.js
CHANGED
|
@@ -109,11 +109,13 @@ var CHART_TOOLTIP_MAX_ROWS = 8;
|
|
|
109
109
|
var CHART_LEGEND_SIDE_GAP = px(SPACE[16]);
|
|
110
110
|
/** @internal Height a side legend gives up to its filter chips: the 8px top padding and a 20px `Chip SMALL`. */
|
|
111
111
|
var CHART_LEGEND_FILTER_EXTENT = px(SPACE[8]) + px(CONTROL_SIZE.xSmall);
|
|
112
|
-
/** @internal Widest the filter chips grow (one or two) before their labels truncate
|
|
112
|
+
/** @internal Widest the filter chips grow (one or two) before their labels truncate. */
|
|
113
113
|
var CHART_LEGEND_FILTER_MAX_WIDTH = 240;
|
|
114
|
+
/** @internal Room a bottom legend always keeps for its filter chips, so pinning never moves an entry; the chips take more, up to the max, when the entries leave it. */
|
|
115
|
+
var CHART_LEGEND_FILTER_MIN_WIDTH = 120;
|
|
114
116
|
/** @internal Height cap of the "+N more" legend list (about eight entries) before it scrolls. */
|
|
115
117
|
var CHART_LEGEND_OVERFLOW_MAX_HEIGHT = 208;
|
|
116
118
|
/** @internal 2:1, the aspect-ratio fallback of cartesian charts and PieChart. */
|
|
117
119
|
var CHART_DEFAULT_ASPECT_RATIO = 2;
|
|
118
120
|
//#endregion
|
|
119
|
-
export { AREA_FILL_OPACITY, AREA_STACKED_FILL_OPACITY, AUTO_INSET_LEFT_STEP, AXIS_LABEL_GAP, AXIS_TITLE_BAND, AXIS_TITLE_GAP, BAR_GAP_RATIO, BAR_RADIUS, BAR_RADIUS_NARROW, CAPTION_CHAR_WIDTH_PX, CAPTION_LINE, CATEGORY_AXIS_LABEL_GAP, CATEGORY_AXIS_LABEL_HEIGHT, CATEGORY_GAP_RATIO, CHART_DEFAULT_ASPECT_RATIO, CHART_LEGEND_FILTER_EXTENT, CHART_LEGEND_FILTER_MAX_WIDTH, CHART_LEGEND_OVERFLOW_MAX_HEIGHT, CHART_LEGEND_SIDE_GAP, CHART_MARK_OPACITY_ACTIVE, CHART_MARK_OPACITY_DIMMED, CHART_MARK_OPACITY_MUTED, CHART_TOOLTIP_MAX_ROWS, CHART_TOOLTIP_OFFSET, DEFAULT_VALUE_TICK_COUNT, GRID_LINE_BLEED, HEATMAP_CELL_GAP_RATIO, LINE_DASH, LINE_POINT_RADIUS, LINE_STROKE_WIDTH, MAX_AUTO_INSET_LEFT, MAX_BAR_GAP, MAX_CATEGORY_GAP, MAX_HEATMAP_CELL_GAP, MIN_AUTO_INSET_LEFT, MIN_BAR_GAP, MIN_BAR_LENGTH, MIN_CATEGORY_GAP, MIN_CATEGORY_LABEL_GAP, MIN_HEATMAP_CELL_GAP, MIN_VALUE_TICK_SPACING, NARROW_BAR_WIDTH, PIE_SLICE_GAP, PLOT_INSET_BOTTOM, PLOT_INSET_RIGHT, PLOT_INSET_TOP, RADIAL_PLOT_INSET, STACK_SEGMENT_GAP, VALUE_AXIS_LABEL_HEIGHT, VALUE_AXIS_TICK_GAP };
|
|
121
|
+
export { AREA_FILL_OPACITY, AREA_STACKED_FILL_OPACITY, AUTO_INSET_LEFT_STEP, AXIS_LABEL_GAP, AXIS_TITLE_BAND, AXIS_TITLE_GAP, BAR_GAP_RATIO, BAR_RADIUS, BAR_RADIUS_NARROW, CAPTION_CHAR_WIDTH_PX, CAPTION_LINE, CATEGORY_AXIS_LABEL_GAP, CATEGORY_AXIS_LABEL_HEIGHT, CATEGORY_GAP_RATIO, CHART_DEFAULT_ASPECT_RATIO, CHART_LEGEND_FILTER_EXTENT, CHART_LEGEND_FILTER_MAX_WIDTH, CHART_LEGEND_FILTER_MIN_WIDTH, CHART_LEGEND_OVERFLOW_MAX_HEIGHT, CHART_LEGEND_SIDE_GAP, CHART_MARK_OPACITY_ACTIVE, CHART_MARK_OPACITY_DIMMED, CHART_MARK_OPACITY_MUTED, CHART_TOOLTIP_MAX_ROWS, CHART_TOOLTIP_OFFSET, DEFAULT_VALUE_TICK_COUNT, GRID_LINE_BLEED, HEATMAP_CELL_GAP_RATIO, LINE_DASH, LINE_POINT_RADIUS, LINE_STROKE_WIDTH, MAX_AUTO_INSET_LEFT, MAX_BAR_GAP, MAX_CATEGORY_GAP, MAX_HEATMAP_CELL_GAP, MIN_AUTO_INSET_LEFT, MIN_BAR_GAP, MIN_BAR_LENGTH, MIN_CATEGORY_GAP, MIN_CATEGORY_LABEL_GAP, MIN_HEATMAP_CELL_GAP, MIN_VALUE_TICK_SPACING, NARROW_BAR_WIDTH, PIE_SLICE_GAP, PLOT_INSET_BOTTOM, PLOT_INSET_RIGHT, PLOT_INSET_TOP, RADIAL_PLOT_INSET, STACK_SEGMENT_GAP, VALUE_AXIS_LABEL_HEIGHT, VALUE_AXIS_TICK_GAP };
|