UNPKG

@servicenow/behavior-rtl

Version:

Now Design System rtl helper

39 lines (37 loc) 1.13 kB
const BEHAVIOR_NAME = 'rtl'; /** * This behavior helps style Now Design System components in right-to-left (RTL) layouts. * It sets the component host's `dir` attribute based on the `document.dir` of * its parent application. If `document.dir` is not explicitly defined, it will * set the component host's `dir` attribute to `'ltr'` by default. * * After installation import the behavior at the top of your component JS file * and register it in your component behaviors list: * * ```js * import rtlBehavior from '@servicenow/behavior-rtl'; * * createCustomElement('sn-example', { * // ... * behaviors: [{behavior: rtlBehavior}] * }); * ``` * * For more information about styling RTL components, see the * [Design System internationalization guide](https://emotive.servicenow.com/develop/resources/i18n). * * @seismicBehavior rtlBehavior * @summary Sets the component host's `dir` attribute to support right-to-left layouts */ export default { name: BEHAVIOR_NAME, properties: { dir: { get default() { return document.dir || 'ltr'; }, reflect: true, schema: {type: 'string'} } } };