@datalayer/primer-addons 1.0.32 → 1.0.33

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/README.md CHANGED
@@ -43,6 +43,103 @@ The [gallery example](examples/gallery) is a Reactor app built on the three: `np
43
43
  <img alt="Primer React Addons" src="https://assets.datalayer.tech/primer-addons-example.png" />
44
44
  </div>
45
45
 
46
+ ## The `loop` theme
47
+
48
+ `loop` is one of the variants of the theme registry (`ThemeVariant`, `themeConfigs`), beside `datalayer`, `spatial`, `lovely`, `matrix`, `earth`, `sand`, `ivory` and `sun`: the look of an application built in LOOP — **one accent, neutral everything else**. A white (near-black in dark mode) canvas, a deep-grey ink, hairlines, soft shadows, round corners and one filled button in the accent. Success, attention and danger are kept for verdicts and rules only. The [gallery](examples/gallery) shows it on its own page, *Loop Theme*, whatever theme the gallery itself wears.
49
+
50
+ ```tsx
51
+ import { DatalayerThemeProvider, loopTheme, loopThemeStyles } from '@datalayer/primer-addons';
52
+
53
+ <DatalayerThemeProvider theme={loopTheme} themeStyles={loopThemeStyles} colorMode="auto">
54
+ {app}
55
+ </DatalayerThemeProvider>
56
+ ```
57
+
58
+ The sources: `src/theme/colors/loopColors.ts` (colours and accents), `src/theme/themes/loopTheme.ts` (the theme), `src/theme/css/createThemeCSSVars.ts` (what every theme sets), `src/theme/DatalayerThemeProvider.tsx` and `src/utils/Portals.tsx` (how a theme's stylesheet is applied).
59
+
60
+ ### Accents
61
+
62
+ Six, and an application takes one. Each is four values — the accent, the text that sits on it, the **stage** (the flat tint behind a hosted application) and a **quiet** tint (the agent's bubble, a draft) — the stage and the quiet tint each with a light and a dark value.
63
+
64
+ | Name | Accent | Text on it | Stage (light / dark) | Quiet (light / dark) |
65
+ |---|---|---|---|---|
66
+ | `green` (mint, the default) | `#7ADBB8` | `#06281E` | `#DDF5EC` / `#10261F` | `#F0FAF6` / `#17211D` |
67
+ | `rose` | `#F6A5C1` | `#3A0A1C` | `#FCE3EC` / `#2B141C` | `#FDF2F6` / `#22181C` |
68
+ | `sky` | `#8CCBF9` | `#06243B` | `#DFF0FD` / `#0F2333` | `#F0F8FE` / `#161E25` |
69
+ | `lime` | `#BEDC55` | `#1F2A00` | `#EEF6CC` / `#1E2609` | `#F7FBE6` / `#1C2014` |
70
+ | `sun` | `#F8D469` | `#2E2200` | `#FDF3CD` / `#2A2209` | `#FEF9E7` / `#221F14` |
71
+ | `violet` | `#C0AEF6` | `#1C0F47` | `#ECE7FD` / `#1B1533` | `#F6F3FE` / `#1C1A27` |
72
+
73
+ `loopAccents` holds them, `loopAccentNames` lists them in the order a picker shows them, and `loopAccentVars(name, mode)` turns one into the four custom properties an application sets on its root: `--loop-accent`, `--loop-accent-on`, `--loop-stage`, `--loop-quiet`. An unknown name falls back to `green`.
74
+
75
+ An application names its accent in its Appspec, as `interface.accent` (one of the six names; `green` when it says nothing), and its host applies it:
76
+
77
+ ```tsx
78
+ import { loopAccentVars } from '@datalayer/primer-addons';
79
+
80
+ <DatalayerThemeProvider theme={loopTheme} themeStyles={loopThemeStyles}
81
+ baseStyles={loopAccentVars(app.interface.accent, mode)}>
82
+ ```
83
+
84
+ `loopAccentVars` sets the four `--loop-*` properties and nothing else: what reads them (the stage, a bubble drawn with them) takes the application's accent, while Primer's own accent tokens — the filled button, `--bgColor-accent-emphasis` — stay the theme's mint.
85
+
86
+ ### Shape, shadow, type and motion
87
+
88
+ **Every theme** sets these, so that a component reads its shape the way it reads its colour (`shapeVars`, `DEFAULT_THEME_SHAPE`). The eight other themes take the defaults — today's corners and no motion at all — and keep every other value they had, which `themeShape.test.ts` holds by a snapshot of each.
89
+
90
+ | Token | Default (every other theme) | `loop` |
91
+ |---|---|---|
92
+ | `--theme-radius-control` | `var(--borderRadius-medium, 6px)` | `999px` |
93
+ | `--theme-radius-card` | `var(--borderRadius-medium, 6px)` | `20px` |
94
+ | `--theme-radius-bubble` | `var(--borderRadius-large, 12px)` | `22px` |
95
+ | `--theme-radius-frame` | `var(--borderRadius-large, 12px)` | `28px` |
96
+ | `--theme-hairline` | `var(--borderWidth-thin, 1px)` | the same |
97
+ | `--theme-shadow` | `var(--shadow-resting-small, none)` | the frame's shadow, per mode |
98
+ | `--theme-motion-status` | `0ms` | `120ms` |
99
+ | `--theme-motion-message` | `0ms` | `200ms` |
100
+ | `--theme-motion-pane` | `0ms` | `320ms` |
101
+ | `--theme-motion-easing` | `ease` | `cubic-bezier(0.2, 0, 0, 1)` |
102
+
103
+ **The `loop` theme's own**, beside them (`loopShapeVars`, `loopShadows`, `loopMotionVars`, `loopTypeVars`):
104
+
105
+ - **Radii**: `--loop-radius-control` (999px), `--loop-radius-card` (20px), `--loop-radius-bubble` (22px), `--loop-radius-frame` (28px); Primer's own `--borderRadius-small`, `-medium`, `-large` are made rounder (10, 14, 20px).
106
+ - **The face** of an application, at three sizes and no other: `--loop-face-large` (72px, a page), `--loop-face-medium` (40px, a header or a card), `--loop-face-small` (20px, a line of a list).
107
+ - **Shadow**: one level, `--loop-shadow-frame`. In light mode a surface floats on a soft, low shadow; in dark mode, where a shadow shows little, on a hairline of light and a deeper shadow. Primer's `--shadow-resting-*` and `--shadow-floating-*` take the same hand, so a menu or a dialog floats as a frame does. `--loop-hairline` is the line between two surfaces (7% of the ink in light, 10% of white in dark).
108
+ - **Motion**: three durations for three things — `--loop-motion-status` (a status changing), `--loop-motion-message` (a message arriving), `--loop-motion-pane` (a pane opening) — and one easing, `--loop-motion-easing`. Nothing else moves; a component honours `prefers-reduced-motion` itself.
109
+ - **Type**: one face, Inter, then the system sans-serif (`loopFontFamily`); two weights, 400 and 600. The titles are set tighter (`--text-display-shorthand` 2.75rem/1.15 down to `--text-title-shorthand-small` 1rem/1.4) and the tracking is a token a component applies: `--loop-tracking-display` (-0.02em), `--loop-tracking-title` (-0.012em), `--loop-tracking-body` (0). The package does not ship the face: a page that has not loaded Inter shows the system face, and nothing but the letterforms changes.
110
+ - **The stage, lit**: `--loop-stage-gradient`, from the stage tint at the top to the quiet tint at the bottom, both the accent's.
111
+ - **The focus ring**: `--focus-outlineColor`, the deep mint `#0F6B4F` in light mode and a mid grey `#636363` in dark mode.
112
+
113
+ ### The controls, as pills
114
+
115
+ Every Primer control takes its corners from one token, `--borderRadius-medium`, which cards and list items take too — so "the controls alone are pills" cannot be said with a custom property. A theme may therefore carry **a stylesheet of its own**, `ThemeStyles.css`, written relative to `:scope` (`buildThemeStyles(light, dark, { css })`). `loop` is the only theme that has one (`loopControlsCss`): buttons, text inputs, selects, segmented controls, button groups (their two ends), toggle switches and underline tabs are pills; a multi-line text area keeps `--borderRadius-medium`, and menus and overlays keep the card's radius. The selectors match the stable prefixes of Primer's class names (`loopControlsSelectors`), and a test reads each back from the installed `@primer/react`, so an upgrade that renames one fails the build.
116
+
117
+ How `DatalayerThemeProvider` applies it:
118
+
119
+ - It stamps its own element with a unique `data-datalayer-theme-scope` and injects one `<style data-datalayer-theme-stylesheet>` into the document's head, wrapping the theme's stylesheet in `@scope (<its element>) to (<any other provider's element>)` — so the rules stop at a provider nested inside, and a widget in its own theme keeps its shapes (`scopeThemeCss`, `injectThemeStylesheet`).
120
+ - The **outermost** provider owns Primer's portal root (`__primerPortalRoot__`, where menus, overlays and dialogs are drawn) and scopes the stylesheet to it too; a nested provider leaves the portal root alone.
121
+ - The stylesheet is removed when the theme changes and when the provider unmounts; it is injected in a layout effect, so the first paint is already in the theme's shapes. A theme without one gets nothing injected.
122
+
123
+ `themeStylesheet.test.tsx` tests each of these.
124
+
125
+ ### Contrast, as tested
126
+
127
+ `src/theme/__tests__/loopContrast.test.ts` fails the build when, for any of the six accents, in either mode:
128
+
129
+ - the text on a bubble and on a filled pill (the accent's `on` on the accent) is under **4.5 to 1** (WCAG AA for body text);
130
+ - the ink on the stage or on the quiet tint, light and dark, is under 4.5 to 1;
131
+ - the focus ring is under **3 to 1** against the page or around a pill of any accent — but on the subtle dark surface, the one place the dark ring falls short, where it holds 2.7 to 1;
132
+ - the filled button — rest, hovered, pressed — or the accent's text on white is under 4.5 to 1, or the accent's fill and the filled button stop being one colour;
133
+ - the secondary text is under 4.5 to 1 on white or on near-black.
134
+
135
+ The same test holds the motion to three durations and one easing.
136
+
137
+ ### What a host may override
138
+
139
+ Today a host overrides through the provider: `baseStyles` is merged on top of the theme's properties, so it may set an accent (`loopAccentVars`), or any `--loop-*` or `--theme-*` property, for the element and — for the outermost provider — the portal root; and it may pass a theme of its own to `themeStyles`, built with `buildThemeStyles`. A person's choice in an appearance menu (`useThemeStore`) is the host's to honour.
140
+
141
+ **Not built yet** (LOOP T-13): the theme travelling inside an embedded application's web component as CSS variables isolated from the host page's styles, with the accent, the face and the mode as the only things the host overrides. Until then an embedded application is themed as any React tree under `DatalayerThemeProvider` is, and the host page's own CSS is not kept out.
142
+
46
143
  ## Develop
47
144
 
48
145
  Install the dependencies.
@@ -6,7 +6,7 @@ export { earthColors } from './earthColors';
6
6
  export { sandColors } from './sandColors';
7
7
  export { ivoryColors } from './ivoryColors';
8
8
  export { sunColors } from './sunColors';
9
- export { loopColors, loopAccents, loopAccentNames, loopAccentVars, type LoopAccent, type LoopAccentName, } from './loopColors';
9
+ export { loopColors, loopAccents, loopAccentNames, loopAccentVars, loopAccentStyles, type LoopAccent, type LoopAccentName, } from './loopColors';
10
10
  import type { ThemeVariant } from '../themeRegistry';
11
11
  /**
12
12
  * Themed color palettes — maps each `ThemeVariant` to its corresponding
@@ -10,7 +10,7 @@ export { earthColors } from './earthColors';
10
10
  export { sandColors } from './sandColors';
11
11
  export { ivoryColors } from './ivoryColors';
12
12
  export { sunColors } from './sunColors';
13
- export { loopColors, loopAccents, loopAccentNames, loopAccentVars, } from './loopColors';
13
+ export { loopColors, loopAccents, loopAccentNames, loopAccentVars, loopAccentStyles, } from './loopColors';
14
14
  import { datalayerColors } from './datalayerColors';
15
15
  import { spatialColors } from './spatialColors';
16
16
  import { lovelyColors } from './lovelyColors';
@@ -92,3 +92,11 @@ export declare const loopAccentNames: LoopAccentName[];
92
92
  * application sets on its root to take its colour.
93
93
  */
94
94
  export declare function loopAccentVars(name: LoopAccentName, mode?: 'light' | 'dark'): Record<string, string>;
95
+ /**
96
+ * An application's accent as everything it colours (LOOP T-05): the four
97
+ * `--loop-*` properties of `loopAccentVars`, and Primer's accent fill and
98
+ * filled button — the person's bubble, the assistant's avatar, the one
99
+ * button to press — in the accent with the text that sits on it. Set on an
100
+ * application's root, it wears its own colour; the page around keeps mint.
101
+ */
102
+ export declare function loopAccentStyles(name: LoopAccentName, mode?: 'light' | 'dark'): Record<string, string>;
@@ -130,3 +130,29 @@ export function loopAccentVars(name, mode = 'light') {
130
130
  '--loop-quiet': accent.quiet[mode],
131
131
  };
132
132
  }
133
+ /**
134
+ * An application's accent as everything it colours (LOOP T-05): the four
135
+ * `--loop-*` properties of `loopAccentVars`, and Primer's accent fill and
136
+ * filled button — the person's bubble, the assistant's avatar, the one
137
+ * button to press — in the accent with the text that sits on it. Set on an
138
+ * application's root, it wears its own colour; the page around keeps mint.
139
+ */
140
+ export function loopAccentStyles(name, mode = 'light') {
141
+ const accent = loopAccents[name];
142
+ if (!accent) {
143
+ throw new Error(`There is no accent "${name}"; the accents are ${loopAccentNames.join(', ')}.`);
144
+ }
145
+ return {
146
+ ...loopAccentVars(name, mode),
147
+ '--bgColor-accent-emphasis': accent.accent,
148
+ '--borderColor-accent-emphasis': accent.accent,
149
+ '--button-primary-bgColor-rest': accent.accent,
150
+ '--button-primary-borderColor-rest': accent.accent,
151
+ '--button-primary-bgColor-hover': accent.accent,
152
+ '--button-primary-borderColor-hover': accent.accent,
153
+ '--button-primary-bgColor-active': accent.accent,
154
+ '--button-primary-borderColor-active': accent.accent,
155
+ '--button-primary-fgColor-rest': accent.on,
156
+ '--button-primary-iconColor-rest': accent.on,
157
+ };
158
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",