@nanahoshi/mona-ui 0.27.2 → 0.29.0
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/docs/api/chart.md +2 -2
- package/docs/api/locales.md +8 -0
- package/docs/api/popup.md +1 -1
- package/docs/api/theme.md +2 -2
- package/docs/chart.md +14 -0
- package/docs/editor.md +2 -0
- package/docs/installation.md +147 -15
- package/docs/introduction.md +37 -15
- package/docs/theming-built-in-themes.md +67 -0
- package/docs/theming-custom-colors.md +274 -0
- package/docs/theming-custom-themes.md +168 -0
- package/docs/theming.md +164 -248
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1089 -603
- package/fesm2022/nanahoshi-mona-ui-avatar.mjs +369 -184
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +658 -371
- package/fesm2022/nanahoshi-mona-ui-button-group.mjs +513 -359
- package/fesm2022/nanahoshi-mona-ui-button.mjs +622 -517
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +2071 -1573
- package/fesm2022/nanahoshi-mona-ui-card.mjs +620 -316
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +61151 -64921
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +646 -317
- package/fesm2022/nanahoshi-mona-ui-chip.mjs +737 -516
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +441 -242
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +443 -390
- package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +1138 -814
- package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +1114 -959
- package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +858 -504
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1181 -742
- package/fesm2022/nanahoshi-mona-ui-command.mjs +1454 -853
- package/fesm2022/nanahoshi-mona-ui-common.mjs +569 -743
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +978 -532
- package/fesm2022/nanahoshi-mona-ui-date-input.mjs +283 -266
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +973 -451
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +1203 -658
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +1415 -936
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +1165 -568
- package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1142 -677
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +1018 -734
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3589 -2122
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +577 -359
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +311 -151
- package/fesm2022/nanahoshi-mona-ui-filter.mjs +1086 -718
- package/fesm2022/nanahoshi-mona-ui-grid-grid-colgroup.component-NhONCVIX.mjs +77 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-row.component-Djv8ZnT5.mjs +480 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-WbXAzGCa.mjs +470 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-DkWTD3pN.mjs +2115 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid-virtual-list.component-DAHqTwBJ.mjs +330 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid.styles-BmLU-3zP.mjs +3766 -0
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +5418 -2
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +1379 -1079
- package/fesm2022/nanahoshi-mona-ui-i18n.mjs +4451 -5077
- package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +344 -143
- package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +257 -127
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +2080 -1829
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +103 -141
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +2498 -2706
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +722 -1007
- package/fesm2022/nanahoshi-mona-ui-label.mjs +313 -202
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +1308 -1009
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +1411 -677
- package/fesm2022/nanahoshi-mona-ui-list.mjs +1 -6
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +556 -577
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +530 -573
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +530 -573
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +533 -576
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +520 -555
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +530 -571
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +520 -555
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +520 -555
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +599 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +530 -571
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +576 -591
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +530 -565
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +520 -555
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +520 -555
- package/fesm2022/nanahoshi-mona-ui-locales.mjs +61 -77
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +1411 -829
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1326 -702
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +763 -675
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1306 -826
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +1122 -897
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +1110 -651
- package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +95 -53
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +559 -397
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +2323 -1694
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +1657 -1455
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +441 -267
- package/fesm2022/nanahoshi-mona-ui-query.mjs +211 -340
- package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +1017 -548
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +874 -624
- package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +1130 -917
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +705 -455
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +461 -283
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +2791 -2449
- package/fesm2022/nanahoshi-mona-ui-skeleton.mjs +145 -90
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +1563 -1103
- package/fesm2022/nanahoshi-mona-ui-spinner.mjs +738 -673
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +1287 -647
- package/fesm2022/nanahoshi-mona-ui-splitter.mjs +1313 -909
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +761 -540
- package/fesm2022/nanahoshi-mona-ui-switch.mjs +611 -280
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +1393 -841
- package/fesm2022/nanahoshi-mona-ui-text-area.mjs +142 -73
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +876 -374
- package/fesm2022/nanahoshi-mona-ui-theme.mjs +1465 -1449
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +897 -443
- package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +1100 -703
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +789 -538
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +1361 -805
- package/fesm2022/nanahoshi-mona-ui-window.mjs +2145 -1531
- package/fesm2022/nanahoshi-mona-ui.mjs +1 -8
- package/llms.txt +7 -3
- package/locales/pl-pl/package.json +4 -0
- package/locales/pl-pl/pl-pl.messages.json +536 -0
- package/package.json +66 -23
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +367 -233
- package/types/nanahoshi-mona-ui-avatar.d.ts +722 -649
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +134 -103
- package/types/nanahoshi-mona-ui-button-group.d.ts +213 -152
- package/types/nanahoshi-mona-ui-button.d.ts +227 -166
- package/types/nanahoshi-mona-ui-calendar.d.ts +324 -259
- package/types/nanahoshi-mona-ui-card.d.ts +125 -111
- package/types/nanahoshi-mona-ui-chart.d.ts +10483 -7326
- package/types/nanahoshi-mona-ui-check-box.d.ts +293 -180
- package/types/nanahoshi-mona-ui-chip.d.ts +208 -141
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +194 -133
- package/types/nanahoshi-mona-ui-collapsible.d.ts +103 -87
- package/types/nanahoshi-mona-ui-color-gradient.d.ts +281 -213
- package/types/nanahoshi-mona-ui-color-palette.d.ts +201 -138
- package/types/nanahoshi-mona-ui-color-picker.d.ts +283 -194
- package/types/nanahoshi-mona-ui-combo-box.d.ts +401 -262
- package/types/nanahoshi-mona-ui-command.d.ts +279 -191
- package/types/nanahoshi-mona-ui-common.d.ts +354 -385
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +142 -117
- package/types/nanahoshi-mona-ui-date-input.d.ts +79 -96
- package/types/nanahoshi-mona-ui-date-picker.d.ts +338 -208
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +413 -259
- package/types/nanahoshi-mona-ui-dialog.d.ts +470 -381
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +216 -168
- package/types/nanahoshi-mona-ui-dropdown-list.d.ts +369 -243
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +231 -217
- package/types/nanahoshi-mona-ui-editor.d.ts +302 -235
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +140 -109
- package/types/nanahoshi-mona-ui-fieldset.d.ts +98 -68
- package/types/nanahoshi-mona-ui-filter.d.ts +150 -124
- package/types/nanahoshi-mona-ui-grid.d.ts +1956 -1678
- package/types/nanahoshi-mona-ui-i18n-icu.d.ts +25 -34
- package/types/nanahoshi-mona-ui-i18n.d.ts +987 -1052
- package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +118 -71
- package/types/nanahoshi-mona-ui-internal-indicator-icon.d.ts +56 -27
- package/types/nanahoshi-mona-ui-internal-list.d.ts +474 -408
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +143 -150
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +493 -506
- package/types/nanahoshi-mona-ui-internal.d.ts +195 -213
- package/types/nanahoshi-mona-ui-label.d.ts +108 -78
- package/types/nanahoshi-mona-ui-list-box.d.ts +392 -322
- package/types/nanahoshi-mona-ui-list-view.d.ts +423 -282
- package/types/nanahoshi-mona-ui-list.d.ts +2 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +540 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +540 -542
- package/types/nanahoshi-mona-ui-locales.d.ts +18 -19
- package/types/nanahoshi-mona-ui-menubar.d.ts +210 -181
- package/types/nanahoshi-mona-ui-multi-select.d.ts +416 -276
- package/types/nanahoshi-mona-ui-notification.d.ts +140 -151
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +407 -270
- package/types/nanahoshi-mona-ui-otp-input.d.ts +364 -241
- package/types/nanahoshi-mona-ui-pager.d.ts +379 -301
- package/types/nanahoshi-mona-ui-placeholder.d.ts +35 -28
- package/types/nanahoshi-mona-ui-popover.d.ts +176 -134
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +488 -344
- package/types/nanahoshi-mona-ui-popup.d.ts +698 -560
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +197 -137
- package/types/nanahoshi-mona-ui-query.d.ts +82 -88
- package/types/nanahoshi-mona-ui-radio-button.d.ts +434 -269
- package/types/nanahoshi-mona-ui-rating.d.ts +348 -254
- package/types/nanahoshi-mona-ui-scroll-view.d.ts +244 -172
- package/types/nanahoshi-mona-ui-segmented.d.ts +250 -175
- package/types/nanahoshi-mona-ui-sheet.d.ts +115 -63
- package/types/nanahoshi-mona-ui-sidebar.d.ts +653 -493
- package/types/nanahoshi-mona-ui-skeleton.d.ts +55 -39
- package/types/nanahoshi-mona-ui-slider.d.ts +503 -354
- package/types/nanahoshi-mona-ui-spinner.d.ts +125 -112
- package/types/nanahoshi-mona-ui-split-button.d.ts +241 -196
- package/types/nanahoshi-mona-ui-splitter.d.ts +124 -78
- package/types/nanahoshi-mona-ui-stepper.d.ts +206 -181
- package/types/nanahoshi-mona-ui-switch.d.ts +197 -131
- package/types/nanahoshi-mona-ui-tabs.d.ts +349 -248
- package/types/nanahoshi-mona-ui-text-area.d.ts +52 -36
- package/types/nanahoshi-mona-ui-text-box.d.ts +349 -218
- package/types/nanahoshi-mona-ui-theme.d.ts +415 -408
- package/types/nanahoshi-mona-ui-time-picker.d.ts +357 -217
- package/types/nanahoshi-mona-ui-time-selector.d.ts +255 -170
- package/types/nanahoshi-mona-ui-tooltip.d.ts +222 -144
- package/types/nanahoshi-mona-ui-tree-view.d.ts +466 -308
- package/types/nanahoshi-mona-ui-window.d.ts +494 -399
- package/types/nanahoshi-mona-ui.d.ts +1 -2
- package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs +0 -181
- package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs +0 -208
- package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs +0 -1082
- package/fesm2022/nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs +0 -186
- package/fesm2022/nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs +0 -7568
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Custom Colors
|
|
2
|
+
|
|
3
|
+
> Generate a palette from brand colors, override tokens, or let users choose a color.
|
|
4
|
+
|
|
5
|
+
Any theme can take on your brand's colors. Mona UI has three ways to change them, and they combine:
|
|
6
|
+
|
|
7
|
+
| To | Use |
|
|
8
|
+
| ----------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
9
|
+
| Generate a complete, accessible palette from your brand colors | `provideThemeColorPalette()` |
|
|
10
|
+
| Set specific tokens to exact values, including corner radii and shadows | `provideThemeOverrides()` |
|
|
11
|
+
| Let users choose a color while the application runs | `ThemeService.setPrimaryColor()` and `setColorPalette()` |
|
|
12
|
+
|
|
13
|
+
## Try It
|
|
14
|
+
|
|
15
|
+
Choose a color and apply it. The whole site changes to match, and Reset brings back its own colors.
|
|
16
|
+
|
|
17
|
+
`runtime-primary-example.component.ts`
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { Component, DestroyRef, inject, signal } from "@angular/core";
|
|
21
|
+
import { ButtonDirective } from "@nanahoshi/mona-ui/button";
|
|
22
|
+
import { ColorPickerComponent } from "@nanahoshi/mona-ui/color-picker";
|
|
23
|
+
import { ThemeService } from "@nanahoshi/mona-ui/theme";
|
|
24
|
+
|
|
25
|
+
@Component({
|
|
26
|
+
selector: "app-theming-custom-colors-runtime-primary-example",
|
|
27
|
+
imports: [ButtonDirective, ColorPickerComponent],
|
|
28
|
+
templateUrl: "./runtime-primary-example.component.html"
|
|
29
|
+
})
|
|
30
|
+
export class ThemingCustomColorsRuntimePrimaryExampleComponent {
|
|
31
|
+
readonly #theme = inject(ThemeService);
|
|
32
|
+
|
|
33
|
+
protected readonly color = signal(this.#theme.colorPaletteSeeds()?.primary ?? null);
|
|
34
|
+
|
|
35
|
+
public constructor() {
|
|
36
|
+
// A preview: the page gets its configured colors back when the example goes away.
|
|
37
|
+
inject(DestroyRef).onDestroy(() => this.#theme.clearColorPalette());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected apply(color: string | null): void {
|
|
41
|
+
this.color.set(color);
|
|
42
|
+
if (color) {
|
|
43
|
+
this.#theme.setPrimaryColor(color);
|
|
44
|
+
} else {
|
|
45
|
+
this.#theme.clearColorPalette();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`runtime-primary-example.component.html`
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
55
|
+
<mona-color-picker
|
|
56
|
+
aria-label="Primary color"
|
|
57
|
+
view="gradient"
|
|
58
|
+
[opacity]="false"
|
|
59
|
+
[value]="color()"
|
|
60
|
+
(valueChange)="apply($event)" />
|
|
61
|
+
<button monaButton look="primary" type="button">Primary action</button>
|
|
62
|
+
<button monaButton type="button" [disabled]="!color()" (click)="apply(null)">Reset</button>
|
|
63
|
+
</div>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Color Roles
|
|
67
|
+
|
|
68
|
+
Colors in Mona UI are named for their job, not for a component, so the same text box looks right on a page and inside a popup:
|
|
69
|
+
|
|
70
|
+
| Role | Tokens | Used for |
|
|
71
|
+
| -------------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| Canvas | `--color-canvas` | The application's backdrop. |
|
|
73
|
+
| Surfaces | `--color-surface`, `--color-surface-muted` | The normal content plane, and quieter areas on it. |
|
|
74
|
+
| Raised and overlay | `--color-surface-raised`, `--color-surface-overlay` | Elevated regions, and menus, popups and dialogs. |
|
|
75
|
+
| Text | `--color-foreground`, `--color-muted-foreground` | Main and secondary text. |
|
|
76
|
+
| Fields and controls | `--color-input-background`, `--color-border-control` | Form fields, buttons and other outlined controls, which share a quiet border so they match side by side. |
|
|
77
|
+
| Interaction | `--color-hover`, `--color-active` | Neutral, temporary feedback when a control is hovered or pressed. |
|
|
78
|
+
| Accent and selection | `--color-accent`, `--color-selected` | Persistent selection and keyboard highlighting. |
|
|
79
|
+
| Primary | `--color-primary`, `--color-focus-indicator` | Prominent buttons and links. Focus rings and selected borders use it too, by default. |
|
|
80
|
+
| Secondary | `--color-secondary` | Actions that should stand out less than primary ones. |
|
|
81
|
+
| Status | `--color-success`, `--color-error`, `--color-warning`, `--color-info` | Messages and states where the color carries meaning. |
|
|
82
|
+
| Charts | `--color-chart-1` to `--color-chart-5` | Chart series. |
|
|
83
|
+
|
|
84
|
+
A role that fills a background has a `-foreground` token for the text on it, and the primary, secondary and status roles also have `-hover`, `-active`, `-subtle`, `-subtle-foreground` and `-border` tokens. This keeps brand color where it belongs: changing the primary recolors main actions and focus, without turning every hover state into the brand color.
|
|
85
|
+
|
|
86
|
+
[Theme Colors](theming-colors.md) shows the roles in the current theme, with their contrast ratios.
|
|
87
|
+
|
|
88
|
+
## Generate a Palette from Brand Colors
|
|
89
|
+
|
|
90
|
+
`provideThemeColorPalette()` turns your brand colors into a full light and dark palette, fitted for contrast. Only `primary` is required. Add it to your application's providers:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { ApplicationConfig } from "@angular/core";
|
|
94
|
+
import { provideThemeColorPalette } from "@nanahoshi/mona-ui/theme";
|
|
95
|
+
|
|
96
|
+
export const appConfig: ApplicationConfig = {
|
|
97
|
+
providers: [
|
|
98
|
+
// ...your existing providers
|
|
99
|
+
provideThemeColorPalette({ theme: "mona", seeds: { primary: "#7444c3" } })
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`theme` names the theme the palette applies to, and each seed replaces its own role. A role without a seed keeps the theme's color:
|
|
105
|
+
|
|
106
|
+
| Seed | Replaces |
|
|
107
|
+
| ------------------------------------- | ------------------------------------------------------------------------------ |
|
|
108
|
+
| `primary` | The primary role, and the accent, selection and focus colors, tinted to match. |
|
|
109
|
+
| `secondary` | The secondary role. |
|
|
110
|
+
| `success`, `error`, `warning`, `info` | That status role. |
|
|
111
|
+
|
|
112
|
+
A seed can be any opaque CSS color, such as hex, `rgb()`, `hsl()` or `oklch()`:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
provideThemeColorPalette({
|
|
116
|
+
theme: "mona",
|
|
117
|
+
seeds: {
|
|
118
|
+
primary: "#7444c3",
|
|
119
|
+
secondary: "hsl(212 27% 39%)",
|
|
120
|
+
success: "oklch(62% 0.14 150)",
|
|
121
|
+
error: "rgb(194 65 59)",
|
|
122
|
+
warning: "#b36b00",
|
|
123
|
+
info: "oklch(60% 0.15 255)"
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The seed's hue and chroma give the palette its identity. Mona UI then chooses each tone's lightness, and lowers the chroma where it must, so that text meets WCAG AA contrast and every color fits in the sRGB gamut, in light and in dark. A palette applies to every variant its theme has, so to light and dark for each built-in theme. An invalid or translucent seed throws an error while the application starts, naming its role.
|
|
129
|
+
|
|
130
|
+
To see the colors before you use them, call `generateThemeColorPalette()`. It returns the tokens as two maps, `light` and `dark`:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { generateThemeColorPalette } from "@nanahoshi/mona-ui/theme";
|
|
134
|
+
|
|
135
|
+
const palette = generateThemeColorPalette({ primary: "#7444c3" });
|
|
136
|
+
palette.light["--color-primary"]; // An oklch() color.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Override Specific Tokens
|
|
140
|
+
|
|
141
|
+
`provideThemeOverrides()` sets tokens of a registered theme to exact values. `common` applies to both variants, and `light` and `dark` to one each. A variant's value wins over `common`:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { provideThemeOverrides } from "@nanahoshi/mona-ui/theme";
|
|
145
|
+
|
|
146
|
+
provideThemeOverrides({
|
|
147
|
+
theme: "mona",
|
|
148
|
+
light: {
|
|
149
|
+
colors: {
|
|
150
|
+
"--color-primary": "oklch(48% 0.16 280)",
|
|
151
|
+
"--color-primary-foreground": "white"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
dark: {
|
|
155
|
+
colors: {
|
|
156
|
+
"--color-primary": "oklch(72% 0.14 280)",
|
|
157
|
+
"--color-primary-foreground": "oklch(18% 0.02 280)"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Overrides aren't only for colors. A variant takes the same sections as a theme, `colors`, `shadows`, `shape`, `motion`, `effects`, `components` and `custom`, so rounder corners for every variant look like this:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
provideThemeOverrides({
|
|
167
|
+
theme: "mona",
|
|
168
|
+
common: {
|
|
169
|
+
shape: { "--radius-sm": "0.375rem", "--radius-md": "0.625rem", "--radius-lg": "0.875rem" }
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
You can use `provideThemeOverrides()` more than once. Later ones win, and leave the tokens they don't name alone. A palette goes through the same steps, so to adjust a generated color, put the override after the palette:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
providers: [
|
|
178
|
+
provideThemeColorPalette({ theme: "mona", seeds: { primary: "#7444c3" } }),
|
|
179
|
+
provideThemeOverrides({
|
|
180
|
+
theme: "mona",
|
|
181
|
+
dark: { colors: { "--color-primary": "oklch(74% 0.14 308.49)" } }
|
|
182
|
+
})
|
|
183
|
+
];
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
An override for a theme or variant that isn't registered throws while the application starts. Overrides change the application's one theme: providing them in a component doesn't give that component a theme of its own.
|
|
187
|
+
|
|
188
|
+
## Use an Exact Brand Color
|
|
189
|
+
|
|
190
|
+
A palette keeps a seed's hue and chroma, but chooses the lightness each role needs for contrast. So a palette can't reproduce an exact brand color: even `#ffffff` and `#000000` give the same palette. To use an exact color, generate a palette from it, then override the base color and its foreground:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
providers: [
|
|
194
|
+
provideThemeColorPalette({ theme: "mona", seeds: { primary: "#e4002b" } }),
|
|
195
|
+
provideThemeOverrides({
|
|
196
|
+
theme: "mona",
|
|
197
|
+
light: { colors: { "--color-primary": "#e4002b", "--color-primary-foreground": "#ffffff" } }
|
|
198
|
+
})
|
|
199
|
+
];
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The palette still provides the hover, pressed, subtle and selection tones, and the dark variant keeps the generated primary, which is lighter so that it stands out on dark surfaces. Check the contrast of the colors you set yourself: text on the primary color needs 4.5:1, and the primary color needs 3:1 against the surface, since focus rings use it. In development, Mona UI warns when text on the primary color is below 4.5:1.
|
|
203
|
+
|
|
204
|
+
## Let Users Choose a Color
|
|
205
|
+
|
|
206
|
+
`ThemeService.setPrimaryColor()` generates a palette from one color and applies it at once, on top of the configured theme, palette and overrides. The example at the top of this page uses it:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { Component, inject } from "@angular/core";
|
|
210
|
+
import { ThemeService } from "@nanahoshi/mona-ui/theme";
|
|
211
|
+
|
|
212
|
+
@Component({
|
|
213
|
+
selector: "app-appearance-settings",
|
|
214
|
+
templateUrl: "./appearance-settings.html"
|
|
215
|
+
})
|
|
216
|
+
export class AppearanceSettings {
|
|
217
|
+
readonly #theme = inject(ThemeService);
|
|
218
|
+
|
|
219
|
+
protected usePrimaryColor(color: string): void {
|
|
220
|
+
this.#theme.setPrimaryColor(color);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
protected restoreColors(): void {
|
|
224
|
+
this.#theme.clearColorPalette();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`setColorPalette()` takes the same seeds as `provideThemeColorPalette()`, for more roles than the primary. `setPrimaryColor()` changes only the primary seed and keeps any others.
|
|
230
|
+
|
|
231
|
+
- The colors stay when the user switches theme or variant, using their light or dark tones as needed.
|
|
232
|
+
- `clearColorPalette()` removes them, and restores the configured colors.
|
|
233
|
+
- `colorPaletteSeeds()` is a signal with the current seeds, or `null` when there are none, for showing the user's choice.
|
|
234
|
+
- A bad color throws before anything changes, so the page never shows half a palette.
|
|
235
|
+
|
|
236
|
+
`persistKey` remembers the theme, not these colors. To keep them, save the seeds in your own settings and apply them again at startup:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import { inject, provideAppInitializer } from "@angular/core";
|
|
240
|
+
import { ThemeService } from "@nanahoshi/mona-ui/theme";
|
|
241
|
+
|
|
242
|
+
providers: [
|
|
243
|
+
provideAppInitializer(() => {
|
|
244
|
+
const seeds = loadSavedColors(); // From your own settings, or null.
|
|
245
|
+
if (seeds) {
|
|
246
|
+
inject(ThemeService).setColorPalette(seeds);
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
];
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
If the saved value can come from anywhere but your own code, catch the error a bad color throws, so it can't stop the application from starting.
|
|
253
|
+
|
|
254
|
+
## Add Your Own Color Names
|
|
255
|
+
|
|
256
|
+
An override can add tokens a theme doesn't have, such as a brand color for your own components:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
provideThemeOverrides({
|
|
260
|
+
theme: "mona",
|
|
261
|
+
light: { colors: { "--color-brand": "oklch(52% 0.18 280)" } },
|
|
262
|
+
dark: { colors: { "--color-brand": "oklch(72% 0.14 280)" } }
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The theme service writes it as a CSS variable like any other, but Tailwind only makes classes for the names it knows at build time. To use it as `bg-brand` or `text-brand`, declare it in your global stylesheet. The value there is only a placeholder, which the theme replaces:
|
|
267
|
+
|
|
268
|
+
```css
|
|
269
|
+
@theme {
|
|
270
|
+
--color-brand: transparent;
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Without the declaration, use `bg-(--color-brand)`, or `var(--color-brand)` in plain CSS.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Custom Themes
|
|
2
|
+
|
|
3
|
+
> Register a theme of your own, from scratch or based on a built-in theme.
|
|
4
|
+
|
|
5
|
+
When changing a few tokens isn't enough, register a theme of your own. A custom theme works like a built-in one: it can have a light variant, a dark variant or both, and users can switch to it. You can write one from scratch, or start from a built-in theme and change what you need.
|
|
6
|
+
|
|
7
|
+
This site's theme menu includes Aurora Dark, a custom theme made this way.
|
|
8
|
+
|
|
9
|
+
## Start from a Built-in Theme
|
|
10
|
+
|
|
11
|
+
The quickest custom theme copies a built-in one and changes some of its tokens. This one takes Mona, gives it a teal palette and rounder corners, and names it `ocean`:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { generateThemeColorPalette, monaTheme, type ThemeFamilyRegistration } from "@nanahoshi/mona-ui/theme";
|
|
15
|
+
|
|
16
|
+
const palette = generateThemeColorPalette({ primary: "#0f766e" });
|
|
17
|
+
const shape = { "--radius-sm": "0.375rem", "--radius-md": "0.625rem", "--radius-lg": "0.875rem" };
|
|
18
|
+
|
|
19
|
+
export const oceanTheme = {
|
|
20
|
+
name: "ocean",
|
|
21
|
+
variants: {
|
|
22
|
+
light: {
|
|
23
|
+
...monaTheme.variants.light,
|
|
24
|
+
colors: { ...monaTheme.variants.light.colors, ...palette.light },
|
|
25
|
+
shape
|
|
26
|
+
},
|
|
27
|
+
dark: {
|
|
28
|
+
...monaTheme.variants.dark,
|
|
29
|
+
colors: { ...monaTheme.variants.dark.colors, ...palette.dark },
|
|
30
|
+
shape
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} satisfies ThemeFamilyRegistration;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Register it with `provideThemeFamily()`, then select it like any other theme:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
providers: [
|
|
40
|
+
provideThemeFamily(oceanTheme),
|
|
41
|
+
provideThemeOptions({ initialTheme: { name: "ocean", variant: "system" } })
|
|
42
|
+
];
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`availableThemes()` now lists Ocean next to the built-in themes, and `setTheme({ name: "ocean", variant: "dark" })` switches to it. Unlike [overrides](theming-custom-colors.md#override-specific-tokens) on Mona, this keeps Mona as it was, so users can choose between the two.
|
|
46
|
+
|
|
47
|
+
## Register a Theme
|
|
48
|
+
|
|
49
|
+
`provideThemeFamily()` takes a theme's `name` and its `variants`. A theme needs at least one variant. With a single one, `variant: "system"` always gives that one:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { provideThemeFamily, type ThemeFamilyRegistration } from "@nanahoshi/mona-ui/theme";
|
|
53
|
+
import { auroraDarkProfile } from "./aurora-dark-profile";
|
|
54
|
+
|
|
55
|
+
const auroraTheme = {
|
|
56
|
+
name: "aurora",
|
|
57
|
+
variants: { dark: auroraDarkProfile }
|
|
58
|
+
} satisfies ThemeFamilyRegistration;
|
|
59
|
+
|
|
60
|
+
providers: [provideThemeFamily(auroraTheme)];
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Register themes in the application's root providers. The theme service writes one theme for the whole application, so a theme provided in a component isn't scoped to that component.
|
|
64
|
+
|
|
65
|
+
## What a Theme Defines
|
|
66
|
+
|
|
67
|
+
Each variant is a complete `ThemeProfile`, with these sections:
|
|
68
|
+
|
|
69
|
+
| Section | Tokens | What they control |
|
|
70
|
+
| ------------ | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
71
|
+
| `colors` | Every `--color-*` token that Mona Light defines | Backgrounds, text, borders, states and charts. See [Color Roles](theming-custom-colors.md#color-roles). |
|
|
72
|
+
| `shadows` | `--shadow-control`, `--shadow-raised`, `--shadow-overlay` | How far controls, raised panels and overlays stand off the page. |
|
|
73
|
+
| `shape` | `--radius-sm`, `--radius-md`, `--radius-lg` | Corner radii. |
|
|
74
|
+
| `motion` | `--mona-motion-fast`, `--mona-motion-standard` | Animation durations. |
|
|
75
|
+
| `effects` | `--mona-effect-*`, for the `control`, `raised` and `overlay` materials | Translucent or opaque backgrounds. See [Materials](#materials). |
|
|
76
|
+
| `components` | Tokens for single components, such as `--mona-menubar-background` | Calendar, list, menubar, pager and slider details. |
|
|
77
|
+
| `custom` | Optional. Any other variables | Optional tokens, such as [indicator colors](#indicator-colors), and tokens of your own. |
|
|
78
|
+
|
|
79
|
+
Every token in the first six sections is required, except the two [contrast borders](#contrast-borders). A variant that's missing one throws while the application starts, and the error lists what's missing. The easiest way to get them all is to start from a built-in theme, or to copy one of its variants, such as `monaTheme.variants.light`, and change the values.
|
|
80
|
+
|
|
81
|
+
A variable in `custom` can't reuse the name of a required token. To add a color name for Tailwind classes, see [Add Your Own Color Names](theming-custom-colors.md#add-your-own-color-names).
|
|
82
|
+
|
|
83
|
+
### Materials
|
|
84
|
+
|
|
85
|
+
The `effects` section defines three materials: `control` for fields and similar controls, `raised` for elevated panels, and `overlay` for menus, popups and dialogs. Each material has four tokens. Here is Luna Light's overlay:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
"--mona-effect-overlay-background-color": "rgb(249 249 250 / 0.72)",
|
|
89
|
+
"--mona-effect-overlay-fallback-background-color": "#f9f9fa",
|
|
90
|
+
"--mona-effect-overlay-background-image": "none",
|
|
91
|
+
"--mona-effect-overlay-backdrop-filter": "blur(28px) saturate(115%)"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
When the browser has no `backdrop-filter`, or the user asks for less transparency, the theme service uses the fallback color and drops the image and the filter. So the fallback has to be opaque, and readable on its own. For an opaque theme, use the same color for both and `none` for the image and the filter, as Mona does: `monaTheme.variants.light.effects` is a good starting point.
|
|
95
|
+
|
|
96
|
+
### Indicator Colors
|
|
97
|
+
|
|
98
|
+
Where a fill alone shows a value, as in slider ranges, progress bars, switches, radio buttons, tab bars and steps, components draw it with `--mona-indicator-color`, and what sits on the fill with `--mona-indicator-foreground`. Both fall back to the primary color and its foreground.
|
|
99
|
+
|
|
100
|
+
If your primary color doesn't reach 3:1 against the surface on its own, set them in `custom`, as Anna Dark does with a lighter violet:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
custom: {
|
|
104
|
+
"--mona-indicator-color": "var(--color-primary-border)",
|
|
105
|
+
"--mona-indicator-foreground": "#161718"
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Contrast Borders
|
|
110
|
+
|
|
111
|
+
`--color-border-control-contrast` and `--color-border-control-contrast-hover` are the only optional colors. When the user asks for more contrast, the theme service uses them in place of `--color-border-control` and `--color-border-control-hover`, for fields, buttons, chips, chart gridlines and everything else that shares those borders. Give them at least 3:1 against `--color-input-background`. A theme without them keeps its usual borders.
|
|
112
|
+
|
|
113
|
+
To meet WCAG 1.4.11 for every user, not only those who ask for more contrast, give `--color-border-control` and `--color-border-control-hover` themselves 3:1.
|
|
114
|
+
|
|
115
|
+
## What's Checked
|
|
116
|
+
|
|
117
|
+
These throw while the application starts:
|
|
118
|
+
|
|
119
|
+
- A theme name that's empty or contains whitespace, or is already registered, including the built-in names.
|
|
120
|
+
- A theme without variants, or a variant missing a required token.
|
|
121
|
+
- A `custom` variable that reuses a required token's name.
|
|
122
|
+
- An override for a theme or variant that isn't registered.
|
|
123
|
+
|
|
124
|
+
In development, custom themes and overrides are also checked, and each problem logs a warning:
|
|
125
|
+
|
|
126
|
+
- A value that isn't a color.
|
|
127
|
+
- A custom variable whose name doesn't start with `--`.
|
|
128
|
+
- A pair below the contrast WCAG AA asks for:
|
|
129
|
+
- 4.5:1 for `--color-foreground` and `--color-muted-foreground` on `--color-surface`, `--color-input-foreground` on `--color-input-background`, and `--color-primary-foreground` on `--color-primary`.
|
|
130
|
+
- 3:1 for `--color-focus-indicator` and `--color-selected-border` on `--color-surface`, and for the contrast borders on `--color-input-background`, when the theme sets them.
|
|
131
|
+
|
|
132
|
+
Values the check can't read, such as `color-mix()`, aren't reported, because they may well be right.
|
|
133
|
+
|
|
134
|
+
## Replace How Themes Are Resolved
|
|
135
|
+
|
|
136
|
+
Behind the theme service, a `ThemeStrategy` turns a theme's name and variant into its tokens. The default, `DefaultThemeStrategy`, uses the registered themes and overrides. To decide yourself, provide your own through the `THEME_STRATEGY` token. This one adds a tenant's colors to whichever theme is selected:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { inject } from "@angular/core";
|
|
140
|
+
import {
|
|
141
|
+
DefaultThemeStrategy,
|
|
142
|
+
THEME_STRATEGY,
|
|
143
|
+
type ThemeAvailability,
|
|
144
|
+
type ThemeProfile,
|
|
145
|
+
type ThemeSelection,
|
|
146
|
+
type ThemeStrategy
|
|
147
|
+
} from "@nanahoshi/mona-ui/theme";
|
|
148
|
+
|
|
149
|
+
class TenantThemeStrategy implements ThemeStrategy {
|
|
150
|
+
readonly #themes = new DefaultThemeStrategy([], []);
|
|
151
|
+
readonly #tenant = inject(TenantSettings);
|
|
152
|
+
|
|
153
|
+
public availableThemes(): readonly ThemeAvailability[] {
|
|
154
|
+
return this.#themes.availableThemes();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public resolve(selection: ThemeSelection): ThemeProfile {
|
|
158
|
+
const profile = this.#themes.resolve(selection);
|
|
159
|
+
return { ...profile, colors: { ...profile.colors, ...this.#tenant.colors(selection.variant) } };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
providers: [{ provide: THEME_STRATEGY, useClass: TenantThemeStrategy }];
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`TenantSettings` stands for a service of your own. A custom strategy replaces the registered themes and overrides, so pass the themes it should know to `DefaultThemeStrategy` yourself: its arguments are a list of themes and a list of overrides. Without an `availableThemes()` method, `ThemeService.availableThemes()` is empty.
|
|
167
|
+
|
|
168
|
+
Most applications don't need a strategy of their own. Themes, palettes and overrides cover nearly every case.
|