mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 23:32:44 +08:00
DEV: Clean up d-toggle-switch (#29385)
move the template to the bottom, inline `checked`, remove unnecessary `template-lint-disable`
This commit is contained in:
parent
98a3e7d6e2
commit
ab7547eb7a
|
@ -3,18 +3,23 @@ import icon from "discourse-common/helpers/d-icon";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
export default class DToggleSwitch extends Component {
|
export default class DToggleSwitch extends Component {
|
||||||
|
get computedLabel() {
|
||||||
|
if (this.args.label) {
|
||||||
|
return I18n.t(this.args.label);
|
||||||
|
}
|
||||||
|
return this.args.translatedLabel;
|
||||||
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="d-toggle-switch">
|
<div class="d-toggle-switch">
|
||||||
<label class="d-toggle-switch__label">
|
<label class="d-toggle-switch__label">
|
||||||
{{! template-lint-disable no-redundant-role }}
|
|
||||||
<button
|
<button
|
||||||
class="d-toggle-switch__checkbox"
|
class="d-toggle-switch__checkbox"
|
||||||
type="button"
|
type="button"
|
||||||
role="switch"
|
role="switch"
|
||||||
aria-checked={{this.checked}}
|
aria-checked={{if @state "true" "false"}}
|
||||||
...attributes
|
...attributes
|
||||||
></button>
|
></button>
|
||||||
{{! template-lint-enable no-redundant-role }}
|
|
||||||
|
|
||||||
<span class="d-toggle-switch__checkbox-slider">
|
<span class="d-toggle-switch__checkbox-slider">
|
||||||
{{#if @state}}
|
{{#if @state}}
|
||||||
|
@ -30,15 +35,4 @@ export default class DToggleSwitch extends Component {
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
get computedLabel() {
|
|
||||||
if (this.args.label) {
|
|
||||||
return I18n.t(this.args.label);
|
|
||||||
}
|
|
||||||
return this.args.translatedLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
get checked() {
|
|
||||||
return this.args.state ? "true" : "false";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user