@typestyles/react 0.2.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.
@@ -0,0 +1,36 @@
1
+ import { TypeStylesContext, resolveCssPropClass } from './chunk-4BYX2HZ7.js';
2
+ import { useContext } from 'react';
3
+ import { Fragment as Fragment$1, jsx as jsx$1, jsxs as jsxs$1 } from 'react/jsx-runtime';
4
+
5
+ function processCssProp(props, styles) {
6
+ if (props.css == null) {
7
+ return props;
8
+ }
9
+ const { css, className, ...rest } = props;
10
+ const nextProps = {
11
+ ...rest,
12
+ className: resolveCssPropClass(styles.hashClass, css, className)
13
+ };
14
+ return nextProps;
15
+ }
16
+ function wrapJsx(factory, type, props, key) {
17
+ const styles = useContext(TypeStylesContext);
18
+ if (props.css != null && styles == null) {
19
+ throw new Error(
20
+ "[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a `styles` instance. Wrap your app in `<TypeStylesProvider styles={styles}>`, or use the Babel plugin for zero-runtime css props."
21
+ );
22
+ }
23
+ const nextProps = styles ? processCssProp(props, styles) : props;
24
+ return factory(type, nextProps, key);
25
+ }
26
+ var Fragment = Fragment$1;
27
+ function jsx(type, props, key) {
28
+ return wrapJsx(jsx$1, type, props, key);
29
+ }
30
+ function jsxs(type, props, key) {
31
+ return wrapJsx(jsxs$1, type, props, key);
32
+ }
33
+
34
+ export { Fragment, jsx, jsxs };
35
+ //# sourceMappingURL=jsx-runtime.js.map
36
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/jsx-runtime.ts"],"names":["ReactFragment","reactJsx","reactJsxs"],"mappings":";;;;AAMA,SAAS,cAAA,CACP,OACA,MAAA,EACG;AACH,EAAA,IAAI,KAAA,CAAM,OAAO,IAAA,EAAM;AACrB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAE,GAAA,EAAK,SAAA,EAAW,GAAG,MAAK,GAAI,KAAA;AACpC,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,GAAG,IAAA;AAAA,IACH,SAAA,EAAW,mBAAA,CAAoB,MAAA,CAAO,SAAA,EAAW,KAAK,SAAS;AAAA,GACjE;AAEA,EAAA,OAAO,SAAA;AACT;AAEA,SAAS,OAAA,CACP,OAAA,EACA,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,MAAM,MAAA,GAAS,WAAW,iBAAiB,CAAA;AAE3C,EAAA,IAAI,KAAA,CAAM,GAAA,IAAO,IAAA,IAAQ,MAAA,IAAU,IAAA,EAAM;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAEA,EAAA,MAAM,SAAA,GAAY,MAAA,GAAS,cAAA,CAAe,KAAA,EAAO,MAAM,CAAA,GAAK,KAAA;AAC5D,EAAA,OAAO,OAAA,CAAQ,IAAA,EAAM,SAAA,EAAW,GAAG,CAAA;AACrC;AAEO,IAAM,QAAA,GAAWA;AAEjB,SAAS,GAAA,CACd,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,OAAO,OAAA,CAAQC,KAAA,EAAU,IAAA,EAAM,KAAA,EAAO,GAAG,CAAA;AAC3C;AAEO,SAAS,IAAA,CACd,IAAA,EACA,KAAA,EACA,GAAA,EACoB;AACpB,EAAA,OAAO,OAAA,CAAQC,MAAA,EAAW,IAAA,EAAM,KAAA,EAAO,GAAG,CAAA;AAC5C","file":"jsx-runtime.js","sourcesContent":["import { useContext, type ElementType, type ReactNode } from 'react';\nimport { jsx as reactJsx, jsxs as reactJsxs, Fragment as ReactFragment } from 'react/jsx-runtime';\nimport { resolveCssPropClass } from './css-prop';\nimport { TypeStylesContext } from './context';\nimport type { WithCssProp } from './types';\n\nfunction processCssProp<P extends Record<string, unknown>>(\n props: WithCssProp<P>,\n styles: NonNullable<React.ContextType<typeof TypeStylesContext>>,\n): P {\n if (props.css == null) {\n return props as P;\n }\n\n const { css, className, ...rest } = props;\n const nextProps = {\n ...rest,\n className: resolveCssPropClass(styles.hashClass, css, className),\n } as unknown as P;\n\n return nextProps;\n}\n\nfunction wrapJsx<P extends Record<string, unknown>>(\n factory: typeof reactJsx,\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n const styles = useContext(TypeStylesContext);\n\n if (props.css != null && styles == null) {\n throw new Error(\n '[@typestyles/react] The `css` prop requires a `TypeStylesProvider` with a `styles` instance. ' +\n 'Wrap your app in `<TypeStylesProvider styles={styles}>`, or use the Babel plugin for zero-runtime css props.',\n );\n }\n\n const nextProps = styles ? processCssProp(props, styles) : (props as P);\n return factory(type, nextProps, key);\n}\n\nexport const Fragment = ReactFragment;\n\nexport function jsx<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsx, type, props, key);\n}\n\nexport function jsxs<P extends Record<string, unknown>>(\n type: ElementType,\n props: WithCssProp<P>,\n key?: React.Key,\n): React.ReactElement {\n return wrapJsx(reactJsxs, type, props, key);\n}\n\nexport type { ReactNode };\n"]}
@@ -0,0 +1,9 @@
1
+ import { CSSProperties } from 'typestyles';
2
+
3
+ type CssPropValue = CSSProperties | false | null | undefined;
4
+ type WithCssProp<P> = P & {
5
+ css?: CssPropValue;
6
+ className?: string;
7
+ };
8
+
9
+ export type { CssPropValue as C, WithCssProp as W };
@@ -0,0 +1,9 @@
1
+ import { CSSProperties } from 'typestyles';
2
+
3
+ type CssPropValue = CSSProperties | false | null | undefined;
4
+ type WithCssProp<P> = P & {
5
+ css?: CssPropValue;
6
+ className?: string;
7
+ };
8
+
9
+ export type { CssPropValue as C, WithCssProp as W };
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "name": "@typestyles/react",
3
+ "version": "0.2.0",
4
+ "description": "React integration for typestyles — styled API and css prop",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./jsx-runtime": {
21
+ "import": {
22
+ "types": "./dist/jsx-runtime.d.ts",
23
+ "default": "./dist/jsx-runtime.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/jsx-runtime.d.cts",
27
+ "default": "./dist/jsx-runtime.cjs"
28
+ }
29
+ },
30
+ "./jsx-dev-runtime": {
31
+ "import": {
32
+ "types": "./dist/jsx-dev-runtime.d.ts",
33
+ "default": "./dist/jsx-dev-runtime.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/jsx-dev-runtime.d.cts",
37
+ "default": "./dist/jsx-dev-runtime.cjs"
38
+ }
39
+ },
40
+ "./babel": {
41
+ "import": {
42
+ "types": "./dist/babel-plugin.d.ts",
43
+ "default": "./dist/babel-plugin.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/babel-plugin.d.cts",
47
+ "default": "./dist/babel-plugin.cjs"
48
+ }
49
+ },
50
+ "./css-prop-runtime": {
51
+ "import": {
52
+ "types": "./dist/css-prop-runtime.d.ts",
53
+ "default": "./dist/css-prop-runtime.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/css-prop-runtime.d.cts",
57
+ "default": "./dist/css-prop-runtime.cjs"
58
+ }
59
+ }
60
+ },
61
+ "files": [
62
+ "dist"
63
+ ],
64
+ "keywords": [
65
+ "react",
66
+ "typestyles",
67
+ "css-in-js",
68
+ "styled",
69
+ "css-prop"
70
+ ],
71
+ "license": "Apache-2.0",
72
+ "repository": {
73
+ "type": "git",
74
+ "url": "https://github.com/type-styles/typestyles",
75
+ "directory": "packages/react"
76
+ },
77
+ "peerDependencies": {
78
+ "react": ">=18.0.0",
79
+ "react-dom": ">=18.0.0",
80
+ "typestyles": ">=0.4.0"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "react": {
84
+ "optional": false
85
+ },
86
+ "react-dom": {
87
+ "optional": false
88
+ }
89
+ },
90
+ "devDependencies": {
91
+ "@babel/core": "^7.29.0",
92
+ "@babel/helper-plugin-utils": "^7.27.1",
93
+ "@babel/types": "^7.29.0",
94
+ "@testing-library/react": "^16.3.0",
95
+ "@types/babel__core": "^7.20.5",
96
+ "@types/react": "^18.3.12",
97
+ "@types/react-dom": "^18.3.1",
98
+ "eslint": "^9.39.2",
99
+ "react": "^18.0.0",
100
+ "react-dom": "^18.0.0",
101
+ "tsup": "^8.0.0",
102
+ "typescript": "^5.4.0",
103
+ "vitest": "^3.0.0",
104
+ "typestyles": "0.7.0"
105
+ },
106
+ "scripts": {
107
+ "build": "tsup",
108
+ "test": "vitest run",
109
+ "lint": "eslint .",
110
+ "typecheck": "tsc --noEmit"
111
+ }
112
+ }