inspector: commit color picker changes on dragend and remove action buttons (#771)

This commit is contained in:
jean-emmanuel 2022-01-26 12:05:53 +01:00
parent e4846688c8
commit 795142adfe
4 changed files with 10 additions and 52 deletions

View file

@ -30,27 +30,25 @@ class ColorPicker extends UiWidget {
this.container = html`
<div class="color-picker">
${this.rgb.container}
<div class="actions">
<div class="btn color-confirm">${locales('inspector_color_confirm')}</div>
<div class="btn color-cancel">${locales('inspector_color_cancel')}</div>
</div>
</div>
`
DOM.get(this.container, '.color-confirm')[0].addEventListener('click', this.confirm.bind(this))
DOM.get(this.container, '.color-cancel')[0].addEventListener('click', this.cancel.bind(this))
this.rgb.on('change', (e)=>{
e.stopPropagation = true
this.value = chroma(this.rgb.value).hex()
this.trigger('change', {preventHistory: true})
})
this.rgb.on('dragend', (e)=>{
this.value = chroma(this.rgb.value).hex()
this.trigger('change')
})
this.opened = 0
this.cancelValue = '#00000000'
this.escKeyHandler = ((e)=>{
if (e.keyCode==27) this.cancel()
if (e.keyCode==27) this.close()
}).bind(this)
this.enterKeyHandler = ((e)=>{
@ -89,16 +87,6 @@ class ColorPicker extends UiWidget {
}
cancel() {
if (this.value !== this.cancelValue) {
this.value = this.cancelValue
this.trigger('change', {preventHistory: true})
}
this.close()
}
isVisible() {
return true
@ -119,12 +107,6 @@ class ColorPicker extends UiWidget {
}
setCancelValue(v) {
this.cancelValue = v
}
setParent(node) {
if (this.opened && node !== this.parentNode) this.close()

View file

@ -68,13 +68,11 @@ class UiInspector extends UiWidget {
textarea = DOM.get(this.container, `textarea[name="${name}"]`)
if (this.colorPicker.name === name) {
this.colorPicker.cancel()
this.colorPicker.close()
} else {
if (this.colorPicker.opened) this.colorPicker.cancel()
this.colorPicker.setParent(node.parentNode)
this.colorPicker.setName(name)
this.colorPicker.setValue(node.getAttribute('value'))
this.colorPicker.setCancelValue(textarea[0].value)
this.colorPicker.open()
}

View file

@ -638,28 +638,6 @@ osc-inspector-color {
}
}
.actions {
display: flex;
flex-direction: row;
align-items: flex-end;
justify-content: stretch;
// height: 24rem + $padding * 2;
line-height: $field-height;
flex-shrink: 0;
background: var(--color-ui-foreground);
// padding: $padding;
.btn {
flex: 1;
text-overflow: clip;
min-width: 0;
background: var(--color-ui-button);
margin-right: 1rem;
&:last-child {
margin: 0;
}
}
}
}
.inspector-help {