@pyreon/rocketstyle 0.11.4 → 0.11.6
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 +32 -32
- package/lib/index.d.ts +25 -6
- package/lib/index.js +85 -72
- package/package.json +25 -24
- package/src/__tests__/attrs.test.ts +49 -49
- package/src/__tests__/chaining.test.ts +27 -27
- package/src/__tests__/collection.test.ts +12 -12
- package/src/__tests__/compose.test.ts +10 -10
- package/src/__tests__/context.test.ts +65 -65
- package/src/__tests__/createLocalProvider.test.ts +53 -53
- package/src/__tests__/dimensions.test.ts +54 -54
- package/src/__tests__/e2e-styler.test.ts +78 -136
- package/src/__tests__/hooks.test.ts +41 -70
- package/src/__tests__/isRocketComponent.test.ts +11 -11
- package/src/__tests__/misc.test.ts +91 -91
- package/src/__tests__/providerConsumer.test.ts +54 -126
- package/src/__tests__/rocketstyleIntegration.test.ts +180 -253
- package/src/__tests__/themeUtils.test.ts +173 -173
- package/src/cache/index.ts +1 -1
- package/src/constants/booleanTags.ts +25 -25
- package/src/constants/defaultDimensions.ts +5 -5
- package/src/constants/index.ts +16 -16
- package/src/context/context.ts +13 -10
- package/src/context/createLocalProvider.ts +22 -12
- package/src/context/localContext.ts +2 -2
- package/src/hoc/index.ts +1 -1
- package/src/hoc/rocketstyleAttrsHoc.ts +12 -9
- package/src/hooks/index.ts +2 -2
- package/src/hooks/usePseudoState.ts +3 -3
- package/src/hooks/useTheme.ts +14 -17
- package/src/index.ts +32 -15
- package/src/init.ts +12 -12
- package/src/isRocketComponent.ts +2 -2
- package/src/rocketstyle.ts +103 -109
- package/src/types/attrs.ts +2 -2
- package/src/types/config.ts +4 -4
- package/src/types/configuration.ts +5 -5
- package/src/types/dimensions.ts +5 -5
- package/src/types/hoc.ts +1 -1
- package/src/types/rocketComponent.ts +4 -4
- package/src/types/rocketstyle.ts +10 -10
- package/src/types/styles.ts +9 -4
- package/src/types/theme.ts +4 -4
- package/src/types/utils.ts +1 -1
- package/src/utils/attrs.ts +2 -2
- package/src/utils/chaining.ts +2 -2
- package/src/utils/compose.ts +1 -1
- package/src/utils/dimensions.ts +6 -6
- package/src/utils/statics.ts +2 -2
- package/src/utils/styles.ts +2 -2
- package/src/utils/theme.ts +10 -10
|
@@ -1,50 +1,17 @@
|
|
|
1
|
-
import { popContext, pushContext } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const mockCss = (_strings: any, ..._args: any[]) => ""
|
|
13
|
-
|
|
14
|
-
const originalStyled = config.styled
|
|
15
|
-
const originalCss = config.css
|
|
16
|
-
|
|
1
|
+
import { popContext, pushContext } from '@pyreon/core'
|
|
2
|
+
import {
|
|
3
|
+
BaseComponent,
|
|
4
|
+
buildThemeContextMap,
|
|
5
|
+
initTestConfig,
|
|
6
|
+
withThemeContext,
|
|
7
|
+
} from '@pyreon/test-utils'
|
|
8
|
+
import rocketstyle from '../init'
|
|
9
|
+
|
|
10
|
+
let cleanup: () => void
|
|
17
11
|
beforeAll(() => {
|
|
18
|
-
|
|
19
|
-
css: mockCss as any,
|
|
20
|
-
styled: mockStyled as any,
|
|
21
|
-
component: "div",
|
|
22
|
-
textComponent: "span",
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterAll(() => {
|
|
27
|
-
config.styled = originalStyled
|
|
28
|
-
config.css = originalCss
|
|
12
|
+
cleanup = initTestConfig()
|
|
29
13
|
})
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Base component that exposes internal props for testing.
|
|
33
|
-
* In Pyreon, components are plain functions — no forwardRef needed.
|
|
34
|
-
*/
|
|
35
|
-
const BaseComponent: any = ({ children, $rocketstyle, $rocketstate, ...rest }: any) => ({
|
|
36
|
-
type: "div",
|
|
37
|
-
props: {
|
|
38
|
-
...rest,
|
|
39
|
-
"data-hover": String($rocketstate?.pseudo?.hover ?? "none"),
|
|
40
|
-
"data-focus": String($rocketstate?.pseudo?.focus ?? "none"),
|
|
41
|
-
"data-pressed": String($rocketstate?.pseudo?.pressed ?? "none"),
|
|
42
|
-
},
|
|
43
|
-
children,
|
|
44
|
-
$rocketstyle,
|
|
45
|
-
$rocketstate,
|
|
46
|
-
})
|
|
47
|
-
BaseComponent.displayName = "BaseComponent"
|
|
14
|
+
afterAll(() => cleanup())
|
|
48
15
|
|
|
49
16
|
/** Child component that reads consumer context */
|
|
50
17
|
const ChildComponent: any = ({
|
|
@@ -54,123 +21,94 @@ const ChildComponent: any = ({
|
|
|
54
21
|
parentHover,
|
|
55
22
|
...rest
|
|
56
23
|
}: any) => ({
|
|
57
|
-
type:
|
|
58
|
-
props: { ...rest,
|
|
24
|
+
type: 'div',
|
|
25
|
+
props: { ...rest, 'data-parent-hover': parentHover ?? 'none' },
|
|
59
26
|
children,
|
|
60
27
|
})
|
|
61
|
-
ChildComponent.displayName =
|
|
62
|
-
|
|
63
|
-
/** Unwrap reactive accessors (EnhancedComponent returns a function for mode switching). */
|
|
64
|
-
const unwrap = (val: any): any => {
|
|
65
|
-
let result = val
|
|
66
|
-
while (typeof result === "function" && !result.IS_ROCKETSTYLE) result = result()
|
|
67
|
-
return result
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Push a theme context and run fn, then pop */
|
|
71
|
-
const withThemeContext = (fn: () => any) => {
|
|
72
|
-
pushContext(
|
|
73
|
-
new Map([
|
|
74
|
-
[
|
|
75
|
-
context.id,
|
|
76
|
-
{
|
|
77
|
-
theme: { rootSize: 16 },
|
|
78
|
-
mode: "light",
|
|
79
|
-
isDark: false,
|
|
80
|
-
isLight: true,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
]),
|
|
84
|
-
)
|
|
85
|
-
try {
|
|
86
|
-
return fn()
|
|
87
|
-
} finally {
|
|
88
|
-
popContext()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
28
|
+
ChildComponent.displayName = 'ChildComponent'
|
|
91
29
|
|
|
92
30
|
// --------------------------------------------------------
|
|
93
31
|
// Provider/Consumer integration
|
|
94
32
|
// --------------------------------------------------------
|
|
95
|
-
describe(
|
|
96
|
-
describe(
|
|
97
|
-
it(
|
|
33
|
+
describe('Provider/Consumer integration', () => {
|
|
34
|
+
describe('provider component', () => {
|
|
35
|
+
it('renders with provider: true', () => {
|
|
98
36
|
const ParentButton: any = rocketstyle()({
|
|
99
|
-
name:
|
|
37
|
+
name: 'ProviderButton',
|
|
100
38
|
component: BaseComponent,
|
|
101
39
|
}).config({ provider: true })
|
|
102
40
|
|
|
103
|
-
const result = withThemeContext(() => ParentButton({ children:
|
|
41
|
+
const result = withThemeContext(() => ParentButton({ children: 'Child' }))
|
|
104
42
|
expect(result).toBeDefined()
|
|
105
43
|
})
|
|
106
44
|
|
|
107
|
-
it(
|
|
45
|
+
it('detects pseudo-state via $rocketstate on provider', () => {
|
|
108
46
|
const ParentButton: any = rocketstyle()({
|
|
109
|
-
name:
|
|
47
|
+
name: 'HoverProvider',
|
|
110
48
|
component: BaseComponent,
|
|
111
49
|
}).config({ provider: true })
|
|
112
50
|
|
|
113
|
-
const result = withThemeContext(() =>
|
|
51
|
+
const result = withThemeContext(() => ParentButton({ children: 'Child' }))
|
|
114
52
|
// Provider wraps with createLocalProvider which injects pseudo state
|
|
115
53
|
// Initial state should be false
|
|
116
|
-
expect(result.props[
|
|
117
|
-
expect(result.props[
|
|
118
|
-
expect(result.props[
|
|
54
|
+
expect(result.props['data-hover']).toBe('false')
|
|
55
|
+
expect(result.props['data-focus']).toBe('false')
|
|
56
|
+
expect(result.props['data-pressed']).toBe('false')
|
|
119
57
|
})
|
|
120
58
|
})
|
|
121
59
|
|
|
122
|
-
describe(
|
|
123
|
-
it(
|
|
60
|
+
describe('consumer component', () => {
|
|
61
|
+
it('consumer receives pseudo-state from provider context', () => {
|
|
124
62
|
const Parent: any = rocketstyle()({
|
|
125
|
-
name:
|
|
63
|
+
name: 'ParentProvider',
|
|
126
64
|
component: BaseComponent,
|
|
127
65
|
}).config({ provider: true })
|
|
128
66
|
|
|
129
67
|
const Child: any = rocketstyle()({
|
|
130
|
-
name:
|
|
68
|
+
name: 'ChildConsumer',
|
|
131
69
|
component: ChildComponent,
|
|
132
70
|
}).config({
|
|
133
71
|
consumer: (ctx: any) =>
|
|
134
72
|
ctx((rawCtx: any) => ({
|
|
135
|
-
parentHover: rawCtx?.pseudo?.hover ?
|
|
73
|
+
parentHover: rawCtx?.pseudo?.hover ? 'yes' : 'no',
|
|
136
74
|
})),
|
|
137
75
|
})
|
|
138
76
|
|
|
139
77
|
// Render parent, then render child within the same context
|
|
140
78
|
withThemeContext(() => {
|
|
141
|
-
const _parentResult =
|
|
79
|
+
const _parentResult = Parent({ children: null })
|
|
142
80
|
// The parent pushes local context — child should see it
|
|
143
|
-
const childResult =
|
|
81
|
+
const childResult = Child({})
|
|
144
82
|
expect(childResult).toBeDefined()
|
|
145
83
|
const childProps = childResult?.props ?? childResult
|
|
146
|
-
expect(childProps[
|
|
84
|
+
expect(childProps['data-parent-hover']).toBe('no')
|
|
147
85
|
})
|
|
148
86
|
})
|
|
149
87
|
|
|
150
|
-
it(
|
|
88
|
+
it('consumer without provider returns default pseudo', () => {
|
|
151
89
|
const Child: any = rocketstyle()({
|
|
152
|
-
name:
|
|
90
|
+
name: 'OrphanConsumer',
|
|
153
91
|
component: ChildComponent,
|
|
154
92
|
}).config({
|
|
155
93
|
consumer: (ctx: any) =>
|
|
156
94
|
ctx((rawCtx: any) => ({
|
|
157
|
-
parentHover: rawCtx?.pseudo?.hover ?
|
|
95
|
+
parentHover: rawCtx?.pseudo?.hover ? 'yes' : 'no',
|
|
158
96
|
})),
|
|
159
97
|
})
|
|
160
98
|
|
|
161
|
-
const result = withThemeContext(() =>
|
|
99
|
+
const result = withThemeContext(() => Child({}))
|
|
162
100
|
const props = result?.props ?? result
|
|
163
|
-
expect(props[
|
|
101
|
+
expect(props['data-parent-hover']).toBe('no')
|
|
164
102
|
})
|
|
165
103
|
|
|
166
|
-
it(
|
|
104
|
+
it('component without consumer ignores provider context', () => {
|
|
167
105
|
const Parent: any = rocketstyle()({
|
|
168
|
-
name:
|
|
106
|
+
name: 'IgnoredProvider',
|
|
169
107
|
component: BaseComponent,
|
|
170
108
|
}).config({ provider: true })
|
|
171
109
|
|
|
172
110
|
const Child: any = rocketstyle()({
|
|
173
|
-
name:
|
|
111
|
+
name: 'NoConsumer',
|
|
174
112
|
component: BaseComponent,
|
|
175
113
|
}).config({})
|
|
176
114
|
|
|
@@ -182,10 +120,10 @@ describe("Provider/Consumer integration", () => {
|
|
|
182
120
|
})
|
|
183
121
|
})
|
|
184
122
|
|
|
185
|
-
describe(
|
|
186
|
-
it(
|
|
123
|
+
describe('theme mode', () => {
|
|
124
|
+
it('light mode is default', () => {
|
|
187
125
|
const Button: any = rocketstyle()({
|
|
188
|
-
name:
|
|
126
|
+
name: 'LightButton',
|
|
189
127
|
component: BaseComponent,
|
|
190
128
|
}).config({})
|
|
191
129
|
|
|
@@ -193,24 +131,14 @@ describe("Provider/Consumer integration", () => {
|
|
|
193
131
|
expect(result).toBeDefined()
|
|
194
132
|
})
|
|
195
133
|
|
|
196
|
-
it(
|
|
134
|
+
it('dark mode is passed through Provider', () => {
|
|
197
135
|
const Button: any = rocketstyle()({
|
|
198
|
-
name:
|
|
136
|
+
name: 'DarkButton',
|
|
199
137
|
component: BaseComponent,
|
|
200
138
|
}).config({})
|
|
201
139
|
|
|
202
140
|
pushContext(
|
|
203
|
-
|
|
204
|
-
[
|
|
205
|
-
context.id,
|
|
206
|
-
{
|
|
207
|
-
theme: { rootSize: 16 },
|
|
208
|
-
mode: "dark",
|
|
209
|
-
isDark: true,
|
|
210
|
-
isLight: false,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
]),
|
|
141
|
+
buildThemeContextMap({ mode: 'dark', isDark: true, isLight: false }),
|
|
214
142
|
)
|
|
215
143
|
try {
|
|
216
144
|
const result = Button({})
|
|
@@ -220,9 +148,9 @@ describe("Provider/Consumer integration", () => {
|
|
|
220
148
|
}
|
|
221
149
|
})
|
|
222
150
|
|
|
223
|
-
it(
|
|
151
|
+
it('inversed config flips the mode', () => {
|
|
224
152
|
const Button: any = rocketstyle()({
|
|
225
|
-
name:
|
|
153
|
+
name: 'InversedButton',
|
|
226
154
|
component: BaseComponent,
|
|
227
155
|
}).config({ inversed: true })
|
|
228
156
|
|
|
@@ -231,15 +159,15 @@ describe("Provider/Consumer integration", () => {
|
|
|
231
159
|
})
|
|
232
160
|
})
|
|
233
161
|
|
|
234
|
-
describe(
|
|
235
|
-
it(
|
|
162
|
+
describe('nested providers', () => {
|
|
163
|
+
it('supports nested provider components', () => {
|
|
236
164
|
const Outer: any = rocketstyle()({
|
|
237
|
-
name:
|
|
165
|
+
name: 'OuterProvider',
|
|
238
166
|
component: BaseComponent,
|
|
239
167
|
}).config({ provider: true })
|
|
240
168
|
|
|
241
169
|
const Inner: any = rocketstyle()({
|
|
242
|
-
name:
|
|
170
|
+
name: 'InnerProvider',
|
|
243
171
|
component: BaseComponent,
|
|
244
172
|
}).config({ provider: true })
|
|
245
173
|
|