shared-lib-web 0.0.2 → 0.0.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/README.md +192 -528
- package/dist/components/app-brand.d.ts.map +1 -1
- package/dist/components/app-brand.js +9 -5
- package/dist/components/app-brand.js.map +1 -1
- package/dist/components/coming-soon.d.ts.map +1 -1
- package/dist/components/coming-soon.js +3 -2
- package/dist/components/coming-soon.js.map +1 -1
- package/dist/components/language-switcher.d.ts +5 -1
- package/dist/components/language-switcher.d.ts.map +1 -1
- package/dist/components/language-switcher.js +20 -7
- package/dist/components/language-switcher.js.map +1 -1
- package/dist/components/otp-modal.d.ts +5 -0
- package/dist/components/otp-modal.d.ts.map +1 -0
- package/dist/components/otp-modal.js +77 -0
- package/dist/components/otp-modal.js.map +1 -0
- package/dist/components/settings-menu.d.ts +4 -0
- package/dist/components/settings-menu.d.ts.map +1 -1
- package/dist/components/settings-menu.js +15 -2
- package/dist/components/settings-menu.js.map +1 -1
- package/dist/context/use-ui.d.ts.map +1 -1
- package/dist/context/use-ui.js +4 -3
- package/dist/context/use-ui.js.map +1 -1
- package/dist/i18n/browser-language.d.ts +9 -0
- package/dist/i18n/browser-language.d.ts.map +1 -0
- package/dist/i18n/browser-language.js +89 -0
- package/dist/i18n/browser-language.js.map +1 -0
- package/dist/i18n/default-messages.d.ts.map +1 -1
- package/dist/i18n/default-messages.js +15 -0
- package/dist/i18n/default-messages.js.map +1 -1
- package/dist/i18n/locale-groups.d.ts +18 -0
- package/dist/i18n/locale-groups.d.ts.map +1 -0
- package/dist/i18n/locale-groups.js +74 -0
- package/dist/i18n/locale-groups.js.map +1 -0
- package/dist/i18n/locale-service.d.ts +22 -4
- package/dist/i18n/locale-service.d.ts.map +1 -1
- package/dist/i18n/locale-service.js +95 -27
- package/dist/i18n/locale-service.js.map +1 -1
- package/dist/i18n/locale-signal.d.ts +18 -0
- package/dist/i18n/locale-signal.d.ts.map +1 -0
- package/dist/i18n/locale-signal.js +142 -0
- package/dist/i18n/locale-signal.js.map +1 -0
- package/dist/i18n/translator.d.ts +8 -1
- package/dist/i18n/translator.d.ts.map +1 -1
- package/dist/i18n/translator.js +36 -12
- package/dist/i18n/translator.js.map +1 -1
- package/dist/index.d.ts +24 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/interfaces/app-types.d.ts +6 -0
- package/dist/interfaces/app-types.d.ts.map +1 -1
- package/dist/interfaces/ui-config.d.ts +184 -15
- package/dist/interfaces/ui-config.d.ts.map +1 -1
- package/dist/interfaces/ui-context.d.ts +1 -1
- package/dist/interfaces/ui-context.d.ts.map +1 -1
- package/dist/layouts/auth-layout.js +1 -1
- package/dist/layouts/auth-layout.js.map +1 -1
- package/dist/providers/provider-effects.d.ts +2 -2
- package/dist/providers/provider-effects.d.ts.map +1 -1
- package/dist/providers/provider-effects.js +4 -1
- package/dist/providers/provider-effects.js.map +1 -1
- package/dist/providers/register-config.d.ts.map +1 -1
- package/dist/providers/register-config.js +2 -0
- package/dist/providers/register-config.js.map +1 -1
- package/dist/providers/shared-web-ui-provider.d.ts +7 -19
- package/dist/providers/shared-web-ui-provider.d.ts.map +1 -1
- package/dist/providers/shared-web-ui-provider.js +21 -22
- package/dist/providers/shared-web-ui-provider.js.map +1 -1
- package/dist/query/query-param.d.ts +4 -1
- package/dist/query/query-param.d.ts.map +1 -1
- package/dist/query/query-param.js +6 -3
- package/dist/query/query-param.js.map +1 -1
- package/dist/state/api-loader.d.ts +19 -0
- package/dist/state/api-loader.d.ts.map +1 -0
- package/dist/state/api-loader.js +187 -0
- package/dist/state/api-loader.js.map +1 -0
- package/dist/state/auth-service.d.ts +9 -0
- package/dist/state/auth-service.d.ts.map +1 -1
- package/dist/state/auth-service.js +70 -3
- package/dist/state/auth-service.js.map +1 -1
- package/dist/state/branch-service.d.ts +1 -1
- package/dist/state/branch-service.js +3 -3
- package/dist/state/branch-service.js.map +1 -1
- package/dist/state/company-service.d.ts +16 -0
- package/dist/state/company-service.d.ts.map +1 -0
- package/dist/state/company-service.js +97 -0
- package/dist/state/company-service.js.map +1 -0
- package/dist/state/language-service.d.ts +5 -2
- package/dist/state/language-service.d.ts.map +1 -1
- package/dist/state/language-service.js +12 -7
- package/dist/state/language-service.js.map +1 -1
- package/dist/state/layout-choice-service.d.ts +10 -0
- package/dist/state/layout-choice-service.d.ts.map +1 -0
- package/dist/state/layout-choice-service.js +34 -0
- package/dist/state/layout-choice-service.js.map +1 -0
- package/dist/state/menu-service.d.ts +1 -1
- package/dist/state/menu-service.js +2 -2
- package/dist/state/menu-service.js.map +1 -1
- package/dist/state/otp-service.d.ts +69 -0
- package/dist/state/otp-service.d.ts.map +1 -0
- package/dist/state/otp-service.js +212 -0
- package/dist/state/otp-service.js.map +1 -0
- package/dist/state/preference-sync.d.ts +1 -1
- package/dist/state/preference-sync.d.ts.map +1 -1
- package/dist/state/preference-sync.js +11 -3
- package/dist/state/preference-sync.js.map +1 -1
- package/dist/state/signals.d.ts +9 -1
- package/dist/state/signals.d.ts.map +1 -1
- package/dist/state/signals.js +28 -4
- package/dist/state/signals.js.map +1 -1
- package/dist/theme/custom-themes.d.ts +28 -0
- package/dist/theme/custom-themes.d.ts.map +1 -0
- package/dist/theme/custom-themes.js +218 -0
- package/dist/theme/custom-themes.js.map +1 -0
- package/dist/theme/dark-themes.d.ts +9 -1
- package/dist/theme/dark-themes.d.ts.map +1 -1
- package/dist/theme/dark-themes.js +74 -2
- package/dist/theme/dark-themes.js.map +1 -1
- package/dist/theme/logo.d.ts +6 -3
- package/dist/theme/logo.d.ts.map +1 -1
- package/dist/theme/logo.js +17 -3
- package/dist/theme/logo.js.map +1 -1
- package/dist/theme/theme-service.d.ts +14 -3
- package/dist/theme/theme-service.d.ts.map +1 -1
- package/dist/theme/theme-service.js +64 -10
- package/dist/theme/theme-service.js.map +1 -1
- package/dist/types/field-wrapper.d.ts +2 -0
- package/dist/types/field-wrapper.d.ts.map +1 -1
- package/dist/types/field-wrapper.js +3 -2
- package/dist/types/field-wrapper.js.map +1 -1
- package/dist/types/type.otp.d.ts +2 -0
- package/dist/types/type.otp.d.ts.map +1 -1
- package/dist/types/type.otp.js +2 -2
- package/dist/types/type.otp.js.map +1 -1
- package/dist/utils/app-http.d.ts +41 -1
- package/dist/utils/app-http.d.ts.map +1 -1
- package/dist/utils/app-http.js +188 -12
- package/dist/utils/app-http.js.map +1 -1
- package/dist/utils/content-util.d.ts +6 -0
- package/dist/utils/content-util.d.ts.map +1 -0
- package/dist/utils/content-util.js +45 -0
- package/dist/utils/content-util.js.map +1 -0
- package/dist/utils/error-util.d.ts +3 -0
- package/dist/utils/error-util.d.ts.map +1 -0
- package/dist/utils/error-util.js +58 -0
- package/dist/utils/error-util.js.map +1 -0
- package/dist/utils/language-util.d.ts +3 -3
- package/dist/utils/language-util.d.ts.map +1 -1
- package/dist/utils/language-util.js +7 -7
- package/dist/utils/language-util.js.map +1 -1
- package/dist/utils/menu-util.js +1 -1
- package/dist/utils/menu-util.js.map +1 -1
- package/dist/utils/signal-source.d.ts +4 -0
- package/dist/utils/signal-source.d.ts.map +1 -0
- package/dist/utils/signal-source.js +13 -0
- package/dist/utils/signal-source.js.map +1 -0
- package/dist/utils/storage-keys.d.ts +5 -0
- package/dist/utils/storage-keys.d.ts.map +1 -1
- package/dist/utils/storage-keys.js +5 -0
- package/dist/utils/storage-keys.js.map +1 -1
- package/package.json +3 -3
- package/src/components/app-brand.tsx +9 -5
- package/src/components/coming-soon.tsx +3 -2
- package/src/components/language-switcher.tsx +26 -7
- package/src/components/otp-modal.tsx +154 -0
- package/src/components/settings-menu.tsx +28 -2
- package/src/context/use-ui.ts +4 -3
- package/src/i18n/browser-language.ts +98 -0
- package/src/i18n/default-messages.ts +15 -0
- package/src/i18n/locale-groups.ts +87 -0
- package/src/i18n/locale-service.ts +99 -27
- package/src/i18n/locale-signal.ts +173 -0
- package/src/i18n/translator.ts +38 -12
- package/src/index.ts +102 -4
- package/src/interfaces/app-types.ts +6 -0
- package/src/interfaces/ui-config.ts +191 -15
- package/src/interfaces/ui-context.ts +1 -1
- package/src/layouts/auth-layout.tsx +1 -1
- package/src/providers/provider-effects.ts +5 -2
- package/src/providers/register-config.ts +2 -0
- package/src/providers/shared-web-ui-provider.tsx +26 -43
- package/src/query/query-param.ts +6 -2
- package/src/state/api-loader.ts +205 -0
- package/src/state/auth-service.ts +84 -3
- package/src/state/branch-service.ts +3 -3
- package/src/state/company-service.ts +107 -0
- package/src/state/language-service.ts +12 -7
- package/src/state/layout-choice-service.ts +40 -0
- package/src/state/menu-service.ts +2 -2
- package/src/state/otp-service.ts +283 -0
- package/src/state/preference-sync.ts +11 -3
- package/src/state/signals.ts +36 -4
- package/src/theme/custom-themes.ts +236 -0
- package/src/theme/dark-themes.ts +80 -3
- package/src/theme/logo.ts +19 -4
- package/src/theme/org-themes.json +70 -0
- package/src/theme/theme-service.ts +70 -10
- package/src/types/field-wrapper.tsx +5 -2
- package/src/types/type.otp.tsx +11 -2
- package/src/utils/app-http.ts +205 -12
- package/src/utils/content-util.ts +49 -0
- package/src/utils/error-util.ts +64 -0
- package/src/utils/language-util.ts +7 -7
- package/src/utils/menu-util.ts +1 -1
- package/src/utils/signal-source.ts +15 -0
- package/src/utils/storage-keys.ts +6 -0
package/src/theme/dark-themes.ts
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
// dark-themes.ts
|
|
2
|
-
// DaisyUI 5
|
|
3
|
-
//
|
|
2
|
+
// The DaisyUI 5 theme names, and which of them are dark ("color-scheme: dark": dark logos, dark markdown editor).
|
|
3
|
+
// config.themes defaults to DAISYUI_THEMES; config.darkThemes replaces DEFAULT_DARK_THEMES.
|
|
4
|
+
// Custom themes (config.customThemes / setCustomThemes) are added to both lists by their own isDark flag.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import type { CustomTheme, Theme } from "../interfaces/ui-config.ts";
|
|
7
|
+
|
|
8
|
+
/** All 35 DaisyUI 5 themes (enable them in CSS with @plugin "daisyui" { themes: all; }). */
|
|
9
|
+
export const DAISYUI_THEMES: Theme[] = [
|
|
10
|
+
"light",
|
|
11
|
+
"dark",
|
|
12
|
+
"cupcake",
|
|
13
|
+
"bumblebee",
|
|
14
|
+
"emerald",
|
|
15
|
+
"corporate",
|
|
16
|
+
"synthwave",
|
|
17
|
+
"retro",
|
|
18
|
+
"cyberpunk",
|
|
19
|
+
"valentine",
|
|
20
|
+
"halloween",
|
|
21
|
+
"garden",
|
|
22
|
+
"forest",
|
|
23
|
+
"aqua",
|
|
24
|
+
"lofi",
|
|
25
|
+
"pastel",
|
|
26
|
+
"fantasy",
|
|
27
|
+
"wireframe",
|
|
28
|
+
"black",
|
|
29
|
+
"luxury",
|
|
30
|
+
"dracula",
|
|
31
|
+
"cmyk",
|
|
32
|
+
"autumn",
|
|
33
|
+
"business",
|
|
34
|
+
"acid",
|
|
35
|
+
"lemonade",
|
|
36
|
+
"night",
|
|
37
|
+
"coffee",
|
|
38
|
+
"winter",
|
|
39
|
+
"dim",
|
|
40
|
+
"nord",
|
|
41
|
+
"sunset",
|
|
42
|
+
"caramellatte",
|
|
43
|
+
"abyss",
|
|
44
|
+
"silk",
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/** The dark DaisyUI 5 themes. */
|
|
48
|
+
export const DEFAULT_DARK_THEMES: Theme[] = [
|
|
6
49
|
"dark",
|
|
7
50
|
"aqua",
|
|
8
51
|
"synthwave",
|
|
@@ -18,3 +61,37 @@ export const DEFAULT_DARK_THEMES = [
|
|
|
18
61
|
"sunset",
|
|
19
62
|
"abyss",
|
|
20
63
|
];
|
|
64
|
+
|
|
65
|
+
/** The dark theme names: the dark custom themes + (darkThemes, else the DaisyUI dark themes). */
|
|
66
|
+
export function buildDarkThemeNames(darkThemes: Theme[] | undefined, customThemes: CustomTheme[]): Theme[] {
|
|
67
|
+
const names: Theme[] = [];
|
|
68
|
+
for (const customTheme of customThemes) {
|
|
69
|
+
if (customTheme.isDark) {
|
|
70
|
+
names.push(customTheme.name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const baseNames = darkThemes ?? DEFAULT_DARK_THEMES;
|
|
74
|
+
for (const name of baseNames) {
|
|
75
|
+
const isAdded = names.includes(name);
|
|
76
|
+
if (!isAdded) {
|
|
77
|
+
names.push(name);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return names;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The theme names of the switcher: the custom themes first, then (themes, else all DaisyUI themes). */
|
|
84
|
+
export function buildThemeNames(themes: Theme[] | undefined, customThemes: CustomTheme[]): Theme[] {
|
|
85
|
+
const names: Theme[] = [];
|
|
86
|
+
for (const customTheme of customThemes) {
|
|
87
|
+
names.push(customTheme.name);
|
|
88
|
+
}
|
|
89
|
+
const baseNames = themes ?? DAISYUI_THEMES;
|
|
90
|
+
for (const name of baseNames) {
|
|
91
|
+
const isAdded = names.includes(name);
|
|
92
|
+
if (!isAdded) {
|
|
93
|
+
names.push(name);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return names;
|
|
97
|
+
}
|
package/src/theme/logo.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
// logo.ts
|
|
2
|
-
// Picks the logo for the current theme.
|
|
2
|
+
// Picks the logo for the current theme. Company details (loadCompanyDetails / setCompanyDetails) win over the config.
|
|
3
3
|
|
|
4
|
-
import type { UiConfig } from "../interfaces/ui-config.ts";
|
|
4
|
+
import type { CompanyDetails, UiConfig } from "../interfaces/ui-config.ts";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/** The company logo for the theme: logoDarkUrl on dark themes (when set), else logoUrl. */
|
|
7
|
+
function readCompanyLogoUrl(details: CompanyDetails | null | undefined, isDarkTheme: boolean): string | undefined {
|
|
8
|
+
if (isDarkTheme && details?.logoDarkUrl) {
|
|
9
|
+
return details.logoDarkUrl;
|
|
10
|
+
}
|
|
11
|
+
return details?.logoUrl;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The logo URL. Dark themes: company logoDarkUrl, company logoUrl, config.logoDarkUrl, config.logoUrl.
|
|
16
|
+
* Light themes: company logoUrl, config.logoUrl.
|
|
17
|
+
*/
|
|
18
|
+
export function readLogoUrl(config: UiConfig, isDarkTheme: boolean, details?: CompanyDetails | null): string | undefined {
|
|
19
|
+
const companyLogoUrl = readCompanyLogoUrl(details, isDarkTheme);
|
|
20
|
+
if (companyLogoUrl) {
|
|
21
|
+
return companyLogoUrl;
|
|
22
|
+
}
|
|
8
23
|
if (isDarkTheme && config.logoDarkUrl) {
|
|
9
24
|
return config.logoDarkUrl;
|
|
10
25
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"org-dark": {
|
|
3
|
+
"isDark": true,
|
|
4
|
+
"name": "org-dark",
|
|
5
|
+
"variables": {
|
|
6
|
+
"border": "1px",
|
|
7
|
+
"color-accent": "oklch(70.4% 0.04 256.8)",
|
|
8
|
+
"color-accent-content": "oklch(12.9% 0.042 264.7)",
|
|
9
|
+
"color-base-100": "oklch(25.5% 0.04 264.5)",
|
|
10
|
+
"color-base-200": "oklch(20.8% 0.042 265.8)",
|
|
11
|
+
"color-base-300": "oklch(32% 0.04 262)",
|
|
12
|
+
"color-base-content": "oklch(92.9% 0.013 255.5)",
|
|
13
|
+
"color-error": "oklch(70.4% 0.191 22.2)",
|
|
14
|
+
"color-error-content": "oklch(25.8% 0.092 26)",
|
|
15
|
+
"color-info": "oklch(78.9% 0.154 211.5)",
|
|
16
|
+
"color-info-content": "oklch(30.2% 0.056 229.7)",
|
|
17
|
+
"color-neutral": "oklch(37.2% 0.044 257.3)",
|
|
18
|
+
"color-neutral-content": "oklch(96.8% 0.007 247.9)",
|
|
19
|
+
"color-primary": "oklch(74.6% 0.16 232.7)",
|
|
20
|
+
"color-primary-content": "oklch(29.3% 0.066 243.2)",
|
|
21
|
+
"color-secondary": "oklch(82.8% 0.189 84.4)",
|
|
22
|
+
"color-secondary-content": "oklch(27.9% 0.077 45.6)",
|
|
23
|
+
"color-success": "oklch(79.2% 0.209 151.7)",
|
|
24
|
+
"color-success-content": "oklch(26.6% 0.065 152.9)",
|
|
25
|
+
"color-warning": "oklch(75% 0.183 55.9)",
|
|
26
|
+
"color-warning-content": "oklch(26.6% 0.079 36.3)",
|
|
27
|
+
"depth": "1",
|
|
28
|
+
"noise": "0",
|
|
29
|
+
"radius-box": "0.75rem",
|
|
30
|
+
"radius-field": "0.5rem",
|
|
31
|
+
"radius-selector": "1rem",
|
|
32
|
+
"size-field": "0.25rem",
|
|
33
|
+
"size-selector": "0.25rem"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"org-light": {
|
|
37
|
+
"isDark": false,
|
|
38
|
+
"name": "org-light",
|
|
39
|
+
"variables": {
|
|
40
|
+
"border": "1px",
|
|
41
|
+
"color-accent": "oklch(55.4% 0.046 257.4)",
|
|
42
|
+
"color-accent-content": "oklch(98.4% 0.003 247.9)",
|
|
43
|
+
"color-base-100": "oklch(100% 0 0)",
|
|
44
|
+
"color-base-200": "oklch(96.8% 0.007 247.9)",
|
|
45
|
+
"color-base-300": "oklch(92.9% 0.013 255.5)",
|
|
46
|
+
"color-base-content": "oklch(20.8% 0.042 265.8)",
|
|
47
|
+
"color-error": "oklch(55% 0.23 27.3)",
|
|
48
|
+
"color-error-content": "oklch(97.1% 0.013 17.4)",
|
|
49
|
+
"color-info": "oklch(71.5% 0.143 215.2)",
|
|
50
|
+
"color-info-content": "oklch(30.2% 0.056 229.7)",
|
|
51
|
+
"color-neutral": "oklch(27.9% 0.041 260)",
|
|
52
|
+
"color-neutral-content": "oklch(98.4% 0.003 247.9)",
|
|
53
|
+
"color-primary": "oklch(55.8% 0.154 249.1)",
|
|
54
|
+
"color-primary-content": "oklch(98.5% 0.01 240)",
|
|
55
|
+
"color-secondary": "oklch(76.9% 0.188 70.1)",
|
|
56
|
+
"color-secondary-content": "oklch(27.9% 0.077 45.6)",
|
|
57
|
+
"color-success": "oklch(52.7% 0.154 150.1)",
|
|
58
|
+
"color-success-content": "oklch(98.2% 0.018 155.8)",
|
|
59
|
+
"color-warning": "oklch(75% 0.183 55.9)",
|
|
60
|
+
"color-warning-content": "oklch(26.6% 0.079 36.3)",
|
|
61
|
+
"depth": "1",
|
|
62
|
+
"noise": "0",
|
|
63
|
+
"radius-box": "0.75rem",
|
|
64
|
+
"radius-field": "0.5rem",
|
|
65
|
+
"radius-selector": "1rem",
|
|
66
|
+
"size-field": "0.25rem",
|
|
67
|
+
"size-selector": "0.25rem"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -3,30 +3,89 @@
|
|
|
3
3
|
//
|
|
4
4
|
// changeTheme("dark"); -> <html data-theme="dark">, saved to localStorage
|
|
5
5
|
//
|
|
6
|
+
// First visit (nothing saved): config.defaultTheme, or without it the browser preference
|
|
7
|
+
// (prefers-color-scheme: dark -> "dark", otherwise "light").
|
|
8
|
+
//
|
|
6
9
|
// The <html> attribute is written by state/document-sync.ts.
|
|
7
10
|
|
|
8
11
|
import type { Theme, UiConfig } from "../interfaces/ui-config.ts";
|
|
9
|
-
import { themeSignal, uiConfigSignal } from "../state/signals.ts";
|
|
12
|
+
import { customThemesSignal, themeSignal, uiConfigSignal } from "../state/signals.ts";
|
|
10
13
|
import { AppStorage } from "../utils/app-storage.ts";
|
|
11
14
|
import { THEME } from "../utils/storage-keys.ts";
|
|
12
|
-
import {
|
|
15
|
+
import { buildDarkThemeNames, buildThemeNames } from "./dark-themes.ts";
|
|
16
|
+
|
|
17
|
+
/** The theme names of the switcher: the custom themes first, then config.themes (default: all DaisyUI themes). */
|
|
18
|
+
export function readThemeNames(config: UiConfig): Theme[] {
|
|
19
|
+
const customThemes = customThemesSignal.value;
|
|
20
|
+
return buildThemeNames(config.themes, customThemes);
|
|
21
|
+
}
|
|
13
22
|
|
|
14
|
-
/** true when the theme is
|
|
23
|
+
/** true when the theme is offered (config.themes or a custom theme). */
|
|
15
24
|
export function isKnownTheme(config: UiConfig, theme: string): boolean {
|
|
16
|
-
const
|
|
17
|
-
return
|
|
25
|
+
const themeNames = readThemeNames(config);
|
|
26
|
+
return themeNames.includes(theme);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
|
|
30
|
+
|
|
31
|
+
/** true when the browser / OS asks for a dark colour scheme. */
|
|
32
|
+
function isBrowserDarkPreferred(): boolean {
|
|
33
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const darkQuery = window.matchMedia(DARK_SCHEME_QUERY);
|
|
37
|
+
return darkQuery.matches;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The first-visit theme: config.defaultTheme, else "dark" or "light" from the browser preference. */
|
|
41
|
+
export function readDefaultTheme(config: UiConfig): Theme {
|
|
42
|
+
if (config.defaultTheme) {
|
|
43
|
+
return config.defaultTheme;
|
|
44
|
+
}
|
|
45
|
+
const isDarkPreferred = isBrowserDarkPreferred();
|
|
46
|
+
return isDarkPreferred ? "dark" : "light";
|
|
18
47
|
}
|
|
19
48
|
|
|
20
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Picks the theme to start with: the saved one if it is in the config, else the default.
|
|
51
|
+
* With config.loadThemes the saved theme is kept while the custom themes load (no flash of the default theme).
|
|
52
|
+
*/
|
|
21
53
|
export function readInitialTheme(config: UiConfig): Theme {
|
|
22
54
|
const storedTheme = AppStorage.getText(THEME);
|
|
23
55
|
if (storedTheme) {
|
|
24
56
|
const isStoredThemeKnown = isKnownTheme(config, storedTheme);
|
|
25
|
-
|
|
57
|
+
const isThemeLoading = Boolean(config.loadThemes);
|
|
58
|
+
if (isStoredThemeKnown || isThemeLoading) {
|
|
26
59
|
return storedTheme;
|
|
27
60
|
}
|
|
28
61
|
}
|
|
29
|
-
return config
|
|
62
|
+
return readDefaultTheme(config);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** After config.loadThemes: a theme that is still unknown (not in the loaded list) falls back to the default. */
|
|
66
|
+
export function leaveUnknownTheme(): void {
|
|
67
|
+
const config = uiConfigSignal.peek();
|
|
68
|
+
if (!config) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const currentTheme = themeSignal.peek();
|
|
72
|
+
const isCurrentThemeKnown = isKnownTheme(config, currentTheme);
|
|
73
|
+
if (!isCurrentThemeKnown) {
|
|
74
|
+
themeSignal.value = readDefaultTheme(config);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Custom themes can arrive after the start (fetched JSON): switch to the saved theme once it is known. */
|
|
79
|
+
export function applySavedThemeWhenKnown(): void {
|
|
80
|
+
const config = uiConfigSignal.peek();
|
|
81
|
+
const storedTheme = AppStorage.getText(THEME);
|
|
82
|
+
if (!config || !storedTheme || storedTheme === themeSignal.peek()) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const isStoredThemeKnown = isKnownTheme(config, storedTheme);
|
|
86
|
+
if (isStoredThemeKnown) {
|
|
87
|
+
themeSignal.value = storedTheme;
|
|
88
|
+
}
|
|
30
89
|
}
|
|
31
90
|
|
|
32
91
|
/** Switches the theme. Themes not listed in the config are ignored. */
|
|
@@ -48,10 +107,11 @@ export interface ThemeGroups {
|
|
|
48
107
|
darkThemes: Theme[];
|
|
49
108
|
}
|
|
50
109
|
|
|
51
|
-
/** The dark theme names: config.darkThemes, else the DaisyUI dark themes. */
|
|
110
|
+
/** The dark theme names: the dark custom themes + (config.darkThemes, else the DaisyUI dark themes). */
|
|
52
111
|
export function readDarkThemeNames(): Theme[] {
|
|
53
112
|
const config = uiConfigSignal.value;
|
|
54
|
-
|
|
113
|
+
const customThemes = customThemesSignal.value;
|
|
114
|
+
return buildDarkThemeNames(config?.darkThemes, customThemes);
|
|
55
115
|
}
|
|
56
116
|
|
|
57
117
|
/** true when the theme has a dark background. */
|
|
@@ -10,6 +10,8 @@ export interface FieldWrapperProps {
|
|
|
10
10
|
errorText?: string;
|
|
11
11
|
hint?: string;
|
|
12
12
|
className?: string;
|
|
13
|
+
/** Keep the label for screen readers only (not shown). Default false. */
|
|
14
|
+
isLabelHidden?: boolean;
|
|
13
15
|
children?: ReactNode;
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -19,16 +21,17 @@ export function readMessageId(inputId: string): string {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function FieldWrapper(props: FieldWrapperProps) {
|
|
22
|
-
const { inputId, label, errorText, hint, className, children } = props;
|
|
24
|
+
const { inputId, label, errorText, hint, className, isLabelHidden = false, children } = props;
|
|
23
25
|
const messageId = readMessageId(inputId);
|
|
24
26
|
const messageText = errorText ?? hint;
|
|
25
27
|
const messageClassName = errorText ? "label text-error" : "label";
|
|
26
28
|
const classList = ["fieldset", className];
|
|
27
29
|
const wrapperClassName = joinClassNames(classList);
|
|
30
|
+
const labelClassName = isLabelHidden ? "sr-only" : "fieldset-legend";
|
|
28
31
|
|
|
29
32
|
return (
|
|
30
33
|
<fieldset className={wrapperClassName}>
|
|
31
|
-
<label className=
|
|
34
|
+
<label className={labelClassName} htmlFor={inputId}>
|
|
32
35
|
{label}
|
|
33
36
|
</label>
|
|
34
37
|
{children}
|
package/src/types/type.otp.tsx
CHANGED
|
@@ -18,6 +18,8 @@ import type { TypeFieldProps } from "./field-props.ts";
|
|
|
18
18
|
export interface TypeOtpProps<TFieldValues extends FieldValues> extends TypeFieldProps<TFieldValues> {
|
|
19
19
|
/** Number of characters. Default 6. */
|
|
20
20
|
length?: number;
|
|
21
|
+
/** Keep the label for screen readers only (not shown). Default false. */
|
|
22
|
+
isLabelHidden?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** Builds the boxes that show one character each. The box at the cursor is highlighted. */
|
|
@@ -43,7 +45,7 @@ function buildOtpBoxes(value: string, length: number, hasError: boolean): ReactE
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export function TypeOtp<TFieldValues extends FieldValues>(props: TypeOtpProps<TFieldValues>) {
|
|
46
|
-
const { control, name, label, rules, error, hint, disabled, className, length = 6 } = props;
|
|
48
|
+
const { control, name, label, rules, error, hint, disabled, className, length = 6, isLabelHidden = false } = props;
|
|
47
49
|
const { t } = useUi();
|
|
48
50
|
const inputId = useId();
|
|
49
51
|
const controllerOptions = { control: control, name: name, rules: rules, disabled: disabled };
|
|
@@ -57,7 +59,14 @@ export function TypeOtp<TFieldValues extends FieldValues>(props: TypeOtpProps<TF
|
|
|
57
59
|
const boxes = buildOtpBoxes(value, length, hasError);
|
|
58
60
|
|
|
59
61
|
return (
|
|
60
|
-
<FieldWrapper
|
|
62
|
+
<FieldWrapper
|
|
63
|
+
inputId={inputId}
|
|
64
|
+
label={label}
|
|
65
|
+
errorText={errorText}
|
|
66
|
+
hint={hint}
|
|
67
|
+
className={className}
|
|
68
|
+
isLabelHidden={isLabelHidden}
|
|
69
|
+
>
|
|
61
70
|
<div className="relative flex w-fit gap-2" dir="ltr">
|
|
62
71
|
<input
|
|
63
72
|
id={inputId}
|