@umber-style/react 0.1.0-alpha.0 → 0.1.0-alpha.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/dist/CacheProvider.cjs +23 -0
- package/dist/CacheProvider.d.cts +10 -0
- package/dist/CacheProvider.d.mts +11 -0
- package/dist/CacheProvider.mjs +22 -0
- package/dist/Global.cjs +52 -0
- package/dist/Global.mjs +52 -0
- package/dist/Global.server.cjs +27 -0
- package/dist/Global.server.mjs +27 -0
- package/dist/GlobalRelease.cjs +32 -0
- package/dist/GlobalRelease.mjs +30 -0
- package/dist/ProviderScope.cjs +201 -0
- package/dist/ProviderScope.d.cts +14 -0
- package/dist/ProviderScope.d.mts +15 -0
- package/dist/ProviderScope.mjs +190 -0
- package/dist/ThemeProvider.cjs +94 -27
- package/dist/ThemeProvider.mjs +95 -28
- package/dist/ThemeProvider.server.cjs +130 -25
- package/dist/ThemeProvider.server.mjs +131 -26
- package/dist/ThemeValue.cjs +52 -20
- package/dist/ThemeValue.d.cts +3 -0
- package/dist/ThemeValue.d.mts +4 -0
- package/dist/ThemeValue.mjs +53 -23
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/createStyle.cjs +30 -20
- package/dist/createStyle.d.cts +4 -2
- package/dist/createStyle.d.mts +4 -2
- package/dist/createStyle.mjs +32 -22
- package/dist/createStyle.server.cjs +29 -22
- package/dist/createStyle.server.mjs +31 -24
- package/dist/defaultStyle.cjs +27 -3
- package/dist/defaultStyle.d.cts +18 -11
- package/dist/defaultStyle.d.mts +18 -11
- package/dist/defaultStyle.mjs +28 -4
- package/dist/defaultStyle.server.cjs +13 -5
- package/dist/defaultStyle.server.d.cts +16 -11
- package/dist/defaultStyle.server.d.mts +16 -11
- package/dist/defaultStyle.server.mjs +14 -6
- package/dist/domProps.cjs +27 -0
- package/dist/domProps.mjs +27 -0
- package/dist/index.cjs +12 -1
- package/dist/index.d.cts +17 -7
- package/dist/index.d.mts +17 -7
- package/dist/index.mjs +4 -2
- package/dist/index.server.cjs +6 -1
- package/dist/index.server.d.cts +15 -7
- package/dist/index.server.d.mts +15 -7
- package/dist/index.server.mjs +2 -2
- package/dist/plainTheme.cjs +49 -0
- package/dist/plainTheme.mjs +49 -0
- package/dist/serverContext.cjs +6 -24
- package/dist/serverContext.d.mts +0 -1
- package/dist/serverContext.mjs +6 -23
- package/dist/styleElements.cjs +75 -9
- package/dist/styleElements.d.cts +1 -0
- package/dist/styleElements.d.mts +2 -0
- package/dist/styleElements.mjs +73 -10
- package/dist/styled.cjs +32 -11
- package/dist/styled.mjs +33 -12
- package/dist/styled.server.cjs +6 -4
- package/dist/styled.server.mjs +6 -4
- package/dist/styledParts.cjs +36 -6
- package/dist/styledParts.mjs +37 -7
- package/dist/types.d.cts +191 -18
- package/dist/types.d.mts +191 -18
- package/dist/useMediaQuery.cjs +20 -0
- package/dist/useMediaQuery.d.cts +13 -0
- package/dist/useMediaQuery.d.mts +13 -0
- package/dist/useMediaQuery.mjs +20 -0
- package/package.json +3 -3
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentProps, ElementType, FunctionComponent, ReactElement, ReactNode } from "react";
|
|
2
|
-
import { AlphaColor, BindingOptions, Cache, ColorScheme, DeepPartial, Engine, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StyleInput, StyleObject, StylerOptions, Theme, ThemeKey, ThemeKey as ThemeKey$1, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
|
|
1
|
+
import { ComponentProps, Context, ElementType, FunctionComponent, JSX, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { AlphaColor, BindingOptions, CSSObject, Cache, ColorScheme, ComponentSelector, CssArgument, CssArgument as CssArgument$1, DeepPartial, Engine, GlobalInput, GlobalInput as GlobalInput$1, GlobalStyleObject, GlobalStyleObject as GlobalStyleObject$1, GlobalStyles, GlobalStyles as GlobalStyles$1, GlobalStylesInput, Interpolation as Interpolation$1, InterpolationResult, InterpolationResult as InterpolationResult$1, Keyframes, Keyframes as Keyframes$1, KeyframesInput, KeyframesOptions, KeyframesSteps, KeyframesSteps as KeyframesSteps$1, NestedKey, ObjectSheet, SchemeKey, SchemeKey as SchemeKey$1, SchemeName, SchemeName as SchemeName$1, SerializedStyles, SerializedStyles as SerializedStyles$1, SheetEntry, SheetEntry as SheetEntry$1, SheetStyles, StaticTemplateValue, StaticTemplateValue as StaticTemplateValue$1, StyleInput, StyleObject, StylerOptions, TemplateValue, TemplateValue as TemplateValue$1, Theme as Theme$1, ThemeInput, ThemeInput as ThemeInput$1, ThemeKey, ThemeKey as ThemeKey$1, UmberCache, WebNested, WebProperties, WebStyleObject, WebStyleObject as WebStyleObject$1 } from "@umber-style/core";
|
|
3
3
|
/** What only the client build of the React binding takes: it can render the style of its classes on a server. */
|
|
4
4
|
export interface ServerStyleOptions {
|
|
5
5
|
/**
|
|
@@ -12,15 +12,55 @@ export interface ServerStyleOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
hasServerStyleElements?: boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The theme of the default style of this binding: what `styled`, `useTheme`, `StyleSheet` and
|
|
17
|
+
* `ThemeProvider` of the default style read. It extends the core's `Theme`, so an app gives it members
|
|
18
|
+
* from either module: `declare module '@umber-style/react' { interface Theme extends MyTheme {} }` for
|
|
19
|
+
* React alone, or `declare module '@umber-style/core'` for a theme that every binding shares. The
|
|
20
|
+
* optional member below only keeps it from being empty.
|
|
21
|
+
*/
|
|
22
|
+
export interface Theme extends Theme$1 {
|
|
23
|
+
readonly _theme?: never;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A style in any form that `styled` takes: a style object, a `css()` result or a sheet entry, a function
|
|
27
|
+
* of the props and the theme, nothing, or a list of them. The core's `Interpolation`, with this binding's
|
|
28
|
+
* `Theme` unless another is given.
|
|
29
|
+
*/
|
|
30
|
+
export type Interpolation<Props = unknown, T = Theme> = Interpolation$1<Props, T>;
|
|
31
|
+
/** The options of `createStyle(theme, options)`: those of the engine it makes, or the engine to use, and the server options. */
|
|
15
32
|
export interface StyleOptions<T = never> extends BindingOptions<T>, ServerStyleOptions {}
|
|
33
|
+
/** The options of `configure()`: those of `StyleOptions` for the engine of the default style, and its base theme. */
|
|
16
34
|
export interface DefaultStyleOptions extends BindingOptions<Theme>, ServerStyleOptions {
|
|
17
35
|
/** The base theme, for an app that has no provider at all. */
|
|
18
36
|
theme?: Theme;
|
|
19
37
|
}
|
|
38
|
+
/** The options of `styled(tag, options)`: the label of the class, which props reach the element, and a class of your own. */
|
|
20
39
|
export interface StyledOptions extends StylerOptions {
|
|
21
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Whether a prop is forwarded to a string tag. It replaces the default, which forwards the attributes
|
|
42
|
+
* of HTML and SVG (by their React names), `data-*`, `aria-*`, event handlers and React's own props, and
|
|
43
|
+
* every prop to a custom element (a tag with a hyphen). `as`, `theme`, `className` and `style` are the
|
|
44
|
+
* component's own and are never forwarded. A component tag receives every prop but those four.
|
|
45
|
+
*/
|
|
22
46
|
shouldForwardProp?: (prop: string) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* A class name of your own that the element always has, after the engine's classes: a stable name
|
|
49
|
+
* that a parent's selector or a test can find. It is not a style and has no rule. A component that
|
|
50
|
+
* wraps this one keeps it, and adds its own.
|
|
51
|
+
*/
|
|
52
|
+
target?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `StyledOptions` whose `shouldForwardProp` is a type guard: the props of the tag that a styled component
|
|
56
|
+
* then takes are only the ones it names, `Forwarded`.
|
|
57
|
+
*/
|
|
58
|
+
export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions {
|
|
59
|
+
/** A type guard of the props that are forwarded to a string tag: the component takes only the props of the tag that it names. */
|
|
60
|
+
shouldForwardProp?: (prop: string) => prop is Forwarded;
|
|
23
61
|
}
|
|
62
|
+
/** The props of a component or a tag, as an element of it takes them. */
|
|
63
|
+
export type PropsOf<C extends ElementType> = JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
|
|
24
64
|
/** What a styled component keeps, so that styling it again flattens into one element. */
|
|
25
65
|
export interface StyledStatics {
|
|
26
66
|
/** Every style of the component, the styles of the components it wraps first. */
|
|
@@ -28,43 +68,118 @@ export interface StyledStatics {
|
|
|
28
68
|
/** The tag or component that is finally rendered. */
|
|
29
69
|
_tag: ElementType;
|
|
30
70
|
_shouldForwardProp?: (prop: string) => boolean;
|
|
71
|
+
/** The `target` classes of the component and of the components it wraps. */
|
|
72
|
+
_target?: string;
|
|
73
|
+
/** The component as a selector: `.` and a class that every element of it has. Throws when it has none. */
|
|
74
|
+
toString(): string;
|
|
31
75
|
}
|
|
32
76
|
/**
|
|
33
77
|
* What the `style` prop of a styled component takes on the web: sheet entries and plain style
|
|
34
78
|
* objects, in arrays, with falsy values dropped. Nothing is rendered as a style attribute: all of it
|
|
35
79
|
* is merged, in order, into the one class of the element, after its own styles and before
|
|
36
|
-
* `className`.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
80
|
+
* `className`. In the browser, a class made with a plain object is removed once no element uses it, so
|
|
81
|
+
* a value that changes often leaves no class behind; each new value still writes a rule. A string is
|
|
82
|
+
* an error.
|
|
39
83
|
*/
|
|
40
84
|
export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefined | readonly StyleProp[];
|
|
41
|
-
|
|
85
|
+
/**
|
|
86
|
+
* A component made by `styled`: it takes the props of the tag (`Base`: all of them, unless a
|
|
87
|
+
* `shouldForwardProp` type guard named some), its own props `P`, `as` and `style`. As text it is a
|
|
88
|
+
* selector: `.` and a class that every element of it has (its `target`, else its class when none of its
|
|
89
|
+
* styles is a function).
|
|
90
|
+
*/
|
|
91
|
+
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & P & {
|
|
42
92
|
as?: ElementType;
|
|
43
93
|
style?: StyleProp;
|
|
44
94
|
}> & StyledStatics;
|
|
45
|
-
|
|
95
|
+
/**
|
|
96
|
+
* What `styled(tag, options)` returns: it takes the styles and makes the component, or is used as a tag,
|
|
97
|
+
* whose template is one style (a function of the props when an interpolation is a function).
|
|
98
|
+
*/
|
|
99
|
+
export interface StyledFactory<T, C extends ElementType, Base extends object = ComponentProps<C>> {
|
|
100
|
+
<P extends object = object>(style: (props: P & {
|
|
101
|
+
theme: T;
|
|
102
|
+
}) => InterpolationResult$1, ...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
|
|
103
|
+
<P extends object = object>(template: TemplateStringsArray, ...values: TemplateValue$1<NoInfer<P>, T>[]): StyledComponent<C, P, Base>;
|
|
104
|
+
<P extends object = object>(...styles: Interpolation<P, T>[]): StyledComponent<C, P, Base>;
|
|
105
|
+
}
|
|
106
|
+
/** The shorthand of each HTML and SVG tag: `styled.div(...styles)` is `styled('div')(...styles)`. */
|
|
107
|
+
export type StyledTags<T> = { readonly [K in keyof JSX.IntrinsicElements]: StyledFactory<T, K>; };
|
|
108
|
+
/** `styled(tag, options)`: with a `shouldForwardProp` type guard, the component takes only the props of `tag` that it names. */
|
|
109
|
+
export interface StyledCall<T> {
|
|
110
|
+
<C extends ElementType, Forwarded extends keyof ComponentProps<C> & string>(tag: C, options: FilteringStyledOptions<ComponentProps<C>, Forwarded> & {
|
|
111
|
+
shouldForwardProp: (prop: string) => prop is Forwarded;
|
|
112
|
+
}): StyledFactory<T, C, Pick<ComponentProps<C>, Forwarded>>;
|
|
113
|
+
<C extends ElementType>(tag: C, options?: StyledOptions): StyledFactory<T, C>;
|
|
114
|
+
}
|
|
115
|
+
/** `styled` of a theme `T`: a call with a tag and options, and the shorthand of each tag. */
|
|
116
|
+
export type Styled<T> = StyledCall<T> & StyledTags<T>;
|
|
117
|
+
/** The type of `styled` itself, with the tag shorthands: `Styled` of this binding's `Theme` unless another is given. */
|
|
118
|
+
export type CreateStyled<T = Theme> = Styled<T>;
|
|
119
|
+
/** `css()`: one style made once and passed around, from styles or from a tagged template. */
|
|
120
|
+
export interface CssFunction {
|
|
121
|
+
(template: TemplateStringsArray, ...values: StaticTemplateValue$1[]): SerializedStyles$1;
|
|
122
|
+
(...styles: CssArgument$1[]): SerializedStyles$1;
|
|
123
|
+
}
|
|
46
124
|
/** A set of named styles; `E` is what one of them becomes: a class name on the web, a style object on React Native. */
|
|
47
125
|
export interface SheetDefinition<S extends SheetStyles, E> {
|
|
48
126
|
/** Never set at run time: it only carries the types. */
|
|
49
127
|
readonly entries?: { [K in keyof S]: E; };
|
|
50
128
|
}
|
|
129
|
+
/** The props of `ThemeProvider`: the theme of the subtree, and on the web its color scheme and wrapper. */
|
|
51
130
|
export interface ThemeProviderProps<T> {
|
|
52
|
-
/**
|
|
53
|
-
|
|
131
|
+
/**
|
|
132
|
+
* The theme, or the part of it that this subtree changes; or a function of the theme above (the base
|
|
133
|
+
* theme, or an empty object, for the outermost provider) that returns it. It is merged over the theme above.
|
|
134
|
+
*/
|
|
135
|
+
readonly theme: ThemeInput$1<T>;
|
|
54
136
|
/** Web only. */
|
|
55
137
|
readonly colorScheme?: ColorScheme;
|
|
56
|
-
/** Web only. */
|
|
138
|
+
/** Web only: a class of the wrapper of a nested provider. */
|
|
57
139
|
readonly className?: string;
|
|
58
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Web only. Renders no element, no class and no rule: the app puts `themeClass(theme)` on an ancestor,
|
|
142
|
+
* usually `<html>`. The theme still reaches the engine and the context. Without it the outermost provider
|
|
143
|
+
* declares its theme on `:root`, and renders no element either.
|
|
144
|
+
*/
|
|
59
145
|
readonly isRoot?: boolean;
|
|
146
|
+
/** The subtree that the theme applies to. */
|
|
60
147
|
readonly children?: ReactNode;
|
|
61
148
|
}
|
|
149
|
+
/** The props of `ThemeScope`. */
|
|
150
|
+
export interface ThemeScopeProps {
|
|
151
|
+
/** The content to wrap in the wrapper of the nearest nested provider: what a portal renders elsewhere. */
|
|
152
|
+
readonly children?: ReactNode;
|
|
153
|
+
}
|
|
154
|
+
/** The props of `CacheProvider`. */
|
|
155
|
+
export interface CacheProviderProps {
|
|
156
|
+
/** The cache of the subtree: one that `createCache` of `@umber-style/cache` (or of the core) made. */
|
|
157
|
+
readonly value: Cache;
|
|
158
|
+
/** The subtree whose rules go to `value`. */
|
|
159
|
+
readonly children?: ReactNode;
|
|
160
|
+
}
|
|
161
|
+
/** The props of `Global`. */
|
|
162
|
+
export interface GlobalProps<T> {
|
|
163
|
+
/**
|
|
164
|
+
* The global styles: a handle that `globalStyles` made, a style object, a function of the theme, or a
|
|
165
|
+
* list of them, written in the order of the list. A function of the theme reads the nearest provider:
|
|
166
|
+
* tokens are references, raw keys (`breakpoints`) are its real values.
|
|
167
|
+
*/
|
|
168
|
+
readonly styles: GlobalInput$1<T>;
|
|
169
|
+
}
|
|
170
|
+
/** The props of `ThemeProvider` on the web: those of every platform, and the element of the wrapper. */
|
|
62
171
|
export interface WebThemeProviderProps<T> extends ThemeProviderProps<T> {
|
|
63
|
-
/** The element
|
|
172
|
+
/** The element of the wrapper of a nested provider. Default 'div'. */
|
|
64
173
|
readonly as?: string;
|
|
65
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* What every platform's styling has, with `E` the entry of a sheet (a class name on the web, a style
|
|
177
|
+
* object on React Native): the exports of the binding of the same names.
|
|
178
|
+
*/
|
|
66
179
|
export interface Style<T, E> {
|
|
180
|
+
/** Makes a styled component from a tag or a component and its styles. */
|
|
67
181
|
styled: Styled<T>;
|
|
182
|
+
/** Makes sheets: named styles, from an object or from a function of the theme. */
|
|
68
183
|
StyleSheet: {
|
|
69
184
|
/** A sheet given as an object is its entries, usable at once, with no hook and no theme. */
|
|
70
185
|
create<K extends string>(styles: ObjectSheet<K>): { readonly [P in K]: E; };
|
|
@@ -74,8 +189,13 @@ export interface Style<T, E> {
|
|
|
74
189
|
/** The entries of a sheet; an object sheet is its own entries and is returned as it is. */
|
|
75
190
|
useStyle<K extends string>(sheet: { readonly [P in K]: E; }): { readonly [P in K]: E; };
|
|
76
191
|
useStyle<S extends SheetStyles>(sheet: SheetDefinition<S, E>): { [K in keyof S]: E; };
|
|
192
|
+
/** Gives the subtree below it its theme, merged over the theme above. */
|
|
77
193
|
ThemeProvider(props: ThemeProviderProps<T>): ReactElement;
|
|
78
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* The real theme values, for JavaScript that needs a number or a name. In a client component: of the
|
|
196
|
+
* nearest provider, else the base theme, else an empty object. In a server component (the server
|
|
197
|
+
* components build): the base theme, the same in every render, else an empty object.
|
|
198
|
+
*/
|
|
79
199
|
useTheme(): T;
|
|
80
200
|
/** The class that declares the variables of `theme`; '' on React Native. */
|
|
81
201
|
themeClass(theme: DeepPartial<T>, colorScheme?: ColorScheme): string;
|
|
@@ -83,19 +203,72 @@ export interface Style<T, E> {
|
|
|
83
203
|
when(theme: DeepPartial<T>, colorScheme?: ColorScheme): ThemeKey$1;
|
|
84
204
|
/** A style key for "the nearest color scheme is this one": the nearest provider given that `colorScheme`, else the system preference. */
|
|
85
205
|
whenScheme(scheme: SchemeName$1): SchemeKey$1;
|
|
206
|
+
/**
|
|
207
|
+
* Registers an animation and returns its name, `<label>-<hash>`, for `animation` or `animationName`.
|
|
208
|
+
* It writes nothing and needs no engine, so a module can call it before `configure()`: the
|
|
209
|
+
* `@keyframes` rule is written once, when a class that uses the name is first written. On React Native
|
|
210
|
+
* it only returns the name.
|
|
211
|
+
*/
|
|
212
|
+
keyframes(steps: (theme: T) => KeyframesSteps$1, options?: KeyframesOptions): Keyframes$1;
|
|
213
|
+
/** As a tag: the steps written as CSS text (`from { ... } to { ... }`); a function among the interpolations is called with `{ theme }`. */
|
|
214
|
+
keyframes(template: TemplateStringsArray, ...values: TemplateValue$1<unknown, T>[]): Keyframes$1;
|
|
215
|
+
keyframes(steps: KeyframesInput<T>, options?: KeyframesOptions): Keyframes$1;
|
|
216
|
+
/** Makes global styles (selectors and at-rules as keys) and returns their handle, for `Global`. It writes nothing and needs no engine. */
|
|
217
|
+
globalStyles(styles: (theme: T) => GlobalStyleObject$1): GlobalStyles$1<T>;
|
|
218
|
+
/** As a tag: the styles written as CSS text (`body { margin: 0; }`); a function among the interpolations is called with `{ theme }`. */
|
|
219
|
+
globalStyles(template: TemplateStringsArray, ...values: TemplateValue$1<unknown, T>[]): GlobalStyles$1<T>;
|
|
220
|
+
globalStyles(styles: GlobalStylesInput<T>): GlobalStyles$1<T>;
|
|
221
|
+
/**
|
|
222
|
+
* Writes global styles into the `global` layer while it is rendered, and renders nothing of its own.
|
|
223
|
+
* In the browser the rules are removed when it unmounts, and replaced when its styles, or what they
|
|
224
|
+
* read of the theme, change. On a server they are written for good, and sent as style elements where
|
|
225
|
+
* the build sends them. Nothing on React Native.
|
|
226
|
+
*/
|
|
227
|
+
Global(props: GlobalProps<T>): ReactElement | null;
|
|
86
228
|
}
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
229
|
+
/**
|
|
230
|
+
* The styling for server components. `useTheme` is a plain function there, not a hook: it returns the base
|
|
231
|
+
* theme. There is no context, and so no `ThemeContext`, `ThemeScope` or `useThemeClass`.
|
|
232
|
+
*/
|
|
233
|
+
export interface ServerStyle<T> extends Omit<WebStyle<T>, 'useTheme' | 'ThemeContext' | 'ThemeScope' | 'useThemeClass'> {
|
|
234
|
+
/**
|
|
235
|
+
* The base theme: the one given to `createStyle(theme)` or `configure({ theme })`, the same in every
|
|
236
|
+
* render, whatever providers render; never the theme of a provider. With none, an empty object, and a
|
|
237
|
+
* warning in development. A component that needs the nearest provider's values is a client component.
|
|
238
|
+
*/
|
|
239
|
+
useTheme(): T;
|
|
240
|
+
/** Another name of `useTheme` in this build. */
|
|
90
241
|
readTheme(): T;
|
|
91
242
|
}
|
|
243
|
+
/** The styling of the client build of the web binding: what `createStyle` returns, and the default style. */
|
|
92
244
|
export interface WebStyle<T> extends Omit<Style<T, SheetEntry$1>, 'ThemeProvider' | 'apply'> {
|
|
93
245
|
/** The props that apply sheet entries (or class names) to a plain element: a class name. */
|
|
94
246
|
apply(...entries: (SheetEntry$1 | string | null | undefined | false)[]): {
|
|
95
247
|
className?: string;
|
|
96
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* One style made once and passed around: style objects, `css()` results and sheet entries (lists too,
|
|
251
|
+
* falsy values dropped) merged in order, the last winning; or, as a tag, the template read as CSS text.
|
|
252
|
+
* It returns a sheet entry: its text is its class name, and it goes in the `style` prop of a styled
|
|
253
|
+
* component, in `apply`, in another `css()`, among the styles of `styled` and under a selector of
|
|
254
|
+
* global styles. Equal styles give the same class. A function is a `TypeError`: there are no props.
|
|
255
|
+
*/
|
|
256
|
+
css: CssFunction;
|
|
257
|
+
/** Gives the subtree below it its theme: the outermost one declares it on `:root`, a nested one renders a wrapper with its theme class. */
|
|
97
258
|
ThemeProvider(props: WebThemeProviderProps<T>): ReactElement;
|
|
259
|
+
/**
|
|
260
|
+
* Renders the wrapper of the nearest nested provider again (the same element and classes) around its
|
|
261
|
+
* children, for content that a portal puts elsewhere in the document; under the outermost provider, or
|
|
262
|
+
* none, its children alone.
|
|
263
|
+
*/
|
|
264
|
+
ThemeScope(props: ThemeScopeProps): ReactElement;
|
|
265
|
+
/** The class string of the wrapper of the nearest nested provider, for an element of your own; undefined under the outermost provider, or none. */
|
|
266
|
+
useThemeClass(): string | undefined;
|
|
267
|
+
/** The context that holds the real theme of the nearest provider (merged over the ones above); undefined with no provider above. */
|
|
268
|
+
ThemeContext: Context<T | undefined>;
|
|
269
|
+
/** The engine that writes the rules of this style. */
|
|
98
270
|
engine: Engine<T>;
|
|
271
|
+
/** The cache of the engine, which holds the rules. */
|
|
99
272
|
cache: Cache;
|
|
100
273
|
}
|
|
101
|
-
export type { AlphaColor, NestedKey, SchemeKey, SchemeName, SheetEntry, StyleObject, ThemeKey, WebNested, WebProperties, WebStyleObject };
|
|
274
|
+
export type { AlphaColor, CSSObject, ComponentSelector, CssArgument, GlobalInput, GlobalStyleObject, GlobalStyles, InterpolationResult, Keyframes, KeyframesSteps, NestedKey, SchemeKey, SchemeName, SerializedStyles, SheetEntry, StaticTemplateValue, StyleObject, TemplateValue, ThemeInput, ThemeKey, UmberCache, WebNested, WebProperties, WebStyleObject };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
let react = require("react");
|
|
3
|
+
// src/useMediaQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether the media query `query` (as `matchMedia` takes it: `(min-width: 600px)`) matches, for what a
|
|
6
|
+
* style cannot do: render one structure or another. The component renders again when the answer
|
|
7
|
+
* changes. On the server, and in the first render of a hydration, it is `defaultMatches` (false unless
|
|
8
|
+
* given), so that the HTML of the server and the hydration agree; the browser's answer follows at once.
|
|
9
|
+
* It uses a hook, so it is not in the server-components build.
|
|
10
|
+
*/
|
|
11
|
+
function useMediaQuery(query, options = {}) {
|
|
12
|
+
const { defaultMatches = false } = options;
|
|
13
|
+
const subscribe = (0, react.useCallback)((onChange) => {
|
|
14
|
+
const list = window.matchMedia(query);
|
|
15
|
+
list.addEventListener("change", onChange);
|
|
16
|
+
return () => list.removeEventListener("change", onChange);
|
|
17
|
+
}, [query]);
|
|
18
|
+
return (0, react.useSyncExternalStore)(subscribe, () => window.matchMedia(query).matches, () => defaultMatches);
|
|
19
|
+
}
|
|
20
|
+
exports.useMediaQuery = useMediaQuery;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The options of `useMediaQuery`. */
|
|
2
|
+
export interface MediaQueryOptions {
|
|
3
|
+
/** The answer on the server and in the first render of a hydration, where there is no window. Default false. */
|
|
4
|
+
defaultMatches?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whether the media query `query` (as `matchMedia` takes it: `(min-width: 600px)`) matches, for what a
|
|
8
|
+
* style cannot do: render one structure or another. The component renders again when the answer
|
|
9
|
+
* changes. On the server, and in the first render of a hydration, it is `defaultMatches` (false unless
|
|
10
|
+
* given), so that the HTML of the server and the hydration agree; the browser's answer follows at once.
|
|
11
|
+
* It uses a hook, so it is not in the server-components build.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useMediaQuery(query: string, options?: MediaQueryOptions): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The options of `useMediaQuery`. */
|
|
2
|
+
export interface MediaQueryOptions {
|
|
3
|
+
/** The answer on the server and in the first render of a hydration, where there is no window. Default false. */
|
|
4
|
+
defaultMatches?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whether the media query `query` (as `matchMedia` takes it: `(min-width: 600px)`) matches, for what a
|
|
8
|
+
* style cannot do: render one structure or another. The component renders again when the answer
|
|
9
|
+
* changes. On the server, and in the first render of a hydration, it is `defaultMatches` (false unless
|
|
10
|
+
* given), so that the HTML of the server and the hydration agree; the browser's answer follows at once.
|
|
11
|
+
* It uses a hook, so it is not in the server-components build.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useMediaQuery(query: string, options?: MediaQueryOptions): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
3
|
+
// src/useMediaQuery.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether the media query `query` (as `matchMedia` takes it: `(min-width: 600px)`) matches, for what a
|
|
6
|
+
* style cannot do: render one structure or another. The component renders again when the answer
|
|
7
|
+
* changes. On the server, and in the first render of a hydration, it is `defaultMatches` (false unless
|
|
8
|
+
* given), so that the HTML of the server and the hydration agree; the browser's answer follows at once.
|
|
9
|
+
* It uses a hook, so it is not in the server-components build.
|
|
10
|
+
*/
|
|
11
|
+
function useMediaQuery(query, options = {}) {
|
|
12
|
+
const { defaultMatches = false } = options;
|
|
13
|
+
const subscribe = useCallback((onChange) => {
|
|
14
|
+
const list = window.matchMedia(query);
|
|
15
|
+
list.addEventListener("change", onChange);
|
|
16
|
+
return () => list.removeEventListener("change", onChange);
|
|
17
|
+
}, [query]);
|
|
18
|
+
return useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => defaultMatches);
|
|
19
|
+
}
|
|
20
|
+
export { useMediaQuery };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umber-style/react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"description": "UmberStyle for React: styled, ThemeProvider, useTheme, StyleSheet, useStyle and apply, with a server build for server components.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"styling",
|
|
@@ -54,12 +54,13 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@umber-style/core": "0.1.0-alpha.
|
|
57
|
+
"@umber-style/core": "0.1.0-alpha.4"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^19.2.8"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"@soroush.tech/bench": "^2.2.3",
|
|
63
64
|
"@emotion/is-prop-valid": "^1.4.0",
|
|
64
65
|
"@soroush.tech/styled-system": "^6.0.1",
|
|
65
66
|
"@testing-library/react": "^16.3.3",
|
|
@@ -76,7 +77,6 @@
|
|
|
76
77
|
"tsdown": "^0.23.7",
|
|
77
78
|
"typescript": "~7.0.2",
|
|
78
79
|
"vitest": "^5.1.0",
|
|
79
|
-
"@umber-bench/shared": "0.1.0",
|
|
80
80
|
"@umber-style/eslint-config": "0.0.0"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|