source: imaps-frontend/node_modules/rtl-css-js/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 12.5 KB
RevLine 
[d565449]1# rtl-css-js
2
3RTL conversion for CSS in JS objects
4
5<!-- prettier-ignore-start -->
6[![Build Status][build-badge]][build]
7[![Code Coverage][coverage-badge]][coverage]
8[![version][version-badge]][package]
9[![downloads][downloads-badge]][npmtrends]
10[![MIT License][license-badge]][license]
11[![All Contributors][all-contributors-badge]](#contributors-)
12[![PRs Welcome][prs-badge]][prs]
13[![Code of Conduct][coc-badge]][coc]
14<!-- prettier-ignore-end -->
15
16## The problem
17
18For some locales, it's necessary to change `padding-left` to `padding-right`
19when your text direction is right to left. There are tools like this for CSS
20([`cssjanus`](https://github.com/cssjanus/cssjanus) for example) which
21manipulate strings of CSS to do this, but none for CSS in JS where your CSS is
22represented by an object.
23
24## This solution
25
26This is a function which accepts a CSS in JS object and can convert
27`padding-left` to `padding-right` as well as all other properties where it makes
28sense to do that (at least, that's what it's going to be when it's done... This
29is a work in progress).
30
31## Table of Contentss
32
33<!-- START doctoc generated TOC please keep comment here to allow auto update -->
34<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
35
36- [Installation](#installation)
37- [Usage](#usage)
38 - [kebab-case](#kebab-case)
39 - [core](#core)
40- [Caveats](#caveats)
41 - [`background`](#background)
42 - [CSS variables - `var()`](#css-variables---var)
43- [Inspiration](#inspiration)
44- [Ecosystem](#ecosystem)
45- [Other Solutions](#other-solutions)
46- [Contributors](#contributors)
47- [LICENSE](#license)
48
49<!-- END doctoc generated TOC please keep comment here to allow auto update -->
50
51## Installation
52
53This module is distributed via [npm][npm] which is bundled with [node][node] and
54should be installed as one of your project's `dependencies`:
55
56```
57npm install --save rtl-css-js
58```
59
60## Usage
61
62This module is exposed via [CommonJS](http://wiki.commonjs.org/wiki/CommonJS) as
63well as [UMD](https://github.com/umdjs/umd) with the global as `rtlCSSJS`
64
65CommonJS:
66
67```javascript
68const rtlCSSJS = require('rtl-css-js')
69const styles = rtlCSSJS({paddingLeft: 23})
70console.log(styles) // logs {paddingRight: 23}
71```
72
73You can also just include a script tag in your browser and use the `rtlCSSJS`
74variable:
75
76```html
77<script src="https://unpkg.com/rtl-css-js"></script>
78<script>
79 const styles = rtlCSSJS({paddingRight: 23})
80 console.log(styles) // logs {paddingLeft: 23}
81</script>
82```
83
84You can also control which rules you don't want to flip by adding a
85`/* @noflip */` CSS comment to your rule
86
87```javascript
88const rtlCSSJS = require('rtl-css-js')
89const styles = rtlCSSJS({paddingLeft: '20px /* @noflip */'})
90console.log(styles) // logs {paddingLeft: '20px /* @noflip */' }
91```
92
93### kebab-case
94
95This library support kebab-case properties too.
96
97```javascript
98const rtlCSSJS = require('rtl-css-js')
99const styles = rtlCSSJS({'padding-right': 23})
100console.log(styles) // logs {'padding-left': 23}
101```
102
103### core
104
105`rtl-css-js` also exposes its internal helpers and utilities so you can deal
106with [certain scenarios](https://github.com/kentcdodds/rtl-css-js/pull/22)
107yourself. To use these you can use the `rtlCSSJSCore` global with the UMD build,
108`require('rtl-css-js/core')`, or use
109`import {propertyValueConverters, arrayToObject} from 'rtl-css-js/core'`.
110
111You can import anything that's exported from `src/core`. Please see the code
112comments for documentation on how to use these.
113
114## Caveats
115
116### `background`
117
118Right now `background` and `backgroundImage` just replace all instances of `ltr`
119with `rtl` and `right` with `left`. This is so you can have a different image
120for your LTR and RTL, and in order to flip linear gradients. Note that this is
121case sensitive! Must be lower case. Note also that it _will not_ change `bright`
122to `bleft`. It's a _little_ smarter than that. But this is definitely something
123to consider with your URLs.
124
125### CSS variables - `var()`
126
127Since it's impossible to know what the contents of a css variable are until the
128styles are actually calculated by the browser, any CSS variable contents will
129not be converted.
130
131## Inspiration
132
133[CSSJanus](https://github.com/cssjanus/cssjanus) was a major inspiration.
134
135## Ecosystem
136
137- **[react-with-styles-interface-aphrodite](https://github.com/airbnb/react-with-styles-interface-aphrodite):**
138 An interface to use
139 [`react-with-styles`](https://github.com/airbnb/react-with-styles) with
140 [Aphrodite](https://github.com/khan/aphrodite)
141- **[fela-plugin-rtl](https://www.npmjs.com/package/fela-plugin-rtl):** A plugin
142 for [fela](http://fela.js.org/) that uses rtl-css-js to convert a style object
143 to its right-to-left counterpart
144- **[bidi-css-js](https://github.com/TxHawks/bidi-css-js):** A library for
145 authoring flow-relative css, which uses `rtl-css-js`'s core.
146- **[jss-rtl](https://github.com/alitaheri/jss-rtl):** A plugin for
147 [`jss`](https://github.com/cssinjs/jss) to support flipping styles
148 dynamically.
149
150## Other Solutions
151
152I'm not aware of any, if you are please
153[make a pull request](http://makeapullrequest.com) and add it here!
154
155## Contributors
156
157Thanks goes to these people ([emoji key][emojis]):
158
159<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
160<!-- prettier-ignore-start -->
161<!-- markdownlint-disable -->
162<table>
163 <tr>
164 <td align="center"><a href="https://kentcdodds.com"><img src="https://avatars.githubusercontent.com/u/1500684?v=3?s=100" width="100px;" alt=""/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=kentcdodds" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=kentcdodds" title="Tests">⚠️</a> <a href="#infra-kentcdodds" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
165 <td align="center"><a href="https://gabri.me"><img src="https://avatars.githubusercontent.com/u/63876?v=3?s=100" width="100px;" alt=""/><br /><sub><b>Ahmed El Gabri</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=ahmedelgabri" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=ahmedelgabri" title="Documentation">📖</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=ahmedelgabri" title="Tests">⚠️</a></td>
166 <td align="center"><a href="https://github.com/majapw"><img src="https://avatars1.githubusercontent.com/u/1383861?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maja Wichrowska</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=majapw" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=majapw" title="Tests">⚠️</a></td>
167 <td align="center"><a href="https://github.com/yzimet"><img src="https://avatars2.githubusercontent.com/u/6600720?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yaniv</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=yzimet" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=yzimet" title="Tests">⚠️</a></td>
168 <td align="center"><a href="https://github.com/TxHawks"><img src="https://avatars2.githubusercontent.com/u/5658514?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan Pollak</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=TxHawks" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=TxHawks" title="Tests">⚠️</a></td>
169 <td align="center"><a href="https://github.com/alitaheri"><img src="https://avatars1.githubusercontent.com/u/8528759?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ali Taheri Moghaddar</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=alitaheri" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=alitaheri" title="Documentation">📖</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=alitaheri" title="Tests">⚠️</a></td>
170 <td align="center"><a href="https://github.com/garrettberg"><img src="https://avatars0.githubusercontent.com/u/844459?v=4?s=100" width="100px;" alt=""/><br /><sub><b>garrettberg</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=garrettberg" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=garrettberg" title="Tests">⚠️</a></td>
171 </tr>
172 <tr>
173 <td align="center"><a href="http://milesj.me"><img src="https://avatars2.githubusercontent.com/u/143744?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Miles Johnson</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=milesj" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=milesj" title="Tests">⚠️</a></td>
174 <td align="center"><a href="https://www.kweber.com"><img src="https://avatars1.githubusercontent.com/u/2785791?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kevin Weber</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=kevinweber" title="Code">💻</a></td>
175 <td align="center"><a href="https://stackshare.io/jdorfman/decisions"><img src="https://avatars1.githubusercontent.com/u/398230?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Justin Dorfman</b></sub></a><br /><a href="#fundingFinding-jdorfman" title="Funding Finding">🔍</a></td>
176 <td align="center"><a href="https://github.com/RoystonS"><img src="https://avatars0.githubusercontent.com/u/19773?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Royston Shufflebotham</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/issues?q=author%3ARoystonS" title="Bug reports">🐛</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=RoystonS" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=RoystonS" title="Tests">⚠️</a></td>
177 <td align="center"><a href="https://twitter.com/layershifter"><img src="https://avatars.githubusercontent.com/u/14183168?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Oleksandr Fediashov</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=layershifter" title="Code">💻</a></td>
178 <td align="center"><a href="https://github.com/ling1726"><img src="https://avatars.githubusercontent.com/u/20744592?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lingfan Gao</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=ling1726" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=ling1726" title="Tests">⚠️</a></td>
179 <td align="center"><a href="https://github.com/miroslavstastny"><img src="https://avatars.githubusercontent.com/u/9615899?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Miroslav Stastny</b></sub></a><br /><a href="https://github.com/kentcdodds/rtl-css-js/commits?author=miroslavstastny" title="Code">💻</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=miroslavstastny" title="Documentation">📖</a> <a href="https://github.com/kentcdodds/rtl-css-js/commits?author=miroslavstastny" title="Tests">⚠️</a></td>
180 </tr>
181</table>
182
183<!-- markdownlint-restore -->
184<!-- prettier-ignore-end -->
185
186<!-- ALL-CONTRIBUTORS-LIST:END -->
187
188This project follows the [all-contributors][all-contributors] specification.
189Contributions of any kind welcome!
190
191## LICENSE
192
193MIT
194
195<!-- prettier-ignore-start -->
196[npm]: https://www.npmjs.com/
197[node]: https://nodejs.org
198[build-badge]: https://img.shields.io/github/workflow/status/kentcdodds/rtl-css-js/validate?logo=github&style=flat-square
199[build]: https://github.com/kentcdodds/rtl-css-js/actions?query=workflow%3Avalidate
200[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/rtl-css-js.svg?style=flat-square
201[coverage]: https://codecov.io/github/kentcdodds/rtl-css-js
202[version-badge]: https://img.shields.io/npm/v/rtl-css-js.svg?style=flat-square
203[package]: https://www.npmjs.com/package/rtl-css-js
204[downloads-badge]: https://img.shields.io/npm/dm/mdx-bundler.svg?style=flat-square
205[npmtrends]: https://www.npmtrends.com/mdx-bundler
206[license-badge]: https://img.shields.io/npm/l/rtl-css-js.svg?style=flat-square
207[license]: https://github.com/kentcdodds/rtl-css-js/blob/main/other/LICENSE
208[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
209[prs]: http://makeapullrequest.com
210[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
211[coc]: https://github.com/kentcdodds/rtl-css-js/blob/main/other/CODE_OF_CONDUCT.md
212[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
213[all-contributors]: https://github.com/kentcdodds/all-contributors
214<!-- prettier-ignore-end -->
Note: See TracBrowser for help on using the repository browser.