wave-ui 2.38.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-ui",
3
- "version": "2.38.0",
3
+ "version": "2.40.0",
4
4
  "description": "An emerging UI framework for Vue.js (2 & 3) with only the bright side. :sunny:",
5
5
  "author": "Antoni Andre <antoniandre.web@gmail.com>",
6
6
  "main": "./dist/wave-ui.umd.js",
@@ -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 DynamicCSS from '../utils/dynamic-css'
9
+ import dynamicCSS from '../utils/dynamic-css'
11
10
 
12
- const breakpointsNames = Object.keys(config.breakpoints)
13
- const breakpointsValues = Object.values(config.breakpoints)
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 = breakpointsValues.slice(0)
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 = breakpointsNames[breakpoints.indexOf(width)] || 'xl'
64
+ const breakpoint = breakpointsDef.keys[breakpoints.indexOf(width)] || 'xl'
66
65
 
67
66
  if (breakpoint !== this.currentBreakpoint) {
68
67
  this.currentBreakpoint = breakpoint
@@ -78,21 +77,22 @@ 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 = this.dynamicStyles()
91
+ css.innerHTML = dynamicCSS(config)
94
92
 
95
- document.head.appendChild(css)
93
+ const firstStyle = document.head.querySelectorAll('style,link[rel="stylesheet"]')[0]
94
+ if (firstStyle) firstStyle.before(css)
95
+ else document.head.appendChild(css)
96
96
  }
97
97
 
98
98
  this.getBreakpoint(window.innerWidth)
@@ -125,6 +125,5 @@ export default {
125
125
  &.justify-space-evenly {justify-content: space-evenly;}
126
126
  &.text-center {text-align: center;}
127
127
  &.text-right {text-align: right;}
128
-
129
128
  }
130
129
  </style>
@@ -1,8 +1,9 @@
1
1
  <template lang="pug">
2
2
  transition(:name="transitionName" appear)
3
3
  .w-notification(v-if="show" :class="classes" :style="styles")
4
- w-alert.white--bg(
4
+ w-alert(
5
5
  v-bind="alertProps"
6
+ :class="alertClasses"
6
7
  @update:model-value="$emit('update:modelValue', false);$emit('input', false)")
7
8
  slot
8
9
  </template>
@@ -118,6 +119,11 @@ export default {
118
119
  }
119
120
  },
120
121
 
122
+ alertClasses () {
123
+ if (this.bgColor || ((this.success || this.info || this.warning || this.error) && this.plain)) return null
124
+ return 'white--bg'
125
+ },
126
+
121
127
  styles () {
122
128
  return {
123
129
  zIndex: this.zIndex || this.zIndex === 0 || null
@@ -330,6 +330,8 @@ export default {
330
330
  &__bar-extra {
331
331
  margin-left: auto;
332
332
  align-self: center;
333
+ position: sticky;
334
+ right: 0;
333
335
 
334
336
  .w-tabs__bar--right &,
335
337
  .w-tabs__bar--center & {margin-left: 0;}
@@ -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 (cssConfig.colorShades && config.colorShades) {
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 < cssConfig.grid; i++) {
66
+ for (let i = 0; i < grid; i++) {
78
67
  styles +=
79
- `${cssScope} .${label}${cssConfig.grid - i}{` +
80
- `width:${parseFloat(((cssConfig.grid - i) * 100 / cssConfig.grid).toFixed(4))}%;}`
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 < cssConfig.grid; i++) {
76
+ for (let i = 0; i < grid; i++) {
88
77
  styles +=
89
- `${cssScope} .${label}${cssConfig.grid - i}{` +
90
- `width:${parseFloat(((cssConfig.grid - i) * 100 / cssConfig.grid).toFixed(4))}%;}`
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
- let styles = ''
235
- computedStyles = getComputedStyle(document.documentElement)
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 += generateColors()
240
- styles += generateBreakpoints()
241
- if (cssConfig.breakpointLayoutClasses) styles += genBreakpointLayoutClasses()
242
- // if (cssConfig.breakpointSpaces) styles += generateBreakpointSpaces()
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
  }