widgets: textarea proto

This commit is contained in:
jean-emmanuel 2021-09-27 11:25:11 +02:00
parent 51260d98e6
commit 1587165c62
4 changed files with 152 additions and 1 deletions

View file

@ -7,6 +7,7 @@
- widgets
- encoder: expose angle in script (as `locals.angle`)
- new textarea widget (multi line input)
## 1.9.14

View file

@ -0,0 +1,113 @@
var Widget = require('../common/widget'),
{deepCopy} = require('../../utils'),
html = require('nanohtml')
class TextArea extends Widget {
static description() {
return 'Text area (multi line input).'
}
static defaults() {
return super.defaults().extend({
style: {
// _separator_input_style: 'Textarea style',
},
class_specific: {
},
})
}
constructor(options) {
super({...options, html: html`
<inner>
<textarea></textarea>
</inner>
`})
this.value = ''
this.stringValue = ''
this.focused = false
this.validation = null
this.input = DOM.get(this.widget, 'textarea')[0]
if (this.getProp('align') === 'left') this.widget.classList.add('left')
if (this.getProp('align') === 'right') this.widget.classList.add('right')
if (this.getProp('interaction')) {
this.input.setAttribute('tabindex', 0)
this.input.addEventListener('focus', this.focus.bind(this))
this.input.addEventListener('blur', (e)=>{
this.blur(true)
})
this.input.addEventListener('keydown', (e)=>{
if (e.keyCode === 13 && !e.shiftKey) {
// enter
e.preventDefault()
this.blur()
}
else if (e.keyCode === 27) {
// esc
this.blur(false)
this.input.value = this.stringValue
}
})
}
}
focus() {
if (this.focused) return
this.focused = true
}
blur(change=true) {
if (!this.focused) return
this.focused = false
this.input.blur()
if (change) this.inputChange()
}
inputChange() {
this.setValue(this.input.value, {sync:true, send:true})
}
setValue(v, options={} ) {
this.value = String(v)
if (this.value === '' || this.value === null) this.value = this.getProp('default')
if (this.input.value !== this.value) this.input.value = this.value
if (options.send && !options.fromSync) this.sendValue()
if (options.sync) this.changed(options)
}
}
TextArea.dynamicProps = TextArea.prototype.constructor.dynamicProps
.filter(x=>x !== 'interaction')
module.exports = TextArea

View file

@ -6,6 +6,7 @@ module.exports.widgets = {
dropdown: require('./basics/dropdown'),
menu: require('./basics/menu'),
input: require('./basics/input'),
textarea: require('./basics/textarea'),
file: require('./basics/file'),
// containers
@ -54,7 +55,7 @@ module.exports.widgets = {
}
module.exports.categories = {
'Basics':['button', 'switch', 'dropdown', 'menu', 'input', 'file'],
'Basics':['button', 'switch', 'dropdown', 'menu', 'input', 'textarea', 'file'],
'Containers':['panel', 'modal', 'clone', 'fragment', 'matrix', 'keyboard', 'patchbay'],
'Frames':['frame', 'svg', 'html', 'image'],
'Graphs':['plot','eq','visualizer'],

View file

@ -629,11 +629,47 @@
}
.textarea-container {
--alpha-fill-off: 0.05;
--widget-padding: 2rem;
inner {
position: relative;
@include pseudo-stroke();
@include pseudo-fill(0.05);
justify-content: center;
align-items: center;
display: flex;
padding: var(--widget-padding);
text-align: center;
&.right {
text-align: right;
}
&.left {
text-align: left;
}
padding: var(--widget-padding);
}
textarea {
background: none;
width: 100%;
height: 100%;
resize: none;
padding: var(--widget-padding);
}
}
.editor-enabled {
.textarea-container textarea,
.input-container inner {
// prevent input focus when selecting
pointer-events: none;
}
.clone-container.editing .textarea-container textarea,
.textarea-container.editing textarea,
.clone-container.editing .input-container inner,
.input-container.editing inner {
// prevent input focus when selecting