css: support special css property class for adding custom classes to widgets (#361)
This commit is contained in:
parent
0b2a94e0d8
commit
2185408fea
3 changed files with 32 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# Changelog
|
||||
|
||||
|
||||
## 0.38.3
|
||||
## 0.38.4
|
||||
|
||||
- bug fixes
|
||||
- `@{parent}` calls not working consistently in clone widgets
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
- undo/redo errors
|
||||
- widgets
|
||||
- 1-level nested property inheritance calls (`@{id_@{id_2}}`) are now updated dynamically
|
||||
- support special css property `class` for adding custom classes to widgets
|
||||
- editor
|
||||
- major performance improvements (containers' children are reused whenever possible instead of being recreated)
|
||||
- removed widget deletion confirmation popup
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ CSS selectors can be used to apply styles to specific elements:
|
|||
!!! tip ""
|
||||
Mixing Inline and Selector syntaxes doesn't work, once you use selectors, you have to use the `:host` selector to target the widget element.
|
||||
|
||||
## Extra css classes: `class`
|
||||
|
||||
This non-standard css property can be used to add custom css classes to the widget element: `class: my-custom-class;`
|
||||
Multiple classes can be added (one per `class` statement).
|
||||
|
||||
!!! warning ""
|
||||
Using class names that are already used in the app can be hazardous. In order to avoid that, custom class names should be prefixed with something uncommon and preferably cool, such as `xxx-myclass` or `crispy-bacon-myclass`.
|
||||
|
||||
## Layering: `z-index`
|
||||
|
||||
Z-Axis ordering can be set using the `z-index` rule. Absolutely positionned widgets (when `top` or `left` is different from `auto`) have `z-index:10;` by default.
|
||||
|
|
|
|||
|
|
@ -767,7 +767,15 @@ class Widget extends EventEmitter {
|
|||
var css = String(this.getProp('css')),
|
||||
prefix = '#' + this.hash,
|
||||
scopedCss = scopeCss(css, prefix),
|
||||
unScopedCss = ''
|
||||
unScopedCss = '',
|
||||
extraCssClasses = []
|
||||
|
||||
|
||||
// extra css "class" property
|
||||
css = css.replace(/^[^\S\n]*class[^\S\n]*:[^\S\n]*([^;\n\s]+);?/igm, (m, c)=>{
|
||||
if (c === 'widget' || c.includes('-container')) return
|
||||
extraCssClasses.push(c.replace(/"'/g,''))
|
||||
})
|
||||
|
||||
try {
|
||||
|
||||
|
|
@ -799,6 +807,19 @@ class Widget extends EventEmitter {
|
|||
this.container.insertBefore(style, this.widget)
|
||||
}
|
||||
|
||||
|
||||
// apply extra css classes
|
||||
|
||||
if (this.extraCssClasses && this.extraCssClasses.length) {
|
||||
this.container.classList.remove(...this.extraCssClasses)
|
||||
this.extraCssClasses = []
|
||||
}
|
||||
|
||||
if (extraCssClasses.length) {
|
||||
this.container.classList.add(...extraCssClasses)
|
||||
this.extraCssClasses = extraCssClasses
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (styles.includes('color')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue