@webitel/ui-sdk 23.12.75 → 23.12.77
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/dist/img/sprite/dark-mode.svg +5 -0
- package/dist/img/sprite/index.js +1 -0
- package/dist/ui-sdk.mjs +1314 -1314
- package/dist/ui-sdk.umd.js +1 -1
- package/package.json +1 -1
- package/src/modules/Appearance/components/__tests__/wt-dark-mode-switcher.spec.js +18 -0
- package/src/modules/Appearance/components/wt-dark-mode-switcher.vue +46 -0
- package/src/modules/Appearance/store/AppearanceStoreModule.js +19 -0
- package/src/modules/Appearance/store/__tests__/AppearanceStoreModule.spec.js +15 -0
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import WtDarkModeSwitcher from '../wt-dark-mode-switcher.vue';
|
|
3
|
+
|
|
4
|
+
describe('WtDarkModeSwitcher', () => {
|
|
5
|
+
it('should render component', () => {
|
|
6
|
+
const wrapper = shallowMount(WtDarkModeSwitcher, {});
|
|
7
|
+
expect(wrapper.exists()).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('toggles dark mode class', async () => {
|
|
11
|
+
const wrapper = shallowMount(WtDarkModeSwitcher, {});
|
|
12
|
+
expect(window.document.documentElement.classList.contains('theme--dark'))
|
|
13
|
+
.toBe(false);
|
|
14
|
+
await wrapper.findComponent({ name: 'wt-switcher' }).trigger('change');
|
|
15
|
+
expect(window.document.documentElement.classList.contains('theme--dark'))
|
|
16
|
+
.toBe(true);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
import { useStore } from 'vuex';
|
|
5
|
+
import WtIcon from '../../../components/wt-icon/wt-icon.vue';
|
|
6
|
+
import WtSwitcher from '../../../components/wt-switcher/wt-switcher.vue';
|
|
7
|
+
|
|
8
|
+
const store = useStore();
|
|
9
|
+
|
|
10
|
+
const mode = ref(localStorage.getItem('colorScheme') || 'light');
|
|
11
|
+
|
|
12
|
+
const setThemeToStore = (theme) => {
|
|
13
|
+
store.dispatch('appearance/SET_THEME', theme);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const toggleDarkMode = () => {
|
|
17
|
+
if (mode.value === 'light') {
|
|
18
|
+
mode.value = 'dark';
|
|
19
|
+
localStorage.setItem('colorScheme', 'dark');
|
|
20
|
+
document.documentElement.classList.add('theme--dark');
|
|
21
|
+
} else {
|
|
22
|
+
mode.value = 'light';
|
|
23
|
+
localStorage.setItem('colorScheme', 'light');
|
|
24
|
+
document.documentElement.classList.remove('theme--dark');
|
|
25
|
+
}
|
|
26
|
+
setThemeToStore(mode.value);
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<div class="wt-dark-mode-switcher">
|
|
32
|
+
<wt-icon icon="dark-mode" />
|
|
33
|
+
<wt-switcher
|
|
34
|
+
:value="mode === 'dark'"
|
|
35
|
+
@change="toggleDarkMode"
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<style lang="scss" scoped>
|
|
41
|
+
.wt-dark-mode-switcher {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
gap: var(--spacing-xs);
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
|
|
2
|
+
|
|
3
|
+
export default class AppearanceStoreModule extends BaseStoreModule {
|
|
4
|
+
state = {
|
|
5
|
+
theme: null,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
actions = {
|
|
9
|
+
SET_THEME: (context, theme) => {
|
|
10
|
+
context.commit('SET_THEME', theme);
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mutations = {
|
|
15
|
+
SET_THEME: (state, theme) => {
|
|
16
|
+
state.theme = theme;
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createStore } from 'vuex';
|
|
2
|
+
import AppearanceStoreModule from '../AppearanceStoreModule';
|
|
3
|
+
|
|
4
|
+
describe('AppearanceStoreModule', () => {
|
|
5
|
+
let store;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
store = createStore(new AppearanceStoreModule().getModule());
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should set theme', async () => {
|
|
12
|
+
await store.dispatch('SET_THEME', 'dark');
|
|
13
|
+
expect(store.state.theme).toBe('dark');
|
|
14
|
+
});
|
|
15
|
+
});
|