diff --git a/src/core/base/root.ts b/src/core/base/root.ts index 870d4251..febd9d85 100644 --- a/src/core/base/root.ts +++ b/src/core/base/root.ts @@ -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 diff --git a/src/core/preview/preview.ts b/src/core/preview/preview.ts index 9a782046..f054c772 100644 --- a/src/core/preview/preview.ts +++ b/src/core/preview/preview.ts @@ -8,13 +8,6 @@ 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); @@ -22,24 +15,8 @@ export class UIPPreview extends UIPPlugin { 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(); } } diff --git a/src/plugins/options/README.md b/src/plugins/options/README.md index ce1b1a3a..99451d5d 100644 --- a/src/plugins/options/README.md +++ b/src/plugins/options/README.md @@ -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 - + ``` **UIPOptions** element doesn't produce or observe UIPStateModel changes. diff --git a/src/plugins/options/option/direction.less b/src/plugins/options/option/direction.less new file mode 100644 index 00000000..3e6106fd --- /dev/null +++ b/src/plugins/options/option/direction.less @@ -0,0 +1,13 @@ +.uip-root { + &.rtl-direction { + & > .uip-preview { + direction: rtl; + } + } + + &.ltr-direction { + & > .uip-preview { + direction: ltr; + } + } +} diff --git a/src/plugins/options/options.less b/src/plugins/options/options.less index 9661aa1d..0d0f48e0 100644 --- a/src/plugins/options/options.less +++ b/src/plugins/options/options.less @@ -1,5 +1,6 @@ @import "./option/mode"; @import "./option/theme"; +@import "./option/direction"; .uip-options { display: flex; diff --git a/src/plugins/options/options.ts b/src/plugins/options/options.ts index 92ec6c2f..71158054 100644 --- a/src/plugins/options/options.ts +++ b/src/plugins/options/options.ts @@ -81,13 +81,13 @@ export class UIPOptions extends UIPPlugin { const dirOptionId = randUID(); $dir.innerHTML = `
- +
- +
`; this.appendChild($dir);