-
Notifications
You must be signed in to change notification settings - Fork 85
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
6d9f99b
commit 168a63d
Showing
17 changed files
with
257 additions
and
67 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
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 |
---|---|---|
|
@@ -3,4 +3,3 @@ | |
export * from "./binding"; | ||
export * from "./controls"; | ||
export * from "./localize"; | ||
export * from "./state"; |
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,23 @@ | ||
.radioGroup { | ||
padding: 8px; | ||
|
||
& span { | ||
margin-left: 4px; | ||
} | ||
|
||
& ul { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
padding: 0; | ||
} | ||
|
||
& li { | ||
margin: 4px; | ||
list-style-type: none; | ||
} | ||
|
||
& input { | ||
margin-right: 4px; | ||
} | ||
} |
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,51 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { SelectableItems } from "chili-core"; | ||
import { div, h2, input, li, span, ul } from "./controls"; | ||
import style from "./itemsControl.module.css"; | ||
|
||
export class RadioGroup extends HTMLElement { | ||
constructor( | ||
readonly header: string, | ||
readonly context: SelectableItems<any>, | ||
) { | ||
super(); | ||
this.appendChild(this.render()); | ||
} | ||
|
||
render() { | ||
return div( | ||
{ className: style.radioGroup }, | ||
span(this.header + ": "), | ||
ul( | ||
...this.context.items.map((x) => { | ||
return li( | ||
input({ type: "radio", value: x, checked: this.context.selectedItems.has(x) }), | ||
x, | ||
); | ||
}), | ||
), | ||
); | ||
} | ||
|
||
connectedCallback() { | ||
this.addEventListener("click", this.#onClick); | ||
} | ||
|
||
disconnectedCallback() { | ||
this.removeEventListener("click", this.#onClick); | ||
} | ||
|
||
#onClick = (e: MouseEvent) => { | ||
const target = e.target as HTMLInputElement; | ||
if (target?.type === "radio") { | ||
this.querySelectorAll("input").forEach((x) => { | ||
if (x !== target) x.checked = false; | ||
}); | ||
target.checked = true; | ||
this.context.selectedItems = new Set([target.value]); | ||
} | ||
}; | ||
} | ||
|
||
customElements.define("chili-radios", RadioGroup); |
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 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 |
---|---|---|
@@ -1,30 +1,44 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { I18n, I18nKeys, IPropertyChanged, Property, SelectableItems } from "chili-core"; | ||
import style from "./dialog.module.css"; | ||
import { button, div } from "./controls"; | ||
import { RadioGroup } from "./controls/itemsControl"; | ||
|
||
export class Dialog { | ||
private constructor() {} | ||
|
||
static show(msg: string, title?: string) { | ||
static show(title: I18nKeys, context: IPropertyChanged, callback: () => void) { | ||
let properties = Property.getProperties(context); | ||
let dialog = document.createElement("dialog"); | ||
dialog.style.padding = "0"; | ||
dialog.innerHTML = ` | ||
<div class="${style.dialog}"> | ||
<div class="${style.title}">${title ?? "chili3d"}</div> | ||
<div class="${style.content}">${msg}</div> | ||
<div class="${style.buttons}"> | ||
<button class="${style.button}">OK</button> | ||
</div> | ||
</div> | ||
`; | ||
dialog.appendChild( | ||
div( | ||
{ className: style.root }, | ||
div({ className: style.title }, I18n.translate(title) ?? "chili3d"), | ||
...properties.map((x) => { | ||
let value = (context as any)[x.name]; | ||
if (value instanceof SelectableItems) { | ||
return new RadioGroup(I18n.translate(x.display), value); | ||
} | ||
return ""; | ||
}), | ||
div( | ||
{ className: style.buttons }, | ||
button({ | ||
textContent: I18n.translate("common.confirm"), | ||
onclick: () => { | ||
dialog.close(); | ||
callback(); | ||
}, | ||
}), | ||
button({ | ||
textContent: I18n.translate("common.cancel"), | ||
onclick: () => dialog.close(), | ||
}), | ||
), | ||
), | ||
); | ||
document.body.appendChild(dialog); | ||
let button = dialog.querySelector(`.${style.button}`)!; | ||
let handler = () => { | ||
dialog.close(); | ||
document.body.removeChild(dialog); | ||
button.removeEventListener("click", handler); | ||
}; | ||
button.addEventListener("click", handler); | ||
dialog.showModal(); | ||
} | ||
} |
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
Oops, something went wrong.