@aleph-alpha/ui-library 2.4.3 → 2.4.4

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/config.d.ts CHANGED
@@ -77,6 +77,12 @@ export type UiLibraryPresetOptions = UiLibraryThemeOptions &
77
77
  */
78
78
  export type UiLibraryTokenColors = Record<string, string>;
79
79
 
80
+ /**
81
+ * UnoCSS border-radius record where keys are utility suffixes
82
+ * and values are CSS length values.
83
+ */
84
+ export type UiLibraryTokenBorderRadius = Record<string, string>;
85
+
80
86
  /**
81
87
  * Helper function for type-safe theme configuration files.
82
88
  * Similar to Tailwind's `defineConfig`.
@@ -130,6 +136,12 @@ export declare const getUiLibraryTokenVars: () => UiLibraryTheme;
130
136
  */
131
137
  export declare const getUiLibraryTokenColors: () => UiLibraryTokenColors;
132
138
 
139
+ /**
140
+ * Get UnoCSS border-radius config from corner-radius design tokens.
141
+ * This allows using classes like rounded-xs, rounded-md, rounded-4xl, rounded-full, etc.
142
+ */
143
+ export declare const getUiLibraryTokenBorderRadius: () => UiLibraryTokenBorderRadius;
144
+
133
145
  /**
134
146
  * Creates an UnoCSS preset with custom theme variables.
135
147
  * Use this when you want full control over the theme.
@@ -151,6 +163,7 @@ export declare const presetUiLibraryTheme: (
151
163
  * This preset bundles everything needed for the UI library:
152
164
  * - CSS variables for all design tokens (light/dark mode)
153
165
  * - Token-based theme colors (bg-background-surface-secondary, text-content-on-surface-primary, etc.)
166
+ * - Token-based border radius utilities (rounded-xs, rounded-md, rounded-full, etc.)
154
167
  * - Semantic color overrides (background, foreground, modal, link, etc.)
155
168
  * - Typography classes from design tokens (heading-48-bold, body-14-normal, label-12-medium, etc.)
156
169
  * - Custom rules for Tailwind v4 CSS variable syntax (w-(--var), h-(--var), etc.)
package/config.js CHANGED
@@ -525,6 +525,74 @@ export const getUiLibraryTokenColors = () => {
525
525
  return colors;
526
526
  };
527
527
 
528
+ const getCornerRadiusTokenGroup = () => {
529
+ const primitives = getTokens()?.['1-primitives/Default'];
530
+ return (
531
+ primitives?.aa?.['corner-radius'] ??
532
+ primitives?.aa26?.['corner-radius'] ??
533
+ null
534
+ );
535
+ };
536
+
537
+ const borderRadiusKeyFromTokenName = (tokenName) => {
538
+ const key = tokenName.replace(/^rounded-/, '');
539
+ return key === 'md' ? ['DEFAULT', key] : [key];
540
+ };
541
+
542
+ /**
543
+ * Get UnoCSS border-radius config from corner-radius design tokens.
544
+ * This powers classes like rounded-xs, rounded-md, rounded-4xl, and rounded-full.
545
+ */
546
+ export const getUiLibraryTokenBorderRadius = () => {
547
+ const cornerRadius = getCornerRadiusTokenGroup();
548
+ if (!cornerRadius) return {};
549
+
550
+ const borderRadius = {};
551
+ for (const [tokenName, tokenData] of Object.entries(cornerRadius)) {
552
+ if (
553
+ !tokenData ||
554
+ typeof tokenData !== 'object' ||
555
+ !('value' in tokenData)
556
+ ) {
557
+ continue;
558
+ }
559
+
560
+ const resolved = resolveReferences(tokenData.value, new Set());
561
+ if (typeof resolved !== 'string' || !resolved.trim()) continue;
562
+
563
+ for (const key of borderRadiusKeyFromTokenName(tokenName)) {
564
+ borderRadius[key] = resolved;
565
+ }
566
+ }
567
+
568
+ return borderRadius;
569
+ };
570
+
571
+ const getUiLibraryTokenBorderRadiusVars = () =>
572
+ Object.fromEntries(
573
+ Object.entries(getUiLibraryTokenBorderRadius()).map(([key, value]) => [
574
+ `radius-${key}`,
575
+ value,
576
+ ]),
577
+ );
578
+
579
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
580
+
581
+ const entriesToRules = (entries) =>
582
+ entries.map(([className, declarations]) => [
583
+ new RegExp(`^${escapeRegExp(className)}$`),
584
+ () => declarations,
585
+ ]);
586
+
587
+ const getBorderRadiusExactUtilityRules = () => {
588
+ const entries = [];
589
+ for (const [key, value] of Object.entries(getUiLibraryTokenBorderRadius())) {
590
+ const className = key === 'DEFAULT' ? 'rounded' : `rounded-${key}`;
591
+ entries.push([className, { 'border-radius': value }]);
592
+ }
593
+ return entriesToRules(entries);
594
+ };
595
+
528
596
  export const defineThemeConfig = (config) => config;
529
597
 
530
598
  export const presetUiLibraryTheme = (theme, options = {}) => {
@@ -572,14 +640,20 @@ export const presetUiLibraryThemeFromTokens = (options = {}) => {
572
640
 
573
641
  // Get base shadcn theme from tokens
574
642
  const baseTheme = getUiLibraryThemeFromTokens();
643
+ const tokenBorderRadiusVars = getUiLibraryTokenBorderRadiusVars();
644
+
645
+ // Radius utilities in Wind v4 resolve through --radius-* variables.
646
+ let finalTheme = {
647
+ light: { ...baseTheme.light, ...tokenBorderRadiusVars },
648
+ dark: { ...baseTheme.dark, ...tokenBorderRadiusVars },
649
+ };
575
650
 
576
651
  // Include all token-based variables (default: true)
577
- let finalTheme = baseTheme;
578
652
  if (includeAllTokens) {
579
653
  const tokenVars = getUiLibraryTokenVars();
580
654
  finalTheme = {
581
- light: { ...tokenVars.light, ...baseTheme.light },
582
- dark: { ...tokenVars.dark, ...baseTheme.dark },
655
+ light: { ...tokenVars.light, ...finalTheme.light },
656
+ dark: { ...tokenVars.dark, ...finalTheme.dark },
583
657
  };
584
658
  }
585
659
 
@@ -642,6 +716,7 @@ export const presetUiLibraryThemeFromTokens = (options = {}) => {
642
716
  },
643
717
  },
644
718
  rules: [
719
+ ...getBorderRadiusExactUtilityRules(),
645
720
  // Typography classes from design tokens (heading-48-bold, body-14-normal, label-12-medium, etc.)
646
721
  ...typographyShortcuts.map(([name, css]) => [
647
722
  new RegExp(`^${name}$`),
@@ -200,12 +200,13 @@ All config functions are exported from `@aleph-alpha/ui-library/config`:
200
200
  |--------|-------------|
201
201
  | `defineUiLibraryConfig(options?)` | **Recommended.** Complete UnoCSS config with all presets, content scanning, fonts, and tokens. Options: `extend`, `darkSelector`, `presets`, `rules`, `shortcuts`, and any other UnoCSS config |
202
202
  | `getUiLibraryContentConfig()` | UnoCSS content/pipeline config to scan library classes |
203
- | `presetUiLibraryThemeFromTokens(options?)` | Token preset. Bundles token CSS variables, theme colors, semantic overrides, and typography classes. Options: `darkSelector` (default: `'html.dark'`), `includeAllTokens` (default: `true`), `extend`, `theme` |
203
+ | `presetUiLibraryThemeFromTokens(options?)` | Token preset. Bundles token CSS variables, theme colors, border radius utilities, semantic overrides, and typography classes. Options: `darkSelector` (default: `'html.dark'`), `includeAllTokens` (default: `true`), `extend`, `theme` |
204
204
  | `presetUiLibraryUtils()` | Utility rules required by library components (`w-(--var)`, `h-(--var)`, etc.) |
205
205
  | `presetUiLibraryTheme(theme, options?)` | Low-level preset with manually provided theme variables (for custom themes) |
206
206
  | `getUiLibraryThemeFromTokens()` | Returns the raw theme object derived from `tokens.json` |
207
207
  | `getUiLibraryTokenVars()` | Returns all token-based CSS variables for light and dark modes |
208
208
  | `getUiLibraryTokenColors()` | Returns UnoCSS theme colors config for all token-based colors (included automatically by `presetUiLibraryThemeFromTokens`) |
209
+ | `getUiLibraryTokenBorderRadius()` | Returns UnoCSS `theme.borderRadius` config from corner-radius tokens (included automatically by `presetUiLibraryThemeFromTokens`) |
209
210
  | `getUiLibraryTypographyShortcuts()` | Returns typography class definitions as `[className, cssProperties]` tuples (included automatically by `presetUiLibraryThemeFromTokens`) |
210
211
  | `defineThemeConfig(config)` | Type-safe helper for external theme config files |
211
212
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/ui-library",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/system/lib.js",
@@ -0,0 +1,115 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { defineComponent, h } from 'vue';
3
+
4
+ const ThemePlaceholder = defineComponent({
5
+ name: 'ThemePlaceholder',
6
+ render() {
7
+ return h('div');
8
+ },
9
+ });
10
+
11
+ const meta: Meta<typeof ThemePlaceholder> = {
12
+ title: 'CSS utility/Border radius',
13
+ component: ThemePlaceholder,
14
+ tags: ['autodocs'],
15
+ parameters: {
16
+ layout: 'fullscreen',
17
+ },
18
+ };
19
+
20
+ export default meta;
21
+ type Story = StoryObj<typeof ThemePlaceholder>;
22
+
23
+ const copyScript = `
24
+ function copyToClipboard(text, el) {
25
+ navigator.clipboard.writeText(text).then(() => {
26
+ el.classList.add('copied');
27
+ setTimeout(() => el.classList.remove('copied'), 1500);
28
+ });
29
+ }
30
+ `;
31
+
32
+ /**
33
+ * Border radius utilities generated from `aa.corner-radius` in `tokens.json`.
34
+ * Use `rounded-xs` … `rounded-4xl` and `rounded-full` instead of raw radius values.
35
+ */
36
+ export const RadiusScale: Story = {
37
+ render: () => ({
38
+ template: `
39
+ <div class="p-8 bg-background-surface-secondary min-h-screen">
40
+ <style>
41
+ .copy-btn { cursor: pointer; transition: all 0.15s; }
42
+ .copy-btn:hover { background: rgba(0,0,0,0.05); }
43
+ .copy-btn.copied { background: #22c55e22; }
44
+ .copy-btn.copied::after { content: ' ✓'; color: #22c55e; }
45
+ </style>
46
+ <script>${copyScript}</script>
47
+
48
+ <div class="mb-8 max-w-3xl">
49
+ <h2 class="heading-s text-content-on-surface-primary mb-1">Border radius</h2>
50
+ <p class="body-14-regular text-content-on-surface-muted">
51
+ Token-backed radius utilities from <code class="label-12-medium">aa.corner-radius</code>.
52
+ Click a class name to copy.
53
+ </p>
54
+ </div>
55
+
56
+ <div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-6">
57
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
58
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-none"></div>
59
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-none', this)">rounded-none</code>
60
+ </div>
61
+
62
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
63
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-xs"></div>
64
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-xs', this)">rounded-xs</code>
65
+ </div>
66
+
67
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
68
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-sm"></div>
69
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-sm', this)">rounded-sm</code>
70
+ </div>
71
+
72
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
73
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded"></div>
74
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded', this)">rounded</code>
75
+ </div>
76
+
77
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
78
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-md"></div>
79
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-md', this)">rounded-md</code>
80
+ </div>
81
+
82
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
83
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-lg"></div>
84
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-lg', this)">rounded-lg</code>
85
+ </div>
86
+
87
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
88
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-xl"></div>
89
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-xl', this)">rounded-xl</code>
90
+ </div>
91
+
92
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
93
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-2xl"></div>
94
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-2xl', this)">rounded-2xl</code>
95
+ </div>
96
+
97
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
98
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-3xl"></div>
99
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-3xl', this)">rounded-3xl</code>
100
+ </div>
101
+
102
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
103
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-4xl"></div>
104
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-4xl', this)">rounded-4xl</code>
105
+ </div>
106
+
107
+ <div class="rounded-lg bg-background-surface-primary shadow-sm p-4">
108
+ <div class="mx-auto h-40 w-32 bg-background-accent-soft border border-border-surface-default rounded-full"></div>
109
+ <code class="copy-btn label-12-regular text-content-on-surface-muted block mt-3" onclick="copyToClipboard('rounded-full', this)">rounded-full</code>
110
+ </div>
111
+ </div>
112
+ </div>
113
+ `,
114
+ }),
115
+ };