-
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
Showing
16 changed files
with
378 additions
and
471 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
abstract class ComponentModel<MsgType> { | ||
abstract update(payload: any, forward: (msg: MsgType) => void): void | ||
} | ||
|
||
abstract class ComponentBase<Model extends ComponentModel<MsgType>, MsgType> { | ||
el: HTMLDivElement | ||
// model: Model | ||
|
||
constructor(public model: Model) { | ||
this.el = document.createElement('div') | ||
// this.model = new componentModelCtor() | ||
} | ||
|
||
public patch(payload: any): void { | ||
this.model.update(payload, this.update.bind(this)) | ||
} | ||
|
||
public abstract mount(el: HTMLDivElement): void | ||
|
||
protected abstract update(msg: MsgType): void | ||
} | ||
|
||
|
||
export { | ||
ComponentModel, | ||
ComponentBase | ||
} |
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,52 @@ | ||
import mdui from "mdui" | ||
import { ComponentBase, ComponentModel } from ".." | ||
|
||
type AButtonMsgType = 'caption' | ||
|
||
class AButtonModel extends ComponentModel<AButtonMsgType> { | ||
caption: string = '' | ||
onclick: () => void = () => {} | ||
|
||
update(payload: any, forward: (msg: AButtonMsgType) => void): void { | ||
if (payload.caption !== undefined) { | ||
this.caption = payload.caption | ||
forward('caption') | ||
} | ||
|
||
if (payload.onclick !== undefined) { | ||
this.onclick = payload.onclick | ||
} | ||
} | ||
} | ||
|
||
class AButton extends ComponentBase<AButtonModel, AButtonMsgType> { | ||
|
||
button_el: HTMLButtonElement | ||
|
||
mount(el: HTMLDivElement): void { | ||
this.button_el = document.createElement('button') | ||
this.button_el.classList.add('mdui-btn') | ||
this.button_el.classList.add('mdui-btn-raised') | ||
this.button_el.classList.add('mdui-ripple') | ||
this.update('caption') | ||
this.el.appendChild(this.button_el) | ||
|
||
this.button_el.addEventListener('click', (_) => { | ||
this.model.onclick() | ||
}) | ||
|
||
el.appendChild(this.el) | ||
} | ||
|
||
update(msg: AButtonMsgType): void { | ||
if (msg === 'caption') { | ||
this.button_el.innerText = this.model.caption | ||
} | ||
mdui.mutation() | ||
} | ||
} | ||
|
||
export { | ||
AButtonModel, | ||
AButton | ||
} |
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,78 @@ | ||
import mdui from "mdui" | ||
import { ComponentBase, ComponentModel } from ".." | ||
|
||
type ACheckboxMsgType = 'value' | 'label' | ||
|
||
type ACheckboxStatus = 'checked' | 'unchecked' // | 'partial' | ||
|
||
class ACheckboxModel extends ComponentModel<ACheckboxMsgType> { | ||
value: ACheckboxStatus = 'unchecked' | ||
label: string = '' | ||
onchange: () => void = () => {} | ||
|
||
update(payload: any, forward: (msg: ACheckboxMsgType) => void): void { | ||
if (payload.value !== undefined) { | ||
this.value = payload.value | ||
forward('value') | ||
} | ||
if (payload.label !== undefined) { | ||
this.label = payload.label | ||
forward('label') | ||
} | ||
if (payload.onchange !== undefined) { | ||
this.onchange = payload.onchange | ||
} | ||
} | ||
} | ||
|
||
class ACheckbox extends ComponentBase<ACheckboxModel, ACheckboxMsgType> { | ||
|
||
label_el: HTMLLabelElement | ||
input_el: HTMLInputElement | ||
i_el: HTMLElement | ||
|
||
mount(el: HTMLDivElement): void { | ||
this.label_el = document.createElement('label') | ||
this.label_el.classList.add('mdui-checkbox') | ||
// this.label_el.textContent = this.model.label | ||
|
||
this.input_el = document.createElement('input') | ||
this.input_el.type = 'checkbox' | ||
this.label_el.appendChild(this.input_el) | ||
|
||
this.i_el = document.createElement('i') | ||
this.i_el.classList.add('mdui-checkbox-icon') | ||
this.label_el.appendChild(this.i_el) | ||
|
||
this.label_el.appendChild(new Text(this.model.label)) | ||
this.update('value') | ||
this.input_el.addEventListener('change', () => { | ||
this.model.value = this.input_el.checked ? 'checked': 'unchecked' | ||
this.update('value') | ||
this.model.onchange() | ||
} ) | ||
this.el.appendChild(this.label_el) | ||
|
||
el.appendChild(this.el) | ||
} | ||
|
||
update(msg: ACheckboxMsgType): void { | ||
if (msg === 'label') { | ||
// this.label_el.textContent = this.model.label | ||
// this.label_el.appendChild(new Text(this.model.label)) | ||
(this.label_el.lastChild as Text).textContent = this.model.label | ||
// this.label_el.appendChild(this.input_el) | ||
// this.label_el.appendChild(this.i_el) | ||
return | ||
} | ||
if (msg === 'value') { | ||
this.input_el.checked = this.model.value === 'checked' | ||
} | ||
mdui.mutation() | ||
} | ||
} | ||
|
||
export { | ||
ACheckboxModel, | ||
ACheckbox | ||
} |
Oops, something went wrong.