` element with a `dir` attribute set to match the `direction` prop, for example: `
`. This maintains consistency when being rendered in a browser. To render inside of a `
` instead of a div, set the `inline` prop to `true`.
51 |
52 | Usage example:
53 |
54 | ```js
55 | import DirectionProvider, { DIRECTIONS } from 'react-with-direction/dist/DirectionProvider';
56 | ```
57 |
58 | ```jsx
59 |
60 |
61 |
62 |
63 |
64 | ```
65 |
66 | To set the `lang` attribute on the wrapping element, provide the `lang` prop to `DirectionProvider`.
67 |
68 | Usage example:
69 |
70 | ```jsx
71 | import DirectionProvider, { DIRECTIONS } from 'react-with-direction/dist/DirectionProvider';
72 |
73 |
74 |
75 |
76 |
77 |
78 | ```
79 |
80 | Note that `lang` and `direction` are independent – `lang` only sets the attribute on the wrapping element.
81 |
82 | ## AutoDirectionProvider
83 |
84 | Use `AutoDirectionProvider` around, for example, user-generated content where the text direction is unknown or may change. This renders a `DirectionProvider` with the `direction` prop automatically set based on the `text` prop provided.
85 |
86 | Direction will be determined based on the first strong LTR/RTL character in the `text` string. Strings with no strong direction (e.g., numbers) will inherit the direction from its nearest `DirectionProvider` ancestor or default to LTR.
87 |
88 | Usage example:
89 |
90 | ```js
91 | import AutoDirectionProvider from 'react-with-direction/dist/AutoDirectionProvider';
92 | ```
93 |
94 | ```js
95 |
96 |
97 | {userGeneratedContent}
98 |
99 |
100 | ```
101 |
102 | `AutoDirectionProvider` also supports the `lang` prop in the same way as `DirectionProvider` does.
103 |
104 | [package-url]: https://npmjs.org/package/react-with-direction
105 | [npm-version-svg]: http://versionbadg.es/airbnb/react-with-direction.svg
106 | [travis-svg]: https://travis-ci.org/airbnb/react-with-direction.svg
107 | [travis-url]: https://travis-ci.org/airbnb/react-with-direction
108 | [deps-svg]: https://david-dm.org/airbnb/react-with-direction.svg
109 | [deps-url]: https://david-dm.org/airbnb/react-with-direction
110 | [dev-deps-svg]: https://david-dm.org/airbnb/react-with-direction/dev-status.svg
111 | [dev-deps-url]: https://david-dm.org/airbnb/react-with-direction#info=devDependencies
112 | [npm-badge-png]: https://nodei.co/npm/react-with-direction.png?downloads=true&stars=true
113 | [license-image]: http://img.shields.io/npm/l/react-with-direction.svg
114 | [license-url]: LICENSE
115 | [downloads-image]: http://img.shields.io/npm/dm/react-with-direction.svg
116 | [downloads-url]: http://npm-stat.com/charts.html?package=react-with-direction
117 |
--------------------------------------------------------------------------------