@datalayer/primer-addons 1.0.38 → 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 (64) hide show
  1. package/README.md +52 -20
  2. package/lib/components/appearance/AppearanceControls.d.ts +6 -1
  3. package/lib/components/appearance/AppearanceControls.js +7 -3
  4. package/lib/components/appearance/AppearanceControlsWithStore.d.ts +4 -0
  5. package/lib/components/appearance/AppearanceControlsWithStore.js +4 -4
  6. package/lib/components/appearance/CollaboratorPalette.js +7 -20
  7. package/lib/components/box/Box.d.ts +103 -16
  8. package/lib/components/box/Box.js +157 -2
  9. package/lib/components/box/boxCss.d.ts +805 -0
  10. package/lib/components/box/boxCss.js +508 -0
  11. package/lib/components/box/boxTokens.d.ts +130 -0
  12. package/lib/components/box/boxTokens.js +125 -0
  13. package/lib/components/calendar-picker/CalendarPicker.js +2 -1
  14. package/lib/components/card/Card.d.ts +119 -5
  15. package/lib/components/card/Card.js +64 -41
  16. package/lib/components/card/Card.stories.d.ts +6 -0
  17. package/lib/components/card/Card.stories.js +26 -0
  18. package/lib/components/color/ColorSwatch.js +2 -1
  19. package/lib/components/color-picker/ColorPicker.js +8 -4
  20. package/lib/components/date-picker/DatePicker.d.ts +12 -3
  21. package/lib/components/date-picker/DatePicker.js +24 -8
  22. package/lib/components/entity-avatar/EntityAvatar.d.ts +73 -0
  23. package/lib/components/entity-avatar/EntityAvatar.js +63 -0
  24. package/lib/components/entity-avatar/index.d.ts +1 -0
  25. package/lib/components/entity-avatar/index.js +5 -0
  26. package/lib/components/hover-card/HoverCard.d.ts +63 -0
  27. package/lib/components/hover-card/HoverCard.js +55 -0
  28. package/lib/components/hover-card/HoverCardAnchor.d.ts +33 -0
  29. package/lib/components/hover-card/HoverCardAnchor.js +26 -0
  30. package/lib/components/hover-card/HoverCardDetails.d.ts +36 -0
  31. package/lib/components/hover-card/HoverCardDetails.js +65 -0
  32. package/lib/components/hover-card/HoverCardLayer.d.ts +34 -0
  33. package/lib/components/hover-card/HoverCardLayer.js +57 -0
  34. package/lib/components/hover-card/index.d.ts +12 -0
  35. package/lib/components/hover-card/index.js +16 -0
  36. package/lib/components/hover-card/useHoverCard.d.ts +57 -0
  37. package/lib/components/hover-card/useHoverCard.js +200 -0
  38. package/lib/components/hover-card/usePrefersReducedMotion.d.ts +10 -0
  39. package/lib/components/hover-card/usePrefersReducedMotion.js +28 -0
  40. package/lib/components/index.d.ts +3 -0
  41. package/lib/components/index.js +3 -0
  42. package/lib/components/sheet/Sheet.d.ts +15 -0
  43. package/lib/components/sheet/Sheet.js +21 -0
  44. package/lib/reactor/page-layout/PageLayout.js +4 -6
  45. package/lib/story-helpers.d.ts +2 -2
  46. package/lib/theme/DatalayerThemeProvider.d.ts +21 -0
  47. package/lib/theme/DatalayerThemeProvider.js +8 -2
  48. package/lib/theme/colors/index.d.ts +2 -1
  49. package/lib/theme/colors/index.js +2 -1
  50. package/lib/theme/colors/loopColors.d.ts +2 -48
  51. package/lib/theme/colors/loopColors.js +2 -98
  52. package/lib/theme/colors/themeAccents.d.ts +81 -0
  53. package/lib/theme/colors/themeAccents.js +139 -0
  54. package/lib/theme/css/createThemeCSSVars.d.ts +18 -1
  55. package/lib/theme/css/createThemeCSSVars.js +20 -1
  56. package/lib/theme/css/primerBaseVars.d.ts +1 -0
  57. package/lib/theme/css/primerBaseVars.js +72 -0
  58. package/lib/theme/css/primerComponentsCss.d.ts +47 -0
  59. package/lib/theme/css/primerComponentsCss.js +72 -0
  60. package/lib/theme/index.d.ts +2 -0
  61. package/lib/theme/index.js +2 -0
  62. package/lib/theme/themes/loopThemeStyles.d.ts +4 -37
  63. package/lib/theme/themes/loopThemeStyles.js +39 -56
  64. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ /*
2
+ * Copyright (c) 2023-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * The tokens `Box` resolves, taken from Primer React's own theme
7
+ * (`@primer/react` 37, `legacy-theme/ts/color-schemes.js`): each colour or
8
+ * shadow path is mapped to the first CSS variable Primer's theme object
9
+ * gives it — the variable Primer itself reads first — and emitted without
10
+ * the fallback chain that follows it. The scales are Primer's theme scales.
11
+ *
12
+ * Generated from Primer's color schemes; regenerate when `@primer/react`
13
+ * changes its theme.
14
+ */
15
+ export const BOX_COLOR_VARS = {
16
+ 'fg.default': '--fgColor-default',
17
+ 'fg.muted': '--fgColor-muted',
18
+ 'fg.subtle': '--fgColor-muted',
19
+ 'fg.onEmphasis': '--fgColor-onEmphasis',
20
+ 'canvas.default': '--bgColor-default',
21
+ 'canvas.overlay': '--overlay-bgColor',
22
+ 'canvas.inset': '--bgColor-inset',
23
+ 'canvas.subtle': '--bgColor-muted',
24
+ 'border.default': '--borderColor-default',
25
+ 'border.muted': '--borderColor-muted',
26
+ 'border.subtle': '--borderColor-muted',
27
+ 'neutral.emphasisPlus': '--bgColor-emphasis',
28
+ 'neutral.emphasis': '--bgColor-neutral-emphasis',
29
+ 'neutral.muted': '--bgColor-neutral-muted',
30
+ 'neutral.subtle': '--bgColor-neutral-muted',
31
+ 'accent.fg': '--fgColor-accent',
32
+ 'accent.emphasis': '--bgColor-accent-emphasis',
33
+ 'accent.muted': '--borderColor-accent-muted',
34
+ 'accent.subtle': '--bgColor-accent-muted',
35
+ 'success.fg': '--fgColor-success',
36
+ 'success.emphasis': '--bgColor-success-emphasis',
37
+ 'success.muted': '--borderColor-success-muted',
38
+ 'success.subtle': '--bgColor-success-muted',
39
+ 'attention.fg': '--fgColor-attention',
40
+ 'attention.emphasis': '--bgColor-attention-emphasis',
41
+ 'attention.muted': '--borderColor-attention-muted',
42
+ 'attention.subtle': '--bgColor-attention-muted',
43
+ 'severe.fg': '--fgColor-severe',
44
+ 'severe.emphasis': '--bgColor-severe-emphasis',
45
+ 'severe.muted': '--borderColor-severe-muted',
46
+ 'severe.subtle': '--bgColor-severe-muted',
47
+ 'danger.fg': '--fgColor-danger',
48
+ 'danger.emphasis': '--borderColor-danger-emphasis',
49
+ 'danger.muted': '--borderColor-danger-muted',
50
+ 'danger.subtle': '--bgColor-danger-muted',
51
+ 'open.fg': '--fgColor-open',
52
+ 'open.emphasis': '--bgColor-open-emphasis',
53
+ 'open.muted': '--borderColor-open-muted',
54
+ 'open.subtle': '--bgColor-open-muted',
55
+ 'closed.fg': '--fgColor-closed',
56
+ 'closed.emphasis': '--bgColor-closed-emphasis',
57
+ 'closed.muted': '--borderColor-closed-muted',
58
+ 'closed.subtle': '--bgColor-closed-muted',
59
+ 'done.fg': '--fgColor-done',
60
+ 'done.emphasis': '--bgColor-done-emphasis',
61
+ 'done.muted': '--borderColor-done-muted',
62
+ 'done.subtle': '--bgColor-done-muted',
63
+ 'sponsors.fg': '--fgColor-sponsors',
64
+ 'sponsors.emphasis': '--bgColor-sponsors-emphasis',
65
+ 'sponsors.muted': '--borderColor-sponsors-muted',
66
+ 'sponsors.subtle': '--bgColor-sponsors-muted',
67
+ 'actionListItem.default.hoverBg': '--control-transparent-bgColor-hover',
68
+ 'actionListItem.default.activeBg': '--control-transparent-bgColor-active',
69
+ };
70
+ export const BOX_SHADOW_VARS = {
71
+ 'shadow.small': '--shadow-resting-small',
72
+ 'shadow.medium': '--shadow-resting-medium',
73
+ 'shadow.large': '--shadow-floating-large',
74
+ 'shadow.extraLarge': '--shadow-floating-xlarge',
75
+ };
76
+ /** Primer's breakpoints: a responsive array's second value from 544px, … */
77
+ export const BOX_BREAKPOINTS = ['544px', '768px', '1012px', '1280px'];
78
+ /** Primer's space scale: `p={3}` is 16px. */
79
+ export const BOX_SPACE = ['0', '4px', '8px', '16px', '24px', '32px', '40px', '48px', '64px', '80px', '96px', '112px', '128px'];
80
+ /** Primer's font sizes: `fontSize={1}` is 14px. */
81
+ export const BOX_FONT_SIZES = ['12px', '14px', '16px', '20px', '24px', '32px', '40px', '48px', '56px'];
82
+ /** Primer's radii by index (`borderRadius={2}` is 6px). */
83
+ export const BOX_RADII = ['0', '3px', '6px', '100px'];
84
+ /** Radii by name: Primer's, and the theme's shapes (LOOP T-03), an overlay's among them. */
85
+ export const BOX_RADIUS_VARS = {
86
+ small: '--borderRadius-small',
87
+ medium: '--borderRadius-medium',
88
+ large: '--borderRadius-large',
89
+ full: '--borderRadius-full',
90
+ control: '--theme-radius-control',
91
+ card: '--theme-radius-card',
92
+ bubble: '--theme-radius-bubble',
93
+ frame: '--theme-radius-frame',
94
+ overlay: '--theme-radius-overlay',
95
+ };
96
+ /** Primer's border widths by index. */
97
+ export const BOX_BORDER_WIDTHS = ['0', '1px'];
98
+ /** Primer's sizes by name (`maxWidth="large"` is 1012px). */
99
+ export const BOX_SIZES = { small: '544px', medium: '768px', large: '1012px', xlarge: '1280px' };
100
+ /**
101
+ * Font weights by name, as the theme's weight variables. Primer's theme
102
+ * names its weights 300, 400, 500, 600 — `light`, `normal`, `semibold`,
103
+ * `bold` — which are the primitives' `light`, `normal`, `medium` and
104
+ * `semibold`: so `semibold` is `--base-text-weight-medium` (500, and 600 in
105
+ * the `loop` theme, which has two weights), as it reads today.
106
+ */
107
+ export const BOX_FONT_WEIGHT_VARS = {
108
+ light: '--base-text-weight-light',
109
+ normal: '--base-text-weight-normal',
110
+ medium: '--base-text-weight-medium',
111
+ semibold: '--base-text-weight-medium',
112
+ bold: '--base-text-weight-semibold',
113
+ };
114
+ /** Primer's line heights by name. */
115
+ export const BOX_LINE_HEIGHTS = { condensedUltra: '1', condensed: '1.25', default: '1.5' };
116
+ /** Font families by name. */
117
+ export const BOX_FONT_VARS = { normal: '--fontStack-system', mono: '--fontStack-monospace' };
118
+ /** Every CSS variable `Box` can emit: the theme provider must set them all. */
119
+ export const BOX_EMITTED_VARS = [
120
+ ...Object.values(BOX_COLOR_VARS),
121
+ ...Object.values(BOX_SHADOW_VARS),
122
+ ...Object.values(BOX_RADIUS_VARS),
123
+ ...Object.values(BOX_FONT_WEIGHT_VARS),
124
+ ...Object.values(BOX_FONT_VARS),
125
+ ];
@@ -117,7 +117,8 @@ export function CalendarPicker({ value, defaultMonth, onChange, min, max, isDisa
117
117
  : isToday
118
118
  ? "var(--borderColor-default)"
119
119
  : "transparent",
120
- borderRadius: 2,
120
+ // The theme's control corner: a pill in loop, Primer's medium elsewhere.
121
+ borderRadius: "var(--theme-radius-control)",
121
122
  height: 30,
122
123
  cursor: disabled ? "not-allowed" : "pointer",
123
124
  fontSize: 1,
@@ -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,53 +1,76 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, IconButton, Text } from "@primer/react";
3
- const roundedVals = {
4
- small: "3px",
5
- medium: "6px",
6
- large: "12px",
7
- full: "100vh",
8
- };
9
- const shadowVals = {
10
- small: '0 1px 0 rgba(31,35,40,0.04)',
11
- medium: '0 3px 6px rgba(140,149,159,0.15)',
12
- large: '0 8px 24px rgba(140,149,159,0.2)',
13
- extraLarge: '0 12px 28px rgba(140,149,159,0.3)',
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
+ };
13
+ /**
14
+ * The corners, read from the theme: each theme sets Primer's radii (loop's
15
+ * are rounder), and a card left unsaid takes the theme's card corner.
16
+ */
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: {},
14
40
  };
15
41
  export const Card = (props) => {
16
- const { sx, rounded, border, shadow, children, ...otherProps } = props;
17
- return (_jsx(Box, { sx: {
18
- ...(sx ? sx : undefined),
19
- ...(rounded ? typeof rounded === "string" ? {
20
- borderRadius: roundedVals[rounded]
21
- } : {
22
- borderRadius: props.rounded
23
- } : undefined),
24
- ...(border ? {
25
- borderWidth: 1,
26
- borderStyle: 'solid',
27
- borderColor: 'border.default'
28
- } : undefined),
29
- ...(shadow ? {
30
- boxShadow: shadowVals[shadow]
31
- } : {
32
- boxShadow: shadowVals['small']
33
- })
34
- }, ...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 }));
35
55
  };
36
56
  Card.Header = (props) => {
37
57
  const { title, description, leadingVisual, action } = props;
38
- 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 })] });
39
59
  };
40
60
  Card.Image = ({ url, image, svg, height }) => {
41
- return (_jsxs(Box, { display: "block", width: "100%", height: `${height}px`, backgroundImage: `url(${url})`, sx: {
42
- backgroundSize: "cover",
43
- backgroundRepeat: "no-repeat",
44
- backgroundPosition: "center",
45
- objectFit: "cover"
46
- }, 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 }));
47
70
  };
48
- Card.Content = ({ children }) => {
49
- 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 }));
50
73
  };
51
74
  Card.Actions = ({ children }) => {
52
- return _jsx(Box, { display: "block", sx: { p: 3 }, children: children });
75
+ return _jsx(Box, { display: "block", p: 3, mt: "auto", children: children });
53
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
+ };
@@ -48,7 +48,8 @@ export function ColorSwatch({ color, label, showValue = true, height = 54, }) {
48
48
  gridTemplateRows: `${height}px auto`,
49
49
  border: "1px solid",
50
50
  borderColor: "var(--borderColor-default)",
51
- borderRadius: 2,
51
+ // The theme's card corner: 20px in loop, Primer's medium elsewhere.
52
+ borderRadius: "var(--theme-radius-card)",
52
53
  overflow: "hidden",
53
54
  minWidth: 0,
54
55
  }, children: [_jsx(Box, { ref: ref, style: { backgroundColor: color } }), _jsxs(Box, { sx: { p: 2, display: "grid", gap: 1 }, children: [_jsx(Text, { sx: {
@@ -283,13 +283,17 @@ export function ColorPicker({ color, onChange, presets = DEFAULT_COLOR_PRESETS,
283
283
  return (_jsxs(Box, { role: "group", "aria-label": ariaLabel, sx: { display: "grid", gap: 2, width, minWidth: 0 }, children: [_jsx(Box, { ref: field.ref, role: "slider", tabIndex: 0, "aria-label": "Saturation and brightness", "aria-valuetext": `saturation ${Math.round(hsv.s)}%, brightness ${Math.round(hsv.v)}%`, onPointerDown: field.onPointerDown, onKeyDown: (event) => nudge(event, event.key === "ArrowUp" || event.key === "ArrowDown" ? "v" : "s"), sx: {
284
284
  position: "relative",
285
285
  height: FIELD_HEIGHT,
286
- borderRadius: 2,
286
+ borderRadius: "var(--theme-radius-card)",
287
287
  border: "1px solid",
288
288
  borderColor: "var(--borderColor-default)",
289
289
  cursor: "crosshair",
290
290
  touchAction: "none",
291
291
  backgroundColor: toHex(hsvToRgb({ h: hsv.h, s: 100, v: 100 })),
292
292
  backgroundImage: "linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)",
293
+ // Sized from the border's outer edge, not repeated into it: a
294
+ // gradient tiled from the padding box drew its black bottom row
295
+ // again in the top border, a dark line over the field.
296
+ backgroundOrigin: "border-box",
293
297
  "&:focus-visible": {
294
298
  outline: "2px solid var(--borderColor-accent-emphasis)",
295
299
  outlineOffset: "1px",
@@ -302,7 +306,7 @@ export function ColorPicker({ color, onChange, presets = DEFAULT_COLOR_PRESETS,
302
306
  } }) }), _jsx(Box, { ref: rail.ref, role: "slider", tabIndex: 0, "aria-label": "Hue", "aria-valuemin": 0, "aria-valuemax": 360, "aria-valuenow": Math.round(hsv.h), onPointerDown: rail.onPointerDown, onKeyDown: (event) => nudge(event, "h"), sx: {
303
307
  position: "relative",
304
308
  height: RAIL_HEIGHT,
305
- borderRadius: 6,
309
+ borderRadius: "var(--theme-radius-control)",
306
310
  border: "1px solid",
307
311
  borderColor: "var(--borderColor-default)",
308
312
  cursor: "ew-resize",
@@ -321,7 +325,7 @@ export function ColorPicker({ color, onChange, presets = DEFAULT_COLOR_PRESETS,
321
325
  width: 28,
322
326
  height: 28,
323
327
  flex: "0 0 auto",
324
- borderRadius: 2,
328
+ borderRadius: "var(--borderRadius-medium)",
325
329
  border: "1px solid",
326
330
  borderColor: "var(--borderColor-default)",
327
331
  backgroundColor: hex,
@@ -338,7 +342,7 @@ export function ColorPicker({ color, onChange, presets = DEFAULT_COLOR_PRESETS,
338
342
  const chosen = preset.toLowerCase() === hex.toLowerCase();
339
343
  return (_jsx(Box, { as: "button", type: "button", "aria-label": preset, "aria-pressed": chosen, onClick: () => setFromText(preset), sx: {
340
344
  height: 22,
341
- borderRadius: 2,
345
+ borderRadius: "var(--theme-radius-control)",
342
346
  cursor: "pointer",
343
347
  backgroundColor: preset,
344
348
  border: "1px solid",
@@ -1,4 +1,6 @@
1
1
  import { type CalendarPickerProps } from "../calendar-picker/CalendarPicker";
2
+ /** Where the time stands against the calendar in the overlay. */
3
+ export type DatePickerTimePosition = "north" | "east" | "south" | "west";
2
4
  /** `YYYY-MM-DD`, the one format that means the same thing everywhere. */
3
5
  export declare function formatISODate(date: Date): string;
4
6
  /** `YYYY-MM-DD HH:mm`, the same date with the minute it holds. */
@@ -53,10 +55,17 @@ export interface DatePickerProps extends Pick<CalendarPickerProps, "min" | "max"
53
55
  * Whether the field holds a time as well as a day.
54
56
  *
55
57
  * With it, the field reads and writes `YYYY-MM-DD HH:mm`, and the overlay
56
- * carries a time beneath the calendar. Without it — the default — nothing
57
- * about the field changes, because most dates are days.
58
+ * carries a time beside the calendar (see `timePosition`). Without it —
59
+ * the default — nothing about the field changes, because most dates are
60
+ * days.
58
61
  */
59
62
  withTime?: boolean;
63
+ /**
64
+ * Where the time stands against the calendar, with `withTime`: `east`
65
+ * (to its right, the default), `west` (to its left), `south` (under it)
66
+ * or `north` (above it).
67
+ */
68
+ timePosition?: DatePickerTimePosition;
60
69
  /**
61
70
  * Minutes between the options the minute column offers. Default: five.
62
71
  *
@@ -77,5 +86,5 @@ export interface DatePickerProps extends Pick<CalendarPickerProps, "min" | "max"
77
86
  * Controlled: `value` is the caller's, and every pick and every parsed entry
78
87
  * arrives through `onChange`.
79
88
  */
80
- export declare function DatePicker({ value, onChange, placeholder, "aria-label": ariaLabel, disabled, size, validationStatus, format, id, min, max, isDisabled, weekStartsOn, locale, withTime, timeStep, defaultTime, }: DatePickerProps): import("react").JSX.Element;
89
+ export declare function DatePicker({ value, onChange, placeholder, "aria-label": ariaLabel, disabled, size, validationStatus, format, id, min, max, isDisabled, weekStartsOn, locale, withTime, timePosition, timeStep, defaultTime, }: DatePickerProps): import("react").JSX.Element;
81
90
  export default DatePicker;
@@ -4,6 +4,20 @@ import { AnchoredOverlay, Box, Button, TextInput } from "@primer/react";
4
4
  import { CalendarIcon } from "@primer/octicons-react";
5
5
  import { CalendarPicker } from "../calendar-picker/CalendarPicker";
6
6
  import { TimeColumns } from "./TimeColumns";
7
+ /** The overlay's flow for each position: the calendar first, the time where it was asked. */
8
+ const TIME_FLOW = {
9
+ east: "row",
10
+ west: "row-reverse",
11
+ south: "column",
12
+ north: "column-reverse",
13
+ };
14
+ /** The hairline between the time and the calendar, on the side that faces it. */
15
+ const TIME_SEPARATOR = {
16
+ east: { pl: 3, borderLeft: "1px solid", borderColor: "border.default", alignSelf: "stretch" },
17
+ west: { pr: 3, borderRight: "1px solid", borderColor: "border.default", alignSelf: "stretch" },
18
+ south: { pt: 3, borderTop: "1px solid", borderColor: "border.default", alignSelf: "stretch" },
19
+ north: { pb: 3, borderBottom: "1px solid", borderColor: "border.default", alignSelf: "stretch" },
20
+ };
7
21
  /** `YYYY-MM-DD`, the one format that means the same thing everywhere. */
8
22
  export function formatISODate(date) {
9
23
  const month = `${date.getMonth() + 1}`.padStart(2, "0");
@@ -81,7 +95,7 @@ export function parseISODateTime(text) {
81
95
  * Controlled: `value` is the caller's, and every pick and every parsed entry
82
96
  * arrives through `onChange`.
83
97
  */
84
- export function DatePicker({ value = null, onChange, placeholder, "aria-label": ariaLabel = "Date", disabled = false, size = "medium", validationStatus, format, id, min, max, isDisabled, weekStartsOn, locale, withTime = false, timeStep = 5, defaultTime = "00:00", }) {
98
+ export function DatePicker({ value = null, onChange, placeholder, "aria-label": ariaLabel = "Date", disabled = false, size = "medium", validationStatus, format, id, min, max, isDisabled, weekStartsOn, locale, withTime = false, timePosition = "east", timeStep = 5, defaultTime = "00:00", }) {
85
99
  // The two shapes, chosen once: a caller that passed a `format` keeps it,
86
100
  // and a caller that asked for a time gets the one that carries a time.
87
101
  const writeDate = format ?? (withTime ? formatISODateTime : formatISODate);
@@ -138,7 +152,13 @@ export function DatePicker({ value = null, onChange, placeholder, "aria-label":
138
152
  next.setHours(hour, minute, 0, 0);
139
153
  return next;
140
154
  };
141
- const calendar = useMemo(() => (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(CalendarPicker, { value: value, defaultMonth: value ?? undefined, onChange: (date) => {
155
+ const calendar = useMemo(() => (_jsxs(Box, { sx: {
156
+ p: 3,
157
+ display: "flex",
158
+ flexDirection: TIME_FLOW[timePosition],
159
+ alignItems: "flex-start",
160
+ gap: 3,
161
+ }, children: [_jsx(CalendarPicker, { value: value, defaultMonth: value ?? undefined, onChange: (date) => {
142
162
  // A day picked while a time is held keeps that time: somebody
143
163
  // moving a window from the 3rd to the 4th did not mean to move
144
164
  // it to midnight.
@@ -148,12 +168,7 @@ export function DatePicker({ value = null, onChange, placeholder, "aria-label":
148
168
  if (!withTime) {
149
169
  setOpen(false);
150
170
  }
151
- }, min: min, max: max, isDisabled: isDisabled, weekStartsOn: weekStartsOn, locale: locale, "aria-label": `${ariaLabel}, choose a day` }), withTime && (_jsxs(Box, { sx: {
152
- mt: 3,
153
- pt: 3,
154
- borderTop: "1px solid",
155
- borderColor: "border.default",
156
- }, children: [_jsx(TimeColumns, { hour: held.hour, minute: held.minute, step: timeStep, disabled: disabled, labelPrefix: ariaLabel, onChange: (hour, minute) => {
171
+ }, min: min, max: max, isDisabled: isDisabled, weekStartsOn: weekStartsOn, locale: locale, "aria-label": `${ariaLabel}, choose a day` }), withTime && (_jsxs(Box, { sx: TIME_SEPARATOR[timePosition], children: [_jsx(TimeColumns, { hour: held.hour, minute: held.minute, step: timeStep, disabled: disabled, labelPrefix: ariaLabel, onChange: (hour, minute) => {
157
172
  const next = atTime(hour, minute);
158
173
  onChange?.(next);
159
174
  setText(writeDate(next));
@@ -178,6 +193,7 @@ export function DatePicker({ value = null, onChange, placeholder, "aria-label":
178
193
  size,
179
194
  timeStep,
180
195
  value,
196
+ timePosition,
181
197
  weekStartsOn,
182
198
  withTime,
183
199
  writeDate,