Tailwind the Language picker
Changes the style and gives Class the ability to receive css-classes. There should also be a label-text given; something like "Change language" which is then hidden for `sr-only`.
This commit is contained in:
parent
415010ba47
commit
40b6b97521
2 changed files with 12 additions and 10 deletions
|
@ -14,10 +14,14 @@ export class DropDown<T> extends InputElement<T> {
|
||||||
|
|
||||||
constructor(label: string | UIElement,
|
constructor(label: string | UIElement,
|
||||||
values: { value: T, shown: string | UIElement }[],
|
values: { value: T, shown: string | UIElement }[],
|
||||||
value: UIEventSource<T> = undefined) {
|
value: UIEventSource<T> = undefined,
|
||||||
|
label_class: string,
|
||||||
|
select_class: string) {
|
||||||
super(undefined);
|
super(undefined);
|
||||||
this._value = value ?? new UIEventSource<T>(undefined);
|
this._value = value ?? new UIEventSource<T>(undefined);
|
||||||
this._label = Translations.W(label);
|
this._label = Translations.W(label);
|
||||||
|
this._label_class = label_class || '';
|
||||||
|
this._select_class = select_class || '';
|
||||||
this._values = values.map(v => {
|
this._values = values.map(v => {
|
||||||
return {
|
return {
|
||||||
value: v.value,
|
value: v.value,
|
||||||
|
@ -31,8 +35,6 @@ export class DropDown<T> extends InputElement<T> {
|
||||||
this.ListenTo(this._value);
|
this.ListenTo(this._value);
|
||||||
|
|
||||||
this.onClick(() => {}) // by registering a click, the click event is consumed and doesn't bubble furter to other elements, e.g. checkboxes
|
this.onClick(() => {}) // by registering a click, the click event is consumed and doesn't bubble furter to other elements, e.g. checkboxes
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetValue(): UIEventSource<T> {
|
GetValue(): UIEventSource<T> {
|
||||||
|
@ -57,13 +59,13 @@ export class DropDown<T> extends InputElement<T> {
|
||||||
for (let i = 0; i < this._values.length; i++) {
|
for (let i = 0; i < this._values.length; i++) {
|
||||||
options += "<option value='" + i + "'>" + this._values[i].shown.InnerRender() + "</option>"
|
options += "<option value='" + i + "'>" + this._values[i].shown.InnerRender() + "</option>"
|
||||||
}
|
}
|
||||||
return "<form>" +
|
|
||||||
"<label for='dropdown-" + this.id + "'>" + this._label.Render() + " </label>" +
|
|
||||||
"<select name='dropdown-" + this.id + "' id='dropdown-" + this.id + "'>" +
|
|
||||||
|
|
||||||
|
return `<form>` +
|
||||||
|
`<label class='${this._label_class}' for='dropdown-${this.id}'>${this._label.Render()}</label>` +
|
||||||
|
`<select class='${this._select_class}' name='dropdown-${this.id}' id='dropdown-${this.id}'>` +
|
||||||
options +
|
options +
|
||||||
"</select>" +
|
`</select>` +
|
||||||
"</form>";
|
`</form>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InnerUpdate(element) {
|
protected InnerUpdate(element) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default class LanguagePicker {
|
||||||
return new DropDown(label, languages.map(lang => {
|
return new DropDown(label, languages.map(lang => {
|
||||||
return {value: lang, shown: lang}
|
return {value: lang, shown: lang}
|
||||||
}
|
}
|
||||||
), Locale.language);
|
), Locale.language, 'sr-only', 'bg-indigo-100 p-1 rounded hover:bg-indigo-200');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue