react-native-unistyles 1.0.0-beta.6 → 1.0.0-rc.1
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 +6 -588
- package/lib/commonjs/createUnistyles.js +0 -9
- package/lib/commonjs/createUnistyles.js.map +1 -1
- package/lib/commonjs/utils/index.js +43 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/createUnistyles.js +0 -9
- package/lib/module/createUnistyles.js.map +1 -1
- package/lib/module/utils/index.js +2 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/src/createUnistyles.d.ts +1 -5
- package/lib/typescript/src/createUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +2 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/package.json +13 -10
- package/src/__tests__/createUnistyles.spec.tsx +158 -0
- package/src/createUnistyles.ts +0 -10
- package/src/utils/index.ts +9 -1
- package/lib/commonjs/utils/breakpoints.spec.js +0 -154
- package/lib/commonjs/utils/breakpoints.spec.js.map +0 -1
- package/lib/commonjs/utils/mediaQueries.spec.js +0 -220
- package/lib/commonjs/utils/mediaQueries.spec.js.map +0 -1
- package/lib/commonjs/utils/styles.spec.js +0 -174
- package/lib/commonjs/utils/styles.spec.js.map +0 -1
- package/lib/module/utils/breakpoints.spec.js +0 -152
- package/lib/module/utils/breakpoints.spec.js.map +0 -1
- package/lib/module/utils/mediaQueries.spec.js +0 -218
- package/lib/module/utils/mediaQueries.spec.js.map +0 -1
- package/lib/module/utils/styles.spec.js +0 -172
- package/lib/module/utils/styles.spec.js.map +0 -1
- package/lib/typescript/src/utils/breakpoints.spec.d.ts +0 -2
- package/lib/typescript/src/utils/breakpoints.spec.d.ts.map +0 -1
- package/lib/typescript/src/utils/mediaQueries.spec.d.ts +0 -2
- package/lib/typescript/src/utils/mediaQueries.spec.d.ts.map +0 -1
- package/lib/typescript/src/utils/styles.spec.d.ts +0 -2
- package/lib/typescript/src/utils/styles.spec.d.ts.map +0 -1
@@ -7,15 +7,6 @@ export const createUnistyles = breakpoints => {
|
|
7
7
|
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints);
|
8
8
|
const sortedBreakpointEntries = Object.entries(sortedBreakpoints);
|
9
9
|
return {
|
10
|
-
/**
|
11
|
-
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
12
|
-
*/
|
13
|
-
createStyles: styles => {
|
14
|
-
if (typeof styles === 'function') {
|
15
|
-
return styles;
|
16
|
-
}
|
17
|
-
return styles;
|
18
|
-
},
|
19
10
|
createStyleSheet: styles => {
|
20
11
|
if (typeof styles === 'function') {
|
21
12
|
return styles;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useContext","StyleSheet","UnistylesContext","useDimensions","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","createUnistyles","breakpoints","sortedBreakpoints","sortedBreakpointEntries","Object","entries","
|
1
|
+
{"version":3,"names":["useContext","StyleSheet","UnistylesContext","useDimensions","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","createUnistyles","breakpoints","sortedBreakpoints","sortedBreakpointEntries","Object","entries","createStyleSheet","styles","useStyles","stylesheet","theme","screenSize","parsedStyles","breakpoint","width","dynamicStyleSheet","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,UAAU,QAAQ,cAAc;AASzC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,aAAa,QAAQ,SAAS;AACvC,SAASC,4BAA4B,EAAEC,eAAe,EAAEC,UAAU,EAAEC,0BAA0B,QAAQ,SAAS;AAE/G,OAAO,MAAMC,eAAe,GAAmCC,WAAc,IAAK;EAC9E,MAAMC,iBAAiB,GAAGH,0BAA0B,CAACE,WAAW,CAAC;EACjE,MAAME,uBAAuB,GAAGC,MAAM,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Z,CAAC;IACL;EACJ,CAAC;AACL,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
export { normalizeStyles } from './normalizeStyles';
|
2
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints } from './breakpoints';
|
2
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
|
3
3
|
export { proxifyFunction, parseStyle } from './styles';
|
4
|
+
export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
|
4
5
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["normalizeStyles","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","proxifyFunction","parseStyle"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,4BAA4B,EAAEC,0BAA0B,QAAQ,eAAe;
|
1
|
+
{"version":3,"names":["normalizeStyles","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","getValueForBreakpoint","proxifyFunction","parseStyle","extractValues","getKeyForCustomMediaQuery","isMediaQuery","isWithinTheHeight","isWithinTheWidth","isWithinTheWidthAndHeight"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,4BAA4B,EAAEC,0BAA0B,EAAEC,qBAAqB,QAAQ,eAAe;AAC/G,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SACIC,aAAa,EACbC,yBAAyB,EACzBC,YAAY,EACZC,iBAAiB,EACjBC,gBAAgB,EAChBC,yBAAyB,QACtB,gBAAgB"}
|
@@ -1,10 +1,6 @@
|
|
1
1
|
import type { Breakpoints, CreateStylesFactory, CustomNamedStyles, ExtractBreakpoints, RemoveKeysWithPrefix } from './types';
|
2
2
|
export declare const createUnistyles: <B extends Breakpoints, T = {}>(breakpoints: B) => {
|
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;
|
3
|
+
createStyleSheet: <S extends CustomNamedStyles<S, B>, X>(styles: S | X | CustomNamedStyles<S, B> | ((theme: T) => X | CustomNamedStyles<X, B>)) => S | X;
|
8
4
|
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T> | undefined) => {
|
9
5
|
theme: T;
|
10
6
|
styles: ExtractBreakpoints<RemoveKeysWithPrefix<ST, B>, B>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EAEvB,MAAM,SAAS,CAAA;AAKhB,eAAO,MAAM,eAAe
|
1
|
+
{"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EAEvB,MAAM,SAAS,CAAA;AAKhB,eAAO,MAAM,eAAe;;;;;;CAqD3B,CAAA"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
export { normalizeStyles } from './normalizeStyles';
|
2
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints } from './breakpoints';
|
2
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
|
3
3
|
export { proxifyFunction, parseStyle } from './styles';
|
4
|
+
export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC/G,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EACH,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EAC5B,MAAM,gBAAgB,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-native-unistyles",
|
3
|
-
"version": "1.0.0-
|
3
|
+
"version": "1.0.0-rc.1",
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
5
5
|
"scripts": {
|
6
6
|
"test": "jest",
|
@@ -9,7 +9,7 @@
|
|
9
9
|
"clean": "del-cli lib",
|
10
10
|
"prepare": "husky install && bob build",
|
11
11
|
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
|
12
|
-
"release": "release-it patch --preRelease=
|
12
|
+
"release": "release-it patch --preRelease=rc"
|
13
13
|
},
|
14
14
|
"main": "lib/commonjs/index",
|
15
15
|
"module": "lib/module/index",
|
@@ -39,19 +39,19 @@
|
|
39
39
|
},
|
40
40
|
"devDependencies": {
|
41
41
|
"@commitlint/config-conventional": "17.7.0",
|
42
|
-
"@evilmartians/lefthook": "1.5.0",
|
43
42
|
"@react-native/eslint-config": "0.73.1",
|
44
43
|
"@release-it/conventional-changelog": "5.1.1",
|
44
|
+
"@testing-library/react-hooks": "8.0.1",
|
45
45
|
"@types/jest": "29.5.5",
|
46
|
-
"@types/react": "18.2.
|
46
|
+
"@types/react": "18.2.28",
|
47
47
|
"@types/react-native": "0.72.3",
|
48
|
-
"@typescript-eslint/eslint-plugin": "6.7.
|
49
|
-
"@typescript-eslint/eslint-plugin-tslint": "6.7.
|
50
|
-
"@typescript-eslint/parser": "6.7.
|
48
|
+
"@typescript-eslint/eslint-plugin": "6.7.5",
|
49
|
+
"@typescript-eslint/eslint-plugin-tslint": "6.7.5",
|
50
|
+
"@typescript-eslint/parser": "6.7.5",
|
51
51
|
"commitlint": "17.7.2",
|
52
52
|
"concurrently": "8.2.1",
|
53
53
|
"del-cli": "5.1.0",
|
54
|
-
"eslint": "8.
|
54
|
+
"eslint": "8.51.0",
|
55
55
|
"eslint-config-codemask": "1.1.7",
|
56
56
|
"eslint-plugin-functional": "6.0.0",
|
57
57
|
"eslint-plugin-import": "2.28.1",
|
@@ -67,8 +67,9 @@
|
|
67
67
|
"jest": "29.7.0",
|
68
68
|
"react": "18.2.0",
|
69
69
|
"react-native": "0.72.5",
|
70
|
-
"react-native-builder-bob": "0.23.
|
70
|
+
"react-native-builder-bob": "0.23.1",
|
71
71
|
"react-native-web": "0.19.9",
|
72
|
+
"react-test-renderer": "18.2.0",
|
72
73
|
"release-it": "16.2.1",
|
73
74
|
"typescript": "5.2.2"
|
74
75
|
},
|
@@ -83,7 +84,8 @@
|
|
83
84
|
}
|
84
85
|
},
|
85
86
|
"workspaces": [
|
86
|
-
"example"
|
87
|
+
"example",
|
88
|
+
"docs"
|
87
89
|
],
|
88
90
|
"packageManager": "yarn@3.6.1",
|
89
91
|
"engines": {
|
@@ -93,6 +95,7 @@
|
|
93
95
|
"preset": "react-native",
|
94
96
|
"modulePathIgnorePatterns": [
|
95
97
|
"<rootDir>/example/node_modules",
|
98
|
+
"<rootDir>/docs/node_modules",
|
96
99
|
"<rootDir>/lib/"
|
97
100
|
]
|
98
101
|
},
|
@@ -0,0 +1,158 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { StyleSheet } from 'react-native'
|
3
|
+
import type { ViewStyle } from 'react-native'
|
4
|
+
import { renderHook } from '@testing-library/react-hooks'
|
5
|
+
import { createUnistyles } from '../createUnistyles'
|
6
|
+
import { UnistylesTheme } from '../UnistylesTheme'
|
7
|
+
import type { CustomNamedStyles } from '../types'
|
8
|
+
|
9
|
+
jest.mock('../hooks', () => ({
|
10
|
+
useDimensions: jest.fn(() => ({
|
11
|
+
width: 500,
|
12
|
+
height: 1000
|
13
|
+
}))
|
14
|
+
}))
|
15
|
+
|
16
|
+
describe('createUnistyles', () => {
|
17
|
+
describe('createStyleSheet', () => {
|
18
|
+
it('should work exactly the same like StyleSheet.create', () => {
|
19
|
+
const breakpoints = {
|
20
|
+
xs: 0
|
21
|
+
}
|
22
|
+
const { createStyleSheet } = createUnistyles(breakpoints)
|
23
|
+
|
24
|
+
const styles = {
|
25
|
+
container: {
|
26
|
+
flex: 1,
|
27
|
+
justifyContent: 'center',
|
28
|
+
alignItems: 'center'
|
29
|
+
},
|
30
|
+
text: {
|
31
|
+
fontWeight: 'bold',
|
32
|
+
fontSize: 32
|
33
|
+
}
|
34
|
+
} as const
|
35
|
+
|
36
|
+
expect(createStyleSheet(styles)).toEqual(StyleSheet.create(styles))
|
37
|
+
})
|
38
|
+
|
39
|
+
it('should inject the theme to the createStyleSheet', () => {
|
40
|
+
const theme = {
|
41
|
+
colors: {
|
42
|
+
barbie: '#ff9ff3',
|
43
|
+
oak: '#1dd1a1',
|
44
|
+
sky: '#48dbfb',
|
45
|
+
fog: '#c8d6e5',
|
46
|
+
aloes: '#00d2d3'
|
47
|
+
}
|
48
|
+
}
|
49
|
+
const breakpoints = {
|
50
|
+
xs: 0
|
51
|
+
}
|
52
|
+
const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, typeof theme>(breakpoints)
|
53
|
+
const stylesheet = createStyleSheet(theme => ({
|
54
|
+
container: {
|
55
|
+
backgroundColor: theme.colors.barbie
|
56
|
+
}
|
57
|
+
}))
|
58
|
+
const { result } = renderHook(() => useStyles(stylesheet), {
|
59
|
+
// @ts-ignore
|
60
|
+
wrapper: ({ children }) => (
|
61
|
+
<UnistylesTheme theme={theme}>
|
62
|
+
{children}
|
63
|
+
</UnistylesTheme>
|
64
|
+
)
|
65
|
+
})
|
66
|
+
|
67
|
+
expect(result.current.theme).toEqual(theme)
|
68
|
+
expect(result.current.styles).not.toBe(Function)
|
69
|
+
expect(result.current.styles.container.backgroundColor).toEqual(theme.colors.barbie)
|
70
|
+
})
|
71
|
+
})
|
72
|
+
|
73
|
+
describe('useStyles', () => {
|
74
|
+
it('should return empty object for optional stylesheet', () => {
|
75
|
+
const breakpoints = {
|
76
|
+
xs: 0
|
77
|
+
}
|
78
|
+
const { useStyles } = createUnistyles(breakpoints)
|
79
|
+
const { result } = renderHook(() => useStyles())
|
80
|
+
|
81
|
+
expect(result.current.styles).toEqual({})
|
82
|
+
expect(result.current.theme).toEqual({})
|
83
|
+
})
|
84
|
+
|
85
|
+
it ('should choose single value from breakpoints', () => {
|
86
|
+
const breakpoints = {
|
87
|
+
xs: 0,
|
88
|
+
sm: 200,
|
89
|
+
md: 500,
|
90
|
+
lg: 1000
|
91
|
+
}
|
92
|
+
|
93
|
+
const { useStyles, createStyleSheet } = createUnistyles(breakpoints)
|
94
|
+
const stylesheet = createStyleSheet({
|
95
|
+
container: {
|
96
|
+
flex: 1,
|
97
|
+
justifyContent: 'center',
|
98
|
+
alignItems: {
|
99
|
+
xs: 'row',
|
100
|
+
md: 'column'
|
101
|
+
}
|
102
|
+
}
|
103
|
+
})
|
104
|
+
const { result } = renderHook(() => useStyles(stylesheet))
|
105
|
+
|
106
|
+
expect(result.current.styles.container.alignItems).toEqual('column')
|
107
|
+
})
|
108
|
+
|
109
|
+
it ('should choose single value from media queries', () => {
|
110
|
+
const breakpoints = {
|
111
|
+
xs: 0
|
112
|
+
}
|
113
|
+
|
114
|
+
const { useStyles, createStyleSheet } = createUnistyles(breakpoints)
|
115
|
+
const stylesheet = createStyleSheet({
|
116
|
+
container: {
|
117
|
+
flex: 1,
|
118
|
+
justifyContent: 'center',
|
119
|
+
alignItems: {
|
120
|
+
xs: 'row',
|
121
|
+
':w[300, 490]': 'column',
|
122
|
+
':w[491]': 'row'
|
123
|
+
}
|
124
|
+
}
|
125
|
+
})
|
126
|
+
const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>))
|
127
|
+
|
128
|
+
expect(result.current.styles.container.alignItems).toEqual('row')
|
129
|
+
})
|
130
|
+
|
131
|
+
it ('should choose wrap dynamic functions in Proxy', () => {
|
132
|
+
const breakpoints = {
|
133
|
+
xs: 0
|
134
|
+
}
|
135
|
+
|
136
|
+
const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, {}>(breakpoints)
|
137
|
+
const stylesheet = createStyleSheet({
|
138
|
+
container: (flex: number) => ({
|
139
|
+
flex,
|
140
|
+
justifyContent: 'center',
|
141
|
+
alignItems: {
|
142
|
+
xs: 'row',
|
143
|
+
':w[300, 490]': 'column',
|
144
|
+
':w[491]': 'row'
|
145
|
+
}
|
146
|
+
})
|
147
|
+
})
|
148
|
+
const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>))
|
149
|
+
|
150
|
+
expect(result.current.styles.container).toBeInstanceOf(Function)
|
151
|
+
expect((result.current.styles.container as (flex: number) => ViewStyle)(2)).toEqual({
|
152
|
+
flex: 2,
|
153
|
+
justifyContent: 'center',
|
154
|
+
alignItems: 'row'
|
155
|
+
})
|
156
|
+
})
|
157
|
+
})
|
158
|
+
})
|
package/src/createUnistyles.ts
CHANGED
@@ -18,16 +18,6 @@ export const createUnistyles = <B extends Breakpoints, T = {}>(breakpoints: B) =
|
|
18
18
|
.entries(sortedBreakpoints) as SortedBreakpointEntries<B>
|
19
19
|
|
20
20
|
return {
|
21
|
-
/**
|
22
|
-
* @deprecated The method should not be used, proposed version by the community is createStyleSheet, will be removed in RC
|
23
|
-
*/
|
24
|
-
createStyles: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
|
25
|
-
if (typeof styles === 'function') {
|
26
|
-
return styles as X
|
27
|
-
}
|
28
|
-
|
29
|
-
return styles as S
|
30
|
-
},
|
31
21
|
createStyleSheet: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
|
32
22
|
if (typeof styles === 'function') {
|
33
23
|
return styles as X
|
package/src/utils/index.ts
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
export { normalizeStyles } from './normalizeStyles'
|
2
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints } from './breakpoints'
|
2
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints'
|
3
3
|
export { proxifyFunction, parseStyle } from './styles'
|
4
|
+
export {
|
5
|
+
extractValues,
|
6
|
+
getKeyForCustomMediaQuery,
|
7
|
+
isMediaQuery,
|
8
|
+
isWithinTheHeight,
|
9
|
+
isWithinTheWidth,
|
10
|
+
isWithinTheWidthAndHeight
|
11
|
+
} from './mediaQueries'
|
@@ -1,154 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _breakpoints = require("./breakpoints");
|
4
|
-
describe('breakpoints', () => {
|
5
|
-
describe('sortAndValidateBreakpoints', () => {
|
6
|
-
it('should throw error for empty breakpoints', () => {
|
7
|
-
const breakpoints = {};
|
8
|
-
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
9
|
-
});
|
10
|
-
it('should throw error for breakpoints that don\'t start with 0', () => {
|
11
|
-
const breakpoints = {
|
12
|
-
sm: -1
|
13
|
-
};
|
14
|
-
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
15
|
-
});
|
16
|
-
it('should return same order for sorted elements', () => {
|
17
|
-
const breakpoints = {
|
18
|
-
sm: 0,
|
19
|
-
md: 200,
|
20
|
-
lg: 300,
|
21
|
-
xl: 500
|
22
|
-
};
|
23
|
-
expect((0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toEqual(breakpoints);
|
24
|
-
});
|
25
|
-
it('should sort the order of breakpoints', () => {
|
26
|
-
const breakpoints = {
|
27
|
-
md: 200,
|
28
|
-
sm: 0,
|
29
|
-
lg: 300,
|
30
|
-
xl: 500
|
31
|
-
};
|
32
|
-
expect((0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toEqual({
|
33
|
-
sm: 0,
|
34
|
-
md: 200,
|
35
|
-
lg: 300,
|
36
|
-
xl: 500
|
37
|
-
});
|
38
|
-
});
|
39
|
-
it('should throw errors for duplicated values', () => {
|
40
|
-
const breakpoints = {
|
41
|
-
md: 200,
|
42
|
-
sm: 0,
|
43
|
-
lg: 300,
|
44
|
-
xl: 300
|
45
|
-
};
|
46
|
-
expect(() => (0, _breakpoints.sortAndValidateBreakpoints)(breakpoints)).toThrow();
|
47
|
-
});
|
48
|
-
});
|
49
|
-
describe('getBreakpointFromScreenWidth', () => {
|
50
|
-
it('should return correct breakpoints based on screen width', () => {
|
51
|
-
const breakpoints = {
|
52
|
-
xs: 0,
|
53
|
-
sm: 300,
|
54
|
-
md: 500,
|
55
|
-
xl: 1200
|
56
|
-
};
|
57
|
-
const breakpointPairs = Object.entries(breakpoints);
|
58
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(0, breakpointPairs)).toEqual('xs');
|
59
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(20, breakpointPairs)).toEqual('xs');
|
60
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(100, breakpointPairs)).toEqual('xs');
|
61
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(101, breakpointPairs)).toEqual('xs');
|
62
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(250, breakpointPairs)).toEqual('xs');
|
63
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(300, breakpointPairs)).toEqual('sm');
|
64
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(499, breakpointPairs)).toEqual('sm');
|
65
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(500, breakpointPairs)).toEqual('md');
|
66
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(799, breakpointPairs)).toEqual('md');
|
67
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(1200, breakpointPairs)).toEqual('xl');
|
68
|
-
expect((0, _breakpoints.getBreakpointFromScreenWidth)(2000, breakpointPairs)).toEqual('xl');
|
69
|
-
});
|
70
|
-
});
|
71
|
-
describe('getValueForBreakpoint', () => {
|
72
|
-
it('should prioritize custom media query', () => {
|
73
|
-
const breakpoint = 'sm';
|
74
|
-
const breakpoints = {
|
75
|
-
xs: 0,
|
76
|
-
sm: 200,
|
77
|
-
md: 500
|
78
|
-
};
|
79
|
-
const breakpointPairs = Object.entries(breakpoints);
|
80
|
-
const style = {
|
81
|
-
':w[, 200]': 'green',
|
82
|
-
':w[201]': 'orange',
|
83
|
-
sm: 'pink'
|
84
|
-
};
|
85
|
-
const screenSize = {
|
86
|
-
width: 200,
|
87
|
-
height: 800
|
88
|
-
};
|
89
|
-
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpointPairs)).toEqual('green');
|
90
|
-
});
|
91
|
-
});
|
92
|
-
it('should match breakpoint if media query doesnt exist', () => {
|
93
|
-
const breakpoint = 'md';
|
94
|
-
const breakpoints = {
|
95
|
-
xs: 0,
|
96
|
-
sm: 200,
|
97
|
-
md: 500
|
98
|
-
};
|
99
|
-
const breakpointPairs = Object.entries(breakpoints);
|
100
|
-
const style = {
|
101
|
-
':w[, 200]': 'green',
|
102
|
-
':w[201, 499]': 'orange',
|
103
|
-
sm: 'pink',
|
104
|
-
md: 'red'
|
105
|
-
};
|
106
|
-
const screenSize = {
|
107
|
-
width: 500,
|
108
|
-
height: 1200
|
109
|
-
};
|
110
|
-
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpointPairs)).toEqual('red');
|
111
|
-
});
|
112
|
-
it('should match breakpoint even if value is undefined', () => {
|
113
|
-
const breakpoint = 'md';
|
114
|
-
const breakpoints = {
|
115
|
-
xs: 0,
|
116
|
-
sm: 200,
|
117
|
-
md: 500
|
118
|
-
};
|
119
|
-
const breakpointPairs = Object.entries(breakpoints);
|
120
|
-
const style = {
|
121
|
-
':w[, 200]': 'green',
|
122
|
-
':w[201, 499]': 'orange',
|
123
|
-
sm: 'pink',
|
124
|
-
md: undefined
|
125
|
-
};
|
126
|
-
const screenSize = {
|
127
|
-
width: 500,
|
128
|
-
height: 1200
|
129
|
-
};
|
130
|
-
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpointPairs)).toEqual(undefined);
|
131
|
-
});
|
132
|
-
it('should match lower breakpoint to match css cascading', () => {
|
133
|
-
const breakpoint = 'xl';
|
134
|
-
const breakpoints = {
|
135
|
-
xs: 0,
|
136
|
-
sm: 200,
|
137
|
-
md: 500,
|
138
|
-
xl: 600
|
139
|
-
};
|
140
|
-
const breakpointPairs = Object.entries(breakpoints);
|
141
|
-
const style = {
|
142
|
-
':w[, 200]': 'green',
|
143
|
-
':w[201, 499]': 'orange',
|
144
|
-
sm: 'pink',
|
145
|
-
md: 'red'
|
146
|
-
};
|
147
|
-
const screenSize = {
|
148
|
-
width: 500,
|
149
|
-
height: 1200
|
150
|
-
};
|
151
|
-
expect((0, _breakpoints.getValueForBreakpoint)(style, breakpoint, screenSize, breakpointPairs)).toEqual('red');
|
152
|
-
});
|
153
|
-
});
|
154
|
-
//# sourceMappingURL=breakpoints.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","describe","it","breakpoints","expect","sortAndValidateBreakpoints","toThrow","sm","md","lg","xl","toEqual","xs","breakpointPairs","Object","entries","getBreakpointFromScreenWidth","breakpoint","style","screenSize","width","height","getValueForBreakpoint","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.spec.ts"],"mappings":";;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,aAAa,EAAE,MAAM;EAC1BA,QAAQ,CAAC,4BAA4B,EAAE,MAAM;IACzCC,EAAE,CAAC,0CAA0C,EAAE,MAAM;MACjD,MAAMC,WAAW,GAAG,CAAC,CAAC;MAEtBC,MAAM,CAAC,MAAM,IAAAC,uCAA0B,EAACF,WAAW,CAAC,CAAC,CAACG,OAAO,CAAC,CAAC;IACnE,CAAC,CAAC;IAEFJ,EAAE,CAAC,6DAA6D,EAAE,MAAM;MACpE,MAAMC,WAAW,GAAG;QAChBI,EAAE,EAAE,CAAC;MACT,CAAC;MAEDH,MAAM,CAAC,MAAM,IAAAC,uCAA0B,EAACF,WAAW,CAAC,CAAC,CAACG,OAAO,CAAC,CAAC;IACnE,CAAC,CAAC;IAEFJ,EAAE,CAAC,8CAA8C,EAAE,MAAM;MACrD,MAAMC,WAAW,GAAG;QAChBI,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MAEDN,MAAM,CAAC,IAAAC,uCAA0B,EAACF,WAAW,CAAC,CAAC,CAACQ,OAAO,CAACR,WAAW,CAAC;IACxE,CAAC,CAAC;IAEFD,EAAE,CAAC,sCAAsC,EAAE,MAAM;MAC7C,MAAMC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