vira 33.4.1 → 33.4.3
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.
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { ViraThemeClient, ViraThemeSelection } from '../util/vira-theme-client.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The part of {@link ViraThemeClient} that {@link ViraThemeSwitcher} uses. Implement this to back the
|
|
5
|
+
* switcher with your own theme storage instead of a `ViraThemeClient`.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
*/
|
|
9
|
+
export type ViraThemeSwitcherClient = Pick<ViraThemeClient, 'getCurrentTheme' | 'setSelectedTheme'>;
|
|
10
|
+
/**
|
|
11
|
+
* A row of buttons for selecting a {@link ViraThemeSelection} (light, dark, or auto). Clicking a
|
|
12
|
+
* button calls `setSelectedTheme` on the `themeClient` input (or on an internal
|
|
13
|
+
* {@link ViraThemeClient} when none is given), which applies the theme, then fires a `themeSelect`
|
|
14
|
+
* event with the selection.
|
|
7
15
|
*
|
|
8
16
|
* @category Elements
|
|
9
17
|
*/
|
|
10
18
|
export declare const ViraThemeSwitcher: import("element-vir").DeclarativeElementDefinition<"vira-theme-switcher", PartialWithUndefined<{
|
|
11
|
-
themeClient: Readonly<
|
|
12
|
-
/**
|
|
19
|
+
themeClient: Readonly<ViraThemeSwitcherClient>;
|
|
20
|
+
/**
|
|
21
|
+
* Override the default English button labels (used as `title` attributes for tooltips and
|
|
22
|
+
* as `aria-label` attributes).
|
|
23
|
+
*/
|
|
13
24
|
labels: Readonly<Record<ViraThemeSelection, string>>;
|
|
14
25
|
}>, {
|
|
15
|
-
internalThemeClient: undefined | Readonly<
|
|
26
|
+
internalThemeClient: undefined | Readonly<ViraThemeSwitcherClient>;
|
|
16
27
|
currentTheme: ViraThemeSelection;
|
|
17
|
-
}, {
|
|
28
|
+
}, {
|
|
29
|
+
/** Fired after the user selects a theme and it has been passed to the theme client. */
|
|
30
|
+
themeSelect: import("element-vir").DefineElementEvent<ViraThemeSelection>;
|
|
31
|
+
}, "vira-theme-switcher-", "vira-theme-switcher-", readonly [], readonly []>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mapEnumToObject } from '@augment-vir/common';
|
|
2
|
-
import { classMap, css, html, listen } from 'element-vir';
|
|
2
|
+
import { classMap, css, defineElementEvent, html, listen } from 'element-vir';
|
|
3
3
|
import { AutoTheme24Icon, Moon24Icon, Sun24Icon } from '../icons/index.js';
|
|
4
4
|
import { viraFormCssVars } from '../styles/form-styles.js';
|
|
5
5
|
import { noNativeFormStyles, noNativeSpacing, viraTheme } from '../styles/index.js';
|
|
@@ -20,14 +20,19 @@ const defaultThemeLabels = {
|
|
|
20
20
|
[ViraThemeSelection.Auto]: 'Auto',
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* A row of buttons for selecting a {@link ViraThemeSelection} (light, dark, or auto).
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
23
|
+
* A row of buttons for selecting a {@link ViraThemeSelection} (light, dark, or auto). Clicking a
|
|
24
|
+
* button calls `setSelectedTheme` on the `themeClient` input (or on an internal
|
|
25
|
+
* {@link ViraThemeClient} when none is given), which applies the theme, then fires a `themeSelect`
|
|
26
|
+
* event with the selection.
|
|
26
27
|
*
|
|
27
28
|
* @category Elements
|
|
28
29
|
*/
|
|
29
30
|
export const ViraThemeSwitcher = defineViraElement()({
|
|
30
31
|
tagName: 'vira-theme-switcher',
|
|
32
|
+
events: {
|
|
33
|
+
/** Fired after the user selects a theme and it has been passed to the theme client. */
|
|
34
|
+
themeSelect: defineElementEvent(),
|
|
35
|
+
},
|
|
31
36
|
styles: css `
|
|
32
37
|
:host {
|
|
33
38
|
display: inline-flex;
|
|
@@ -71,7 +76,7 @@ export const ViraThemeSwitcher = defineViraElement()({
|
|
|
71
76
|
currentTheme: ViraThemeSelection.Auto,
|
|
72
77
|
};
|
|
73
78
|
},
|
|
74
|
-
render({ inputs, state, updateState }) {
|
|
79
|
+
render({ inputs, state, updateState, dispatch, events }) {
|
|
75
80
|
const themeClient = inputs.themeClient || state.internalThemeClient || new ViraThemeClient();
|
|
76
81
|
updateState({
|
|
77
82
|
internalThemeClient: themeClient,
|
|
@@ -85,12 +90,16 @@ export const ViraThemeSwitcher = defineViraElement()({
|
|
|
85
90
|
selected: themeClient.getCurrentTheme() === theme,
|
|
86
91
|
})}
|
|
87
92
|
title=${labels[theme]}
|
|
93
|
+
aria-label=${labels[theme]}
|
|
88
94
|
${listen('click', (event) => {
|
|
89
95
|
event.stopPropagation();
|
|
90
96
|
themeClient.setSelectedTheme(theme);
|
|
91
97
|
updateState({
|
|
92
98
|
currentTheme: themeClient.getCurrentTheme(),
|
|
93
99
|
});
|
|
100
|
+
dispatch(new events.themeSelect({
|
|
101
|
+
detail: theme,
|
|
102
|
+
}));
|
|
94
103
|
})}
|
|
95
104
|
>
|
|
96
105
|
<${ViraIcon.assign({
|
|
@@ -10,5 +10,5 @@ export declare const viraIconCssVars: import("lit-css-vars").CssVarDefinitions<{
|
|
|
10
10
|
readonly 'vira-icon-stroke-color': "currentColor";
|
|
11
11
|
/** To be used for coloring an icon's fill. */
|
|
12
12
|
readonly 'vira-icon-fill-color': "none";
|
|
13
|
-
readonly 'vira-icon-stroke-width': "
|
|
13
|
+
readonly 'vira-icon-stroke-width': "1.5px";
|
|
14
14
|
}>;
|