react-native-unistyles 1.0.0-beta.3 → 1.0.0-beta.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +342 -35
- package/lib/commonjs/createUnistyles.js +15 -1
- package/lib/commonjs/createUnistyles.js.map +1 -1
- package/lib/commonjs/utils/styles.js +1 -2
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/module/createUnistyles.js +15 -1
- package/lib/module/createUnistyles.js.map +1 -1
- package/lib/module/utils/styles.js +1 -2
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/typescript/src/createUnistyles.d.ts +5 -1
- package/lib/typescript/src/createUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +26 -8
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/createUnistyles.ts +18 -2
- package/src/types.ts +64 -20
- package/src/utils/styles.ts +14 -5
package/README.md
CHANGED
@@ -28,7 +28,6 @@ Suggestions, ideas, and potential improvements are always welcome!
|
|
28
28
|
|
29
29
|
## Setup
|
30
30
|
|
31
|
-
|
32
31
|
**1. Install library**
|
33
32
|
|
34
33
|
```cmd
|
@@ -39,6 +38,26 @@ yarn add react-native-unistyles
|
|
39
38
|
|
40
39
|
You don't have to follow a specific format. Just make an object and add any keys/values you like.
|
41
40
|
|
41
|
+
```ts
|
42
|
+
// theme.ts
|
43
|
+
export const theme = {
|
44
|
+
colors: {
|
45
|
+
blood: '#eb4d4b',
|
46
|
+
barbie: '#e056fd',
|
47
|
+
pumpkin: '#f0932b',
|
48
|
+
background: '#ffffff'
|
49
|
+
},
|
50
|
+
margins: {
|
51
|
+
sm: 2,
|
52
|
+
md: 4,
|
53
|
+
lg: 8,
|
54
|
+
xl: 12
|
55
|
+
}
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
or something more advanced with nested objects / functions:
|
60
|
+
|
42
61
|
```ts
|
43
62
|
// theme.ts
|
44
63
|
export const theme = {
|
@@ -106,7 +125,7 @@ export const App: React.FunctionComponent = () => (
|
|
106
125
|
)
|
107
126
|
```
|
108
127
|
|
109
|
-
**5. Access
|
128
|
+
**5. Access createStyleSheet and useStyles with a factory**
|
110
129
|
|
111
130
|
```ts
|
112
131
|
// styles.ts
|
@@ -119,22 +138,22 @@ import { breakpoints } from './breakpoints'
|
|
119
138
|
import { theme } from './theme'
|
120
139
|
|
121
140
|
export const {
|
122
|
-
|
141
|
+
createStyleSheet,
|
123
142
|
useStyles,
|
124
143
|
} = createUnistyles<typeof breakpoints, typeof theme>(breakpoints)
|
125
144
|
```
|
126
145
|
|
127
146
|
## Basic Usage
|
128
147
|
|
129
|
-
|
130
|
-
- `
|
131
|
-
- `useStyles` which parses your styles
|
148
|
+
After the initial setup, you only need to focus on two functions responsible for your styles:
|
149
|
+
- `createStyleSheet` which replaces `StyleSheet.create`
|
150
|
+
- `useStyles` which parses your styles and ensures TypeScript compatibility with media queries and breakpoints
|
132
151
|
|
133
152
|
```tsx
|
134
153
|
import React from 'react'
|
135
154
|
import { View, Text } from 'react-native'
|
136
|
-
// access
|
137
|
-
import {
|
155
|
+
// access createStyleSheet and useStyles exported from factory
|
156
|
+
import { createStyleSheet, useStyles } from 'lib/styles'
|
138
157
|
|
139
158
|
export const ExampleUnistyles = () => {
|
140
159
|
const { styles } = useStyles(stylesheet)
|
@@ -148,7 +167,7 @@ export const ExampleUnistyles = () => {
|
|
148
167
|
)
|
149
168
|
}
|
150
169
|
|
151
|
-
const stylesheet =
|
170
|
+
const stylesheet = createStyleSheet(theme => ({
|
152
171
|
container: {
|
153
172
|
flex: 1,
|
154
173
|
justifyContent: 'center',
|
@@ -161,24 +180,82 @@ const stylesheet = createStyles(theme => ({
|
|
161
180
|
}))
|
162
181
|
```
|
163
182
|
|
164
|
-
|
183
|
+
## createStyleSheet
|
184
|
+
|
185
|
+
`createStyleSheet` is interchangeable with `StyleSheet.create`. You can use objects, and it will function identically to its React Native counterpart.
|
186
|
+
|
187
|
+
```ts
|
188
|
+
const stylesheet = createStyleSheet({
|
189
|
+
container: {
|
190
|
+
flex: 1,
|
191
|
+
justifyContent: 'center',
|
192
|
+
alignItems: 'center',
|
193
|
+
},
|
194
|
+
})
|
195
|
+
```
|
196
|
+
The difference is that you can now use breakpoints and media queries:
|
197
|
+
|
198
|
+
```ts
|
199
|
+
const stylesheet = createStyleSheet({
|
200
|
+
container: {
|
201
|
+
flex: 1,
|
202
|
+
justifyContent: 'center',
|
203
|
+
alignItems: 'center',
|
204
|
+
flexDirection: {
|
205
|
+
xs: 'row',
|
206
|
+
sm: 'column',
|
207
|
+
':w[800]': 'row'
|
208
|
+
}
|
209
|
+
},
|
210
|
+
})
|
211
|
+
```
|
212
|
+
|
213
|
+
`createStyleSheet` also accepts a function, to which the library will inject your theme:
|
214
|
+
|
215
|
+
```ts
|
216
|
+
const stylesheet = createStyleSheet(theme => ({
|
217
|
+
container: {
|
218
|
+
flex: 1,
|
219
|
+
justifyContent: 'center',
|
220
|
+
alignItems: 'center',
|
221
|
+
flexDirection: {
|
222
|
+
xs: 'row',
|
223
|
+
sm: 'column',
|
224
|
+
':w[800]': 'row'
|
225
|
+
},
|
226
|
+
backgroundColor: theme.colors.background
|
227
|
+
},
|
228
|
+
}))
|
229
|
+
```
|
230
|
+
|
231
|
+
Importantly, you'll receive the same TypeScript hints as with `StyleSheet.create`!
|
165
232
|
|
166
|
-
|
167
|
-
- `styles` - parsed styles that can be used directly in React Native components
|
168
|
-
- `theme` - your app's theme that can be used in JSX
|
233
|
+
## useStyles
|
169
234
|
|
170
|
-
|
235
|
+
`useStyle` ties everything together and handles the heavy lifting. Without `useStyles`, you can't utilize features like:
|
236
|
+
- breakpoints
|
237
|
+
- media queries
|
238
|
+
- themes
|
239
|
+
|
240
|
+
_useStyles_ allows you to skip the `stylesheet` if you only want to access the `theme`:
|
171
241
|
|
172
242
|
```tsx
|
173
243
|
const { theme } = useStyles()
|
174
244
|
```
|
175
245
|
|
246
|
+
For more advanced usage, pass your `stylesheet` generated with `createStyleSheet`:
|
247
|
+
|
248
|
+
```tsx
|
249
|
+
// you can still access theme
|
250
|
+
const { styles, theme } = useStyles(stylesheet)
|
251
|
+
```
|
252
|
+
|
176
253
|
## Breakpoints
|
177
254
|
|
178
255
|
Any style can change based on breakpoints. To do this, change a value to an object:
|
179
256
|
|
180
257
|
```ts
|
181
|
-
const stylesheet =
|
258
|
+
const stylesheet = createStyleSheet(theme => ({
|
182
259
|
container: {
|
183
260
|
flex: 1,
|
184
261
|
justifyContent: 'center',
|
@@ -195,6 +272,33 @@ const stylesheet = createStyles(theme => ({
|
|
195
272
|
}))
|
196
273
|
```
|
197
274
|
|
275
|
+
You can even use it with nested objects like `transform` or `shadowOffset`:
|
276
|
+
|
277
|
+
```ts
|
278
|
+
const stylesheet = createStyleSheet(theme => ({
|
279
|
+
container: {
|
280
|
+
flex: 1,
|
281
|
+
justifyContent: 'center',
|
282
|
+
alignItems: 'center',
|
283
|
+
backgroundColor: {
|
284
|
+
xs: theme.colors.background,
|
285
|
+
sm: theme.colors.barbie
|
286
|
+
},
|
287
|
+
transform: [
|
288
|
+
{
|
289
|
+
translateX: 100
|
290
|
+
},
|
291
|
+
{
|
292
|
+
scale: {
|
293
|
+
xs: 1.5,
|
294
|
+
':w[500]': 1
|
295
|
+
}
|
296
|
+
}
|
297
|
+
]
|
298
|
+
}
|
299
|
+
}))
|
300
|
+
```
|
301
|
+
|
198
302
|
Library will choose the correct value (based on screen width) in the runtime.
|
199
303
|
|
200
304
|
## Media queries
|
@@ -211,7 +315,7 @@ For more advanced usage and pixel perfect designs you can also use a custom medi
|
|
211
315
|
Media queries can be mixed with breakpoints, but have a bigger priority:
|
212
316
|
|
213
317
|
```tsx
|
214
|
-
const stylesheet =
|
318
|
+
const stylesheet = createStyleSheet(theme => ({
|
215
319
|
container: {
|
216
320
|
justifyContent: 'center',
|
217
321
|
alignItems: 'center',
|
@@ -220,7 +324,8 @@ const stylesheet = createStyles(theme => ({
|
|
220
324
|
sm: 'row',
|
221
325
|
},
|
222
326
|
backgroundColor: {
|
223
|
-
|
327
|
+
md: theme.colors.background,
|
328
|
+
// even though md might overlap with >600px, lib will use 'barbie'
|
224
329
|
':w[600]': theme.colors.barbie
|
225
330
|
}
|
226
331
|
},
|
@@ -255,7 +360,7 @@ export const ExampleUnistyles = () => {
|
|
255
360
|
)
|
256
361
|
}
|
257
362
|
|
258
|
-
const stylesheet =
|
363
|
+
const stylesheet = createStyleSheet({
|
259
364
|
scrollContainer: {
|
260
365
|
flex: 1,
|
261
366
|
justifyContent: 'center',
|
@@ -267,16 +372,221 @@ const stylesheet = createStyles({
|
|
267
372
|
})
|
268
373
|
})
|
269
374
|
```
|
375
|
+
If you use a dynamic function, library will wrap it in a `Proxy` to make sure the correct values of breakpoints will be used:
|
376
|
+
|
377
|
+
```ts
|
378
|
+
const stylesheet = createStyleSheet(theme => ({
|
379
|
+
scrollContainer: {
|
380
|
+
flex: 1,
|
381
|
+
justifyContent: 'center',
|
382
|
+
alignItems: 'center',
|
383
|
+
},
|
384
|
+
post: (index: number) => ({
|
385
|
+
// breakpoints and media queries works with dynamic function
|
386
|
+
backgroundColor: {
|
387
|
+
xs: index % 2 === 0
|
388
|
+
? theme.colors.gold
|
389
|
+
: theme.colors.silver,
|
390
|
+
sm: theme.colors.red
|
391
|
+
}
|
392
|
+
})
|
393
|
+
}))
|
394
|
+
```
|
395
|
+
|
396
|
+
## Dynamic themes
|
397
|
+
|
398
|
+
You can incorporate as many themes as you desire in your application. While there's flexibility in how you structure your theme, it's essential to maintain consistency with the TypeScript type:
|
399
|
+
|
400
|
+
To promote reusability and maintainability, it's a good practice to share as many values between themes as possible:
|
401
|
+
|
402
|
+
```ts
|
403
|
+
// move shared colors to object
|
404
|
+
const sharedColors = {
|
405
|
+
barbie: '#ff9ff3',
|
406
|
+
oak: '#1dd1a1',
|
407
|
+
sky: '#48dbfb',
|
408
|
+
fog: '#c8d6e5',
|
409
|
+
aloes: '#00d2d3'
|
410
|
+
}
|
411
|
+
|
412
|
+
export const lightTheme = {
|
413
|
+
colors: {
|
414
|
+
// reuse or override them
|
415
|
+
...sharedColors,
|
416
|
+
backgroundColor: '#ffffff',
|
417
|
+
typography: '#000000'
|
418
|
+
}
|
419
|
+
// other keys in common with darkTheme
|
420
|
+
}
|
421
|
+
|
422
|
+
export const darkTheme = {
|
423
|
+
colors: {
|
424
|
+
// reuse or override them
|
425
|
+
...sharedColors,
|
426
|
+
backgroundColor: '#000000',
|
427
|
+
typography: '#ffffff'
|
428
|
+
}
|
429
|
+
// other keys in common with lightTheme
|
430
|
+
}
|
431
|
+
|
432
|
+
// export type that will be used to describe your theme
|
433
|
+
export type AppTheme = typeof lightTheme | typeof darkTheme
|
434
|
+
```
|
435
|
+
|
436
|
+
With the themes set up, modify your `createUnistyles` to consume your `AppTheme` type:
|
437
|
+
|
438
|
+
```ts
|
439
|
+
export const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, AppTheme>(breakpoints)
|
440
|
+
```
|
441
|
+
|
442
|
+
The final step is to switch your theme based on certain states, persisted values, databases, etc.:
|
443
|
+
|
444
|
+
```tsx
|
445
|
+
export const App: React.FunctionComponent = () => {
|
446
|
+
// obtain here your dark or light theme. It can be storage, state, mmkv, or whateber you use
|
447
|
+
// const [yourAppTheme] = useState(lightTheme)
|
448
|
+
// const [yourAppTheme] = useYourStorage()
|
449
|
+
// const [yourAppTheme] = useMMKVObject<AppTheme>(Theme)
|
450
|
+
|
451
|
+
// switching theme will re-render your stylesheets automatically
|
452
|
+
return (
|
453
|
+
<UnistylesTheme theme={yourAppTheme}>
|
454
|
+
<Examples.Extreme />
|
455
|
+
</UnistylesTheme>
|
456
|
+
)
|
457
|
+
}
|
458
|
+
```
|
459
|
+
|
460
|
+
## Variants
|
461
|
+
|
462
|
+
`react-native-unistyles` isn't a UI/component library, so you're in charge of designing variants. With no restrictions and using your creativity, you can easily create variants for your components.
|
463
|
+
|
464
|
+
Let's examine variants for the `Text` component. Imagine you want to create several variants for your `Typography` components:
|
465
|
+
- Heading
|
466
|
+
- Regular
|
467
|
+
- Thin
|
468
|
+
|
469
|
+
To achieve this, add variants to your theme:
|
470
|
+
|
471
|
+
```ts
|
472
|
+
export const lightTheme = {
|
473
|
+
colors: {
|
474
|
+
...sharedColors,
|
475
|
+
backgroundColor: '#ffffff',
|
476
|
+
typography: '#000000'
|
477
|
+
},
|
478
|
+
components: {
|
479
|
+
typography: {
|
480
|
+
base: {
|
481
|
+
fontFamily: 'Roboto',
|
482
|
+
fontSize: 12,
|
483
|
+
},
|
484
|
+
heading: {
|
485
|
+
fontFamily: 'Roboto-Medium',
|
486
|
+
fontSize: 24,
|
487
|
+
},
|
488
|
+
regular: {
|
489
|
+
fontFamily: 'Roboto',
|
490
|
+
fontSize: 12,
|
491
|
+
},
|
492
|
+
thin: {
|
493
|
+
fontFamily: 'Roboto-Thin',
|
494
|
+
fontSize: 12,
|
495
|
+
},
|
496
|
+
bold: {
|
497
|
+
fontWeight: 'bold'
|
498
|
+
}
|
499
|
+
}
|
500
|
+
}
|
501
|
+
}
|
502
|
+
```
|
503
|
+
Next, create a base component:
|
504
|
+
|
505
|
+
```tsx
|
506
|
+
import React from 'react'
|
507
|
+
import type { PropsWithChildren } from 'react'
|
508
|
+
import { Text, TextStyle } from 'react-native'
|
509
|
+
import { createStyleSheet, useStyles } from 'lib/styles'
|
510
|
+
|
511
|
+
interface BaseTextProps extends PropsWithChildren {
|
512
|
+
bold: boolean,
|
513
|
+
style: TextStyle
|
514
|
+
}
|
515
|
+
|
516
|
+
export const BaseText: React.FunctionComponent<BaseTextProps> = ({
|
517
|
+
children,
|
518
|
+
bold = false,
|
519
|
+
style = {}
|
520
|
+
}) => {
|
521
|
+
const {styles} = useStyles(stylesheet)
|
522
|
+
|
523
|
+
return (
|
524
|
+
<Text
|
525
|
+
style={{
|
526
|
+
...styles.baseText,
|
527
|
+
...bold
|
528
|
+
? styles.baseText
|
529
|
+
: {},
|
530
|
+
// pass other styles via props
|
531
|
+
...style
|
532
|
+
}}
|
533
|
+
>
|
534
|
+
{children}
|
535
|
+
</Text>
|
536
|
+
)
|
537
|
+
}
|
538
|
+
|
539
|
+
const stylesheet = createStyleSheet(theme => ({
|
540
|
+
baseText: {
|
541
|
+
...theme.components.typography.base
|
542
|
+
},
|
543
|
+
bold: {
|
544
|
+
...theme.components.typography.bold
|
545
|
+
}
|
546
|
+
}))
|
547
|
+
```
|
548
|
+
|
549
|
+
Now, let's create another variant, e.g., Heading:
|
550
|
+
|
551
|
+
```tsx
|
552
|
+
import React from 'react'
|
553
|
+
import type { PropsWithChildren } from 'react'
|
554
|
+
import { Text, TextStyle } from 'react-native'
|
555
|
+
import { createStyleSheet, useStyles } from 'lib/styles'
|
556
|
+
import { BaseText } from 'lib/components'
|
557
|
+
|
558
|
+
interface BaseTextProps extends PropsWithChildren {
|
559
|
+
bold: boolean,
|
560
|
+
text: string
|
561
|
+
}
|
562
|
+
|
563
|
+
export const Heading: React.FunctionComponent<BaseTextProps> = ({
|
564
|
+
text,
|
565
|
+
bold = false
|
566
|
+
}) => {
|
567
|
+
const { theme } = useStyles()
|
568
|
+
|
569
|
+
return (
|
570
|
+
<BaseText
|
571
|
+
bold={bold}
|
572
|
+
style={theme.components.typography.heading}
|
573
|
+
>
|
574
|
+
{text}
|
575
|
+
</BaseText>
|
576
|
+
)
|
577
|
+
}
|
578
|
+
```
|
579
|
+
And so on...
|
270
580
|
|
271
581
|
## Migrate from StyleSheet
|
272
582
|
|
273
583
|
`react-native-unistyles` embraces the simplicity of `StyleSheet`, making it easy to integrate into your project.
|
274
584
|
|
275
|
-
You can replace `StyleSheet.create` with `
|
585
|
+
You can replace `StyleSheet.create` with `createStyleSheet` and it will work exactly the same:
|
276
586
|
|
277
587
|
```diff
|
278
588
|
-const styles = StyleSheet.create({
|
279
|
-
+const styles =
|
589
|
+
+const styles = createStyleSheet({
|
280
590
|
scrollContainer: {
|
281
591
|
flex: 1,
|
282
592
|
justifyContent: 'center',
|
@@ -294,21 +604,7 @@ export const ExampleUnistyles = () => {
|
|
294
604
|
}
|
295
605
|
```
|
296
606
|
|
297
|
-
With the hook in place, you can now use
|
298
|
-
|
299
|
-
Additionally, to access the `theme` use a function instead of an `object`:
|
300
|
-
|
301
|
-
```diff
|
302
|
-
-const stylesheet = createStyles({
|
303
|
-
+const stylesheet = createStyles(theme => ({
|
304
|
-
scrollContainer: {
|
305
|
-
flex: 1,
|
306
|
-
justifyContent: 'center',
|
307
|
-
alignItems: 'center',
|
308
|
-
backgroundColor: theme.colors.background
|
309
|
-
}
|
310
|
-
}))
|
311
|
-
```
|
607
|
+
With the hook in place, you can now use all the features.
|
312
608
|
|
313
609
|
## Example
|
314
610
|
|
@@ -318,6 +614,17 @@ In order to check out working example go to [example/](./example).
|
|
318
614
|
|
319
615
|
For more detailed explanation please refer to my blog post [here](https://www.reactnativecrossroads.com/posts/level-up-react-native-styles).
|
320
616
|
|
617
|
+
|
618
|
+
## Sponsor my work
|
619
|
+
|
620
|
+
If you found the `react-native-unistyles` time-saving and valuable, please consider sponsoring my work. Your support enables me to continue creating libraries with a fresh approach.
|
621
|
+
|
622
|
+
Github: https://github.com/sponsors/jpudysz
|
623
|
+
|
624
|
+
Ko-fi: https://ko-fi.com/jpudysz
|
625
|
+
|
626
|
+
Your support is greatly appreciated and helps me dedicate more time and resources to creating quality libraries. Thank you for all the support!
|
627
|
+
|
321
628
|
## License
|
322
629
|
|
323
630
|
MIT
|
@@ -11,7 +11,21 @@ var _hooks = require("./hooks");
|
|
11
11
|
const createUnistyles = breakpoints => {
|
12
12
|
const sortedBreakpoints = (0, _utils.sortAndValidateBreakpoints)(breakpoints);
|
13
13
|
return {
|
14
|
-
|
14
|
+
/**
|
15
|
+
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
16
|
+
*/
|
17
|
+
createStyles: styles => {
|
18
|
+
if (typeof styles === 'function') {
|
19
|
+
return styles;
|
20
|
+
}
|
21
|
+
return styles;
|
22
|
+
},
|
23
|
+
createStyleSheet: styles => {
|
24
|
+
if (typeof styles === 'function') {
|
25
|
+
return styles;
|
26
|
+
}
|
27
|
+
return styles;
|
28
|
+
},
|
15
29
|
useStyles: stylesheet => {
|
16
30
|
const theme = (0, _react.useContext)(_UnistylesTheme.UnistylesContext);
|
17
31
|
const dimensions = (0, _hooks.useDimensions)();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_UnistylesTheme","_utils","_hooks","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAG,IAAAC,iCAA0B,EAACF,WAAW,
|
1
|
+
{"version":3,"names":["_react","require","_UnistylesTheme","_utils","_hooks","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","createStyleSheet","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC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,UAAU,EAAEG,UAAU,EAAEf,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGsB,GAAG;UACN,CAACE,GAAG,GAAG,IAAAI,iBAAU,EAAQF,CAAC,EAAEd,UAAU,EAAEG,UAAU,EAAEf,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHO,KAAK;QACLJ,MAAM,EAAEe;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAA/B,eAAA,GAAAA,eAAA"}
|
@@ -73,8 +73,7 @@ const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
|
|
73
73
|
if (isDynamicFunction || isValidStyle) {
|
74
74
|
return [key, value];
|
75
75
|
}
|
76
|
-
|
77
|
-
return [key, (0, _breakpoints.getValueForBreakpoint)(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
|
76
|
+
return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize, breakpoints)];
|
78
77
|
}));
|
79
78
|
};
|
80
79
|
exports.parseStyle = parseStyle;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","
|
1
|
+
{"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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BAAiB,GAAG,OAAOL,KAAK,KAAK,UAAU;IACrD,MAAMM,YAAY,GAAG,OAAON,KAAK,KAAK,QAAQ;IAE9C,IAAIK,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACP,GAAG,EAAEC,KAAK,CAAC;IACvB;IAEA,OAAO,CACHD,GAAG,EACH,IAAAQ,kCAAqB,EACjBP,KAAK,EACLjB,UAAU,EACVC,UAAU,EACVC,WACJ,CAAC,CACJ;EACL,CAAC,CACL,CAAC;AACT,CAAC;AAAAO,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
|
@@ -5,7 +5,21 @@ import { useDimensions } from './hooks';
|
|
5
5
|
export const createUnistyles = breakpoints => {
|
6
6
|
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints);
|
7
7
|
return {
|
8
|
-
|
8
|
+
/**
|
9
|
+
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
10
|
+
*/
|
11
|
+
createStyles: styles => {
|
12
|
+
if (typeof styles === 'function') {
|
13
|
+
return styles;
|
14
|
+
}
|
15
|
+
return styles;
|
16
|
+
},
|
17
|
+
createStyleSheet: styles => {
|
18
|
+
if (typeof styles === 'function') {
|
19
|
+
return styles;
|
20
|
+
}
|
21
|
+
return styles;
|
22
|
+
},
|
9
23
|
useStyles: stylesheet => {
|
10
24
|
const theme = useContext(UnistylesContext);
|
11
25
|
const dimensions = useDimensions();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useContext","UnistylesContext","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","useDimensions","createUnistyles","breakpoints","sortedBreakpoints","createStyles","styles","useStyles","stylesheet","theme","dimensions","breakpoint","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,4BAA4B,EAAEC,eAAe,EAAEC,UAAU,EAAEC,0BAA0B,QAAQ,SAAS;AAC/G,SAASC,aAAa,QAAQ,SAAS;AAEvC,OAAO,MAAMC,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAGJ,0BAA0B,CAACG,WAAW,
|
1
|
+
{"version":3,"names":["useContext","UnistylesContext","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","useDimensions","createUnistyles","breakpoints","sortedBreakpoints","createStyles","styles","createStyleSheet","useStyles","stylesheet","theme","dimensions","breakpoint","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,4BAA4B,EAAEC,eAAe,EAAEC,UAAU,EAAEC,0BAA0B,QAAQ,SAAS;AAC/G,SAASC,aAAa,QAAQ,SAAS;AAEvC,OAAO,MAAMC,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAGJ,0BAA0B,CAACG,WAAW,CAAC;EAEjE,OAAO;IACH;AACR;AACA;IACQE,YAAY,EAAyCC,MAAqF,IAAY;MAClJ,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;QAC9B,OAAOA,MAAM;MACjB;MAEA,OAAOA,MAAM;IACjB,CAAC;IACDC,gBAAgB,EAAyCD,MAAqF,IAAY;MACtJ,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;QAC9B,OAAOA,MAAM;MACjB;MAEA,OAAOA,MAAM;IACjB,CAAC;IACDE,SAAS,EAAwCC,UAA4C,IAAK;MAC9F,MAAMC,KAAK,GAAGf,UAAU,CAACC,gBAAgB,CAAM;MAC/C,MAAMe,UAAU,GAAGV,aAAa,CAAC,CAAC;MAClC,MAAMW,UAAU,GAAGf,4BAA4B,CAAIc,UAAU,CAACE,KAAK,EAAET,iBAAiB,CAAC;MACvF,MAAMU,UAAsB,GAAG;QAC3BD,KAAK,EAAEF,UAAU,CAACE,KAAK;QACvBE,MAAM,EAAEJ,UAAU,CAACI;MACvB,CAAC;MAED,IAAI,CAACN,UAAU,EAAE;QACb,OAAO;UACHC,KAAK;UACLJ,MAAM,EAAE,CAAC;QACb,CAAC;MACL;MAEA,MAAMU,YAAY,GAAG,OAAOP,UAAU,KAAK,UAAU,GAC/CA,UAAU,CAACC,KAAK,CAAC,GACjBD,UAAU;MAEhB,MAAMQ,iBAAiB,GAAGC,MAAM,CAC3BC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QACtB,MAAMG,CAAC,GAAGD,KAAiC;QAE3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAGzB,eAAe,CAAI0B,KAAK,EAAEZ,UAAU,EAAEE,UAAU,EAAEV,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGiB,GAAG;UACN,CAACE,GAAG,GAAGxB,UAAU,CAAQ0B,CAAC,EAAEb,UAAU,EAAEE,UAAU,EAAEV,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHM,KAAK;QACLJ,MAAM,EAAEW;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC"}
|
@@ -67,8 +67,7 @@ export const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
|
|
67
67
|
if (isDynamicFunction || isValidStyle) {
|
68
68
|
return [key, value];
|
69
69
|
}
|
70
|
-
|
71
|
-
return [key, getValueForBreakpoint(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
|
70
|
+
return [key, getValueForBreakpoint(value, breakpoint, screenSize, breakpoints)];
|
72
71
|
}));
|
73
72
|
};
|
74
73
|
//# sourceMappingURL=styles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle"
|
1
|
+
{"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":"AACA,SAASA,qBAAqB,QAAQ,eAAe;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEP,UAAU,EAAEC,UAAU,EAAEC,WAAW;AAC5F,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,UAAU,GAAGA,CACtBC,KAA8B,EAC9BT,UAA4B,EAC5BC,UAAsB,EACtBC,WAAc,KACV;EACJ,MAAMQ,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACD,KAAK,CAGnC;EAED,OAAOE,MAAM,CACRC,WAAW,CAACF,OAAO,CACfG,GAAG,CAACC,IAAA,IAAkB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACd,MAAMG,aAAa,GAAGF,GAAG,KAAK,cAAc;IAE5C,IAAIE,aAAa,EAAE;MACf,OAAO,CACHF,GAAG,EACHP,UAAU,CAACQ,KAAK,EAA6BhB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CACpF;IACL;IAEA,MAAMgB,WAAW,GAAGH,GAAG,KAAK,WAAW;IAEvC,IAAIG,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MACrC,OAAO,CACHD,GAAG,EACHC,KAAK,CAACH,GAAG,CAACG,KAAK,IAAIR,UAAU,CAACQ,KAAK,EAAEhB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC,CAC7E;IACL;IAEA,MAAMmB,iBAAiB,GAAG,OAAOL,KAAK,KAAK,UAAU;IACrD,MAAMM,YAAY,GAAG,OAAON,KAAK,KAAK,QAAQ;IAE9C,IAAIK,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACP,GAAG,EAAEC,KAAK,CAAC;IACvB;IAEA,OAAO,CACHD,GAAG,EACHlB,qBAAqB,CACjBmB,KAAK,EACLhB,UAAU,EACVC,UAAU,EACVC,WACJ,CAAC,CACJ;EACL,CAAC,CACL,CAAC;AACT,CAAC"}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import type { CreateStylesFactory, CustomNamedStyles, ExtractBreakpoints, RemoveKeysWithPrefix } from './types';
|
2
2
|
export declare const createUnistyles: <B extends Record<string, number>, T = {}>(breakpoints: B) => {
|
3
|
-
|
3
|
+
/**
|
4
|
+
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
5
|
+
*/
|
6
|
+
createStyles: <S extends CustomNamedStyles<S, B>, X>(styles: S | X | CustomNamedStyles<S, B> | ((theme: T) => X | CustomNamedStyles<X, B>)) => S | X;
|
7
|
+
createStyleSheet: <S_1 extends CustomNamedStyles<S_1, B>, X_1>(styles: S_1 | X_1 | CustomNamedStyles<S_1, B> | ((theme: T) => X_1 | CustomNamedStyles<X_1, B>)) => S_1 | X_1;
|
4
8
|
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T> | undefined) => {
|
5
9
|
theme: T;
|
6
10
|
styles: ExtractBreakpoints<RemoveKeysWithPrefix<ST, B>, B>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAc,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3H,eAAO,MAAM,eAAe
|
1
|
+
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAc,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3H,eAAO,MAAM,eAAe;IAIpB;;OAEG;;;;;;;CA2DV,CAAA"}
|
@@ -1,19 +1,37 @@
|
|
1
|
-
import type { ImageStyle, TextStyle,
|
2
|
-
import type {
|
1
|
+
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
|
2
|
+
import type { MatrixTransform, PerpectiveTransform, RotateTransform, RotateXTransform, RotateYTransform, RotateZTransform, ScaleTransform, ScaleXTransform, ScaleYTransform, SkewXTransform, SkewYTransform, TranslateXTransform, TranslateYTransform } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
|
3
3
|
export type ScreenSize = {
|
4
4
|
width: number;
|
5
5
|
height: number;
|
6
6
|
};
|
7
|
-
export type CreateStylesFactory<
|
7
|
+
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST;
|
8
8
|
type StyleProperty<T, B extends Record<string, number>> = {
|
9
|
-
[
|
10
|
-
[innerKey in keyof B]?: T[
|
9
|
+
[K in keyof T]: {
|
10
|
+
[innerKey in keyof B]?: T[K];
|
11
11
|
} | {
|
12
|
-
[innerKey in
|
13
|
-
} | T[
|
12
|
+
[innerKey in string]?: T[K];
|
13
|
+
} | T[K];
|
14
14
|
};
|
15
|
+
type ShadowOffsetProps<B extends Record<string, number>> = {
|
16
|
+
shadowOffset: {
|
17
|
+
width: number | {
|
18
|
+
[innerKey in keyof B]?: number;
|
19
|
+
};
|
20
|
+
height: number | {
|
21
|
+
[innerKey in keyof B]?: number;
|
22
|
+
};
|
23
|
+
};
|
24
|
+
};
|
25
|
+
type TransformStyles<B extends Record<string, number>> = PerpectiveTransform | StyleProperty<PerpectiveTransform, B> | RotateTransform | StyleProperty<RotateTransform, B> | RotateXTransform | StyleProperty<RotateXTransform, B> | RotateYTransform | StyleProperty<RotateYTransform, B> | RotateZTransform | StyleProperty<RotateZTransform, B> | ScaleTransform | StyleProperty<ScaleTransform, B> | ScaleXTransform | StyleProperty<ScaleXTransform, B> | ScaleYTransform | StyleProperty<ScaleYTransform, B> | TranslateXTransform | StyleProperty<TranslateXTransform, B> | TranslateYTransform | StyleProperty<TranslateYTransform, B> | SkewXTransform | StyleProperty<SkewXTransform, B> | SkewYTransform | StyleProperty<SkewYTransform, B> | MatrixTransform | StyleProperty<MatrixTransform, B>;
|
26
|
+
type TransformProps<B extends Record<string, number>> = {
|
27
|
+
transform: Array<TransformStyles<B>>;
|
28
|
+
};
|
29
|
+
type UnistyleView = Omit<Omit<ViewStyle, 'shadowOffset'>, 'transform'>;
|
30
|
+
type UnistyleText = Omit<Omit<TextStyle, 'shadowOffset'>, 'transform'>;
|
31
|
+
type UnistyleImage = Omit<Omit<ImageStyle, 'shadowOffset'>, 'transform'>;
|
32
|
+
export type StaticStyles<B extends Record<string, number>> = (UnistyleView | StyleProperty<UnistyleView, B>) | (UnistyleText | StyleProperty<UnistyleText, B>) | (UnistyleImage | StyleProperty<UnistyleImage, B>) & TransformProps<B> & ShadowOffsetProps<B>;
|
15
33
|
export type CustomNamedStyles<T, B extends Record<string, number>> = {
|
16
|
-
[
|
34
|
+
[K in keyof T]: T[K] extends (...args: infer A) => unknown ? (...args: A) => StaticStyles<B> : StaticStyles<B>;
|
17
35
|
};
|
18
36
|
export type ExtractBreakpoints<T, B extends Record<string, number>> = T extends Partial<Record<keyof B & string, infer V>> ? V : T extends (...args: infer A) => infer R ? (...args: A) => ExtractBreakpoints<R, B> : {
|
19
37
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => ExtractBreakpoints<R, B> : T[K] extends object ? ExtractBreakpoints<T[K], B> : T[K];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EACR,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,mDAAmD,CAAA;AAE1D,MAAM,MAAM,UAAU,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,EAAE,CAAA;AAEjE,KAAK,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI;K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AC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAAE,GACnH;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAAE,GACrD,CAAC,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU,
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU,sBA+CzB,CAAA"}
|
package/package.json
CHANGED
package/src/createUnistyles.ts
CHANGED
@@ -5,10 +5,26 @@ import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValid
|
|
5
5
|
import { useDimensions } from './hooks'
|
6
6
|
|
7
7
|
export const createUnistyles = <B extends Record<string, number>, T = {}>(breakpoints: B) => {
|
8
|
-
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints)
|
8
|
+
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints)
|
9
9
|
|
10
10
|
return {
|
11
|
-
|
11
|
+
/**
|
12
|
+
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
13
|
+
*/
|
14
|
+
createStyles: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
|
15
|
+
if (typeof styles === 'function') {
|
16
|
+
return styles as X
|
17
|
+
}
|
18
|
+
|
19
|
+
return styles as S
|
20
|
+
},
|
21
|
+
createStyleSheet: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
|
22
|
+
if (typeof styles === 'function') {
|
23
|
+
return styles as X
|
24
|
+
}
|
25
|
+
|
26
|
+
return styles as S
|
27
|
+
},
|
12
28
|
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
|
13
29
|
const theme = useContext(UnistylesContext) as T
|
14
30
|
const dimensions = useDimensions()
|
package/src/types.ts
CHANGED
@@ -1,36 +1,80 @@
|
|
1
|
-
import type { ImageStyle, TextStyle,
|
2
|
-
import type {
|
1
|
+
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
|
2
|
+
import type {
|
3
|
+
MatrixTransform,
|
4
|
+
PerpectiveTransform,
|
5
|
+
RotateTransform,
|
6
|
+
RotateXTransform,
|
7
|
+
RotateYTransform,
|
8
|
+
RotateZTransform,
|
9
|
+
ScaleTransform,
|
10
|
+
ScaleXTransform,
|
11
|
+
ScaleYTransform,
|
12
|
+
SkewXTransform,
|
13
|
+
SkewYTransform,
|
14
|
+
TranslateXTransform,
|
15
|
+
TranslateYTransform
|
16
|
+
} from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
|
3
17
|
|
4
18
|
export type ScreenSize = {
|
5
19
|
width: number,
|
6
20
|
height: number
|
7
21
|
}
|
8
22
|
|
9
|
-
export type CreateStylesFactory<
|
23
|
+
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
|
10
24
|
|
11
25
|
type StyleProperty<T, B extends Record<string, number>> = {
|
12
|
-
[
|
13
|
-
[innerKey in keyof B]?: T[
|
26
|
+
[K in keyof T]: {
|
27
|
+
[innerKey in keyof B]?: T[K]
|
14
28
|
} | {
|
15
|
-
[innerKey in
|
16
|
-
} | T[
|
29
|
+
[innerKey in string]?: T[K]
|
30
|
+
} | T[K]
|
17
31
|
}
|
18
32
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
type ShadowOffsetProps<B extends Record<string, number>> = {
|
34
|
+
shadowOffset: {
|
35
|
+
width: number | {
|
36
|
+
[innerKey in keyof B]?: number
|
37
|
+
},
|
38
|
+
height: number | {
|
39
|
+
[innerKey in keyof B]?: number
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
type TransformStyles<B extends Record<string, number>> =
|
45
|
+
PerpectiveTransform | StyleProperty<PerpectiveTransform, B>
|
46
|
+
| RotateTransform | StyleProperty<RotateTransform, B>
|
47
|
+
| RotateXTransform | StyleProperty<RotateXTransform, B>
|
48
|
+
| RotateYTransform | StyleProperty<RotateYTransform, B>
|
49
|
+
| RotateZTransform | StyleProperty<RotateZTransform, B>
|
50
|
+
| ScaleTransform | StyleProperty<ScaleTransform, B>
|
51
|
+
| ScaleXTransform | StyleProperty<ScaleXTransform, B>
|
52
|
+
| ScaleYTransform | StyleProperty<ScaleYTransform, B>
|
53
|
+
| TranslateXTransform | StyleProperty<TranslateXTransform, B>
|
54
|
+
| TranslateYTransform | StyleProperty<TranslateYTransform, B>
|
55
|
+
| SkewXTransform | StyleProperty<SkewXTransform, B>
|
56
|
+
| SkewYTransform | StyleProperty<SkewYTransform, B>
|
57
|
+
| MatrixTransform | StyleProperty<MatrixTransform, B>
|
58
|
+
|
59
|
+
type TransformProps<B extends Record<string, number>> = {
|
60
|
+
transform: Array<TransformStyles<B>>
|
32
61
|
}
|
33
62
|
|
63
|
+
type UnistyleView = Omit<Omit<ViewStyle, 'shadowOffset'>, 'transform'>
|
64
|
+
type UnistyleText = Omit<Omit<TextStyle, 'shadowOffset'>, 'transform'>
|
65
|
+
type UnistyleImage = Omit<Omit<ImageStyle, 'shadowOffset'>, 'transform'>
|
66
|
+
|
67
|
+
export type StaticStyles<B extends Record<string, number>> =
|
68
|
+
| (UnistyleView | StyleProperty<UnistyleView, B>)
|
69
|
+
| (UnistyleText | StyleProperty<UnistyleText, B>)
|
70
|
+
| (UnistyleImage | StyleProperty<UnistyleImage, B>)
|
71
|
+
& TransformProps<B> & ShadowOffsetProps<B>
|
72
|
+
|
73
|
+
export type CustomNamedStyles<T, B extends Record<string, number>> = {
|
74
|
+
[K in keyof T]: T[K] extends (...args: infer A) => unknown
|
75
|
+
? (...args: A) => StaticStyles<B>
|
76
|
+
: StaticStyles<B>
|
77
|
+
}
|
34
78
|
export type ExtractBreakpoints<T, B extends Record<string, number>> = T extends Partial<Record<keyof B & string, infer V>>
|
35
79
|
? V
|
36
80
|
: T extends (...args: infer A) => infer R
|
package/src/utils/styles.ts
CHANGED
@@ -62,7 +62,10 @@ export const parseStyle = <T, B extends Record<string, number>>(
|
|
62
62
|
screenSize: ScreenSize,
|
63
63
|
breakpoints: B
|
64
64
|
): T => {
|
65
|
-
const entries = Object.entries(style) as [[
|
65
|
+
const entries = Object.entries(style) as [[
|
66
|
+
keyof T,
|
67
|
+
CustomNamedStyles<T, B> | Record<keyof B & string, string | number | undefined>]
|
68
|
+
]
|
66
69
|
|
67
70
|
return Object
|
68
71
|
.fromEntries(entries
|
@@ -72,7 +75,7 @@ export const parseStyle = <T, B extends Record<string, number>>(
|
|
72
75
|
if (isNestedStyle) {
|
73
76
|
return [
|
74
77
|
key,
|
75
|
-
parseStyle(value, breakpoint, screenSize, breakpoints)
|
78
|
+
parseStyle(value as CustomNamedStyles<T, B>, breakpoint, screenSize, breakpoints)
|
76
79
|
]
|
77
80
|
}
|
78
81
|
|
@@ -92,9 +95,15 @@ export const parseStyle = <T, B extends Record<string, number>>(
|
|
92
95
|
return [key, value]
|
93
96
|
}
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
+
return [
|
99
|
+
key,
|
100
|
+
getValueForBreakpoint<B>(
|
101
|
+
value as Record<keyof B & string, string | number | undefined>,
|
102
|
+
breakpoint,
|
103
|
+
screenSize,
|
104
|
+
breakpoints
|
105
|
+
)
|
106
|
+
]
|
98
107
|
})
|
99
108
|
)
|
100
109
|
}
|