Skip to content

Commit

Permalink
Allow switching ltr/rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Oct 30, 2021
1 parent 684bee6 commit 10bf0bf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ If you want to control more than one entity with the same slider, use [light gro

Available options:

| Option | Values | Description | default |
| ------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `min` | number | Minimum value of slider | |
| `max` | number | Maximum value of slider | |
| `step` | number | Step size of slider selection | |
| `toggle` | `true`/`false` | Show a toggle or mute button if possible | `false` |
| `hide_state` | `true`/`false` | `true`: Do not display the current state <br>`false`: Always display current state - even when the card is too narrow for it to be usable | none |
| `hide_when_off` | `true`/`false` | `true`: Hide slider when state is off <br>`false`: Always display slider | `false` |
| `grow` | `true`/`false` | Make the slider as wide as possible (which is really just a little bit wider) | `false` |
| `full_row` | `true`/`false` | Hide the icon and name and stretch slider to full width | `false` |
| `attribute` | (see below) | Which attribute the slider should control | |
| Option | Values | Description | default |
| --------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `min` | number | Minimum value of slider | |
| `max` | number | Maximum value of slider | |
| `step` | number | Step size of slider selection | |
| `toggle` | `true`/`false` | Show a toggle or mute button if possible | `false` |
| `hide_state` | `true`/`false` | `true`: Do not display the current state <br>`false`: Always display current state - even when the card is too narrow for it to be usable | none |
| `hide_when_off` | `true`/`false` | `true`: Hide slider when state is off <br>`false`: Always display slider | `false` |
| `grow` | `true`/`false` | Make the slider as wide as possible (which is really just a little bit wider) | `false` |
| `full_row` | `true`/`false` | Hide the icon and name and stretch slider to full width | `false` |
| `attribute` | (see below) | Which attribute the slider should control | |
| `dir` | `ltr`/`rtl` | Use this to override your languages Right-To-Left or Left-To-Right setting | language |

Most general Entities row options like `name`, `icon` and `tap_action` et.al. are also supported.

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ControllerConfig {
step?: number;
attribute?: string;
grow?: boolean;
dir?: string;
}

export abstract class Controller {
Expand Down Expand Up @@ -78,4 +79,7 @@ export abstract class Controller {
get step(): number {
return this._config.step ?? this._step ?? 5;
}
get dir(): string {
return this._config.dir ?? undefined;
}
}
17 changes: 9 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class SliderEntityRow extends LitElement {
</hui-warning>
`;

const dir = this.hass.translationMetadata.translations[
this.hass.language || "en"
].isRTL
? "rtl"
: "ltr";
const dir =
c.dir ??
this.hass.translationMetadata.translations[this.hass.language || "en"]
.isRTL
? "rtl"
: "ltr";

const showSlider =
c.stateObj.state !== "unavailable" &&
Expand Down Expand Up @@ -80,9 +81,9 @@ class SliderEntityRow extends LitElement {
.dir=${dir}
pin
@change=${(ev) =>
(c.value = (this.shadowRoot.querySelector(
"ha-slider"
) as any).value)}
(c.value = (
this.shadowRoot.querySelector("ha-slider") as any
).value)}
class=${this._config.full_row || this._config.grow
? "full"
: ""}
Expand Down
14 changes: 14 additions & 0 deletions test/views/2_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,17 @@ cards:
entity: media_player.bedroom
name: media_player
toggle: true

- type: vertical-stack
cards:
- <<: *desc
content: |
## Invert
- type: entities
show_header_toggle: false
entities:
- type: custom:slider-entity-row
entity: light.bed_light
- type: custom:slider-entity-row
entity: light.bed_light
dir: rtl

0 comments on commit 10bf0bf

Please sign in to comment.