-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lexical: Added color picker/indicator to form fields
- Loading branch information
1 parent
c091f67
commit 04cca77
Showing
10 changed files
with
125 additions
and
36 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {EditorContainerUiElement, EditorUiBuilderDefinition, EditorUiContext} from "../core"; | ||
import {EditorFormField, EditorFormFieldDefinition} from "../forms"; | ||
import {EditorColorPicker} from "./color-picker"; | ||
import {EditorDropdownButton} from "./dropdown-button"; | ||
|
||
import colorDisplayIcon from "@icons/editor/color-display.svg" | ||
|
||
export class EditorColorField extends EditorContainerUiElement { | ||
protected input: EditorFormField; | ||
protected pickerButton: EditorDropdownButton; | ||
|
||
constructor(input: EditorFormField) { | ||
super([]); | ||
|
||
this.input = input; | ||
|
||
this.pickerButton = new EditorDropdownButton({ | ||
button: { icon: colorDisplayIcon, label: 'Select color'} | ||
}, [ | ||
new EditorColorPicker(this.onColorSelect.bind(this)) | ||
]); | ||
this.addChildren(this.pickerButton, this.input); | ||
} | ||
|
||
protected buildDOM(): HTMLElement { | ||
const dom = this.input.getDOMElement(); | ||
dom.append(this.pickerButton.getDOMElement()); | ||
dom.classList.add('editor-color-field-container'); | ||
|
||
const field = dom.querySelector('input') as HTMLInputElement; | ||
field.addEventListener('change', () => { | ||
this.setIconColor(field.value); | ||
}); | ||
|
||
return dom; | ||
} | ||
|
||
onColorSelect(color: string, context: EditorUiContext): void { | ||
this.input.setValue(color); | ||
} | ||
|
||
setIconColor(color: string) { | ||
const icon = this.getDOMElement().querySelector('svg .editor-icon-color-display'); | ||
if (icon) { | ||
icon.setAttribute('fill', color || 'url(#pattern2)'); | ||
} | ||
} | ||
} | ||
|
||
export function colorFieldBuilder(field: EditorFormFieldDefinition): EditorUiBuilderDefinition { | ||
return { | ||
build() { | ||
return new EditorColorField(new EditorFormField(field)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters