Skip to content

Commit

Permalink
feat(rtl-option): replace dir attribute with styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisha0 committed Dec 25, 2021
1 parent 4c9a2d5 commit 53f915f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/core/base/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class UIPRoot extends ESLBaseElement {
* Attribute for controlling preview's content direction.
* Has two values: `LTR` and `RTL`.
*/
@attr({defaultValue: 'LTR'}) public direction: string;
@attr({defaultValue: 'ltr'}) public direction: string;

/**
* Attribute for setup media query rules
Expand Down
23 changes: 0 additions & 23 deletions src/core/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,15 @@ import {UIPPlugin} from '../base/plugin';
export class UIPPreview extends UIPPlugin {
static is = 'uip-preview';

protected connectedCallback() {
super.connectedCallback();
if (this.root) this.$inner.dir = this.root.direction;

this.bindEvents();
}

@bind
protected _onRootStateChange(): void {
if (this.$inner.parentElement === this) this.removeChild(this.$inner);
this.$inner.innerHTML = this.model!.html;
this.appendChild(this.$inner);
}

protected bindEvents() {
this.root?.addEventListener('uip:configchange', this._onRootConfigChange);
}

protected unbindEvents() {
this.root?.removeEventListener('uip:configchange', this._onRootConfigChange);
}

/** Callback to catch direction changes from {@link UIPRoot}. */
@bind
protected _onRootConfigChange(e: CustomEvent) {
if (e.detail.attribute !== 'direction') return false;
this.$inner.dir = e.detail.value;
}

protected disconnectedCallback() {
if (this.$inner.parentElement === this) this.removeChild(this.$inner);
this.unbindEvents();
super.disconnectedCallback();
}
}
4 changes: 2 additions & 2 deletions src/plugins/options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Extends [UIPPlugin](src/core/base/README.md#uip-plugin).

- **Theme** can be *light* (default) and *dark*. It sets color theme for other elements.
- **Mode** can be *vertical* (default) and *horizontal*. It controls UIP container's layout.
- **Direction** can be *LTR* (default) and *RTL*. It changes the direction of preview's content.
- **Direction** can be *ltr* (default) and *rtl*. It changes the direction of preview's content.

These options can be manually set (and observed) with corresponding attributes:

```html
<uip-root mode="horizontal" theme="dark" direction="RTL"></uip-root>
<uip-root mode="horizontal" theme="dark" direction="rtl"></uip-root>
```

**UIPOptions** element doesn't produce or observe UIPStateModel changes.
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/options/option/direction.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.uip-root {
&.rtl-direction {
& > .uip-preview {
direction: rtl;
}
}

&.ltr-direction {
& > .uip-preview {
direction: ltr;
}
}
}
1 change: 1 addition & 0 deletions src/plugins/options/options.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./option/mode";
@import "./option/theme";
@import "./option/direction";

.uip-options {
display: flex;
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ export class UIPOptions extends UIPPlugin {
const dirOptionId = randUID();
$dir.innerHTML = `
<div class="option-item">
<input type="radio" id=${dirOptionId}-uip-ltr name=${dirOptionId}-dir direction="LTR"
class="option-radio-btn" ${this.root?.direction === 'LTR' ? 'checked' : ''}>
<input type="radio" id=${dirOptionId}-uip-ltr name=${dirOptionId}-dir direction="ltr"
class="option-radio-btn" ${this.root?.direction === 'ltr' ? 'checked' : ''}>
<label class="option-label" for=${dirOptionId}-uip-ltr>LTR</label>
</div>
<div class="option-item">
<input type="radio" id=${dirOptionId}-uip-rtl name=${dirOptionId}-dir direction="RTL"
class="option-radio-btn" ${this.root?.direction === 'RTL' ? 'checked' : ''}>
<input type="radio" id=${dirOptionId}-uip-rtl name=${dirOptionId}-dir direction="rtl"
class="option-radio-btn" ${this.root?.direction === 'rtl' ? 'checked' : ''}>
<label class="option-label" for=${dirOptionId}-uip-rtl>RTL</label>
</div>`;
this.appendChild($dir);
Expand Down

0 comments on commit 53f915f

Please # to comment.