@datalayer/primer-addons 1.0.39 → 1.0.40

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.
Files changed (36) hide show
  1. package/lib/components/box/boxCss.js +17 -1
  2. package/lib/components/box/boxTokens.d.ts +2 -1
  3. package/lib/components/box/boxTokens.js +2 -1
  4. package/lib/components/card/Card.d.ts +119 -5
  5. package/lib/components/card/Card.js +60 -46
  6. package/lib/components/card/Card.stories.d.ts +6 -0
  7. package/lib/components/card/Card.stories.js +26 -0
  8. package/lib/components/entity-avatar/EntityAvatar.d.ts +73 -0
  9. package/lib/components/entity-avatar/EntityAvatar.js +63 -0
  10. package/lib/components/entity-avatar/index.d.ts +1 -0
  11. package/lib/components/entity-avatar/index.js +5 -0
  12. package/lib/components/hover-card/HoverCard.d.ts +63 -0
  13. package/lib/components/hover-card/HoverCard.js +55 -0
  14. package/lib/components/hover-card/HoverCardAnchor.d.ts +33 -0
  15. package/lib/components/hover-card/HoverCardAnchor.js +26 -0
  16. package/lib/components/hover-card/HoverCardDetails.d.ts +36 -0
  17. package/lib/components/hover-card/HoverCardDetails.js +65 -0
  18. package/lib/components/hover-card/HoverCardLayer.d.ts +34 -0
  19. package/lib/components/hover-card/HoverCardLayer.js +57 -0
  20. package/lib/components/hover-card/index.d.ts +12 -0
  21. package/lib/components/hover-card/index.js +16 -0
  22. package/lib/components/hover-card/useHoverCard.d.ts +57 -0
  23. package/lib/components/hover-card/useHoverCard.js +200 -0
  24. package/lib/components/hover-card/usePrefersReducedMotion.d.ts +10 -0
  25. package/lib/components/hover-card/usePrefersReducedMotion.js +28 -0
  26. package/lib/components/index.d.ts +2 -0
  27. package/lib/components/index.js +2 -0
  28. package/lib/theme/css/createThemeCSSVars.d.ts +18 -1
  29. package/lib/theme/css/createThemeCSSVars.js +17 -1
  30. package/lib/theme/css/primerComponentsCss.d.ts +47 -0
  31. package/lib/theme/css/primerComponentsCss.js +72 -0
  32. package/lib/theme/index.d.ts +1 -0
  33. package/lib/theme/index.js +1 -0
  34. package/lib/theme/themes/loopThemeStyles.d.ts +4 -31
  35. package/lib/theme/themes/loopThemeStyles.js +17 -44
  36. package/package.json +1 -1
@@ -300,6 +300,22 @@ const UNITLESS = new Set([
300
300
  ]);
301
301
  /** A camelCased property as CSS: `WebkitLineClamp` is `-webkit-line-clamp`; `--x` stays. */
302
302
  const kebab = (key) => key.startsWith('--') ? key : key.replace(/^(Webkit|Moz|ms)(?=[A-Z])/, m => `-${m.toLowerCase()}`).replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
303
+ /**
304
+ * The keys of a style, with the resets first.
305
+ *
306
+ * `all` is a shorthand that sets *every* property: written after `width` it
307
+ * undoes it, whatever the author meant. A grown card's picture collapsed to
308
+ * 40px that way — `<Box as="button" display="block" width="100%" all="unset">`
309
+ * — and the artwork of the Library's hover card was a sliver at its left
310
+ * (seen 2026-10-09). An author may write the props in any order; a reset is
311
+ * emitted before what it would reset.
312
+ */
313
+ const RESETS = ['all'];
314
+ const keysOf = (style) => {
315
+ const keys = Object.keys(style);
316
+ const resets = keys.filter(key => RESETS.includes(key));
317
+ return resets.length === 0 ? keys : [...resets, ...keys.filter(key => !resets.includes(key))];
318
+ };
303
319
  /**
304
320
  * A style's declarations. With `raw` (an `sx` object), a key that is no
305
321
  * style prop is CSS as written — its number in pixels unless the property
@@ -307,7 +323,7 @@ const kebab = (key) => key.startsWith('--') ? key : key.replace(/^(Webkit|Moz|ms
307
323
  */
308
324
  function blockOf(style, raw = false) {
309
325
  const block = [];
310
- for (const key of Object.keys(style)) {
326
+ for (const key of keysOf(style)) {
311
327
  const value = style[key];
312
328
  if (key in BOX_STYLE_PROPS) {
313
329
  addDeclarations(block, key, value);
@@ -79,7 +79,7 @@ export declare const BOX_SPACE: readonly ["0", "4px", "8px", "16px", "24px", "32
79
79
  export declare const BOX_FONT_SIZES: readonly ["12px", "14px", "16px", "20px", "24px", "32px", "40px", "48px", "56px"];
80
80
  /** Primer's radii by index (`borderRadius={2}` is 6px). */
81
81
  export declare const BOX_RADII: readonly ["0", "3px", "6px", "100px"];
82
- /** Radii by name: Primer's, and the theme's shapes (LOOP T-03). */
82
+ /** Radii by name: Primer's, and the theme's shapes (LOOP T-03), an overlay's among them. */
83
83
  export declare const BOX_RADIUS_VARS: {
84
84
  readonly small: "--borderRadius-small";
85
85
  readonly medium: "--borderRadius-medium";
@@ -89,6 +89,7 @@ export declare const BOX_RADIUS_VARS: {
89
89
  readonly card: "--theme-radius-card";
90
90
  readonly bubble: "--theme-radius-bubble";
91
91
  readonly frame: "--theme-radius-frame";
92
+ readonly overlay: "--theme-radius-overlay";
92
93
  };
93
94
  export type BoxRadiusToken = keyof typeof BOX_RADIUS_VARS;
94
95
  /** Primer's border widths by index. */
@@ -81,7 +81,7 @@ export const BOX_SPACE = ['0', '4px', '8px', '16px', '24px', '32px', '40px', '48
81
81
  export const BOX_FONT_SIZES = ['12px', '14px', '16px', '20px', '24px', '32px', '40px', '48px', '56px'];
82
82
  /** Primer's radii by index (`borderRadius={2}` is 6px). */
83
83
  export const BOX_RADII = ['0', '3px', '6px', '100px'];
84
- /** Radii by name: Primer's, and the theme's shapes (LOOP T-03). */
84
+ /** Radii by name: Primer's, and the theme's shapes (LOOP T-03), an overlay's among them. */
85
85
  export const BOX_RADIUS_VARS = {
86
86
  small: '--borderRadius-small',
87
87
  medium: '--borderRadius-medium',
@@ -91,6 +91,7 @@ export const BOX_RADIUS_VARS = {
91
91
  card: '--theme-radius-card',
92
92
  bubble: '--theme-radius-bubble',
93
93
  frame: '--theme-radius-frame',
94
+ overlay: '--theme-radius-overlay',
94
95
  };
95
96
  /** Primer's border widths by index. */
96
97
  export const BOX_BORDER_WIDTHS = ['0', '1px'];
@@ -1,9 +1,93 @@
1
+ /**
2
+ * `Card`: a surface that follows the theme.
3
+ *
4
+ * It is this package's own `Box`, so every colour, shadow and corner is one
5
+ * of the theme's variables: the ground is `canvas.default` (a card is never
6
+ * the page showing through), the hairline `border.default`, the shadow one of
7
+ * Primer's (`shadow.small`…, which each colour mode sets for itself — no
8
+ * literal `rgba` that reads as a smudge on a dark page), and the corner the
9
+ * theme's card corner unless `rounded` says otherwise.
10
+ *
11
+ * Every `Box` prop passes through and wins over the card's defaults (`bg`,
12
+ * `p`, `as`, …), and `sx` wins over both, as it does on `Box`.
13
+ *
14
+ * - `interactive` — a card that is clicked: a pointer, a border that takes
15
+ * the accent and a lifted shadow on hover, a focus ring for the keyboard.
16
+ * It always has a border, so a card rendered `as="button"` shows the
17
+ * card's hairline rather than the browser's button border, and a button
18
+ * reads its text left to right in the page's font.
19
+ * - `variant` — the card's flavour: `default`, `subtle`, `inset`, or a
20
+ * tone (`accent`, `success`, `attention`, `danger`), each a ground and a
21
+ * hairline from the theme.
22
+ * - `dashed` — a dashed hairline, for a placeholder or a "create new" card;
23
+ * `disabled` — quieter, no pointer, no hover;
24
+ * - `accent` — a colour along the top edge, a token or the item's own;
25
+ * - slots: `Card.Header`, `Card.Cover` (image, gradient or colour, a glyph,
26
+ * a top-right accessory), `Card.Image`, `Card.Content`, `Card.Footer`
27
+ * (the metadata line, over a hairline) and `Card.Actions`; the slots take
28
+ * `Box` props over their defaults.
29
+ * - `selected` — the card that is chosen among others: an accent border on
30
+ * an accent wash. It says nothing to assistive technology by itself: the
31
+ * caller sets `aria-pressed` or `aria-selected`, as its role requires.
32
+ */
1
33
  import React from "react";
2
- import { BoxProps } from "@primer/react";
3
- export type CardProps = Omit<BoxProps, 'border'> & {
4
- rounded?: 'small' | 'medium' | 'large' | 'full' | number;
34
+ import { type BoxColorToken, type BoxProps, type BoxPseudoProps, type BoxRadiusToken, type BoxStyleProps } from "../box/Box";
35
+ /**
36
+ * `Box`'s props, but `border` is the card's switch rather than a CSS value.
37
+ * Spelled out rather than `Omit<BoxProps, 'border'>`: `BoxProps` has an index
38
+ * signature, and `Omit` over one drops every named key (`children` would be
39
+ * `unknown`).
40
+ */
41
+ type CardBoxProps = Omit<BoxStyleProps, 'border'> & BoxPseudoProps & Omit<React.HTMLAttributes<HTMLElement>, keyof BoxStyleProps | 'as'> & {
42
+ as?: React.ElementType;
43
+ sx?: BoxProps['sx'];
44
+ className?: string;
45
+ style?: React.CSSProperties;
46
+ children?: React.ReactNode;
47
+ [prop: string]: unknown;
48
+ };
49
+ /**
50
+ * A card's flavour: its ground and, when it is bordered, its hairline.
51
+ *
52
+ * - `default` — the page's own surface, `canvas.default`;
53
+ * - `subtle` — a quieter ground, `canvas.subtle`, for a card among cards
54
+ * or one inside a panel;
55
+ * - `inset` — sunk into the page, `canvas.inset`, for code, logs, a prompt;
56
+ * - `accent`, `success`, `attention`, `danger` — a note in that tone: the
57
+ * tone's wash with the tone's muted hairline.
58
+ */
59
+ export type CardVariant = 'default' | 'subtle' | 'inset' | 'accent' | 'success' | 'attention' | 'danger';
60
+ export type CardProps = CardBoxProps & {
61
+ /**
62
+ * The corner: a radius by name — Primer's (`small`, `medium`, `large`,
63
+ * `full`) or the theme's shapes (`control`, `card`, `bubble`, `frame`,
64
+ * `overlay` for a panel floating over the page) —
65
+ * or an index of Primer's radii. The theme's `card` corner by default.
66
+ */
67
+ rounded?: BoxRadiusToken | number;
68
+ /** The card's flavour, `default` by default; see {@link CardVariant}. */
69
+ variant?: CardVariant;
70
+ /** A hairline around the card, `border.default`. */
5
71
  border?: boolean;
6
- shadow?: 'small' | 'medium' | 'large' | 'extraLarge';
72
+ /** Primer's shadows by name; `none` for a card that lies flat. `small` by default. */
73
+ shadow?: 'none' | 'small' | 'medium' | 'large' | 'extraLarge';
74
+ /** A card that is clicked: hover and focus states, a pointer, a border. */
75
+ interactive?: boolean;
76
+ /** The chosen card among others: an accent border on an accent wash. */
77
+ selected?: boolean;
78
+ /** A dashed hairline: a placeholder, a drop zone, a "create new" card. */
79
+ dashed?: boolean;
80
+ /**
81
+ * A card that cannot be used now: quieter, no pointer, no hover. With
82
+ * `interactive`, it also sets `aria-disabled`.
83
+ */
84
+ disabled?: boolean;
85
+ /**
86
+ * A colour along the card's top edge: a theme token (`accent.emphasis`,
87
+ * `success.emphasis`…) or any CSS colour the caller has from its theme,
88
+ * such as an item's own colour.
89
+ */
90
+ accent?: BoxColorToken | (string & {});
7
91
  };
8
92
  export type CardHeaderProps = {
9
93
  /**
@@ -22,15 +106,45 @@ export type CardImageProps = {
22
106
  svg?: string;
23
107
  height: number;
24
108
  };
25
- export type CardContentProps = {
109
+ /** A slot's props: the slot's own defaults, overridden by any `Box` prop. */
110
+ export type CardContentProps = CardBoxProps & {
111
+ children: React.ReactNode;
112
+ };
113
+ /** The card's last line: metadata, chips, an owner, an action. */
114
+ export type CardFooterProps = CardBoxProps & {
26
115
  children: React.ReactNode;
27
116
  };
117
+ /**
118
+ * The card's cover, above its content: an image, or a gradient between two
119
+ * colours, or a theme colour, with an optional glyph centred on it and an
120
+ * accessory (a label, a menu) in its top-right corner.
121
+ */
122
+ export type CardCoverProps = CardBoxProps & {
123
+ /** The cover's height, in pixels. 110 by default. */
124
+ height?: number;
125
+ /** An image URL; it covers the area. */
126
+ image?: string;
127
+ /** A gradient between two colours, top left to bottom right. */
128
+ gradient?: {
129
+ from: string;
130
+ to: string;
131
+ };
132
+ /** The ground under (or instead of) the image or gradient. `neutral.emphasis` by default. */
133
+ color?: BoxColorToken | (string & {});
134
+ /** What sits in the top-right corner: a label, a menu. */
135
+ accessory?: React.ReactNode;
136
+ /** A glyph centred on the cover, drawn in `fg.onEmphasis`. */
137
+ children?: React.ReactNode;
138
+ };
28
139
  export type CardActionsProps = {
29
140
  children: React.ReactNode;
30
141
  };
31
142
  export declare const Card: React.FC<CardProps> & {
32
143
  Header: React.FC<CardHeaderProps>;
144
+ Cover: React.FC<CardCoverProps>;
33
145
  Image: React.FC<CardImageProps>;
34
146
  Content: React.FC<CardContentProps>;
147
+ Footer: React.FC<CardFooterProps>;
35
148
  Actions: React.FC<CardActionsProps>;
36
149
  };
150
+ export {};
@@ -1,62 +1,76 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, IconButton, Text } from "@primer/react";
2
+ import { IconButton, Text } from "@primer/react";
3
+ import { Box, } from "../box/Box";
4
+ const VARIANTS = {
5
+ default: { bg: 'canvas.default', borderColor: 'border.default' },
6
+ subtle: { bg: 'canvas.subtle', borderColor: 'border.default' },
7
+ inset: { bg: 'canvas.inset', borderColor: 'border.default' },
8
+ accent: { bg: 'accent.subtle', borderColor: 'accent.muted' },
9
+ success: { bg: 'success.subtle', borderColor: 'success.muted' },
10
+ attention: { bg: 'attention.subtle', borderColor: 'attention.muted' },
11
+ danger: { bg: 'danger.subtle', borderColor: 'danger.muted' },
12
+ };
3
13
  /**
4
14
  * The corners, read from the theme: each theme sets Primer's radii (loop's
5
15
  * are rounder), and a card left unsaid takes the theme's card corner.
6
16
  */
7
- const roundedVals = {
8
- small: "var(--borderRadius-small)",
9
- medium: "var(--borderRadius-medium)",
10
- large: "var(--borderRadius-large)",
11
- full: "var(--borderRadius-full)",
12
- };
13
- const CARD_RADIUS = "var(--theme-radius-card)";
14
- const shadowVals = {
15
- small: '0 1px 0 rgba(31,35,40,0.04)',
16
- medium: '0 3px 6px rgba(140,149,159,0.15)',
17
- large: '0 8px 24px rgba(140,149,159,0.2)',
18
- extraLarge: '0 12px 28px rgba(140,149,159,0.3)',
17
+ const CARD_RADIUS = 'card';
18
+ const SHADOWS = {
19
+ none: 'none',
20
+ small: 'shadow.small',
21
+ medium: 'shadow.medium',
22
+ large: 'shadow.large',
23
+ extraLarge: 'shadow.extraLarge',
24
+ };
25
+ /** What `interactive` adds: a pointer, the hover and focus states, a button reset. */
26
+ const INTERACTIVE = {
27
+ cursor: 'pointer',
28
+ textAlign: 'left',
29
+ font: 'inherit',
30
+ transition: 'border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease',
31
+ hover: { borderColor: 'accent.emphasis', boxShadow: SHADOWS.medium },
32
+ focusVisible: { outline: '2px solid', outlineColor: 'accent.emphasis', outlineOffset: '2px' },
33
+ reducedMotion: { transition: 'none' },
34
+ };
35
+ /** What `disabled` takes away: the pointer and the hover, at a lower voice. */
36
+ const DISABLED = {
37
+ cursor: 'not-allowed',
38
+ opacity: 0.6,
39
+ hover: {},
19
40
  };
20
41
  export const Card = (props) => {
21
- const { sx, rounded, border, shadow, children, ...otherProps } = props;
22
- return (_jsx(Box, { sx: {
23
- // A column, so the actions stand at the bottom however long the
24
- // text above them: cards side by side end on one line.
25
- display: "flex",
26
- flexDirection: "column",
27
- ...(sx ? sx : undefined),
28
- borderRadius: rounded === undefined
29
- ? CARD_RADIUS
30
- : typeof rounded === "string"
31
- ? roundedVals[rounded]
32
- : rounded,
33
- ...(border ? {
34
- borderWidth: 1,
35
- borderStyle: 'solid',
36
- borderColor: 'border.default'
37
- } : undefined),
38
- ...(shadow ? {
39
- boxShadow: shadowVals[shadow]
40
- } : {
41
- boxShadow: shadowVals['small']
42
- })
43
- }, ...otherProps, children: children }));
42
+ const { rounded, border, shadow = 'small', variant = 'default', interactive, selected, dashed, disabled, accent, children, ...otherProps } = props;
43
+ const outlined = border || interactive || selected || dashed;
44
+ const flavour = VARIANTS[variant];
45
+ return (_jsx(Box
46
+ // A column, so the actions stand at the bottom however long the text
47
+ // above them: cards side by side end on one line.
48
+ , {
49
+ // A column, so the actions stand at the bottom however long the text
50
+ // above them: cards side by side end on one line.
51
+ display: "flex", flexDirection: "column", bg: selected ? 'accent.subtle' : flavour.bg, color: "fg.default", borderRadius: rounded ?? CARD_RADIUS, boxShadow: SHADOWS[shadow], ...(outlined ? {
52
+ border: '1px solid',
53
+ borderColor: selected ? 'accent.emphasis' : flavour.borderColor,
54
+ } : undefined), ...(dashed ? { borderStyle: 'dashed' } : undefined), ...(accent ? { borderTop: '3px solid', borderTopColor: accent } : undefined), ...(interactive ? INTERACTIVE : undefined), ...(disabled ? DISABLED : undefined), ...(interactive && disabled ? { 'aria-disabled': true } : undefined), ...otherProps, children: children }));
44
55
  };
45
56
  Card.Header = (props) => {
46
57
  const { title, description, leadingVisual, action } = props;
47
- return _jsxs(Box, { display: "flex", alignItems: "center", sx: { p: 3 }, children: [leadingVisual && _jsx(Box, { sx: { mr: 3 }, children: _jsx(IconButton, { size: "medium", icon: leadingVisual, "aria-label": "" }) }), _jsxs(Box, { sx: { flexGrow: 1 }, children: [_jsx(Text, { as: "div", display: "block", children: title }), _jsx(Text, { display: "block", color: "fg.muted", children: description })] }), action && _jsx(Box, { children: action })] });
58
+ return _jsxs(Box, { display: "flex", alignItems: "center", p: 3, children: [leadingVisual && _jsx(Box, { mr: 3, children: _jsx(IconButton, { size: "medium", icon: leadingVisual, "aria-label": "" }) }), _jsxs(Box, { flexGrow: 1, children: [_jsx(Text, { as: "div", display: "block", children: title }), _jsx(Text, { display: "block", color: "fg.muted", children: description })] }), action && _jsx(Box, { children: action })] });
48
59
  };
49
60
  Card.Image = ({ url, image, svg, height }) => {
50
- return (_jsxs(Box, { display: "block", width: "100%", height: `${height}px`, backgroundImage: `url(${url})`, sx: {
51
- backgroundSize: "cover",
52
- backgroundRepeat: "no-repeat",
53
- backgroundPosition: "center",
54
- objectFit: "cover"
55
- }, children: [image && _jsx("img", { src: image, style: { maxHeight: `${height}px` } }), svg && _jsx("img", { src: `data:image/svg+xml;utf8,${svg}`, style: { maxHeight: height } })] }));
61
+ return (_jsxs(Box, { display: "block", width: "100%", height: `${height}px`, backgroundImage: url ? `url(${url})` : undefined, backgroundSize: "cover", backgroundRepeat: "no-repeat", backgroundPosition: "center", objectFit: "cover", children: [image && _jsx("img", { src: image, style: { maxHeight: `${height}px` } }), svg && _jsx("img", { src: `data:image/svg+xml;utf8,${svg}`, style: { maxHeight: height } })] }));
62
+ };
63
+ Card.Cover = ({ height = 110, image, gradient, color = 'neutral.emphasis', accessory, children, ...rest }) => {
64
+ return (_jsxs(Box, { position: "relative", width: "100%", height: `${height}px`, flexShrink: 0, display: "flex", alignItems: "center", justifyContent: "center", bg: color, backgroundImage: image
65
+ ? `url(${image})`
66
+ : gradient ? `linear-gradient(135deg, ${gradient.from} 0%, ${gradient.to} 100%)` : undefined, backgroundSize: "cover", backgroundPosition: "center", color: "fg.onEmphasis", fontSize: 4, fontWeight: "semibold", ...rest, children: [children, accessory && (_jsx(Box, { position: "absolute", top: 2, right: 2, display: "flex", alignItems: "center", gap: 1, children: accessory }))] }));
67
+ };
68
+ Card.Content = ({ children, ...rest }) => {
69
+ return (_jsx(Box, { display: "block", p: 3, ...rest, children: children }));
56
70
  };
57
- Card.Content = ({ children }) => {
58
- return (_jsx(Box, { display: "block", sx: { p: 3 }, children: children }));
71
+ Card.Footer = ({ children, ...rest }) => {
72
+ return (_jsx(Box, { display: "flex", alignItems: "center", gap: 2, flexWrap: "wrap", mt: "auto", px: 3, py: 2, borderTop: "1px solid", borderColor: "border.muted", ...rest, children: children }));
59
73
  };
60
74
  Card.Actions = ({ children }) => {
61
- return _jsx(Box, { display: "block", sx: { p: 3, mt: "auto" }, children: children });
75
+ return _jsx(Box, { display: "block", p: 3, mt: "auto", children: children });
62
76
  };
@@ -4,8 +4,10 @@ declare const meta: {
4
4
  title: string;
5
5
  component: import("react").FC<CardProps> & {
6
6
  Header: React.FC<import("./Card").CardHeaderProps>;
7
+ Cover: React.FC<import("./Card").CardCoverProps>;
7
8
  Image: React.FC<import("./Card").CardImageProps>;
8
9
  Content: React.FC<import("./Card").CardContentProps>;
10
+ Footer: React.FC<import("./Card").CardFooterProps>;
9
11
  Actions: React.FC<import("./Card").CardActionsProps>;
10
12
  };
11
13
  tags: string[];
@@ -18,3 +20,7 @@ type Story = StoryObj<typeof meta>;
18
20
  export declare const CardDay: Story;
19
21
  export declare const CardDaySvg: Story;
20
22
  export declare const CardNight: Story;
23
+ /** A card that is clicked: rendered as a button, with hover and focus states. */
24
+ export declare const CardInteractive: Story;
25
+ /** The chosen card among others: an accent border on an accent wash. */
26
+ export declare const CardSelected: Story;
@@ -49,3 +49,29 @@ export const CardNight = {
49
49
  },
50
50
  render: (args) => _jsxs(ThemedCard, { ...args, colorMode: "night", children: [_jsx(Card.Header, { leadingVisual: ProjectIcon, title: "Shrimp and Chorizo Paella", description: "September 14, 2016", action: _jsx(IconButton, { "aria-label": "Menu", onClick: () => alert("Menu"), icon: ThreeBarsIcon }) }), _jsx(Card.Image, { height: 200, url: "https://images.unsplash.com/photo-1623961990059-28356e226a77?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb&dl=douglas-lopez-4B0cLMtJxWw-unsplash.jpg&w=640" }), _jsxs(Card.Content, { children: [_jsx(Text, { display: "block", fontSize: 22, children: "Paella" }), _jsx(Text, { color: "fg.muted", children: "This impressive paella is a perfect party dish and a fun meal to cook together with your guests. Add 1 cup of frozen peas along with the mussels, if you like." })] }), _jsx(Card.Actions, { children: _jsxs(ButtonGroup, { children: [_jsx(Button, { variant: 'invisible', onClick: () => alert("Share it on Socials!"), children: "Share" }), _jsx(Button, { variant: 'invisible', onClick: () => alert("Learn more about Paella"), children: "Learn More" })] }) })] })
51
51
  };
52
+ /** A card that is clicked: rendered as a button, with hover and focus states. */
53
+ export const CardInteractive = {
54
+ args: {
55
+ as: "button",
56
+ type: "button",
57
+ interactive: true,
58
+ shadow: "none",
59
+ p: 3,
60
+ sx: { maxWidth: 360 },
61
+ },
62
+ render: (args) => _jsxs(ThemedCard, { ...args, onClick: () => alert("Opened"), children: [_jsx(Text, { display: "block", fontWeight: "bold", children: "Tutor" }), _jsx(Text, { color: "fg.muted", children: "Author lessons, exercises and assignments, and follow the courses you give and take." })] })
63
+ };
64
+ /** The chosen card among others: an accent border on an accent wash. */
65
+ export const CardSelected = {
66
+ args: {
67
+ interactive: true,
68
+ selected: true,
69
+ shadow: "none",
70
+ role: "button",
71
+ tabIndex: 0,
72
+ "aria-pressed": true,
73
+ p: 3,
74
+ sx: { maxWidth: 360 },
75
+ },
76
+ render: (args) => _jsxs(ThemedCard, { ...args, children: [_jsx(Text, { display: "block", fontWeight: "bold", children: "Selected example" }), _jsx(Text, { color: "fg.muted", children: "The one picked among its siblings." })] })
77
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `EntityAvatar`: the face of a person, an agent, an app or a space, drawn
3
+ * by the theme.
4
+ *
5
+ * One of three things, in this order:
6
+ *
7
+ * - an **image** (`src`), cropped to the shape — and, if it fails to load,
8
+ * what would have been drawn without it;
9
+ * - a **glyph** (`children`): an emoji's drawing, an icon — whatever the
10
+ * caller draws, on the avatar's ground;
11
+ * - the **initials** of `name`.
12
+ *
13
+ * Its ground is the theme's: a tone's wash with the tone's foreground
14
+ * (`ground="subtle"`, the default), the tone's solid colour with
15
+ * `fg.onEmphasis` (`ground="emphasis"`), the page's own surface with a
16
+ * hairline (`ground="canvas"`), or the entity's own colour (`color`), as a
17
+ * profile's cards give one, with `fg.onEmphasis`.
18
+ *
19
+ * Its shape is the theme's too: a `circle` for a person, `rounded` for
20
+ * anything else — the theme's medium corner (rounder in `loop`), never more
21
+ * than a little over a quarter of the avatar, so a small one stays a square
22
+ * with soft corners rather than turning into a circle.
23
+ *
24
+ * Not Primer's `Avatar` (an image only, in a circle or a fixed square).
25
+ */
26
+ import { type CSSProperties, type ElementType, type HTMLAttributes, type JSX, type ReactNode } from 'react';
27
+ import { type BoxProps, type BoxPseudoProps, type BoxStyleProps } from '../box/Box';
28
+ export type EntityAvatarShape = 'circle' | 'rounded';
29
+ export type EntityAvatarTone = 'accent' | 'success' | 'attention' | 'severe' | 'danger' | 'done' | 'sponsors' | 'neutral';
30
+ export type EntityAvatarGround = 'subtle' | 'emphasis' | 'canvas';
31
+ /**
32
+ * `Box`'s props but `color` and `children`, which are the avatar's own.
33
+ * Spelled out rather than `Omit<BoxProps, …>`: `BoxProps` has an index
34
+ * signature, and `Omit` over one drops every named key.
35
+ */
36
+ type EntityAvatarBoxProps = Omit<BoxStyleProps, 'color'> & BoxPseudoProps & Omit<HTMLAttributes<HTMLElement>, keyof BoxStyleProps | 'as' | 'color' | 'children'> & {
37
+ as?: ElementType;
38
+ sx?: BoxProps['sx'];
39
+ className?: string;
40
+ style?: CSSProperties;
41
+ [prop: string]: unknown;
42
+ };
43
+ export type EntityAvatarProps = EntityAvatarBoxProps & {
44
+ /** An image URL; it covers the avatar. */
45
+ src?: string;
46
+ /** What the avatar is of, for assistive technology; the name by default. */
47
+ alt?: string;
48
+ /** A glyph drawn on the ground: an emoji's drawing, an icon. */
49
+ children?: ReactNode;
50
+ /** The entity's name: its initials when there is neither image nor glyph. */
51
+ name?: string;
52
+ /** Its edge, in pixels. 32 by default. */
53
+ size?: number;
54
+ /** `circle` for a person, `rounded` (the theme's corner) for the rest. */
55
+ shape?: EntityAvatarShape;
56
+ /** The tone of its ground. `accent` by default. */
57
+ tone?: EntityAvatarTone;
58
+ /** How the ground is drawn: the tone's wash, its solid colour, or the page's. */
59
+ ground?: EntityAvatarGround;
60
+ /**
61
+ * The entity's own colour, as the theme gives it — a palette colour, a
62
+ * token — drawn solid under `fg.onEmphasis`; it overrides `tone`.
63
+ */
64
+ color?: string;
65
+ /** A hairline just outside the edge, for an avatar on a ground like its own. */
66
+ ring?: boolean;
67
+ };
68
+ /** The theme's corner for an avatar that is not a person's. */
69
+ export declare const ENTITY_AVATAR_RADIUS = "min(var(--borderRadius-medium), 28%)";
70
+ /** Up to two letters: the first of the first two words. */
71
+ export declare const initialsOf: (name?: string) => string;
72
+ export declare function EntityAvatar({ src, alt, children, name, size, shape, tone, ground, color, ring, ...rest }: EntityAvatarProps): JSX.Element;
73
+ export default EntityAvatar;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `EntityAvatar`: the face of a person, an agent, an app or a space, drawn
8
+ * by the theme.
9
+ *
10
+ * One of three things, in this order:
11
+ *
12
+ * - an **image** (`src`), cropped to the shape — and, if it fails to load,
13
+ * what would have been drawn without it;
14
+ * - a **glyph** (`children`): an emoji's drawing, an icon — whatever the
15
+ * caller draws, on the avatar's ground;
16
+ * - the **initials** of `name`.
17
+ *
18
+ * Its ground is the theme's: a tone's wash with the tone's foreground
19
+ * (`ground="subtle"`, the default), the tone's solid colour with
20
+ * `fg.onEmphasis` (`ground="emphasis"`), the page's own surface with a
21
+ * hairline (`ground="canvas"`), or the entity's own colour (`color`), as a
22
+ * profile's cards give one, with `fg.onEmphasis`.
23
+ *
24
+ * Its shape is the theme's too: a `circle` for a person, `rounded` for
25
+ * anything else — the theme's medium corner (rounder in `loop`), never more
26
+ * than a little over a quarter of the avatar, so a small one stays a square
27
+ * with soft corners rather than turning into a circle.
28
+ *
29
+ * Not Primer's `Avatar` (an image only, in a circle or a fixed square).
30
+ */
31
+ import { useState } from 'react';
32
+ import { Box } from '../box/Box';
33
+ /** The theme's corner for an avatar that is not a person's. */
34
+ export const ENTITY_AVATAR_RADIUS = 'min(var(--borderRadius-medium), 28%)';
35
+ /** Up to two letters: the first of the first two words. */
36
+ export const initialsOf = (name) => (name ?? '')
37
+ .trim()
38
+ .split(/[\s._-]+/)
39
+ .filter(Boolean)
40
+ .slice(0, 2)
41
+ .map(word => word[0].toUpperCase())
42
+ .join('');
43
+ const wash = (tone) => tone === 'neutral'
44
+ ? { bg: 'neutral.muted', color: 'fg.default' }
45
+ : { bg: `${tone}.subtle`, color: `${tone}.fg` };
46
+ const solid = (tone) => ({
47
+ bg: tone === 'neutral' ? 'neutral.emphasis' : `${tone}.emphasis`,
48
+ color: 'fg.onEmphasis',
49
+ });
50
+ export function EntityAvatar({ src, alt, children, name, size = 32, shape = 'circle', tone = 'accent', ground = 'subtle', color, ring = false, ...rest }) {
51
+ const [failed, setFailed] = useState(false);
52
+ const label = alt ?? name;
53
+ const paint = color
54
+ ? { bg: color, color: 'fg.onEmphasis' }
55
+ : ground === 'emphasis'
56
+ ? solid(tone)
57
+ : ground === 'canvas'
58
+ ? { bg: 'canvas.default', color: 'fg.default', border: '1px solid', borderColor: 'border.default' }
59
+ : wash(tone);
60
+ const image = src && !failed;
61
+ return (_jsx(Box, { role: "img", "aria-label": label, "data-entity-avatar": shape, width: size, height: size, minWidth: size, display: "inline-flex", alignItems: "center", justifyContent: "center", overflow: "hidden", borderRadius: shape === 'circle' ? '50%' : ENTITY_AVATAR_RADIUS, fontSize: `${Math.max(9, Math.round(size * 0.4))}px`, fontWeight: "semibold", lineHeight: "1", userSelect: "none", boxShadow: ring ? '0 0 0 1px var(--borderColor-default)' : undefined, ...(image ? { bg: 'canvas.subtle' } : paint), ...rest, children: image ? (_jsx(Box, { as: "img", src: src, alt: "", width: size, height: size, objectFit: "cover", display: "block", referrerPolicy: "no-referrer", onError: () => setFailed(true) })) : (children ?? initialsOf(name)) }));
62
+ }
63
+ export default EntityAvatar;
@@ -0,0 +1 @@
1
+ export * from './EntityAvatar';
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright (c) 2021-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ export * from './EntityAvatar';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A card in three sizes, the way a shelf of films is read.
3
+ *
4
+ * A shelf is scanned at a glance, one thing catches the eye, and the reader
5
+ * wants a little more before committing — then, sometimes, a lot more:
6
+ *
7
+ * - the **small card** in the page is the caller's own, wrapped in a
8
+ * `HoverCardAnchor`;
9
+ * - **hovering** it grows this card out of it, covering it (`HoverCardLayer`
10
+ * places it, `useHoverCard` times it): the same picture larger, what to do
11
+ * with it, the whole title and description;
12
+ * - its **chevron** opens the large one, `HoverCardDetails`, over the page.
13
+ *
14
+ * Drawn by the theme: it is a `Card`, so its corner is the theme's card
15
+ * corner (rounder in `loop`, with nothing said here), its ground the
16
+ * overlay's, its hairline and shadow the theme's.
17
+ *
18
+ * @module components/hover-card/HoverCard
19
+ */
20
+ import type { JSX, ReactNode } from 'react';
21
+ /**
22
+ * How much bigger than its anchor the hover card is.
23
+ *
24
+ * Enough that the growth is visible and the artwork gets room; not so much
25
+ * that it stops reading as the same object enlarged.
26
+ */
27
+ export declare const HOVER_CARD_SCALE = 1.45;
28
+ export type HoverCardProps = {
29
+ /** The width of what this grew out of, so the card can be larger. */
30
+ anchorWidth: number;
31
+ /** How much larger; {@link HOVER_CARD_SCALE} by default. */
32
+ scale?: number;
33
+ /** Whether it is being taken away, so it plays the entrance backwards. */
34
+ closing?: boolean;
35
+ /**
36
+ * The picture at the top, drawn at the height given — half the card's
37
+ * width. A function, because only the card knows how wide it is.
38
+ */
39
+ picture?: (height: number) => ReactNode;
40
+ /** The picture is a way in: what pressing it does. */
41
+ onOpen?: () => void;
42
+ /** What pressing the picture is called, for assistive technology. */
43
+ openLabel?: string;
44
+ /** What to do with the thing: buttons, on the left of the chevron. */
45
+ actions?: ReactNode;
46
+ /**
47
+ * Open the large card. Without it there is no third size, and no chevron
48
+ * offering one.
49
+ */
50
+ onExpand?: () => void;
51
+ /** What the chevron is called, for assistive technology. */
52
+ expandLabel?: string;
53
+ /** Its name, on two lines at most. */
54
+ title: ReactNode;
55
+ /** What it is and whose: a line of labels. */
56
+ meta?: ReactNode;
57
+ /** The whole description, which the small card had to cut. */
58
+ description?: ReactNode;
59
+ /** Anything after it: tags, say. */
60
+ children?: ReactNode;
61
+ };
62
+ export declare function HoverCard({ anchorWidth, scale, closing, picture, onOpen, openLabel, actions, onExpand, expandLabel, title, meta, description, children, }: HoverCardProps): JSX.Element;
63
+ export default HoverCard;