@supersoniks/concorde 5.0.3 → 5.0.5
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/.agents/skills/concorde-component-docs/SKILL.md +194 -0
- package/.agents/skills/concorde-component-docs/template.md +45 -0
- package/ai/cursor/rules/concorde-theme.mdc +1 -1
- package/ai/cursor/rules/concorde.mdc +1 -1
- package/ai/skills/concorde/SKILL.md +1 -1
- package/ai/skills/concorde-theme/SKILL.md +21 -10
- package/build-infos.json +1 -1
- package/concorde-core.bundle.js +515 -521
- package/concorde-core.es.js +5151 -5056
- package/dist/concorde-core.bundle.js +515 -521
- package/dist/concorde-core.es.js +5151 -5056
- package/dist/docs-mock-api-sw.js +2 -0
- package/dist/docs-mock-api-sw.js.map +2 -2
- package/docs/assets/index-CD4WyL6o.css +1 -0
- package/docs/assets/{index-BnK6OS7w.js → index-wVZpLVYW.js} +815 -808
- package/docs/crawl/core/components/ui/alert/alert.html +76 -5
- package/docs/crawl/core/components/ui/alert-messages/alert-messages.html +113 -5
- package/docs/crawl/core/components/ui/badge/badge.html +57 -8
- package/docs/crawl/core/components/ui/captcha/captcha.html +90 -8
- package/docs/crawl/core/components/ui/card/card.html +122 -12
- package/docs/crawl/core/components/ui/divider/divider.html +117 -31
- package/docs/crawl/core/components/ui/form/fieldset/fieldset.html +232 -101
- package/docs/crawl/core/components/ui/form/form-actions/form-actions.html +95 -52
- package/docs/crawl/core/components/ui/form/form-layout/form-layout.html +97 -38
- package/docs/crawl/core/components/ui/group/group.html +60 -38
- package/docs/crawl/core/components/ui/icon/icon.html +136 -47
- package/docs/crawl/core/components/ui/image/image.html +118 -6
- package/docs/crawl/core/components/ui/link/link.html +65 -7
- package/docs/crawl/core/components/ui/loader/loader.html +97 -23
- package/docs/crawl/core/components/ui/menu/menu.html +162 -90
- package/docs/crawl/core/components/ui/modal/modal.html +275 -50
- package/docs/crawl/core/components/ui/pop/pop.html +242 -124
- package/docs/crawl/core/components/ui/progress/progress.html +103 -30
- package/docs/crawl/core/components/ui/table/table.html +303 -171
- package/docs/crawl/core/components/ui/theme/theme.html +131 -0
- package/docs/crawl/core/components/ui/toast/toast.html +170 -59
- package/docs/crawl/core/components/ui/tooltip/tooltip.html +90 -29
- package/docs/crawl/docs/_decorators/ancestor-attribute.html +3 -2
- package/docs/crawl/docs/_getting-started/start.html +1 -1
- package/docs/crawl/docs/_getting-started/theming.html +311 -63
- package/docs/crawl/hubs/form-components.html +71 -49
- package/docs/crawl/index.html +7 -6
- package/docs/docs-mock-api-sw.js +2 -0
- package/docs/docs-mock-api-sw.js.map +2 -2
- package/docs/index.html +6 -4
- package/docs/llms-full.txt +1468 -405
- package/docs/llms.txt +23 -30
- package/docs/sitemap.xml +3 -0
- package/docs/src/core/components/ui/alert/alert.md +21 -2
- package/docs/src/core/components/ui/alert-messages/alert-messages.md +85 -0
- package/docs/src/core/components/ui/badge/badge.md +19 -6
- package/docs/src/core/components/ui/captcha/captcha.md +65 -6
- package/docs/src/core/components/ui/card/card.md +73 -10
- package/docs/src/core/components/ui/divider/divider.md +107 -13
- package/docs/src/core/components/ui/form/fieldset/fieldset.md +175 -99
- package/docs/src/core/components/ui/form/form-actions/form-actions.md +75 -52
- package/docs/src/core/components/ui/form/form-layout/form-layout.md +109 -34
- package/docs/src/core/components/ui/group/group.md +36 -36
- package/docs/src/core/components/ui/icon/icon.md +132 -43
- package/docs/src/core/components/ui/image/image.md +35 -3
- package/docs/src/core/components/ui/link/link.md +43 -5
- package/docs/src/core/components/ui/loader/loader.md +79 -22
- package/docs/src/core/components/ui/menu/menu.md +133 -92
- package/docs/src/core/components/ui/modal/modal.md +163 -47
- package/docs/src/core/components/ui/pop/pop.md +217 -123
- package/docs/src/core/components/ui/progress/progress.md +76 -30
- package/docs/src/core/components/ui/table/table.md +147 -171
- package/docs/src/core/components/ui/theme/theme.md +122 -0
- package/docs/src/core/components/ui/toast/toast.md +108 -58
- package/docs/src/core/components/ui/tooltip/tooltip.md +68 -26
- package/docs/src/docs/_decorators/ancestor-attribute.md +3 -2
- package/docs/src/docs/_getting-started/start.md +1 -1
- package/docs/src/docs/_getting-started/theming.md +223 -61
- package/docs/src/docs/search/docs-search.json +2504 -399
- package/docs/src/tsconfig.json +18 -0
- package/index.html +4 -2
- package/package.json +7 -1
- package/public/docs-mock-api-sw.js +2 -0
- package/public/docs-mock-api-sw.js.map +2 -2
- package/src/core/components/ui/_css/align.ts +1 -0
- package/src/core/components/ui/_css/type.ts +86 -8
- package/src/core/components/ui/_i18n/ui-aria-labels.ts +8 -0
- package/src/core/components/ui/alert/alert.md +21 -2
- package/src/core/components/ui/alert-messages/alert-messages.md +85 -0
- package/src/core/components/ui/badge/badge.md +19 -6
- package/src/core/components/ui/badge/badge.ts +8 -9
- package/src/core/components/ui/button/button.ts +5 -15
- package/src/core/components/ui/captcha/captcha.md +65 -6
- package/src/core/components/ui/card/card.md +73 -10
- package/src/core/components/ui/card/card.ts +24 -22
- package/src/core/components/ui/divider/divider.md +107 -13
- package/src/core/components/ui/divider/divider.ts +40 -33
- package/src/core/components/ui/form/fieldset/fieldset.md +175 -99
- package/src/core/components/ui/form/fieldset/fieldset.ts +15 -28
- package/src/core/components/ui/form/fieldset/legend.ts +13 -13
- package/src/core/components/ui/form/form-actions/form-actions.md +75 -52
- package/src/core/components/ui/form/form-actions/form-actions.ts +7 -5
- package/src/core/components/ui/form/form-layout/form-layout.md +109 -34
- package/src/core/components/ui/form/form-layout/form-layout.ts +27 -24
- package/src/core/components/ui/form/textarea/textarea.ts +4 -3
- package/src/core/components/ui/group/group.md +36 -36
- package/src/core/components/ui/group/group.ts +5 -10
- package/src/core/components/ui/icon/icon.md +132 -43
- package/src/core/components/ui/image/image.md +35 -3
- package/src/core/components/ui/link/link.md +43 -5
- package/src/core/components/ui/loader/loader.md +79 -22
- package/src/core/components/ui/loader/loader.ts +67 -27
- package/src/core/components/ui/loader/styles/fixed.ts +6 -11
- package/src/core/components/ui/menu/menu.md +133 -92
- package/src/core/components/ui/menu/menu.ts +53 -58
- package/src/core/components/ui/modal/modal.md +163 -47
- package/src/core/components/ui/modal/modal.ts +2 -4
- package/src/core/components/ui/pop/pop.md +217 -123
- package/src/core/components/ui/pop/pop.ts +0 -1
- package/src/core/components/ui/progress/progress.md +76 -30
- package/src/core/components/ui/progress/progress.ts +25 -56
- package/src/core/components/ui/table/table-caption.ts +2 -2
- package/src/core/components/ui/table/table-tbody.ts +3 -3
- package/src/core/components/ui/table/table-td.ts +23 -18
- package/src/core/components/ui/table/table-th.ts +8 -8
- package/src/core/components/ui/table/table-tr.ts +4 -4
- package/src/core/components/ui/table/table.md +147 -171
- package/src/core/components/ui/table/table.ts +20 -19
- package/src/core/components/ui/theme/theme-collection/auto.ts +15 -0
- package/src/core/components/ui/theme/theme-collection/core-variables.ts +8 -31
- package/src/core/components/ui/theme/theme-collection/dark.ts +1 -7
- package/src/core/components/ui/theme/theme-collection/light.ts +30 -26
- package/src/core/components/ui/theme/theme.md +122 -0
- package/src/core/components/ui/theme/theme.ts +30 -7
- package/src/core/components/ui/toast/toast-item.ts +6 -9
- package/src/core/components/ui/toast/toast.md +108 -58
- package/src/core/components/ui/toast/types.ts +1 -1
- package/src/core/components/ui/tooltip/tooltip.md +68 -26
- package/src/core/decorators/subscriber/ancestorAttribute.spec.ts +26 -0
- package/src/core/decorators/subscriber/ancestorAttribute.ts +3 -4
- package/src/core/utils/AncestorAttributeObserver.ts +183 -70
- package/src/docs/_decorators/ancestor-attribute.md +3 -2
- package/src/docs/_getting-started/start.md +1 -1
- package/src/docs/_getting-started/theming.md +223 -61
- package/src/docs/code.ts +125 -58
- package/src/docs/header/header.ts +62 -54
- package/src/docs/mock-api/router.ts +2 -0
- package/src/docs/navigation/navigation.ts +6 -3
- package/src/docs/search/docs-search.json +2504 -399
- package/src/docs/search/markdown-renderer.ts +6 -6
- package/src/docs/search/search.ts +4 -4
- package/src/docs/tailwind/css/tailwind.css +6 -5
- package/src/tsconfig.json +18 -0
- package/src/tsconfig.tsbuildinfo +1 -1
- package/tailwind.config.js +19 -0
- package/docs/assets/index--GpD7R7a.css +0 -1
|
@@ -1,91 +1,253 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Customization
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Theme-first customization
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Concorde components ship with **default styles** (fallback values in each component and in `<sonic-theme>`).
|
|
6
|
+
You do not need to define any CSS variables to get a usable UI.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
These styles are scoped and do not impact the outside.
|
|
11
|
-
- We use CSS variables as the value of properties intended to be customized from the outside.
|
|
12
|
-
For each variable, we define a default value to have a simple but consistent base style.
|
|
13
|
-
- We only rewrite inheritable properties with hard values if they are truly specific to the component.
|
|
14
|
-
- The `<style>` tag as a direct child can be used as a last resort, especially if there is a need for particularly dynamic customization. Performance is reduced.
|
|
15
|
-
- **During use / from the outside:**
|
|
16
|
-
We define values for **inheritable CSS properties** (e.g., font-\_, color...) using tools like Tailwind.
|
|
17
|
-
We modify the value of **CSS variables** used by the component.
|
|
8
|
+
To align the kit with your brand, override **only the essential theme tokens** on `<sonic-theme>`, on `:root`, or in a project stylesheet.
|
|
9
|
+
Concorde derives radius steps, button/input rounding, shadows, and most per-component layout from these primitives—**do not copy long lists of derived variables** unless you have a specific need.
|
|
18
10
|
|
|
19
|
-
|
|
11
|
+
<sonic-code language="html">
|
|
12
|
+
<template>
|
|
13
|
+
<sonic-theme color font class="block bg-base min-h-screen">
|
|
14
|
+
<!-- your app -->
|
|
15
|
+
</sonic-theme>
|
|
16
|
+
</template>
|
|
17
|
+
</sonic-code>
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
<sonic-code language="javascript">
|
|
20
|
+
<template>
|
|
21
|
+
import "@supersoniks/concorde/theme";
|
|
22
|
+
</template>
|
|
23
|
+
</sonic-code>
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
| Attribute | Effect |
|
|
26
|
+
|-----------|--------|
|
|
27
|
+
| *(omit)* \| `theme="custom"` | Default: core tokens + your `--sc-*`; no built-in light/dark palette |
|
|
28
|
+
| `theme="light"` \| `"dark"` \| `"auto"` | Opt-in presets; `auto` follows `prefers-color-scheme` |
|
|
29
|
+
| `class="bg-base block"` (Tailwind) | Page/surface background (`--sc-base`) |
|
|
30
|
+
| `color` | Text color (`--sc-base-content`) |
|
|
31
|
+
| `font` | Base font family/weight (`--sc-font-family-base`, etc.) |
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
Popovers, modals, and toasts mount under the nearest `<sonic-theme>`.
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
## Customization example
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
Example (full brand override on `<sonic-theme>` or `:root`). Set every essential token below; derived radii and shadows still come from the theme engine—only `--sc-rounded` is listed here.
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
<sonic-code language="css">
|
|
40
|
+
<template>
|
|
41
|
+
sonic-theme {
|
|
42
|
+
/* Semantic fills */
|
|
43
|
+
--sc-primary: #353429;
|
|
44
|
+
--sc-secondary: #f43f5e;
|
|
45
|
+
--sc-info: #7c3aed;
|
|
46
|
+
--sc-danger: #d71839;
|
|
47
|
+
--sc-warning: #f97316;
|
|
48
|
+
--sc-success: #10b981;
|
|
49
|
+
--sc-contrast: #111;
|
|
50
|
+
|
|
51
|
+
/* Text/icons on semantic fills */
|
|
52
|
+
--sc-primary-content: #fff;
|
|
53
|
+
--sc-secondary-content: #fff;
|
|
54
|
+
--sc-info-content: #fff;
|
|
55
|
+
--sc-danger-content: #fff;
|
|
56
|
+
--sc-warning-content: #fff;
|
|
57
|
+
--sc-success-content: #fff;
|
|
58
|
+
--sc-contrast-content: #fff;
|
|
59
|
+
|
|
60
|
+
/* Neutral fills */
|
|
61
|
+
--sc-base: #fff;
|
|
62
|
+
--sc-base-50: #f6f6f5;
|
|
63
|
+
--sc-base-100: #ededec;
|
|
64
|
+
--sc-base-200: #d7d7d4;
|
|
65
|
+
--sc-base-300: #c8c7c4;
|
|
66
|
+
--sc-base-400: #a8a7a2;
|
|
67
|
+
--sc-base-500: #94938c;
|
|
68
|
+
--sc-base-600: #76756c;
|
|
69
|
+
--sc-base-700: #59584e;
|
|
70
|
+
--sc-base-800: #47463b;
|
|
71
|
+
--sc-base-900: #353429;
|
|
72
|
+
|
|
73
|
+
/* Text/icons on neutral surfaces */
|
|
74
|
+
--sc-base-content: var(--sc-base-900);
|
|
75
|
+
|
|
76
|
+
/* Typography */
|
|
77
|
+
--sc-font-family-base: "Oswald", system-ui, -apple-system, "Segoe UI", Roboto,
|
|
78
|
+
"Helvetica Neue", Arial, sans-serif;
|
|
79
|
+
--sc-headings-font-family: "alternate-gothic-compressed", system-ui, sans-serif;
|
|
80
|
+
--sc-headings-line-height: 1.1;
|
|
81
|
+
--sc-headings-font-weight: bold;
|
|
82
|
+
--sc-headings-text-transform: none;
|
|
83
|
+
|
|
84
|
+
/* Shape (primitive only) */
|
|
85
|
+
--sc-rounded: 0;
|
|
86
|
+
|
|
87
|
+
/* Forms */
|
|
88
|
+
--sc-border-width: 0.2rem;
|
|
89
|
+
--sc-form-height: 2em;
|
|
90
|
+
--sc-input-bg: var(--sc-base);
|
|
91
|
+
--sc-input-color: var(--sc-base-content);
|
|
92
|
+
--sc-input-border-color: var(--sc-input-color);
|
|
93
|
+
--sc-input-active-bg: var(--sc-primary);
|
|
94
|
+
--sc-input-active-color: var(--sc-primary-content);
|
|
95
|
+
--sc-input-active-border-color: var(--sc-primary);
|
|
96
|
+
}
|
|
97
|
+
</template>
|
|
98
|
+
</sonic-code>
|
|
33
99
|
|
|
34
|
-
|
|
100
|
+
<sonic-button href="https://delanfranchi.github.io/concordecolors/"> Palette generator: concordecolors</sonic-button>
|
|
35
101
|
|
|
36
|
-
- It almost always leads to the creation of wrappers to style the content (instead of using `:host`).
|
|
37
|
-
- It is no longer possible to directly add classes to the component or style it from the outside.
|
|
38
|
-
Ultimately, the amount of code to write increases significantly.
|
|
39
102
|
|
|
40
|
-
|
|
103
|
+
**Without these overrides**, components keep Concorde’s per-component fallbacks. Built-in light/dark palettes apply only when you set `theme="light"`, `theme="dark"`, or `theme="auto"`.
|
|
41
104
|
|
|
42
|
-
|
|
43
|
-
To use it, you need to import the following:
|
|
105
|
+
**What we intentionally avoid:** large public `--sc-alert-*` / `--sc-badge-*` APIs or `::part()` styling hooks on most components. Prefer attributes (`type`, `status`, `size`, …) and the theme tokens above.
|
|
44
106
|
|
|
45
|
-
<sonic-code language="javascript">
|
|
46
|
-
<template>
|
|
47
|
-
import { tailwind } from "@supersoniks/concorde/la-billetterie/ui/theme/theme";
|
|
48
|
-
</template>
|
|
49
|
-
</sonic-code>
|
|
50
107
|
|
|
51
|
-
|
|
108
|
+
## Only essential CSS variables (public theme API)
|
|
52
109
|
|
|
53
|
-
|
|
54
|
-
<template>
|
|
55
|
-
static styles = [tailwind];
|
|
56
|
-
</template>
|
|
57
|
-
</sonic-code>
|
|
110
|
+
These are the **smallest set** we recommend customizing. Everything else should stay internal to the theme or to components (`--sc_*` private variables, attributes like `type`, `size`, `variant`).
|
|
58
111
|
|
|
59
|
-
|
|
112
|
+
### Surfaces and foreground
|
|
60
113
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
114
|
+
Tokens **without** a `-content` suffix are **fill / background** colors.
|
|
115
|
+
Tokens **with** `-content` are **text and icons** on top of the matching fill (solid buttons, badges, alerts, etc.).
|
|
116
|
+
|
|
117
|
+
#### Neutral fills
|
|
118
|
+
|
|
119
|
+
| Variable | Role |
|
|
120
|
+
|----------|------|
|
|
121
|
+
| `--sc-base` | Main surface / page background |
|
|
122
|
+
| `--sc-base-50` … `--sc-base-900` | Neutral scale (borders, subtle backgrounds, muted UI) |
|
|
123
|
+
|
|
124
|
+
#### Neutral foreground
|
|
125
|
+
|
|
126
|
+
| Variable | Role |
|
|
127
|
+
|----------|------|
|
|
128
|
+
| `--sc-base-content` | Default body text and icons on neutral surfaces |
|
|
66
129
|
|
|
67
|
-
|
|
130
|
+
#### Semantic fills
|
|
68
131
|
|
|
69
|
-
|
|
132
|
+
| Variable | Role |
|
|
133
|
+
|----------|------|
|
|
134
|
+
| `--sc-primary` | Primary actions, links, emphasis |
|
|
135
|
+
| `--sc-secondary` | Secondary brand accent (when used) |
|
|
136
|
+
| `--sc-info`, `--sc-success`, `--sc-warning`, `--sc-danger` | Status and feedback |
|
|
137
|
+
| `--sc-contrast` | High-contrast fills (e.g. on media) |
|
|
70
138
|
|
|
71
|
-
|
|
139
|
+
#### Semantic foreground
|
|
72
140
|
|
|
73
|
-
|
|
74
|
-
|
|
141
|
+
| Variable | Role |
|
|
142
|
+
|----------|------|
|
|
143
|
+
| `--sc-primary-content`, `--sc-secondary-content`, … | Text/icons on the matching semantic **fill** (`--sc-primary`, etc.) |
|
|
75
144
|
|
|
76
|
-
|
|
145
|
+
### Shape
|
|
77
146
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
147
|
+
| Variable | Role |
|
|
148
|
+
|----------|------|
|
|
149
|
+
| `--sc-rounded` | **Single primitive** corner radius; the theme computes `--sc-rounded-sm`, `--sc-btn-rounded`, `--sc-input-rounded`, etc. |
|
|
81
150
|
|
|
82
|
-
###
|
|
151
|
+
### Typography
|
|
83
152
|
|
|
84
|
-
|
|
153
|
+
| Variable | Role |
|
|
154
|
+
|----------|------|
|
|
155
|
+
| `--sc-font-family-base` | Body UI text |
|
|
156
|
+
| `--sc-font-weight-base`, `--sc-font-style-base` | Optional |
|
|
157
|
+
| `--sc-headings-font-family`, `--sc-headings-line-height`, `--sc-headings-font-weight`, `--sc-headings-text-transform` | Headings (modal titles, etc.) |
|
|
85
158
|
|
|
86
|
-
|
|
87
|
-
- The element and its content can be styled in a traditional manner.
|
|
159
|
+
### Forms (only if you customize inputs globally)
|
|
88
160
|
|
|
89
|
-
|
|
161
|
+
Interactive controls expose a few extra **theme-level** tokens; prefer these over styling individual inputs from outside.
|
|
162
|
+
|
|
163
|
+
| Variable | Role |
|
|
164
|
+
|----------|------|
|
|
165
|
+
| `--sc-border-width` | Default border thickness |
|
|
166
|
+
| `--sc-form-height` | Control height |
|
|
167
|
+
| `--sc-input-bg`, `--sc-input-color`, `--sc-input-border-color` | Default field chrome |
|
|
168
|
+
| `--sc-input-active-bg`, `--sc-input-active-color`, `--sc-input-active-border-color` | Focus/active state |
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Tailwind in new components ?
|
|
173
|
+
|
|
174
|
+
Set <code>tailwind.config.js</code> to match concorde style token in your custom component.
|
|
175
|
+
|
|
176
|
+
<sonic-code language="js">
|
|
177
|
+
<template>
|
|
178
|
+
...
|
|
179
|
+
theme: {
|
|
180
|
+
borderRadius: {
|
|
181
|
+
DEFAULT: "var(--sc-rounded)",
|
|
182
|
+
none: "0",
|
|
183
|
+
sm: "var(--sc-rounded-sm)",
|
|
184
|
+
md: "var(--sc-rounded-md)",
|
|
185
|
+
lg: "var(--sc-rounded-lg)",
|
|
186
|
+
xl: "var(--sc-rounded-xl)",
|
|
187
|
+
full: "9999px",
|
|
188
|
+
},
|
|
189
|
+
boxShadow: {
|
|
190
|
+
DEFAULT: "var(--sc-shadow)",
|
|
191
|
+
none: "none",
|
|
192
|
+
sm: "var(--sc-shadow-sm)",
|
|
193
|
+
md: "var(--sc-shadow-md)",
|
|
194
|
+
lg: "var(--sc-shadow-lg)",
|
|
195
|
+
xl: "var(--sc-shadow-xl)",
|
|
196
|
+
},
|
|
197
|
+
colors: {
|
|
198
|
+
transparent: "transparent",
|
|
199
|
+
current: "currentColor",
|
|
200
|
+
content: "var(--sc-base-content)",
|
|
201
|
+
base: "var(--sc-base)",
|
|
202
|
+
neutral: {
|
|
203
|
+
0: "var(--sc-base)",
|
|
204
|
+
50: "var(--sc-base-50)",
|
|
205
|
+
100: "var(--sc-base-100)",
|
|
206
|
+
200: "var(--sc-base-200)",
|
|
207
|
+
300: "var(--sc-base-300)",
|
|
208
|
+
400: "var(--sc-base-400)",
|
|
209
|
+
500: "var(--sc-base-500)",
|
|
210
|
+
600: "var(--sc-base-600)",
|
|
211
|
+
700: "var(--sc-base-700)",
|
|
212
|
+
800: "var(--sc-base-800)",
|
|
213
|
+
900: "var(--sc-base-900)",
|
|
214
|
+
content: "var(--sc-base)",
|
|
215
|
+
},
|
|
216
|
+
primary: {
|
|
217
|
+
DEFAULT: "var(--sc-primary)",
|
|
218
|
+
content: "var(--sc-primary-content)",
|
|
219
|
+
},
|
|
220
|
+
success: {
|
|
221
|
+
DEFAULT: "var(--sc-success)",
|
|
222
|
+
content: "var(--sc-success-content)",
|
|
223
|
+
},
|
|
224
|
+
danger: {
|
|
225
|
+
DEFAULT: "var(--sc-danger)",
|
|
226
|
+
content: "var(--sc-danger-content)",
|
|
227
|
+
},
|
|
228
|
+
warning: {
|
|
229
|
+
DEFAULT: "var(--sc-warning)",
|
|
230
|
+
content: "var(--sc-warning-content)",
|
|
231
|
+
},
|
|
232
|
+
info: {
|
|
233
|
+
DEFAULT: "var(--sc-info)",
|
|
234
|
+
content: "var(--sc-info-content)",
|
|
235
|
+
},
|
|
236
|
+
contrast: {
|
|
237
|
+
DEFAULT: "var(--sc-contrast)",
|
|
238
|
+
content: "var(--sc-contrast-content)",
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
extend: {
|
|
242
|
+
borderWidth: {
|
|
243
|
+
DEFAULT: "var(--sc-border-width)",
|
|
244
|
+
},
|
|
245
|
+
fontFamily: {
|
|
246
|
+
headings: ["var(--sc-headings-font-family, var(--sc-font-family-base, sans-serif))"],
|
|
247
|
+
body: ["var(--sc-font-family-base)"],
|
|
248
|
+
monospace: ["var(--sc-font-family-monospace, monospace)"],
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
</template>
|
|
252
|
+
</sonic-code>
|
|
90
253
|
|
|
91
|
-
ℹ️ **Note:** Specifically in this case, it may be useful to set the `display` property to `contents`.
|
package/src/docs/code.ts
CHANGED
|
@@ -18,6 +18,25 @@ import "prismjs/components/prism-bash"; // Language
|
|
|
18
18
|
// import "prismjs/components/prism-css"; // Language
|
|
19
19
|
import "prismjs/components/prism-markup"; // Language
|
|
20
20
|
|
|
21
|
+
let normalizeWhitespaceDefaultsApplied = false;
|
|
22
|
+
|
|
23
|
+
function normalizeDocsCodeLanguage(language: string): string {
|
|
24
|
+
return language === "html" ? "markup" : language;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function applyNormalizeWhitespaceDefaults(): void {
|
|
28
|
+
if (normalizeWhitespaceDefaultsApplied) return;
|
|
29
|
+
normalizeWhitespaceDefaultsApplied = true;
|
|
30
|
+
Prism.plugins.NormalizeWhitespace.setDefaults({
|
|
31
|
+
"remove-trailing": true,
|
|
32
|
+
"remove-indent": true,
|
|
33
|
+
"left-trim": true,
|
|
34
|
+
"right-trim": true,
|
|
35
|
+
"remove-initial-line-feed": true,
|
|
36
|
+
"tabs-to-tabs": 2,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
const tagName = "sonic-code";
|
|
22
41
|
@customElement(tagName)
|
|
23
42
|
export class DocsCode extends LitElement {
|
|
@@ -38,6 +57,7 @@ export class DocsCode extends LitElement {
|
|
|
38
57
|
padding-right: 5rem !important;
|
|
39
58
|
border: 1px solid var(--sc-base-200);
|
|
40
59
|
border-radius: var(--sc-rounded);
|
|
60
|
+
margin: 0 !important;
|
|
41
61
|
}
|
|
42
62
|
.custom-scroll {
|
|
43
63
|
overflow: auto !important;
|
|
@@ -70,62 +90,95 @@ export class DocsCode extends LitElement {
|
|
|
70
90
|
@property({ type: Boolean, reflect: true }) showCode = false;
|
|
71
91
|
@property({ type: Boolean, reflect: true }) toggleCode = false;
|
|
72
92
|
@property({ type: Boolean, reflect: true }) noEdit = false;
|
|
73
|
-
@property({ type: Boolean, reflect: true }) noOutput = false;
|
|
74
93
|
|
|
75
94
|
@property() language = "markup";
|
|
76
|
-
@property() defaultCode?: string;
|
|
77
|
-
@property() currentCode?: string;
|
|
95
|
+
@property({ attribute: false }) defaultCode?: string;
|
|
96
|
+
@property({ attribute: false }) currentCode?: string;
|
|
97
|
+
@property({ attribute: false }) codeOutput?: string;
|
|
78
98
|
|
|
79
|
-
@
|
|
99
|
+
@query("#codePreview") codePreview!: HTMLPreElement;
|
|
80
100
|
|
|
81
|
-
|
|
82
|
-
@property() templateEl: HTMLTemplateElement | null;
|
|
83
|
-
@query("#codePreview") codePreview;
|
|
84
|
-
@query("#codeRender") codeRender;
|
|
101
|
+
private templateEl: HTMLTemplateElement | null = null;
|
|
85
102
|
|
|
86
|
-
//States
|
|
87
103
|
@state() codeEdited = false;
|
|
88
104
|
|
|
89
|
-
/**
|
|
90
|
-
private get
|
|
91
|
-
return this.language
|
|
105
|
+
/** Live preview only for markup (avoid injecting HTML from JS/TS examples). */
|
|
106
|
+
private get prismLanguage(): string {
|
|
107
|
+
return normalizeDocsCodeLanguage(this.language);
|
|
92
108
|
}
|
|
93
109
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
110
|
+
private get rendersLiveOutput(): boolean {
|
|
111
|
+
return this.prismLanguage === "markup";
|
|
112
|
+
}
|
|
97
113
|
|
|
98
114
|
connectedCallback() {
|
|
99
115
|
super.connectedCallback();
|
|
100
116
|
if (!this.toggleCode) {
|
|
101
117
|
this.showCode = true;
|
|
102
118
|
}
|
|
119
|
+
this.syncFromTemplate();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
willUpdate(changedProperties: PropertyValues) {
|
|
123
|
+
if (
|
|
124
|
+
changedProperties.has("language") &&
|
|
125
|
+
changedProperties.get("language") !== undefined
|
|
126
|
+
) {
|
|
127
|
+
this.applyLanguageChange();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
103
130
|
|
|
131
|
+
private normalizeSourceForHighlight(source: string): string {
|
|
132
|
+
applyNormalizeWhitespaceDefaults();
|
|
133
|
+
const nw = Prism.plugins.NormalizeWhitespace;
|
|
134
|
+
return nw
|
|
135
|
+
.normalize(source)
|
|
136
|
+
.replaceAll('=""', "")
|
|
137
|
+
.replaceAll(""", '"')
|
|
138
|
+
.replaceAll('"{', "'{")
|
|
139
|
+
.replaceAll('}"', "}'")
|
|
140
|
+
.replaceAll("&", "&");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private highlightSource(source: string): string {
|
|
144
|
+
const lang = this.prismLanguage;
|
|
145
|
+
const grammar = Prism.languages[lang];
|
|
146
|
+
if (!grammar) {
|
|
147
|
+
return source;
|
|
148
|
+
}
|
|
149
|
+
return Prism.highlight(
|
|
150
|
+
this.normalizeSourceForHighlight(source),
|
|
151
|
+
grammar,
|
|
152
|
+
lang,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private syncFromTemplate() {
|
|
104
157
|
this.templateEl = this.querySelector("template");
|
|
105
158
|
this.defaultCode = this.readTemplateSourceCode();
|
|
159
|
+
this.codeEdited = false;
|
|
106
160
|
|
|
107
161
|
if (this.defaultCode) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
);
|
|
162
|
+
this.currentCode = this.highlightSource(this.defaultCode);
|
|
163
|
+
} else {
|
|
164
|
+
this.currentCode = undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (this.rendersLiveOutput) {
|
|
168
|
+
this.codeOutput = this.defaultCode;
|
|
169
|
+
} else {
|
|
170
|
+
this.removeOutputSlot();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private applyLanguageChange() {
|
|
175
|
+
this.defaultCode = this.readTemplateSourceCode();
|
|
176
|
+
this.codeEdited = false;
|
|
177
|
+
|
|
178
|
+
if (this.defaultCode) {
|
|
179
|
+
this.currentCode = this.highlightSource(this.defaultCode);
|
|
180
|
+
} else {
|
|
181
|
+
this.currentCode = undefined;
|
|
129
182
|
}
|
|
130
183
|
|
|
131
184
|
if (this.rendersLiveOutput) {
|
|
@@ -148,10 +201,10 @@ export class DocsCode extends LitElement {
|
|
|
148
201
|
* when the fragment has elements; otherwise textContent (imports, types, etc.).
|
|
149
202
|
*/
|
|
150
203
|
private readTemplateSourceCode(): string {
|
|
151
|
-
const template = this.templateEl;
|
|
204
|
+
const template = this.templateEl ?? this.querySelector("template");
|
|
152
205
|
if (!template) return "";
|
|
153
206
|
|
|
154
|
-
if (this.
|
|
207
|
+
if (this.prismLanguage === "markup") {
|
|
155
208
|
return this.decodeTemplateEntities(template.innerHTML);
|
|
156
209
|
}
|
|
157
210
|
|
|
@@ -160,11 +213,16 @@ export class DocsCode extends LitElement {
|
|
|
160
213
|
return template.content.textContent ?? "";
|
|
161
214
|
}
|
|
162
215
|
|
|
216
|
+
private getPreviewPlainText(): string {
|
|
217
|
+
return this.codePreview?.innerText ?? "";
|
|
218
|
+
}
|
|
219
|
+
|
|
163
220
|
updateCodeRender() {
|
|
164
|
-
|
|
165
|
-
|
|
221
|
+
const plain = this.getPreviewPlainText();
|
|
222
|
+
this.codeEdited = plain !== (this.defaultCode ?? "");
|
|
223
|
+
if (this.rendersLiveOutput) {
|
|
224
|
+
this.codeOutput = plain;
|
|
166
225
|
}
|
|
167
|
-
this.codeOutput = this.codePreview?.innerText;
|
|
168
226
|
}
|
|
169
227
|
|
|
170
228
|
resetCode() {
|
|
@@ -173,11 +231,7 @@ export class DocsCode extends LitElement {
|
|
|
173
231
|
if (this.defaultCode) {
|
|
174
232
|
this.currentCode = "";
|
|
175
233
|
window.requestAnimationFrame(() => {
|
|
176
|
-
this.currentCode =
|
|
177
|
-
this.defaultCode || "",
|
|
178
|
-
Prism.languages[this.language],
|
|
179
|
-
this.language,
|
|
180
|
-
);
|
|
234
|
+
this.currentCode = this.highlightSource(this.defaultCode || "");
|
|
181
235
|
});
|
|
182
236
|
}
|
|
183
237
|
if (this.rendersLiveOutput) {
|
|
@@ -189,15 +243,27 @@ export class DocsCode extends LitElement {
|
|
|
189
243
|
this.showCode = !this.showCode;
|
|
190
244
|
}
|
|
191
245
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
246
|
+
private getCopyText(): string {
|
|
247
|
+
if (!this.noEdit) {
|
|
248
|
+
const fromPreview = this.getPreviewPlainText();
|
|
249
|
+
if (fromPreview) return fromPreview;
|
|
250
|
+
}
|
|
251
|
+
return this.codeOutput ?? this.defaultCode ?? "";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async handleCopyCode(e: Event) {
|
|
255
|
+
const text = this.getCopyText();
|
|
256
|
+
if (!text) return;
|
|
257
|
+
|
|
258
|
+
const button = e.currentTarget as HTMLButtonElement;
|
|
259
|
+
try {
|
|
260
|
+
await navigator.clipboard.writeText(text);
|
|
197
261
|
button?.setAttribute("active", "");
|
|
198
262
|
setTimeout(() => {
|
|
199
263
|
button?.removeAttribute("active");
|
|
200
264
|
}, 500);
|
|
265
|
+
} catch {
|
|
266
|
+
// Clipboard unavailable or permission denied.
|
|
201
267
|
}
|
|
202
268
|
}
|
|
203
269
|
|
|
@@ -205,8 +271,7 @@ export class DocsCode extends LitElement {
|
|
|
205
271
|
super.updated(changedProperties);
|
|
206
272
|
if (
|
|
207
273
|
changedProperties.has("codeOutput") ||
|
|
208
|
-
changedProperties.has("language")
|
|
209
|
-
changedProperties.has("noOutput")
|
|
274
|
+
changedProperties.has("language")
|
|
210
275
|
) {
|
|
211
276
|
this.appendOutput();
|
|
212
277
|
}
|
|
@@ -216,6 +281,7 @@ export class DocsCode extends LitElement {
|
|
|
216
281
|
this.querySelector("[slot=output]")?.remove();
|
|
217
282
|
}
|
|
218
283
|
|
|
284
|
+
/** Trusted doc demo markup only — same source as the live preview slot. */
|
|
219
285
|
appendOutput() {
|
|
220
286
|
if (!this.rendersLiveOutput) {
|
|
221
287
|
this.removeOutputSlot();
|
|
@@ -231,20 +297,21 @@ export class DocsCode extends LitElement {
|
|
|
231
297
|
output.innerHTML = this.codeOutput || "";
|
|
232
298
|
}
|
|
233
299
|
}
|
|
300
|
+
|
|
234
301
|
handleGetSDUI() {
|
|
235
302
|
SDUIUtils.toJson(this.templateEl?.content.children);
|
|
236
303
|
}
|
|
237
304
|
|
|
238
305
|
render() {
|
|
239
|
-
|
|
306
|
+
const isMarkup = this.prismLanguage === "markup";
|
|
240
307
|
|
|
241
308
|
return html`
|
|
242
309
|
<div
|
|
243
|
-
class="relative ${
|
|
310
|
+
class="relative ${isMarkup
|
|
244
311
|
? "rounded-md border border-neutral-200 bg-neutral-50/80 dark:border-neutral-700/80 dark:bg-neutral-900/40 p-4"
|
|
245
312
|
: ""}"
|
|
246
313
|
>
|
|
247
|
-
${
|
|
314
|
+
${isMarkup
|
|
248
315
|
? html`<slot name="output" class="block py-3"></slot>`
|
|
249
316
|
: nothing}
|
|
250
317
|
|
|
@@ -282,7 +349,7 @@ export class DocsCode extends LitElement {
|
|
|
282
349
|
name="check"
|
|
283
350
|
></sonic-icon>
|
|
284
351
|
</sonic-button>
|
|
285
|
-
${
|
|
352
|
+
${isMarkup
|
|
286
353
|
? html`<sonic-button
|
|
287
354
|
size="2xs"
|
|
288
355
|
shape
|
|
@@ -316,7 +383,7 @@ export class DocsCode extends LitElement {
|
|
|
316
383
|
<div>
|
|
317
384
|
<pre
|
|
318
385
|
id="codePreview"
|
|
319
|
-
class="rounded-md custom-scroll language-${this.
|
|
386
|
+
class="rounded-md custom-scroll language-${this.prismLanguage} ${!this
|
|
320
387
|
.showCode || !this.currentCode
|
|
321
388
|
? "hidden"
|
|
322
389
|
: ""}"
|