@stylix/core 4.1.1 → 5.0.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 +4 -4
- package/dist/index.d.ts +317 -0
- package/dist/index.js +1241 -728
- package/dist/index.js.map +1 -1
- package/package.json +37 -45
- package/tsconfig.json +15 -0
- package/dist/module.mjs +0 -866
- package/dist/module.mjs.map +0 -1
- package/dist/types.d.ts +0 -213
- package/dist/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -45,10 +45,10 @@ function App() {
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
The `<StylixProvider>` element can provide
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
The `<StylixProvider>` element can provide media queries and plugins to descendent elements. Each
|
|
49
|
+
`<StylixProvider>` element outputs the CSS for its descendant elements to a `<style>` element that
|
|
50
|
+
it places in your page's `<head>`. This behavior, and a few other configuration options, can be
|
|
51
|
+
customized.
|
|
52
52
|
|
|
53
53
|
### Style your markup with Stylix HTML tags
|
|
54
54
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import * as CSS from 'csstype';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gets the props of a given HTML tag.
|
|
7
|
+
*/
|
|
8
|
+
type HTMLProps<TTag extends keyof React.JSX.IntrinsicElements> = React.JSX.IntrinsicElements[TTag];
|
|
9
|
+
|
|
10
|
+
type CSSProperties = CSS.StandardPropertiesHyphen<number | string> & CSS.VendorPropertiesHyphen<number | string> & CSS.StandardProperties<number | string> & CSS.VendorProperties<number | string>;
|
|
11
|
+
type Override<T, U> = Omit<T, keyof U> & U;
|
|
12
|
+
/**
|
|
13
|
+
* Utility type that extends T1 with T2, T3, T4, overriding any properties that are already defined in previous types.
|
|
14
|
+
*/
|
|
15
|
+
type Extends<T1, T2, T3 = unknown, T4 = unknown> = Override<Override<Override<T1, T2>, T3>, T4>;
|
|
16
|
+
/**
|
|
17
|
+
* An object containing styles.
|
|
18
|
+
*/
|
|
19
|
+
type StylixObject = Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Used to represent any value that can appear within a StylixObject.
|
|
22
|
+
*/
|
|
23
|
+
type StylixStyles = StylixObject | null | undefined | false | StylixStyles[];
|
|
24
|
+
/**
|
|
25
|
+
* Used to represent a value for a CSS prop in a Stylix object.
|
|
26
|
+
* The value can be a single value or an object with keys for different media queries.
|
|
27
|
+
*/
|
|
28
|
+
type StylixValue<T> = T | Record<string, T>;
|
|
29
|
+
/**
|
|
30
|
+
* Used to indicate that a component can accept all Stylix properties, including
|
|
31
|
+
* all standard CSS properties, additional user-defined custom style props, and the $css prop.
|
|
32
|
+
*
|
|
33
|
+
* `TOverrideProps` specifies a type whose properties will override any CSS style props if they conflict.
|
|
34
|
+
* `TExtendsFromProps` specifies a type whose conflicting style properties will be omitted.
|
|
35
|
+
*
|
|
36
|
+
* To allow for HTML element props, use `StylixHTMLProps` instead.
|
|
37
|
+
*/
|
|
38
|
+
type StylixProps<TOverrideProps = unknown, TExtendsFromProps = unknown> = Extends<TExtendsFromProps, {
|
|
39
|
+
/**
|
|
40
|
+
* Additional styles.
|
|
41
|
+
*/
|
|
42
|
+
$css?: StylixStyles;
|
|
43
|
+
} & {
|
|
44
|
+
[key in keyof CSSProperties]?: StylixValue<CSSProperties[key]>;
|
|
45
|
+
} & {
|
|
46
|
+
[key in keyof StylixPropsExtensions]?: StylixValue<key extends keyof StylixPropsExtensions ? StylixPropsExtensions[key] : never>;
|
|
47
|
+
}, TOverrideProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Used to indicate that a component can accept all Stylix properties, including
|
|
50
|
+
* all standard CSS properties, additional user-defined custom style props, and the $css prop,
|
|
51
|
+
* as well as all standard HTML element props for the given tag.
|
|
52
|
+
*
|
|
53
|
+
* For Stylix properties without allowing HTML props, use `StylixProps` instead.
|
|
54
|
+
*
|
|
55
|
+
* Note that some HTML elements have properties that conflict with CSS properties (e.g. `content`, or `width` and `height`
|
|
56
|
+
* on inputs). By default, Stylix always consumes CSS properties as if they were styles, so HTML props are suppressed
|
|
57
|
+
* and style props take precedence. If you need to use a conflicting prop as its original type from the HTML element,
|
|
58
|
+
* consider passing it in the `TOverrideProps` type parameter. E.g.:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* function MyComponent(props: StylixHTMLProps<'input', Pick<HTMLProps<'input'>, 'width'>>) {
|
|
62
|
+
* // props.width is a string, not a CSS value
|
|
63
|
+
* return <input {...props} />;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
type StylixHTMLProps<TTag extends keyof React.JSX.IntrinsicElements, TOverrideProps = unknown, TExtendsFromProps = unknown> = StylixProps<TOverrideProps, HTMLProps<TTag> & TExtendsFromProps>;
|
|
68
|
+
/**
|
|
69
|
+
* Used to allow users to add custom props to Stylix components.
|
|
70
|
+
*
|
|
71
|
+
* E.g.
|
|
72
|
+
* ```ts
|
|
73
|
+
* declare module '@stylix/core' {
|
|
74
|
+
* interface StylixStyleProperties {
|
|
75
|
+
* ...
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
interface StylixPropsExtensions {
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare const customProps: (customProps: Record<string, any>) => StylixPlugin[];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stylix plugin function context object
|
|
87
|
+
*/
|
|
88
|
+
type StylixPluginFunctionContext = StylixPublicContext & {
|
|
89
|
+
className: string | null;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Stylix plugin interface
|
|
93
|
+
*/
|
|
94
|
+
type StylixPlugin = {
|
|
95
|
+
name: string;
|
|
96
|
+
before?: StylixPlugin;
|
|
97
|
+
after?: StylixPlugin;
|
|
98
|
+
atIndex?: number;
|
|
99
|
+
} & ({
|
|
100
|
+
name: string;
|
|
101
|
+
type: 'initialize';
|
|
102
|
+
plugin(ctx: StylixPluginFunctionContext): void;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'processStyles' | 'preprocessStyles';
|
|
105
|
+
plugin(ctx: StylixPluginFunctionContext, styles: StylixStyles): StylixStyles;
|
|
106
|
+
});
|
|
107
|
+
declare const defaultPlugins: StylixPlugin[];
|
|
108
|
+
|
|
109
|
+
type OpaqueMediaStyles = {
|
|
110
|
+
__opaqueMediaStyles: true;
|
|
111
|
+
};
|
|
112
|
+
type StylixMediaValue = {
|
|
113
|
+
[key: string]: OpaqueMediaStyles | StylixMediaValue;
|
|
114
|
+
};
|
|
115
|
+
type StylixMediaFunc = (styles: OpaqueMediaStyles) => StylixMediaValue;
|
|
116
|
+
type StylixMediaDefinition = Record<string, StylixMediaFunc>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Stylix context
|
|
120
|
+
*
|
|
121
|
+
* The <StylixProvider> wrapper represents an "instance" of Stylix - a configuration, set of plugins, and reference to
|
|
122
|
+
* the <style> element where css is output. All nodes contained within a <StylixProvider> element will share this
|
|
123
|
+
* Stylix instance's configuration.
|
|
124
|
+
*
|
|
125
|
+
* See the README for more details.
|
|
126
|
+
*/
|
|
127
|
+
type StylixProviderProps = {
|
|
128
|
+
id?: string;
|
|
129
|
+
devMode?: boolean;
|
|
130
|
+
plugins?: StylixPlugin[] | StylixPlugin[][];
|
|
131
|
+
styleElement?: HTMLStyleElement;
|
|
132
|
+
media?: StylixMediaDefinition;
|
|
133
|
+
ssr?: boolean;
|
|
134
|
+
children: any;
|
|
135
|
+
};
|
|
136
|
+
type StylixContext$1 = {
|
|
137
|
+
id: string;
|
|
138
|
+
devMode: boolean;
|
|
139
|
+
media: StylixMediaDefinition | undefined;
|
|
140
|
+
plugins: StylixPlugin[];
|
|
141
|
+
stylesheet?: CSSStyleSheet;
|
|
142
|
+
styleElement?: HTMLStyleElement;
|
|
143
|
+
styleCollector?: string[];
|
|
144
|
+
styleCounter: number;
|
|
145
|
+
rules: {
|
|
146
|
+
[key: string]: undefined | {
|
|
147
|
+
className: string;
|
|
148
|
+
rules: string[];
|
|
149
|
+
refs: number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
styleProps: Record<string, string>;
|
|
153
|
+
ssr?: boolean;
|
|
154
|
+
cleanupRequest?: number;
|
|
155
|
+
requestApply: boolean;
|
|
156
|
+
classifyProps(props: Record<string, unknown>): [Record<string, unknown>, Record<string, unknown>];
|
|
157
|
+
};
|
|
158
|
+
type StylixPublicContext = Pick<StylixContext$1, 'id' | 'devMode' | 'media' | 'stylesheet' | 'styleElement' | 'styleProps'>;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the current Stylix context.
|
|
161
|
+
*/
|
|
162
|
+
declare function useStylixContext(): StylixContext$1;
|
|
163
|
+
declare function StylixProvider({ id, devMode, plugins, media, styleElement, children, ssr, }: StylixProviderProps): React.ReactElement;
|
|
164
|
+
|
|
165
|
+
declare function StyleElement(props: {
|
|
166
|
+
styles: string[];
|
|
167
|
+
} & Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Accepts a Stylix CSS object and returns a unique className.
|
|
171
|
+
* The styles are registered with the Stylix context and will be applied to the document.
|
|
172
|
+
* If `global` is false, provided styles will be nested within the generated classname.
|
|
173
|
+
* Returns the className if enabled, or an empty string.
|
|
174
|
+
*/
|
|
175
|
+
declare function useStyles(styles: StylixStyles, options?: {
|
|
176
|
+
global?: boolean;
|
|
177
|
+
debugLabel?: string;
|
|
178
|
+
}): string;
|
|
179
|
+
declare function useKeyframes(keyframes: any): string;
|
|
180
|
+
declare function useGlobalStyles(styles: StylixStyles, options?: {
|
|
181
|
+
disabled?: boolean;
|
|
182
|
+
}): string;
|
|
183
|
+
|
|
184
|
+
type MapObjectFunction = (key: string | number, value: any, source: unknown, context: any, mapRecursive: (value: unknown) => unknown) => unknown;
|
|
185
|
+
/**
|
|
186
|
+
* Returns a new object or array, generated by invoking `map` on each key-value pair in `source` and merging the returned value into
|
|
187
|
+
* the result. The return value should be an object or array (to match `source`), or undefined to omit the key-value pair from the result.
|
|
188
|
+
*
|
|
189
|
+
* If `source` is an object, Object.assign() will be used to merge the response into the result object.
|
|
190
|
+
*
|
|
191
|
+
* If `source` is an array, the returned array entries will be pushed onto the result array (i.e. it will be flattened, one level deep).
|
|
192
|
+
*
|
|
193
|
+
* The `map` function will receive the following arguments:
|
|
194
|
+
* - The current key or index
|
|
195
|
+
* - The current value
|
|
196
|
+
* - The current object/array being mapped
|
|
197
|
+
* - A context object. This is a plain object that you can modify as needed. The value will be shallow cloned for each key, and the clone
|
|
198
|
+
* will be passed into the `mapRecursive` method in order to persist it in recursive mapping.
|
|
199
|
+
* - A `mapRecursive` function that can be used to recursively map nested objects or arrays. You can call this by passing the current value,
|
|
200
|
+
* which will run the same mapping function on the value and return the result. If the value is not an object or array, it will just
|
|
201
|
+
* return the value. The mapping function will receive the context object for the current key, and any modifications made to the context
|
|
202
|
+
* object will be persisted into the recursive call. This could be used, for example, to keep track of the current depth of the recursion
|
|
203
|
+
* or the full path of the current value.
|
|
204
|
+
*
|
|
205
|
+
* Example:
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* const value = {
|
|
209
|
+
* ignoreMe: null,
|
|
210
|
+
* string: 'value',
|
|
211
|
+
* object: {
|
|
212
|
+
* a: 1,
|
|
213
|
+
* b: 2,
|
|
214
|
+
* },
|
|
215
|
+
* array: [1, 2, 3, 4],
|
|
216
|
+
* }
|
|
217
|
+
* const result = mapObjectRecursive(value, (key, value, source, context) => {
|
|
218
|
+
* if (key === 'ignoreMe')
|
|
219
|
+
* return undefined; // will omit key from result
|
|
220
|
+
* if (typeof key === 'string' && typeof value === 'string')
|
|
221
|
+
* return { [key]: value + '-mapped' }; // will append '-mapped' to string values
|
|
222
|
+
* if (typeof key === 'string' && typeof value === 'number')
|
|
223
|
+
* return { [key]: value, [`${key}-mapped`]: value * 2 }; // will add a new key with the value doubled
|
|
224
|
+
* if (typeof value === 'object')
|
|
225
|
+
* return { [key]: value }; // will leave object unchanged
|
|
226
|
+
* if (Array.isArray(source) && typeof value === 'number')
|
|
227
|
+
* return [value, value * 2]; // will add the value and the value doubled to the array
|
|
228
|
+
* });
|
|
229
|
+
* // result:
|
|
230
|
+
* // {
|
|
231
|
+
* // string: 'value-mapped',
|
|
232
|
+
* // object: {
|
|
233
|
+
* // a: 1,
|
|
234
|
+
* // 'a-mapped': 2,
|
|
235
|
+
* // b: 2,
|
|
236
|
+
* // 'b-mapped': 4,
|
|
237
|
+
* // },
|
|
238
|
+
* // array: [1, 2, 2, 4, 3, 6, 4, 8],
|
|
239
|
+
* // }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
declare function mapObject<TSource>(source: TSource, map: MapObjectFunction, context?: any): TSource;
|
|
243
|
+
|
|
244
|
+
interface StyleCollector {
|
|
245
|
+
collect: (element: React.ReactElement) => React.ReactElement;
|
|
246
|
+
render: React.FC<React.ComponentProps<'style'>>;
|
|
247
|
+
styles: string[];
|
|
248
|
+
}
|
|
249
|
+
declare const styleCollectorContext: React.Context<string[] | undefined>;
|
|
250
|
+
declare function createStyleCollector(): StyleCollector;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Additional properties on the Stylix ($) component and its html component properties (`<$.div>`, etc).
|
|
254
|
+
*/
|
|
255
|
+
type StylixComponentMeta = {
|
|
256
|
+
displayName?: string;
|
|
257
|
+
__isStylix: true;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Defines the static meta properties and the HTML elements on the `$` object ($.div, $.span, etc).
|
|
261
|
+
*/
|
|
262
|
+
type Stylix$ComponentExtras = StylixComponentMeta & {
|
|
263
|
+
[key in keyof React.JSX.IntrinsicElements]: React.FC<StylixProps<unknown, React.JSX.IntrinsicElements[key]> & {
|
|
264
|
+
htmlContent?: string;
|
|
265
|
+
htmlTranslate?: 'yes' | 'no';
|
|
266
|
+
}>;
|
|
267
|
+
};
|
|
268
|
+
type StylixRenderFn<TProps = any> = (className: string | undefined, props: TProps) => React.ReactNode;
|
|
269
|
+
/**
|
|
270
|
+
* The props for the Stylix ($) component when using the $render prop.
|
|
271
|
+
*/
|
|
272
|
+
type Stylix$renderProp = StylixProps & Record<string, unknown> & {
|
|
273
|
+
$el?: never;
|
|
274
|
+
$render: StylixRenderFn;
|
|
275
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* The props for the Stylix ($) component when using the children render function.
|
|
279
|
+
*/
|
|
280
|
+
type Stylix$childrenProp = StylixProps & Record<string, unknown> & {
|
|
281
|
+
$el?: never;
|
|
282
|
+
$render?: never;
|
|
283
|
+
children: StylixRenderFn;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* The props for the Stylix ($) component when using the $el prop as a component.
|
|
287
|
+
*/
|
|
288
|
+
type Stylix$elAsComponentProp<TComponent extends React.ElementType> = (TComponent extends React.ElementType<infer P> ? StylixProps<object, P> : never) & {
|
|
289
|
+
$el: TComponent;
|
|
290
|
+
$render?: never;
|
|
291
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* The props for the Stylix ($) component when using the $el prop.
|
|
295
|
+
*/
|
|
296
|
+
type Stylix$elAsElementProp = StylixProps & Record<string, unknown> & {
|
|
297
|
+
$render?: never;
|
|
298
|
+
$el: React.ReactElement;
|
|
299
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Props for the Stylix ($) component
|
|
303
|
+
*/
|
|
304
|
+
type Stylix$Props<TComponent extends React.ElementType> = Stylix$elAsComponentProp<TComponent> | Stylix$elAsElementProp | Stylix$renderProp | Stylix$childrenProp;
|
|
305
|
+
/**
|
|
306
|
+
* Type of main Stylix component ($).
|
|
307
|
+
*/
|
|
308
|
+
interface Stylix$Component extends Stylix$ComponentExtras {
|
|
309
|
+
<TComponent extends React.ElementType>(props: Stylix$Props<TComponent>): React.ReactNode;
|
|
310
|
+
}
|
|
311
|
+
declare const Stylix: Stylix$Component;
|
|
312
|
+
|
|
313
|
+
declare function RenderServerStyles(props: Partial<HTMLProps<'style'>>): react_jsx_runtime.JSX.Element;
|
|
314
|
+
|
|
315
|
+
type StylixContext = StylixPublicContext;
|
|
316
|
+
|
|
317
|
+
export { type Extends, type HTMLProps, RenderServerStyles, type StyleCollector, StyleElement, type Stylix$Component, type StylixContext, type StylixHTMLProps, type StylixObject, type StylixPlugin, type StylixPluginFunctionContext, type StylixProps, type StylixPropsExtensions, StylixProvider, type StylixStyles, createStyleCollector, customProps, Stylix as default, defaultPlugins, mapObject, styleCollectorContext, useGlobalStyles, useKeyframes, useStyles, useStylixContext };
|