-
Notifications
You must be signed in to change notification settings - Fork 81
/
generateGlobalStyles.js
52 lines (45 loc) · 1.57 KB
/
generateGlobalStyles.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
import { StyleSheet as baseStyleSheet, setStyleTagSuffix } from 'aphrodite/no-important';
import { themeTokens, themePalette, themeBrand, themeOutlineStyle } from './theme';
// include global styles
import 'purecss/build/base-min.css';
setStyleTagSuffix('kolibriVue');
const globalSelectorHandler = (selector, _, generateSubtreeStyles) => {
if (selector[0] !== '*') {
return null;
}
return generateSubtreeStyles(selector.slice(1));
};
const globalExtension = { selectorHandler: globalSelectorHandler };
const { StyleSheet, css } = baseStyleSheet.extend([globalExtension]);
// generate a minimal set of global, unscoped styles using theme variables
export default function generateGlobalStyles() {
const printStyle = {
'@media print': {
color: '#000 !important',
background: 'none !important',
boxShadow: 'none !important',
},
};
const htmlBodyStyles = {
color: themeTokens().text,
backgroundColor: themePalette().grey.v_100,
...printStyle,
};
const globalStyles = StyleSheet.create({
globals: {
'**': printStyle,
'*html': htmlBodyStyles,
'*body': htmlBodyStyles,
'*:focus': themeOutlineStyle(),
'*:focus:hover': themeOutlineStyle(),
'*::selection': {
background: themeBrand().secondary.v_100,
},
},
});
// Have to do this to actually generate and inject the stylesheet
// Return to have a value that will change when the dynamic styles change
// This should be a cheap computation due to the caching that
// Aphrodite is doing internally.
return css(globalStyles.globals);
}