@stylix/core 6.2.1 → 6.4.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 +140 -280
- package/dist/index.d.ts +95 -61
- package/dist/index.js +276 -195
- package/dist/index.js.map +1 -1
- package/docs/cheatsheet.md +354 -0
- package/docs/patterns.md +754 -0
- package/docs/performance.md +291 -0
- package/docs/philosophy.md +168 -0
- package/package.json +23 -20
- package/tsconfig.json +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { FC, ComponentType } from 'react';
|
|
2
2
|
import * as CSS from 'csstype';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
@@ -9,12 +9,27 @@ type IntrinsicElements = (typeof htmlTags)[number];
|
|
|
9
9
|
*/
|
|
10
10
|
type HTMLProps<TTag extends keyof React.JSX.IntrinsicElements> = React.JSX.IntrinsicElements[TTag];
|
|
11
11
|
|
|
12
|
+
type OpaqueMediaStyles = {
|
|
13
|
+
__opaqueMediaStyles: true;
|
|
14
|
+
};
|
|
15
|
+
type StylixMediaValue = {
|
|
16
|
+
[key: string]: OpaqueMediaStyles | StylixMediaValue;
|
|
17
|
+
};
|
|
18
|
+
type StylixMediaFunc = (styles: OpaqueMediaStyles) => StylixMediaValue;
|
|
19
|
+
type StylixMediaDefinition = Record<string, StylixMediaFunc>;
|
|
20
|
+
|
|
12
21
|
type CSSProperties = CSS.StandardPropertiesHyphen<number | string> & CSS.VendorPropertiesHyphen<number | string> & CSS.StandardProperties<number | string> & CSS.VendorProperties<number | string>;
|
|
13
22
|
type Override<T, U> = Omit<T, keyof U> & U;
|
|
14
23
|
/**
|
|
15
24
|
* Utility type that extends T1 with T2, T3, T4, overriding any properties that are already defined in previous types.
|
|
16
25
|
*/
|
|
17
26
|
type Extends<T1, T2, T3 = unknown, T4 = unknown> = Override<Override<Override<T1, T2>, T3>, T4>;
|
|
27
|
+
/**
|
|
28
|
+
* Any React component or intrinsic element that accepts a className prop.
|
|
29
|
+
*/
|
|
30
|
+
type ClassNameComponent = IntrinsicElements & FC<{
|
|
31
|
+
className?: string;
|
|
32
|
+
}>;
|
|
18
33
|
/**
|
|
19
34
|
* An object containing styles.
|
|
20
35
|
*/
|
|
@@ -27,7 +42,10 @@ type StylixStyles = StylixObject | null | undefined | false | StylixStyles[];
|
|
|
27
42
|
* Represents a value for a CSS prop in a Stylix object.
|
|
28
43
|
* The value can be a single value or an object with keys for different media queries.
|
|
29
44
|
*/
|
|
30
|
-
type StylixValue<T> = T |
|
|
45
|
+
type StylixValue<T> = T | {
|
|
46
|
+
default?: T | undefined;
|
|
47
|
+
[key: string]: T | undefined;
|
|
48
|
+
};
|
|
31
49
|
/**
|
|
32
50
|
* Used to indicate that a component can accept all Stylix properties, including
|
|
33
51
|
* all standard CSS properties, additional user-defined custom style props, and the $css prop.
|
|
@@ -75,6 +93,10 @@ type StylixProps = {
|
|
|
75
93
|
* ```
|
|
76
94
|
*/
|
|
77
95
|
type StylixHTMLProps<TTag extends IntrinsicElements> = Extends<HTMLProps<TTag>, StylixProps>;
|
|
96
|
+
/**
|
|
97
|
+
* Props for any component or HTML tag that can accept Stylix properties in addition to its own.
|
|
98
|
+
*/
|
|
99
|
+
type StylixElementProps<TElement extends ClassNameComponent> = TElement extends IntrinsicElements ? Extends<HTMLProps<TElement>, StylixProps> : TElement extends ComponentType<infer P> ? Extends<P, StylixProps> : never;
|
|
78
100
|
/**
|
|
79
101
|
* Used to allow users to add custom props to Stylix components.
|
|
80
102
|
*
|
|
@@ -90,60 +112,19 @@ type StylixHTMLProps<TTag extends IntrinsicElements> = Extends<HTMLProps<TTag>,
|
|
|
90
112
|
interface StylixPropsExtensions {
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
declare const customProps: (customProps: Record<string, any>) => StylixPlugin[];
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Stylix plugin function context object
|
|
97
|
-
*/
|
|
98
|
-
type StylixPluginFunctionContext = StylixPublicContext & {
|
|
99
|
-
className: string | null;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Stylix plugin interface
|
|
103
|
-
*/
|
|
104
|
-
type StylixPlugin = {
|
|
105
|
-
name: string;
|
|
106
|
-
before?: string;
|
|
107
|
-
after?: string;
|
|
108
|
-
atIndex?: number;
|
|
109
|
-
} & ({
|
|
110
|
-
name: string;
|
|
111
|
-
type: 'initialize';
|
|
112
|
-
plugin(ctx: StylixPluginFunctionContext): void;
|
|
113
|
-
} | {
|
|
114
|
-
type: 'processStyles' | 'preprocessStyles';
|
|
115
|
-
plugin(ctx: StylixPluginFunctionContext, styles: StylixStyles): StylixStyles;
|
|
116
|
-
});
|
|
117
|
-
declare const defaultPlugins: StylixPlugin[];
|
|
118
|
-
|
|
119
|
-
type OpaqueMediaStyles = {
|
|
120
|
-
__opaqueMediaStyles: true;
|
|
121
|
-
};
|
|
122
|
-
type StylixMediaValue = {
|
|
123
|
-
[key: string]: OpaqueMediaStyles | StylixMediaValue;
|
|
124
|
-
};
|
|
125
|
-
type StylixMediaFunc = (styles: OpaqueMediaStyles) => StylixMediaValue;
|
|
126
|
-
type StylixMediaDefinition = Record<string, StylixMediaFunc>;
|
|
127
|
-
|
|
128
115
|
/**
|
|
129
116
|
* Stylix context
|
|
130
117
|
*
|
|
131
|
-
*
|
|
132
|
-
* the <style> element where css is output.
|
|
133
|
-
* Stylix instance's configuration.
|
|
118
|
+
* A Stylix context represents an "instance" of Stylix - a configuration, set of plugins, and reference to
|
|
119
|
+
* the <style> element where css is output.
|
|
134
120
|
*
|
|
135
|
-
*
|
|
121
|
+
* A <StylixProvider> creates a context instance and provides it via React context to its descendent elements.
|
|
122
|
+
* All nodes contained within a <StylixProvider> element will share this context.
|
|
136
123
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
styleElement?: HTMLStyleElement;
|
|
142
|
-
media?: StylixMediaDefinition;
|
|
143
|
-
ssr?: boolean;
|
|
144
|
-
children: any;
|
|
145
|
-
};
|
|
146
|
-
type StylixContext$1 = {
|
|
124
|
+
/**
|
|
125
|
+
* The Stylix context object.
|
|
126
|
+
*/
|
|
127
|
+
type StylixContext = {
|
|
147
128
|
id: string;
|
|
148
129
|
devMode: boolean;
|
|
149
130
|
media: StylixMediaDefinition | undefined;
|
|
@@ -164,20 +145,75 @@ type StylixContext$1 = {
|
|
|
164
145
|
cleanupRequest?: number;
|
|
165
146
|
requestApply: boolean;
|
|
166
147
|
classifyProps(props: Record<string, unknown>): [Record<string, unknown>, Record<string, unknown>];
|
|
148
|
+
styles(styles: StylixStyles, config?: {
|
|
149
|
+
global: boolean;
|
|
150
|
+
}): string;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* React hook that gets the current Stylix context.
|
|
154
|
+
*/
|
|
155
|
+
declare function useStylixContext(): StylixContext;
|
|
156
|
+
/**
|
|
157
|
+
* Props for StylixProvider when passing an existing context.
|
|
158
|
+
*/
|
|
159
|
+
type StylixProviderPropsWithContext = {
|
|
160
|
+
context: StylixContext;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Props for StylixProvider when creating a new context.
|
|
164
|
+
*/
|
|
165
|
+
type StylixProviderPropsWithConfig = {
|
|
166
|
+
id?: string;
|
|
167
|
+
devMode?: boolean;
|
|
168
|
+
plugins?: StylixPlugin[] | StylixPlugin[][];
|
|
169
|
+
styleElement?: HTMLStyleElement;
|
|
170
|
+
media?: StylixMediaDefinition;
|
|
171
|
+
ssr?: boolean;
|
|
172
|
+
children: any;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Props for the StylixProvider component.
|
|
176
|
+
*/
|
|
177
|
+
type StylixProviderProps = StylixProviderPropsWithContext | StylixProviderPropsWithConfig;
|
|
178
|
+
/**
|
|
179
|
+
* StylixProvider component. Provides a Stylix context to its descendent elements.
|
|
180
|
+
* Can either accept an existing context via the `context` prop, or create a new context
|
|
181
|
+
* using the other configuration props.
|
|
182
|
+
*/
|
|
183
|
+
declare function StylixProvider(props: StylixProviderProps): React.ReactElement;
|
|
184
|
+
|
|
185
|
+
declare const customProps: (customProps: Record<string, any>) => StylixPlugin[];
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Stylix plugin function context object
|
|
189
|
+
*/
|
|
190
|
+
type StylixPluginFunctionContext = Pick<StylixContext, 'id' | 'devMode' | 'media' | 'stylesheet' | 'styleElement' | 'styleProps'> & {
|
|
191
|
+
className: string | null;
|
|
167
192
|
};
|
|
168
|
-
type StylixPublicContext = Pick<StylixContext$1, 'id' | 'devMode' | 'media' | 'stylesheet' | 'styleElement' | 'styleProps'>;
|
|
169
193
|
/**
|
|
170
|
-
*
|
|
194
|
+
* Stylix plugin interface
|
|
171
195
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
196
|
+
type StylixPlugin = {
|
|
197
|
+
name: string;
|
|
198
|
+
before?: string;
|
|
199
|
+
after?: string;
|
|
200
|
+
atIndex?: number;
|
|
201
|
+
} & ({
|
|
202
|
+
name: string;
|
|
203
|
+
type: 'initialize';
|
|
204
|
+
plugin(ctx: StylixPluginFunctionContext): void;
|
|
205
|
+
} | {
|
|
206
|
+
type: 'processStyles' | 'preprocessStyles';
|
|
207
|
+
plugin(ctx: StylixPluginFunctionContext, styles: StylixStyles): StylixStyles;
|
|
208
|
+
});
|
|
209
|
+
declare const defaultPlugins: StylixPlugin[];
|
|
210
|
+
|
|
211
|
+
declare function RenderServerStyles(props: Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
174
212
|
|
|
175
213
|
declare function StyleElement(props: {
|
|
176
214
|
styles: string[];
|
|
177
215
|
} & Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
178
216
|
|
|
179
|
-
declare function RenderServerStyles(props: Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
180
|
-
|
|
181
217
|
/**
|
|
182
218
|
* Additional properties on the Stylix ($) component and its html component properties (`<$.div>`, etc).
|
|
183
219
|
*/
|
|
@@ -257,7 +293,7 @@ type ClassName = ClassNamePrimitive | ClassName[] | {
|
|
|
257
293
|
*/
|
|
258
294
|
declare function cx(...args: ClassName[]): string;
|
|
259
295
|
|
|
260
|
-
type ObjectOrArray = Record<string
|
|
296
|
+
type ObjectOrArray = unknown[] & Record<string, unknown>;
|
|
261
297
|
type MapObjectFunction<TContext extends object = object> = (key: string | number, value: unknown, target: ObjectOrArray, context: TContext, mapRecursive: (value: unknown) => ObjectOrArray) => void;
|
|
262
298
|
/**
|
|
263
299
|
* Returns a new object or array, generated by invoking `map` on each key-value pair in `source` and merging the returned value into
|
|
@@ -318,7 +354,5 @@ type MapObjectFunction<TContext extends object = object> = (key: string | number
|
|
|
318
354
|
*/
|
|
319
355
|
declare function mapObject<TSource, TContext extends object>(source: TSource, mapFn: MapObjectFunction<TContext>, context?: TContext): TSource;
|
|
320
356
|
|
|
321
|
-
type StylixContext = StylixPublicContext;
|
|
322
|
-
|
|
323
357
|
export { RenderServerStyles, StyleElement, StylixProvider, createStyleCollector, customProps, cx, Stylix as default, defaultPlugins, mapObject, styleCollectorContext, useGlobalStyles, useKeyframes, useStyles, useStylixContext };
|
|
324
|
-
export type { Extends, HTMLProps, IntrinsicElements, StyleCollector, Stylix$Component, StylixContext, StylixHTMLProps, StylixObject, StylixPlugin, StylixPluginFunctionContext, StylixProps, StylixPropsExtensions, StylixStyles, StylixValue };
|
|
358
|
+
export type { ClassNameComponent, Extends, HTMLProps, IntrinsicElements, StyleCollector, Stylix$Component, StylixContext, StylixElementProps, StylixHTMLProps, StylixObject, StylixPlugin, StylixPluginFunctionContext, StylixProps, StylixPropsExtensions, StylixStyles, StylixValue };
|