0.3.0 • Published 5 years ago

jss-rtl v0.3.0

Weekly downloads
59,217
License
MIT
Repository
github
Last release
5 years ago

RTL Support for jss

This plugin enables right-to-left support by flipping every rule on the x-axis. Internally, it's wrapping rtl-css-js.

You can write your application left-to-right and then turn it into right-to-left using this plugin. Or you can start right-to-left and turn it into left-to-right.

Make sure you read how to use plugins in general.

Important Notice: This plugin must come last in the plugin array since it can only transforms raw styles.

Installation

You can install this package with the following command:

npm install jss-rtl

Examples

These examples will give you a brief overview of how this library is used:

Simple Usage

You can use jss.use(...) to augment the global jss instance.

import jss from 'jss';
import rtl from 'jss-rtl';

jss.use(rtl());

const styles = {
  foo: {
    'padding-left': '2px',
    'margin-right': '2px',
  },
  bar: {
    'transform': 'translate3d(30%, 20%, 10%)',
  },
  baz: {
    flip: false, // opt-out of conversion for a specific rule-set
    'margin-right': '1px',
  },
};

jss.createStyleSheet(styles); /* =>
.foo-0-0 {
  padding-right: 2px;
  margin-left: 2px;
}
.bar-0-1 {
  transform: translate3d(-30%, 20%, 10%);
}
.baz-0-2 {
  margin-right: 1px;
}
*/

Or you can use the jss-preset-default library and append this one to the end.

import { create } from 'jss';
import preset from 'jss-preset-default';
import rtl from 'jss-rtl';

const presets = preset().plugins;

const jss = create({ plugins: [...presets, rtl()] });

// ...

Opting-out for an entire sheet

You can opt-out for a sheet entirely.

const styles = {
  foo: {
    'padding-left': '2px',
    'margin-right': '2px',
  },
  baz: {
    flip: true, // rules take precedence, this one is forced to flip
    'margin-right': '1px',
  },
};

jss.createStyleSheet(styles, { flip: false }); /* =>
.foo-0-0 {
  padding-left: 2px;
  margin-right: 2px;
}
.baz-0-1 {
  margin-left: 1px;
}
*/

Option enabled

While using this library you might add flip: false or flip: true to some of your rule-sets. It is recommended that you disable this plugin instead of removing it from the plugins array so that it can at least remove the flip props from your rule-sets.

This option is also the best method for switching between rtl and ltr.

jss.use(rtl({ enabled: false }));

const styles = {
  foo: {
    'padding-left': '2px',
    'margin-right': '2px',
  },
  baz: {
    flip: true, // This gets overruled by enable: false, and gets removed from the rule-set
    'margin-right': '1px',
  },
};

// Doesn't matter, rtl is disabled entirely
jss.createStyleSheet(styles, { flip: true }); /* =>
.foo-0-0 {
  padding-left: 2px;
  margin-right: 2px;
}
.baz-0-1 {
  margin-right: 1px;
}
*/

Option opt

It's also possible to change the default behavior to opt-in.

jss.use(rtl({ opt: 'in' }));

const styles = {
  foo: { // This is ignored by the plugin
    'padding-left': '2px',
    'margin-right': '2px',
  },
  baz: {
    flip: true, // This gets flipped
    'margin-right': '1px',
  },
};

jss.createStyleSheet(styles); /* =>
.foo-0-0 {
  padding-left: 2px;
  margin-right: 2px;
}
.baz-0-1 {
  margin-left: 1px;
}
*/

// Or opt-in an entire sheet

const styles = {
  foo: {
    'padding-left': '2px',
    'margin-right': '2px',
  },
  baz: {
    'margin-right': '1px',
  },
};

jss.createStyleSheet(styles, { flip: true }); /* =>
.foo-0-0 {
  padding-right: 2px;
  margin-left: 2px;
}
.baz-0-1 {
  margin-left: 1px;
}
*/

Typings

The typescript type definitions are also available and are installed via npm.

License

This project is licensed under the MIT license.

tarnet-jumbo-react@smileit/react-smilemirador-biblissimamuithemeselectorchinese-mirador@cloudhub-ux/coreshop-panel@everything-registry/sub-chunk-1990production-websmartech-supportstonex-uirain-tech-design-systemradman-kitreact-codeartreact-yumreactjs-uploaderred-quick-templatetarnet-uitamu-miradoreureka-webcomponentsfarapod-course-productionfarapod-course-sandboxform007fuse-react-appfinno-uifinal-radman-kitfinal-radman-kit-maryfinal-radman-kittmongezm6azeez-react-componentsmui-reusemy_module222macoolka-ui-appgoals-goolahasanadehcoursejelly-smart-crudgatsby-docs-uijumbo-reactcra-template-typescript-redux-redquick@hilma/licenses-admincra-template-red-quick@hxsllc/mirador@hxsllc/mirador-react17common-frontend-componentsbooking-systemwebstudio-appbusiness-card-viewer--stagingdandelion_prodashboardvisualizationdeveloper_portaldeveloper_portal01-pratham@infinitebrahmanuniverse/nolb-jssbrandshield-commoncloudhub-mincloudhubuicloudhubui-mincloudhub-components@plurall-boss/components@openemp/styleguide@mephistowa/cra-template-typescript-redux-red-quick@mathewjordan/mirador-garb@mehdi9795/foo@lincolnteste/components@nazmul_mpower/dashboardvisualization@nakamura196/mirador@m00n/gatsby-docs-ui@m00n/gatsby-starter-docs-material-ui@regang/mirador@zalastax/nolb-jssamllaak-data-modelsamllaak-shared@europeana/mirador@eureka-ds/theme@thegreenwoodapps/sms-suite-number-capture@test88282/buttonakhpck@backlight-dev/various-trouble-hjmth.bricks-l6ngliw7-fork-lgq24azv@backlight-dev/various-trouble-hjmth.bricks-lgq27cpj@backlight-dev/veil-steal-hej64.bricks-l7gtkkiy@backlight-dev/soap-distribute-dux20.rjid@backlight-dev/setbrain.ink-forego-vnavb.bricks-l5gkcnmk@backlight-dev/sillyleo.bricks-lccvkr2p@avangard/ui@backlight-dev/another-one.bricks-2htydw13pkxg0gsvc@backlight-dev/power-drive-tgm7r.bricks-lo057i5n@backlight-dev/hdn-test.hdn-bricks@backlight-dev/human-apple-pfrt9.bricks-l0gqrlz3@backlight-dev/icky-boys-h9rid.bricks-lglce3zu@backlight-dev/cent-undress-o9ffc.bricks-l6ngliw7@backlight-dev/rapid-sweater-1n8dt.bricks-l3yzvl9g@bluebase/plugin-material-uiberry-free-react-material-admin-templateberry-material-react-free
0.3.0

5 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago