@umber-style/rtl 0.10.1 → 0.11.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,16 +1,170 @@
|
|
|
1
1
|
# @umber-style/rtl
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- gen:readme description start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The plugin of the UmberStyle default style that writes both directions of a style in one class: each declaration that has a side under :dir(ltr) as written and under :dir(rtl) flipped.
|
|
6
|
+
|
|
7
|
+
<!-- gen:readme end -->
|
|
8
|
+
|
|
9
|
+
One class holds both directions, so a server render sends the same CSS for a right-to-left page as for a left-to-right one, and switching the direction is an attribute change: no render, no new class.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
<!-- gen:readme install start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm add @umber-style/rtl
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
<!-- gen:readme end -->
|
|
20
|
+
|
|
21
|
+
It depends on `@umber-style/core` only and knows no framework; `Direction` is in the bindings.
|
|
22
|
+
|
|
23
|
+
## React
|
|
24
|
+
|
|
25
|
+
`rtl()` goes in `configure`; `dir()` gives a property a value of its own for each direction; `Direction` keeps an area in one direction. See [right-to-left.md](https://github.com/soroush-tech/umber-style/blob/main/docs/right-to-left.md#one-configure-both-directions).
|
|
26
|
+
|
|
27
|
+
<!-- gen:readme example rtl.react.test.tsx start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { configure, Direction, styled } from '@umber-style/react'
|
|
31
|
+
import { dir, rtl } from '@umber-style/rtl'
|
|
32
|
+
import { renderToString } from 'react-dom/server'
|
|
33
|
+
|
|
34
|
+
configure({ prefix: 'app', plugins: [rtl()] })
|
|
35
|
+
|
|
36
|
+
const Item = styled('li', { name: 'Item' })({
|
|
37
|
+
marginLeft: 8,
|
|
38
|
+
textAlign: 'left',
|
|
39
|
+
color: 'teal',
|
|
40
|
+
marginTop: dir({ ltr: 2, rtl: 4 }),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
function List() {
|
|
44
|
+
return (
|
|
45
|
+
<ul>
|
|
46
|
+
<Item>One</Item>
|
|
47
|
+
<Direction dir="ltr">
|
|
48
|
+
<Item>Two</Item>
|
|
49
|
+
</Direction>
|
|
50
|
+
</ul>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Both items have one class, which holds both directions.
|
|
55
|
+
const html = renderToString(<List />)
|
|
56
|
+
const expectedClass = 'app-item-root-1wrr0da'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
From the passing test [`rtl.react.test.tsx`](https://github.com/soroush-tech/umber-style/blob/main/packages/umber-style/readme-examples/rtl.react.test.tsx).
|
|
60
|
+
|
|
61
|
+
<!-- gen:readme end -->
|
|
62
|
+
|
|
63
|
+
## Vue
|
|
64
|
+
|
|
65
|
+
The same plugin, with `Direction` of `@umber-style/vue`. See [right-to-left.md](https://github.com/soroush-tech/umber-style/blob/main/docs/right-to-left.md#one-configure-both-directions).
|
|
66
|
+
|
|
67
|
+
<!-- gen:readme example rtl.vue.test.ts start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
6
68
|
|
|
7
69
|
```ts
|
|
8
|
-
import { configure } from '@umber-style/
|
|
9
|
-
import { rtl } from '@umber-style/rtl'
|
|
70
|
+
import { configure, Direction, styled } from '@umber-style/vue'
|
|
71
|
+
import { dir, rtl } from '@umber-style/rtl'
|
|
72
|
+
import { createSSRApp, h } from 'vue'
|
|
73
|
+
import { renderToString } from 'vue/server-renderer'
|
|
74
|
+
|
|
75
|
+
configure({ prefix: 'app', plugins: [rtl()] })
|
|
76
|
+
|
|
77
|
+
const Item = styled('li', { name: 'Item' })({
|
|
78
|
+
marginLeft: 8,
|
|
79
|
+
textAlign: 'left',
|
|
80
|
+
marginTop: dir({ ltr: 2, rtl: 4 }),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const app = createSSRApp({
|
|
84
|
+
render: () =>
|
|
85
|
+
h('ul', [h(Item, () => 'One'), h(Direction, { dir: 'ltr' }, () => h(Item, () => 'Two'))]),
|
|
86
|
+
})
|
|
87
|
+
const html = await renderToString(app)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
From the passing test [`rtl.vue.test.ts`](https://github.com/soroush-tech/umber-style/blob/main/packages/umber-style/readme-examples/rtl.vue.test.ts).
|
|
91
|
+
|
|
92
|
+
<!-- gen:readme end -->
|
|
93
|
+
|
|
94
|
+
## React Native
|
|
95
|
+
|
|
96
|
+
React Native has no CSS and the platform mirrors layout itself: the plugin flips what it does not mirror. See [right-to-left.md](https://github.com/soroush-tech/umber-style/blob/main/docs/right-to-left.md#react-native).
|
|
97
|
+
|
|
98
|
+
<!-- gen:readme example rtl.react-native.test.tsx start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { configure, Direction, styled } from '@umber-style/react-native'
|
|
102
|
+
import { dir, rtl } from '@umber-style/rtl'
|
|
103
|
+
import { View } from 'react-native'
|
|
10
104
|
|
|
11
105
|
configure({ plugins: [rtl()] })
|
|
106
|
+
|
|
107
|
+
const Box = styled(View, { name: 'Box' })({
|
|
108
|
+
marginLeft: 4,
|
|
109
|
+
transform: [{ translateX: 8 }],
|
|
110
|
+
marginTop: dir({ ltr: 2, rtl: 4 }),
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
export function Screen() {
|
|
114
|
+
return (
|
|
115
|
+
<Direction dir="rtl">
|
|
116
|
+
<Box />
|
|
117
|
+
<Direction dir="ltr">
|
|
118
|
+
<Box />
|
|
119
|
+
</Direction>
|
|
120
|
+
</Direction>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// In the right-to-left area the translation is flipped; the platform mirrors the margin itself.
|
|
125
|
+
const expected = [
|
|
126
|
+
{ marginLeft: 4, transform: [{ translateX: -8 }], marginTop: 4 },
|
|
127
|
+
{ marginLeft: 4, transform: [{ translateX: 8 }], marginTop: 2 },
|
|
128
|
+
]
|
|
12
129
|
```
|
|
13
130
|
|
|
14
|
-
|
|
131
|
+
From the passing test [`rtl.react-native.test.tsx`](https://github.com/soroush-tech/umber-style/blob/main/packages/umber-style/readme-examples/rtl.react-native.test.tsx).
|
|
132
|
+
|
|
133
|
+
<!-- gen:readme end -->
|
|
134
|
+
|
|
135
|
+
## API at a glance
|
|
136
|
+
|
|
137
|
+
<!-- gen:readme docs right-to-left.md#region:rtl-api start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
138
|
+
|
|
139
|
+
| Export | What it is |
|
|
140
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| `rtl(options?)` | The plugin of `configure({ plugins })`, one object for every binding: each declaration that has a side is written under `:dir(ltr)` as it is and under `:dir(rtl)` flipped. `options` are the switches that turn each kind of flip off |
|
|
142
|
+
| `dir({ ltr, rtl })` | A value of its own for each direction, written as given and never flipped; the plugin reads it |
|
|
143
|
+
| `RtlOptions`, `DirValues` | The types of the options of `rtl()` and of the argument of `dir()` |
|
|
144
|
+
| `Direction` | Not in this package: `@umber-style/react`, `@umber-style/vue` and `@umber-style/react-native` export it |
|
|
145
|
+
|
|
146
|
+
<!-- gen:readme end -->
|
|
147
|
+
|
|
148
|
+
## Limits
|
|
149
|
+
|
|
150
|
+
<!-- gen:readme docs right-to-left.md#region:rtl-limits start - regenerated by `pnpm gen:readmes`; do not edit by hand -->
|
|
151
|
+
|
|
152
|
+
- `:dir()` is supported in every major browser from late 2023 (no version was checked here: see [Browser support](https://github.com/soroush-tech/umber-style/blob/main/docs/browser-support.md)). An older browser gets the left-to-right layout through the fallback, whatever `dir` says. A browser that knows neither `:dir()` nor `@supports selector()` gets neither the rules of a direction nor the fallback: no declaration with a side applies there.
|
|
153
|
+
- One extra rule for each class that has a declaration with a side, and one for its fallback: a class with such declarations is four rules where it was one.
|
|
154
|
+
- A declaration with a side has the specificity of two classes (`.class:dir(rtl)`): against a rule of your own CSS with the specificity of one class, in the same cascade layer, it wins where the plain declaration would have lost. The layers of the engine (`app-components`, `app-overrides`) order the engine's own classes as before.
|
|
155
|
+
|
|
156
|
+
<!-- gen:readme end -->
|
|
157
|
+
|
|
158
|
+
The full list is in [Limits](https://github.com/soroush-tech/umber-style/blob/main/docs/right-to-left.md#limits).
|
|
159
|
+
|
|
160
|
+
## Documentation
|
|
161
|
+
|
|
162
|
+
- [Right to left](https://github.com/soroush-tech/umber-style/blob/main/docs/right-to-left.md)
|
|
163
|
+
- [React](https://github.com/soroush-tech/umber-style/blob/main/docs/react.md)
|
|
164
|
+
- [Vue](https://github.com/soroush-tech/umber-style/blob/main/docs/vue.md)
|
|
165
|
+
- [React Native](https://github.com/soroush-tech/umber-style/blob/main/docs/react-native.md)
|
|
166
|
+
- [All the documentation](https://github.com/soroush-tech/umber-style/blob/main/docs/README.md)
|
|
167
|
+
|
|
168
|
+
## License
|
|
15
169
|
|
|
16
|
-
|
|
170
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umber-style/rtl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-alpha.0",
|
|
4
4
|
"description": "The plugin of the UmberStyle default style that writes both directions of a style in one class: each declaration that has a side under :dir(ltr) as written and under :dir(rtl) flipped.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"styling",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "Masoud Soroush <masoud@soroush.tech>",
|
|
15
|
-
"homepage": "https://umber-style.
|
|
15
|
+
"homepage": "https://github.com/soroush-tech/umber-style/blob/main/docs/README.md",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/soroush-tech/umber-style.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@umber-style/core": "
|
|
45
|
+
"@umber-style/core": "0.11.0-alpha.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^26.6.6",
|