diff --git a/src/client/app/widgets/buttons/menu.js b/src/client/app/widgets/buttons/menu.js index e6654f10..ff8c7b71 100644 --- a/src/client/app/widgets/buttons/menu.js +++ b/src/client/app/widgets/buttons/menu.js @@ -5,21 +5,49 @@ var Widget = require('../common/widget'), class Menu extends Widget { + static description() { + + return 'Drag and drop menu with a circular layout' + + } + static defaults() { return super.defaults({ _menu:'menu', - size: {type: 'number', value: 200}, + size: {type: 'number|array', value: 200, help: [ + '- If `circular` is `true`: diameter (in px)', + '- If `circular` is `false`: square size or `[width, height]` array', + ]}, + circular: {type: 'boolean', value: true, help: [ + 'Defines whether the menu should be rendered in a circle or in a box' + ]}, + vertical: {type: 'boolean|number', value: false, help: [ + 'If `circular` is `false`, set this to `true` for vertical layout', + 'Ignored when `grid` is `true`' + ]}, + grid: {type: 'boolean|number', value: false, help: [ + '- If `circular` is `false`, set this to `true` for grid layout', + '- Can be a `number` to define the number of columns' + ]}, values: {type: 'array|object', value: {'Value 1':1,'Value 2':2}, help: [ '`Array` of possible values to switch between : `[1,2,3]`', '`Object` of label:value pairs. Numeric labels must be prepended or appended with a white space (or any other non-numeric character) otherwise the order of the values won\'t be kept', ]}, weights: {type: 'array', value: '', help: [ - '`Array` of `number` defining the weights of each value in `values`' + '`Array` of `number` defining the weights of each value in `values`', + 'Ignored when `grid` is `true`' ]} + }, [], { + + css: {type: 'string', value: '', help: [ + 'When `circular` is `false`, the layout can be altered by changing the following properties on the `.menu` selector:', + '- `flex-direction: column;` for a vertical layout', + '- `display: grid; grid-template-columns: repeat(X, 1fr);` for a X-columns grid', + ]} }) } @@ -66,9 +94,8 @@ class Menu extends Widget { }, {element: this.widget}) - this.container.style.setProperty('--size', parseInt(this.getProp('size')) + 'rem') - - + this.setMode() + this.setSize() } @@ -94,6 +121,7 @@ class Menu extends Widget { var nval = 0, i = 0, + circular = this.getProp('circular'), values = this.getProp('values'), weights = this.getProp('weights'), totalWeight @@ -103,6 +131,7 @@ class Menu extends Widget { } this.values = [] + this.widget.removeChild(this.menu) this.menu.innerHTML = '' @@ -117,8 +146,8 @@ class Menu extends Widget { skew = 90 - angle this.values.push(values[k]) this.menu.appendChild(html` -
-
${raw(iconify(parseFloat(k) != k ? k : values[k]))}
+
+
${raw(iconify(parseFloat(k) != k ? k : values[k]))}
`) i++ @@ -126,6 +155,40 @@ class Menu extends Widget { } + + this.setValue(this.value) + + this.widget.appendChild(this.menu) + + if (!this.getProp('circular') && this.getProp('grid')) { + this.container.style.setProperty('--grid-columns', this.getProp('grid') === true ? parseInt(nval / 2) : parseInt(this.getProp('grid'))) + } + + } + + setMode() { + + this.container.classList.toggle('box', !this.getProp('circular')) + this.container.classList.toggle('circular', this.getProp('circular')) + this.container.classList.toggle('grid', this.getProp('grid') && !this.getProp('circular')) + this.container.classList.toggle('vertical', this.getProp('vertical') && !this.getProp('circular')) + + } + + setSize() { + + var size = this.getProp('size') + if (Array.isArray(size)) { + this.container.style.setProperty('--size', parseInt(size[0]) + 'rem') + this.container.style.setProperty('--size-box-w', parseInt(size[0]) + 'rem') + this.container.style.setProperty('--size-box-h', parseInt(size[1]) + 'rem') + + } else { + this.container.style.setProperty('--size', parseInt(size) + 'rem') + this.container.style.setProperty('--size-box-w', parseInt(size) + 'rem') + this.container.style.setProperty('--size-box-h', parseInt(size) + 'rem') + } + } scrollOffset() { @@ -163,9 +226,22 @@ class Menu extends Widget { switch (propName) { + case 'size': + this.setSize() + return + case 'vertical': + this.setMode() + return + case 'circular': + this.setMode() + this.parseValues() + return + case 'grid': + this.setMode() + if (this.getProp('grid') === true) this.parseValues() + return case 'values': this.parseValues() - this.setValue(this.value) return } @@ -177,6 +253,10 @@ class Menu extends Widget { } Menu.dynamicProps = Menu.prototype.constructor.dynamicProps.concat( + 'size', + 'circular', + 'vertical', + 'grid', 'values' ) diff --git a/src/scss/widgets/menu.scss b/src/scss/widgets/menu.scss index c3cf3ad8..57fd2ad5 100644 --- a/src/scss/widgets/menu.scss +++ b/src/scss/widgets/menu.scss @@ -9,28 +9,72 @@ border-radius: 0!important; // border radius breaks it somehow z-index: initial!important; - --size:300rem; + --size: 300rem; + --grid-columns: 2; .menu { display:none; &.show { display:block; - animation: menu-widget-fade .1s forwards; } + animation: menu-widget-fade .1s forwards; - width:var(--size); - height:var(--size); position: fixed; z-index: 999999999; - margin-left: calc(var(--x) - var(--size) / 2); - margin-top: calc(var(--y) - var(--size) / 2); background: var(--color-fg); - border-radius: 100%; overflow: hidden; box-shadow: 0 0 0 1rem var(--color-light) inset, 0 0 5rem 0 var(--color-bg) ; + + + .item { + + z-index: 1; + overflow: hidden; + + &.on:before { + content:""; + position: absolute; + top:0; + left:0; + right:0; + bottom:0; + pointer-events: none; + background: var(--color-custom); + opacity: 0.3; + + } + + &.active:after { + content:""; + position: absolute; + top:0; + left:0; + right:0; + bottom:0; + pointer-events: none; + background: var(--color-light); + } + + div { + text-align: center; + pointer-events: none; + } + + } + + } + + &.circular .menu { + + border-radius: 100%; + width:var(--size); + height:var(--size); + margin-left: calc(var(--x) - var(--size) / 2); + margin-top: calc(var(--y) - var(--size) / 2); + &:after { content:""; position: absolute; @@ -46,17 +90,13 @@ z-index: 10; } - .item { - - position: absolute; - z-index: 1; top: calc(-1 * var(--size) / 2); left: calc(-1 * var(--size) / 2); width: 100%; height: 100%; transform-origin: 100% 100%; - overflow: hidden; + position: absolute; box-shadow: 0 0 0 2.5rem var(--color-light) inset, 0 0 0 1.5rem var(--color-bg) inset; &.on div:before { @@ -71,35 +111,10 @@ box-shadow: 0 0 0 4rem var(--color-custom); } - &.on:before { - content:""; - position: absolute; - top:0; - left:0; - right:0; - bottom:0; - pointer-events: none; - background: var(--color-custom); - opacity: 0.3; - } - - &.active:after { - content:""; - position: absolute; - top:0; - left:0; - right:0; - bottom:0; - pointer-events: none; - background: var(--color-light); - } - div { position: absolute; bottom: 0; right: 0; - text-align: center; - pointer-events: none; } span { @@ -111,7 +126,66 @@ } + } + + &.box .menu { + + width:var(--size-box-w); + height:var(--size-box-h); + margin-left: calc(var(--x) - var(--size-box-w) / 2); + margin-top: calc(var(--y) - var(--size-box-h) / 2); + background: var(--color-bg); + + &.show { + display: flex; + } + + flex-direction: row; + + .item { + position: relative; + margin:.5rem; + background: var(--color-fg); + box-shadow: 0 0 0 1rem var(--color-light) inset; + + &.on div:before { + content:""; + position: absolute; + width: 100%; + height: 100%; + left: 0; + top: 0; + pointer-events: none; + box-shadow: 0 0 0 1rem var(--color-custom) inset; + opacity: 0.3; + } + + div { + display: flex; + justify-content: center; + align-items: center; + height: 100%; + } + } + + } + + &.grid .menu { + + &.show { + display: grid; + grid-template-columns: repeat(var(--grid-columns), 1fr); + } + + } + + &.vertical .menu { + + flex-direction: column; + + } + } .widget.menu-container > .label:after {