button, switch: add soft wrap mode

This commit is contained in:
bordun 2021-05-06 20:27:50 +02:00
parent 231f5c8312
commit 3e97e84943
3 changed files with 26 additions and 2 deletions

View file

@ -24,8 +24,8 @@ class Button extends Widget {
'- Icons can be transformed with the following suffixes: `.flip-[horizontal|vertical|both]`, `.rotate-[90|180|270]`, `.spin`, `.pulse`. Example: `^play.flip-horizontal`',
]},
vertical: {type: 'boolean', value: false, help: 'Set to `true` to display the text vertically'},
wrap: {type: 'boolean', value: false, help: [
'Set to `true` to wrap long lines automatically.',
wrap: {type: 'boolean|string', value: false, choices: [false, true, 'soft'], help: [
'Set to `true` to wrap long lines automatically. Set to `soft` to avoid breaking words.',
]},
},
class_specific: {
@ -139,6 +139,7 @@ class Button extends Widget {
this.label = html`<label></label>`
if (this.getProp('wrap')) this.label.classList.add('wrap')
if (this.getProp('wrap') === 'soft') this.label.classList.add('wrap-soft')
if (this.getProp('vertical')) this.label.classList.add('vertical')
this.updateLabel()

View file

@ -19,6 +19,9 @@ class Switch extends MenuBase {
colorTextOn: {type: 'string', value: 'auto', help: 'Defines the widget\'s text color when active.'},
layout: {type: 'string', value: 'vertical', choices: ['vertical', 'horizontal', 'grid'], help:'Defines how items should be laid out'},
gridTemplate: {type: 'string|number', value: '', help:'If `layout` is `grid`, can be either a number of columns or a valid value for the css property "grid-template".'},
wrap: {type: 'boolean|string', value: false, choices: [false, true, 'soft'], help: [
'Set to `true` to wrap long lines automatically. Set to `soft` to avoid breaking words.',
]},
},
class_specific: {
values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [
@ -42,6 +45,8 @@ class Switch extends MenuBase {
super({...options, html: html`<inner></inner>`})
this.container.classList.add('layout-' + this.getProp('layout'))
if (this.getProp('wrap')) this.container.classList.add('wrap')
if (this.getProp('wrap') === 'soft') this.container.classList.add('wrap-soft')
if (this.getProp('layout') === 'grid') {
var template = this.getProp('gridTemplate') || 2

View file

@ -56,6 +56,9 @@
white-space: pre-wrap;
word-break: break-all;
}
&.wrap-soft {
word-break: normal
}
&.vertical {
transform: rotate(180deg);
text-overflow: ellipsis;
@ -139,6 +142,12 @@
justify-content: center;
text-overflow: clip;
overflow: hidden;
white-space: pre;
text-align: center;
word-wrap: break-word;
@include pseudo-fill($z: -1);
&:after {
--line-width: 1rem;
@ -153,6 +162,15 @@
}
&.wrap value {
white-space: pre-wrap;
word-break: break-all;
}
&.wrap-soft value {
word-break: normal
}
}
// @keyframes menu-widget-fade {