forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKThemePlugin.js
167 lines (156 loc) · 5.87 KB
/
KThemePlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { isNuxtServerSideRendering } from '../lib/utils';
import computedClass from './styles/computedClass';
import { darken1, darken2, darken3 } from './styles/darkenColors.js';
import KBreadcrumbs from './KBreadcrumbs';
import KButton from './buttons-and-links/KButton';
import KButtonGroup from './buttons-and-links/KButtonGroup';
import KCard from './cards/KCard';
import KCardGrid from './cards/KCardGrid';
import KCheckbox from './KCheckbox';
import KCircularLoader from './loaders/KCircularLoader';
import KDateRange from './KDateRange';
import KDropdownMenu from './KDropdownMenu';
import KEmptyPlaceholder from './KEmptyPlaceholder';
import KListWithOverflow from './KListWithOverflow';
import KExternalLink from './buttons-and-links/KExternalLink';
import KFixedGrid from './grids/KFixedGrid';
import KFixedGridItem from './grids/KFixedGridItem';
import KGrid from './grids/KGrid';
import KGridItem from './grids/KGridItem';
import KIcon from './KIcon';
import KIconButton from './buttons-and-links/KIconButton';
import KImg from './KImg';
import KLabeledIcon from './KLabeledIcon';
import KLinearLoader from './loaders/KLinearLoader';
import KModal from './KModal';
import KOptionalText from './KOptionalText';
import KPageContainer from './KPageContainer';
import KRadioButton from './KRadioButton';
import KRouterLink from './buttons-and-links/KRouterLink';
import KSelect from './KSelect';
import KSwitch from './KSwitch';
import KTable from './KTable';
import KTabs from './tabs/KTabs';
import KTabsList from './tabs/KTabsList';
import KTabsPanel from './tabs/KTabsPanel';
import KOverlay from './KOverlay';
import KTextbox from './KTextbox';
import KTooltip from './KTooltip';
import KTransition from './KTransition';
import KTextTruncator from './KTextTruncator';
import KLogo from './KLogo';
import KRadioButtonGroup from './KRadioButtonGroup.vue';
import KFocusTrap from './KFocusTrap.vue';
import KToolbar from './KToolbar';
import { themeTokens, themeBrand, themePalette, themeOutlineStyle } from './styles/theme';
import globalThemeState from './styles/globalThemeState';
import useKLiveRegion from './composables/useKLiveRegion';
import _useOverlay from './composables/_useOverlay';
const { _mountLiveRegion } = useKLiveRegion();
const { mountOverlay } = _useOverlay();
require('./grids/globalStyles.js'); // global grid styles
/**
* Install Kolibri theme helpers on all Vue instances.
* Also, set up global state, listeners, and styles.
*/
export default function KThemePlugin(Vue) {
if (!isNuxtServerSideRendering()) {
const onDomReady = () => {
_mountLiveRegion();
mountOverlay();
document.removeEventListener('DOMContentLoaded', onDomReady);
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', onDomReady);
} else {
onDomReady();
}
}
Vue.mixin({
computed: {
$coreOutline() {
if (globalThemeState.inputModality === 'keyboard') {
return themeOutlineStyle();
}
return {
outline: 'none',
};
},
$inputModality() {
return globalThemeState.inputModality;
},
$mediaType() {
return globalThemeState.mediaType;
},
$isPrint() {
return this.$mediaType === 'print';
},
},
methods: {
/**
* Because `window.print()` blocks in most browsers, we need to manually update our
* `mediaType` before calling it so that the printable version of the page is as we expect.
*
* Triggering a print from Ctrl+P or the menu does not have this problem.
* @public
*/
$print() {
const mediaType = globalThemeState.mediaType;
globalThemeState.mediaType = 'print';
this.$nextTick(() => {
window.print();
globalThemeState.mediaType = mediaType;
});
},
},
});
Vue.prototype.$themeBrand = themeBrand();
Vue.prototype.$themeTokens = themeTokens();
Vue.prototype.$themePalette = themePalette();
Vue.prototype.$computedClass = computedClass;
Vue.prototype.$darken1 = darken1;
Vue.prototype.$darken2 = darken2;
Vue.prototype.$darken3 = darken3;
// globally-accessible components
Vue.component('KButton', KButton);
Vue.component('KButtonGroup', KButtonGroup);
Vue.component('KBreadcrumbs', KBreadcrumbs);
Vue.component('KCard', KCard);
Vue.component('KCardGrid', KCardGrid);
Vue.component('KCheckbox', KCheckbox);
Vue.component('KCircularLoader', KCircularLoader);
Vue.component('KDateRange', KDateRange);
Vue.component('KDropdownMenu', KDropdownMenu);
Vue.component('KEmptyPlaceholder', KEmptyPlaceholder);
Vue.component('KListWithOverflow', KListWithOverflow);
Vue.component('KExternalLink', KExternalLink);
Vue.component('KFixedGrid', KFixedGrid);
Vue.component('KFixedGridItem', KFixedGridItem);
Vue.component('KGrid', KGrid);
Vue.component('KGridItem', KGridItem);
Vue.component('KIcon', KIcon);
Vue.component('KIconButton', KIconButton);
Vue.component('KImg', KImg);
Vue.component('KLabeledIcon', KLabeledIcon);
Vue.component('KLinearLoader', KLinearLoader);
Vue.component('KLogo', KLogo);
Vue.component('KModal', KModal);
Vue.component('KOptionalText', KOptionalText);
Vue.component('KPageContainer', KPageContainer);
Vue.component('KRadioButton', KRadioButton);
Vue.component('KRouterLink', KRouterLink);
Vue.component('KSelect', KSelect);
Vue.component('KSwitch', KSwitch);
Vue.component('KTable', KTable);
Vue.component('KTabs', KTabs);
Vue.component('KTabsList', KTabsList);
Vue.component('KTabsPanel', KTabsPanel);
Vue.component('KOverlay', KOverlay);
Vue.component('KTextbox', KTextbox);
Vue.component('KTooltip', KTooltip);
Vue.component('KTransition', KTransition);
Vue.component('KTextTruncator', KTextTruncator);
Vue.component('KRadioButtonGroup', KRadioButtonGroup);
Vue.component('KFocusTrap', KFocusTrap);
Vue.component('KToolbar', KToolbar);
}