wave-ui 2.39.1 → 2.40.0
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/wave-ui.cjs.js +1 -1
- package/dist/wave-ui.css +1 -1
- package/dist/wave-ui.es.js +124 -140
- package/dist/wave-ui.umd.js +1 -1
- package/package.json +1 -1
- package/src/wave-ui/components/w-app.vue +9 -12
- package/src/wave-ui/core.js +3 -0
- package/src/wave-ui/utils/dynamic-css.js +26 -31
package/package.json
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
-
import config from '../utils/config'
|
|
9
8
|
import NotificationManager from './w-notification-manager.vue'
|
|
10
|
-
import
|
|
9
|
+
import dynamicCSS from '../utils/dynamic-css'
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
// Global var for faster results in the resize event handler.
|
|
12
|
+
let breakpointsDef = { keys: [], values: [] }
|
|
14
13
|
|
|
15
14
|
export default {
|
|
16
15
|
name: 'w-app',
|
|
@@ -58,11 +57,11 @@ export default {
|
|
|
58
57
|
methods: {
|
|
59
58
|
getBreakpoint () {
|
|
60
59
|
const width = window.innerWidth
|
|
61
|
-
const breakpoints =
|
|
60
|
+
const breakpoints = breakpointsDef.values.slice(0)
|
|
62
61
|
// Most performant lookup.
|
|
63
62
|
breakpoints.push(width)
|
|
64
63
|
breakpoints.sort((a, b) => a - b)
|
|
65
|
-
const breakpoint =
|
|
64
|
+
const breakpoint = breakpointsDef.keys[breakpoints.indexOf(width)] || 'xl'
|
|
66
65
|
|
|
67
66
|
if (breakpoint !== this.currentBreakpoint) {
|
|
68
67
|
this.currentBreakpoint = breakpoint
|
|
@@ -78,19 +77,18 @@ export default {
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
this.$waveui.breakpoint.width = width
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
dynamicStyles () {
|
|
84
|
-
return DynamicCSS()
|
|
85
80
|
}
|
|
86
81
|
},
|
|
87
82
|
|
|
88
83
|
mounted () {
|
|
84
|
+
const { config } = this.$waveui
|
|
85
|
+
breakpointsDef = { keys: Object.keys(config.breakpoints), values: Object.values(config.breakpoints) }
|
|
86
|
+
|
|
89
87
|
// Inject global dynamic CSS classes in document head.
|
|
90
88
|
if (!document.getElementById('wave-ui-styles')) {
|
|
91
89
|
const css = document.createElement('style')
|
|
92
90
|
css.id = 'wave-ui-styles'
|
|
93
|
-
css.innerHTML =
|
|
91
|
+
css.innerHTML = dynamicCSS(config)
|
|
94
92
|
|
|
95
93
|
const firstStyle = document.head.querySelectorAll('style,link[rel="stylesheet"]')[0]
|
|
96
94
|
if (firstStyle) firstStyle.before(css)
|
|
@@ -127,6 +125,5 @@ export default {
|
|
|
127
125
|
&.justify-space-evenly {justify-content: space-evenly;}
|
|
128
126
|
&.text-center {text-align: center;}
|
|
129
127
|
&.text-right {text-align: right;}
|
|
130
|
-
|
|
131
128
|
}
|
|
132
129
|
</style>
|
package/src/wave-ui/core.js
CHANGED
|
@@ -40,6 +40,8 @@ export default class WaveUI {
|
|
|
40
40
|
return obj
|
|
41
41
|
}, { ...config.colors, black: '#000', white: '#fff', transparent: 'transparent', inherit: 'inherit' })
|
|
42
42
|
|
|
43
|
+
config = {} // Store and expose the config in the $waveui object.
|
|
44
|
+
|
|
43
45
|
static install (app, options = {}) {
|
|
44
46
|
// Register directives.
|
|
45
47
|
// for (const id in directives) {
|
|
@@ -108,6 +110,7 @@ export default class WaveUI {
|
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
this.config = config
|
|
111
114
|
WaveUI.instance = this
|
|
112
115
|
// Make waveui reactive and expose the single instance in Vue.
|
|
113
116
|
app.config.globalProperties.$waveui = reactive(this)
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import config from './config'
|
|
2
|
-
|
|
3
|
-
const { css: cssConfig } = config
|
|
4
|
-
const entries = Object.entries(config.breakpoints)
|
|
5
|
-
const breakpoints = entries.map(([label, max], i) => {
|
|
6
|
-
// Construct the breakpoint objects.
|
|
7
|
-
const [, value = 0] = entries[i - 1] || []
|
|
8
|
-
return { label, min: value ? value + 1 : 0, max }
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
let computedStyles = null
|
|
12
1
|
// Defaults CSS variables. Will be overridden in the main function of this file (the export default)
|
|
13
2
|
// which fetches the CSS :root variables generated by _layout.scss.
|
|
14
3
|
const cssVars = {
|
|
@@ -16,7 +5,7 @@ const cssVars = {
|
|
|
16
5
|
baseIncrement: 4
|
|
17
6
|
}
|
|
18
7
|
|
|
19
|
-
const generateColors =
|
|
8
|
+
const generateColors = config => {
|
|
20
9
|
let styles = ''
|
|
21
10
|
const { cssScope } = cssVars
|
|
22
11
|
|
|
@@ -30,7 +19,7 @@ const generateColors = () => {
|
|
|
30
19
|
}
|
|
31
20
|
|
|
32
21
|
// Color shades are generated in core.js, if the option is on.
|
|
33
|
-
if (
|
|
22
|
+
if (config.css.colorShades && config.colorShades) {
|
|
34
23
|
Object.entries(config.colorShades).forEach(([label, color]) => {
|
|
35
24
|
styles +=
|
|
36
25
|
`${cssScope} .${label}--bg{background-color:${color}}` +
|
|
@@ -56,7 +45,7 @@ const generateColors = () => {
|
|
|
56
45
|
}
|
|
57
46
|
|
|
58
47
|
// Generate the layout grid. E.g. xs1, xs2, ..., xl12.
|
|
59
|
-
const generateBreakpoints = () => {
|
|
48
|
+
const generateBreakpoints = (breakpoints, grid) => {
|
|
60
49
|
let styles = ''
|
|
61
50
|
const { cssScope } = cssVars
|
|
62
51
|
|
|
@@ -74,20 +63,20 @@ const generateBreakpoints = () => {
|
|
|
74
63
|
// Discard `xs` since the min is 0 (`media query (min-width: 0)`), and leave in _layout.scss.
|
|
75
64
|
if (label === 'xs') {
|
|
76
65
|
// For each breakpoint, loop from 1 to 12. E.g. xs1, xs2, ..., xl12.
|
|
77
|
-
for (let i = 0; i <
|
|
66
|
+
for (let i = 0; i < grid; i++) {
|
|
78
67
|
styles +=
|
|
79
|
-
`${cssScope} .${label}${
|
|
80
|
-
`width:${parseFloat(((
|
|
68
|
+
`${cssScope} .${label}${grid - i}{` +
|
|
69
|
+
`width:${parseFloat(((grid - i) * 100 / grid).toFixed(4))}%;}`
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
else {
|
|
84
73
|
styles += `@media(min-width:${min}px){`
|
|
85
74
|
|
|
86
75
|
// For each breakpoint, loop from 1 to 12. E.g. xs1, xs2, ..., xl12.
|
|
87
|
-
for (let i = 0; i <
|
|
76
|
+
for (let i = 0; i < grid; i++) {
|
|
88
77
|
styles +=
|
|
89
|
-
`${cssScope} .${label}${
|
|
90
|
-
`width:${parseFloat(((
|
|
78
|
+
`${cssScope} .${label}${grid - i}{` +
|
|
79
|
+
`width:${parseFloat(((grid - i) * 100 / grid).toFixed(4))}%;}`
|
|
91
80
|
}
|
|
92
81
|
|
|
93
82
|
styles += '}'
|
|
@@ -104,7 +93,7 @@ const generateBreakpoints = () => {
|
|
|
104
93
|
The drawback is that it generates so much CSS that I don't think it is worth it.
|
|
105
94
|
In this test, for only 2 margin rules, it already generates 35kb of CSS...
|
|
106
95
|
|
|
107
|
-
const generateBreakpointSpaces =
|
|
96
|
+
const generateBreakpointSpaces = breakpoints => {
|
|
108
97
|
let styles = ''
|
|
109
98
|
const { cssScope, baseIncrement } = cssVars
|
|
110
99
|
|
|
@@ -128,7 +117,7 @@ const generateBreakpointSpaces = () => {
|
|
|
128
117
|
styles += `${cssScope} .${label}-mx${i}{margin-right:${i * baseIncrement}px;margin-left:${i * baseIncrement}px}`
|
|
129
118
|
}
|
|
130
119
|
styles += '}'
|
|
131
|
-
})
|
|
120
|
+
})
|
|
132
121
|
|
|
133
122
|
breakpoints.forEach(({ label, max }) => {
|
|
134
123
|
// Discard `xs`: xsd is just like xs.
|
|
@@ -148,7 +137,7 @@ const generateBreakpointSpaces = () => {
|
|
|
148
137
|
return styles
|
|
149
138
|
} */
|
|
150
139
|
|
|
151
|
-
const genBreakpointLayoutClasses =
|
|
140
|
+
const genBreakpointLayoutClasses = breakpoints => {
|
|
152
141
|
let styles = ''
|
|
153
142
|
const { cssScope, baseIncrement } = cssVars
|
|
154
143
|
const layoutClasses = [
|
|
@@ -188,7 +177,6 @@ const genBreakpointLayoutClasses = () => {
|
|
|
188
177
|
const array12 = Array(12).fill()
|
|
189
178
|
|
|
190
179
|
// Define media queries for each breakpoint: xs, sm, md, lg, xl.
|
|
191
|
-
|
|
192
180
|
breakpoints.forEach(({ label, min }) => {
|
|
193
181
|
// Discard `xs` since the min is 0 (`media query (min-width: 0)`), and leave in _layout.scss.
|
|
194
182
|
if (label !== 'xs') {
|
|
@@ -230,16 +218,23 @@ const genBreakpointLayoutClasses = () => {
|
|
|
230
218
|
return styles
|
|
231
219
|
}
|
|
232
220
|
|
|
233
|
-
export default
|
|
234
|
-
|
|
235
|
-
|
|
221
|
+
export default config => {
|
|
222
|
+
const entries = Object.entries(config.breakpoints)
|
|
223
|
+
const breakpointsDef = entries.map(([label, max], i) => {
|
|
224
|
+
// Construct the breakpoint objects.
|
|
225
|
+
const [, value = 0] = entries[i - 1] || []
|
|
226
|
+
return { label, min: value ? value + 1 : 0, max }
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const computedStyles = getComputedStyle(document.documentElement)
|
|
236
230
|
cssVars.cssScope = computedStyles.getPropertyValue('--css-scope')
|
|
237
231
|
cssVars.baseIncrement = parseInt(computedStyles.getPropertyValue('--base-increment'))
|
|
238
232
|
|
|
239
|
-
styles
|
|
240
|
-
styles +=
|
|
241
|
-
|
|
242
|
-
|
|
233
|
+
let styles = ''
|
|
234
|
+
styles += generateColors(config)
|
|
235
|
+
styles += generateBreakpoints(breakpointsDef, config.css.grid)
|
|
236
|
+
if (config.css.breakpointLayoutClasses) styles += genBreakpointLayoutClasses(breakpointsDef)
|
|
237
|
+
// if (config.css.breakpointSpaces) styles += generateBreakpointSpaces(breakpointsDef)
|
|
243
238
|
|
|
244
239
|
return styles
|
|
245
240
|
}
|