-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e96827
commit be3a27a
Showing
11 changed files
with
142 additions
and
77 deletions.
There are no files selected for viewing
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,29 @@ | ||
import { StringPropertyEditor } from './properties/editors/string/string-property-editor'; | ||
|
||
class PropertiesEditorsClass { | ||
private readonly editors = { | ||
string: StringPropertyEditor.tagName, | ||
default: StringPropertyEditor.tagName, | ||
}; | ||
|
||
public findEditorFor(name: string, value: any) { | ||
// TODO what abount null / undefined values? | ||
|
||
const editors = this.editors; | ||
// first, try to find by the name of the property | ||
if (name in editors) return editors[name]; | ||
|
||
// second, try to find by its type | ||
const type = typeof value; | ||
if (type !== 'object' && type in editors) | ||
return editors[type]; | ||
|
||
// next, since it's an object, try to find by its contructor name | ||
const ctor = value.contructor?.name; | ||
if (ctor && ctor in editors) return editors[ctor]; | ||
|
||
return editors.default; | ||
} | ||
} | ||
|
||
export const PropertiesEditors = new PropertiesEditorsClass(); |
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,37 @@ | ||
@import 'colors'; | ||
|
||
$property-input-background: rgba(white, 0.05); | ||
$property-foreground: $on-background-color; | ||
|
||
.property-editor { | ||
display: flex; | ||
flex-direction: row; | ||
padding: 2px 0; | ||
|
||
.property-title { | ||
width: 30%; | ||
padding: 4px 2px 2px 0; | ||
font-size: 14px; | ||
color: rgba($on-background-color, 0.6); | ||
} | ||
|
||
.property-content { | ||
flex: 1; | ||
color: $property-foreground; | ||
|
||
input[type="text"] { | ||
width: 100%; | ||
font-size: 16px; | ||
background-color: $property-input-background; | ||
color: $property-foreground; | ||
border: 1px solid transparent; | ||
padding: 2px 4px; | ||
outline: none !important; | ||
transition: all 0.1s; | ||
|
||
&:focus { | ||
border-color: rgba($on-background-color, 0.5); | ||
} | ||
} | ||
} | ||
} |
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,25 @@ | ||
import './property-editor.scss'; | ||
|
||
export abstract class PropertyEditor<T> extends HTMLElement { | ||
public connectedCallback() { | ||
this.classList.add('property-editor'); | ||
} | ||
|
||
protected createLabel(title: string, propertyId: string): HTMLElement { | ||
const label = document.createElement('label'); | ||
label.classList.add('property-title'); | ||
label.append(title); | ||
label.setAttribute('for', propertyId); | ||
return label; | ||
} | ||
|
||
protected abstract createValue(value: T, propertyId: string): HTMLElement; | ||
|
||
public setContent(name: string, value: T) { | ||
const propId = `prop-${name}`; | ||
const title = this.createLabel(name, propId); | ||
const content = this.createValue(value, propId); | ||
this.appendChild(title); | ||
this.appendChild(content); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/ui/properties/editors/string/string-property-editor.ts
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,21 @@ | ||
import { PropertyEditor } from '../property-editor'; | ||
// import './string-property-editor.scss'; | ||
|
||
export class StringPropertyEditor extends PropertyEditor<string> { | ||
public static readonly tagName = 'phed-string-property-editor'; | ||
|
||
protected createValue(value: string, propertyId: string) { | ||
const propContent = document.createElement('div'); | ||
propContent.classList.add('property-content'); | ||
|
||
const propValue = document.createElement('input'); | ||
propValue.id = propertyId; | ||
propValue.setAttribute('type', 'text'); | ||
propValue.setAttribute('value', value ?? ''); | ||
propContent.append(propValue); | ||
|
||
return propContent; | ||
} | ||
} | ||
|
||
customElements.define(StringPropertyEditor.tagName, StringPropertyEditor); |
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