@umber-style/react 0.1.0-alpha.2 → 0.1.0-rc.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/dist/styledParts.cjs +6 -5
- package/dist/styledParts.mjs +6 -5
- package/dist/types.d.cts +15 -6
- package/dist/types.d.mts +15 -6
- package/package.json +2 -2
package/dist/styledParts.cjs
CHANGED
|
@@ -5,15 +5,16 @@ const require_domProps = require("./domProps.cjs");
|
|
|
5
5
|
function isStyledComponent(tag) {
|
|
6
6
|
return typeof tag === "function" && "_styles" in tag;
|
|
7
7
|
}
|
|
8
|
-
/** The filter of the props of `element`: the one given, else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop)
|
|
8
|
+
/** The filter of the props of `element`: the one given, whatever the element is; else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop), and none for a component. */
|
|
9
9
|
function readFilter(element, given) {
|
|
10
|
-
if (typeof element !== "string") return
|
|
11
|
-
return
|
|
10
|
+
if (given || typeof element !== "string") return given;
|
|
11
|
+
return element.includes("-") ? void 0 : require_domProps.isDomProp;
|
|
12
12
|
}
|
|
13
13
|
/** What both builds of `styled` share: the styler, and the element and props that a component renders. */
|
|
14
14
|
function prepareStyled(engine, tag, options, styles) {
|
|
15
15
|
const inner = isStyledComponent(tag) ? tag : void 0;
|
|
16
16
|
const baseTag = inner?._tag ?? tag;
|
|
17
|
+
const isTag = typeof baseTag === "string";
|
|
17
18
|
const shouldForward = options.shouldForwardProp ?? inner?._shouldForwardProp;
|
|
18
19
|
const target = [inner?._target, options.target].filter(Boolean).join(" ") || void 0;
|
|
19
20
|
const styler = engine.createStyler(options, styles, inner?._styles);
|
|
@@ -40,10 +41,10 @@ function prepareStyled(engine, tag, options, styles) {
|
|
|
40
41
|
const held = canHold && props.style ? own.getHeldClass(props, extra, theme) : void 0;
|
|
41
42
|
let className = held ? held.className : own.getClassName(props, extra, theme);
|
|
42
43
|
if (target) className = className ? `${className} ${target}` : target;
|
|
43
|
-
const element = props.as ?? baseTag;
|
|
44
|
+
const element = isTag ? props.as ?? baseTag : baseTag;
|
|
44
45
|
const filter = readFilter(element, shouldForward);
|
|
45
46
|
const forwarded = {};
|
|
46
|
-
for (const [key, value] of Object.entries(props)) if (!(key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
|
|
47
|
+
for (const [key, value] of Object.entries(props)) if (!(isTag && key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
|
|
47
48
|
forwarded.className = className || void 0;
|
|
48
49
|
return {
|
|
49
50
|
element,
|
package/dist/styledParts.mjs
CHANGED
|
@@ -5,15 +5,16 @@ import { isDomProp } from "./domProps.mjs";
|
|
|
5
5
|
function isStyledComponent(tag) {
|
|
6
6
|
return typeof tag === "function" && "_styles" in tag;
|
|
7
7
|
}
|
|
8
|
-
/** The filter of the props of `element`: the one given, else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop)
|
|
8
|
+
/** The filter of the props of `element`: the one given, whatever the element is; else for a string tag the attributes of HTML and SVG (a custom element, with a hyphen in its name, receives every prop), and none for a component. */
|
|
9
9
|
function readFilter(element, given) {
|
|
10
|
-
if (typeof element !== "string") return
|
|
11
|
-
return
|
|
10
|
+
if (given || typeof element !== "string") return given;
|
|
11
|
+
return element.includes("-") ? void 0 : isDomProp;
|
|
12
12
|
}
|
|
13
13
|
/** What both builds of `styled` share: the styler, and the element and props that a component renders. */
|
|
14
14
|
function prepareStyled(engine, tag, options, styles) {
|
|
15
15
|
const inner = isStyledComponent(tag) ? tag : void 0;
|
|
16
16
|
const baseTag = inner?._tag ?? tag;
|
|
17
|
+
const isTag = typeof baseTag === "string";
|
|
17
18
|
const shouldForward = options.shouldForwardProp ?? inner?._shouldForwardProp;
|
|
18
19
|
const target = [inner?._target, options.target].filter(Boolean).join(" ") || void 0;
|
|
19
20
|
const styler = engine.createStyler(options, styles, inner?._styles);
|
|
@@ -40,10 +41,10 @@ function prepareStyled(engine, tag, options, styles) {
|
|
|
40
41
|
const held = canHold && props.style ? own.getHeldClass(props, extra, theme) : void 0;
|
|
41
42
|
let className = held ? held.className : own.getClassName(props, extra, theme);
|
|
42
43
|
if (target) className = className ? `${className} ${target}` : target;
|
|
43
|
-
const element = props.as ?? baseTag;
|
|
44
|
+
const element = isTag ? props.as ?? baseTag : baseTag;
|
|
44
45
|
const filter = readFilter(element, shouldForward);
|
|
45
46
|
const forwarded = {};
|
|
46
|
-
for (const [key, value] of Object.entries(props)) if (!(key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
|
|
47
|
+
for (const [key, value] of Object.entries(props)) if (!(isTag && key === "as" || key === "theme" || key === "className" || key === "style") && (!filter || filter(key))) forwarded[key] = value;
|
|
47
48
|
forwarded.className = className || void 0;
|
|
48
49
|
return {
|
|
49
50
|
element,
|
package/dist/types.d.cts
CHANGED
|
@@ -42,10 +42,12 @@ export interface DefaultStyleOptions extends BindingOptions<Theme>, ServerStyleO
|
|
|
42
42
|
*/
|
|
43
43
|
export interface StyledOptions<_Props = unknown> extends StylerOptions {
|
|
44
44
|
/**
|
|
45
|
-
* Whether a prop is forwarded to
|
|
46
|
-
* of HTML and SVG (by their React names), `data-*`,
|
|
47
|
-
* every prop to a custom element (a tag with a
|
|
48
|
-
*
|
|
45
|
+
* Whether a prop is forwarded to the element or component that is rendered. It replaces the default,
|
|
46
|
+
* which forwards to a string tag the attributes of HTML and SVG (by their React names), `data-*`,
|
|
47
|
+
* `aria-*`, event handlers and React's own props, and every prop to a custom element (a tag with a
|
|
48
|
+
* hyphen) and to a component. `theme`, `className` and `style` are the component's own and are never
|
|
49
|
+
* forwarded, and so is `as` where it replaces a string tag; a component that is not made by `styled`
|
|
50
|
+
* is always rendered, and is given `as` as a prop.
|
|
49
51
|
*/
|
|
50
52
|
shouldForwardProp?: (prop: string) => boolean;
|
|
51
53
|
/**
|
|
@@ -60,7 +62,7 @@ export interface StyledOptions<_Props = unknown> extends StylerOptions {
|
|
|
60
62
|
* then takes are only the ones it names, `Forwarded`.
|
|
61
63
|
*/
|
|
62
64
|
export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions<Props> {
|
|
63
|
-
/** A type guard of the props that are forwarded
|
|
65
|
+
/** A type guard of the props that are forwarded: the component takes only the props of the tag that it names. */
|
|
64
66
|
shouldForwardProp?: (prop: string) => prop is Forwarded;
|
|
65
67
|
}
|
|
66
68
|
/** The props of a component or a tag, as an element of it takes them. */
|
|
@@ -86,6 +88,13 @@ export interface StyledStatics {
|
|
|
86
88
|
* an error.
|
|
87
89
|
*/
|
|
88
90
|
export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefined | readonly StyleProp[];
|
|
91
|
+
/**
|
|
92
|
+
* The `as` of a styled component whose tag takes the props `Base`: the type of the tag's own `as` when it
|
|
93
|
+
* has one (a component that is not made by `styled` is given `as` as a prop), else any element type.
|
|
94
|
+
*/
|
|
95
|
+
type AsProp<Base> = Base extends {
|
|
96
|
+
as?: infer As;
|
|
97
|
+
} ? unknown extends As ? ElementType : As : ElementType;
|
|
89
98
|
/**
|
|
90
99
|
* A component made by `styled`: it takes the props of the tag (`Base`: all of them, unless a
|
|
91
100
|
* `shouldForwardProp` type guard named some), its own props `P`, `as` and `style`. As text it is a
|
|
@@ -93,7 +102,7 @@ export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefin
|
|
|
93
102
|
* styles is a function).
|
|
94
103
|
*/
|
|
95
104
|
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & P & {
|
|
96
|
-
as?:
|
|
105
|
+
as?: AsProp<Base>;
|
|
97
106
|
style?: StyleProp;
|
|
98
107
|
}> & StyledStatics;
|
|
99
108
|
/** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
|
package/dist/types.d.mts
CHANGED
|
@@ -42,10 +42,12 @@ export interface DefaultStyleOptions extends BindingOptions<Theme>, ServerStyleO
|
|
|
42
42
|
*/
|
|
43
43
|
export interface StyledOptions<_Props = unknown> extends StylerOptions {
|
|
44
44
|
/**
|
|
45
|
-
* Whether a prop is forwarded to
|
|
46
|
-
* of HTML and SVG (by their React names), `data-*`,
|
|
47
|
-
* every prop to a custom element (a tag with a
|
|
48
|
-
*
|
|
45
|
+
* Whether a prop is forwarded to the element or component that is rendered. It replaces the default,
|
|
46
|
+
* which forwards to a string tag the attributes of HTML and SVG (by their React names), `data-*`,
|
|
47
|
+
* `aria-*`, event handlers and React's own props, and every prop to a custom element (a tag with a
|
|
48
|
+
* hyphen) and to a component. `theme`, `className` and `style` are the component's own and are never
|
|
49
|
+
* forwarded, and so is `as` where it replaces a string tag; a component that is not made by `styled`
|
|
50
|
+
* is always rendered, and is given `as` as a prop.
|
|
49
51
|
*/
|
|
50
52
|
shouldForwardProp?: (prop: string) => boolean;
|
|
51
53
|
/**
|
|
@@ -60,7 +62,7 @@ export interface StyledOptions<_Props = unknown> extends StylerOptions {
|
|
|
60
62
|
* then takes are only the ones it names, `Forwarded`.
|
|
61
63
|
*/
|
|
62
64
|
export interface FilteringStyledOptions<Props = Record<string, unknown>, Forwarded extends keyof Props & string = keyof Props & string> extends StyledOptions<Props> {
|
|
63
|
-
/** A type guard of the props that are forwarded
|
|
65
|
+
/** A type guard of the props that are forwarded: the component takes only the props of the tag that it names. */
|
|
64
66
|
shouldForwardProp?: (prop: string) => prop is Forwarded;
|
|
65
67
|
}
|
|
66
68
|
/** The props of a component or a tag, as an element of it takes them. */
|
|
@@ -86,6 +88,13 @@ export interface StyledStatics {
|
|
|
86
88
|
* an error.
|
|
87
89
|
*/
|
|
88
90
|
export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefined | readonly StyleProp[];
|
|
91
|
+
/**
|
|
92
|
+
* The `as` of a styled component whose tag takes the props `Base`: the type of the tag's own `as` when it
|
|
93
|
+
* has one (a component that is not made by `styled` is given `as` as a prop), else any element type.
|
|
94
|
+
*/
|
|
95
|
+
type AsProp<Base> = Base extends {
|
|
96
|
+
as?: infer As;
|
|
97
|
+
} ? unknown extends As ? ElementType : As : ElementType;
|
|
89
98
|
/**
|
|
90
99
|
* A component made by `styled`: it takes the props of the tag (`Base`: all of them, unless a
|
|
91
100
|
* `shouldForwardProp` type guard named some), its own props `P`, `as` and `style`. As text it is a
|
|
@@ -93,7 +102,7 @@ export type StyleProp = SheetEntry$1 | WebStyleObject$1 | false | null | undefin
|
|
|
93
102
|
* styles is a function).
|
|
94
103
|
*/
|
|
95
104
|
export type StyledComponent<C extends ElementType, P extends object, Base extends object = ComponentProps<C>> = FunctionComponent<Omit<Base, keyof P | 'as' | 'style'> & P & {
|
|
96
|
-
as?:
|
|
105
|
+
as?: AsProp<Base>;
|
|
97
106
|
style?: StyleProp;
|
|
98
107
|
}> & StyledStatics;
|
|
99
108
|
/** The props that a function style reads: the props of the tag `Base`, with the component's own `P` over them. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umber-style/react",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-rc.0",
|
|
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,7 +54,7 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@umber-style/core": "0.1.0-
|
|
57
|
+
"@umber-style/core": "0.1.0-rc.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^19.2.8"
|