@saunos/restyle-components 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 saunos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @saunos/restyle-components
2
+
3
+ `@saunos/restyle-components` is a library that provides jsx transform to expose `css` prop from [Restyle](https://github.com/souporserious/restyle) for React components.
4
+
5
+ ## Features
6
+
7
+ - 🎨 Use ReStyle's css prop with React's function components
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @saunos/restyle-components restyle
13
+ ```
14
+
15
+ ## Setup
16
+
17
+ 1. Update your `tsconfig.json` to use the custom JSX transform:
18
+
19
+ ```json
20
+ {
21
+ "compilerOptions": {
22
+ "jsx": "react-jsx",
23
+ "jsxImportSource": "@saunos/restyle-components"
24
+ }
25
+ }
26
+ ```
27
+
28
+ 2. If you prefer per-file configuration, add this comment at the top of your `.tsx` files:
29
+
30
+ ```tsx
31
+ /** @jsxImportSource @saunos/restyle-components */
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Here's a basic example of how to use `@saunos/restyle-components`:
37
+
38
+ ```tsx
39
+ import React from 'react';
40
+ import { Button, Text } from '@mantine/core';
41
+ import { theme } from './theme';
42
+
43
+ function App() {
44
+ return (
45
+ <div>
46
+ <Button
47
+ css={{
48
+ backgroundColor: theme.colors.primary,
49
+ marginBottom: theme.spacing.m,
50
+ }}
51
+ >
52
+ Styled Button
53
+ </Button>
54
+ <Text
55
+ css={{
56
+ fontSize: 18,
57
+ }}
58
+ >
59
+ Styled Text
60
+ </Text>
61
+ </div>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ## API Reference
67
+
68
+ ### `css` prop
69
+
70
+ Please refer to [Restyle's docs](https://github.com/souporserious/restyle/blob/main/README.md) for more details.
71
+
72
+ ## Contributing
73
+
74
+ Contributions are welcome! Please feel free to submit a Pull Request.
75
+
76
+ ## License
77
+
78
+ This project is licensed under the MIT License.
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ /** Create a `restyle` JSX props object that handles the `css` prop to generate atomic class names. */
3
+ export declare function createRestyleProps(type: React.ElementType, props: Record<string, any>): [Record<string, any>, (() => React.ReactNode) | null];
@@ -0,0 +1,11 @@
1
+ import { css } from 'restyle';
2
+ /** Create a `restyle` JSX props object that handles the `css` prop to generate atomic class names. */
3
+ export function createRestyleProps(type, props) {
4
+ const input = props.css;
5
+ const [classNames, Styles] = css(input);
6
+ delete props.css;
7
+ props.className = props.className
8
+ ? `${props.className} ${classNames}`
9
+ : classNames;
10
+ return [props, Styles];
11
+ }
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export declare const ForwardRefWrapper: React.ForwardRefExoticComponent<{
3
+ Fragment: React.ElementType;
4
+ element: React.ReactElement;
5
+ styles: React.ReactElement;
6
+ } & React.RefAttributes<React.ElementType<any, keyof React.JSX.IntrinsicElements>>>;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export const ForwardRefWrapper = React.forwardRef(({ element, styles, Fragment }, ref) => {
3
+ const elementWithRef = React.isValidElement(element)
4
+ ? React.cloneElement(element, { ref })
5
+ : element;
6
+ return React.createElement(Fragment, null, elementWithRef, styles);
7
+ });
8
+ ForwardRefWrapper.displayName = 'ForwardRefWrapper';
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ export declare const Fragment: React.ExoticComponent<{
3
+ children?: React.ReactNode | undefined;
4
+ }>;
5
+ /** Create a JSX element that accepts a `css` prop to generate atomic class names. */
6
+ export declare function jsxDEV(type: React.ElementType, props: Record<string, any>, key: string, isStaticChildren: boolean, source: any, self: any): React.JSX.Element;
@@ -0,0 +1,19 @@
1
+ import ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
2
+ import { createRestyleProps } from './create-restyle-props';
3
+ import { ForwardRefWrapper } from './forward-ref-wrapper';
4
+ export const Fragment = ReactJSXRuntimeDev.Fragment;
5
+ /** Create a JSX element that accepts a `css` prop to generate atomic class names. */
6
+ export function jsxDEV(type, props, key, isStaticChildren, source, self) {
7
+ if (props.css) {
8
+ const [parsedProps, Styles] = createRestyleProps(type, props);
9
+ if (Styles) {
10
+ return ReactJSXRuntimeDev.jsxDEV(ForwardRefWrapper, {
11
+ Fragment,
12
+ element: ReactJSXRuntimeDev.jsxDEV(type, parsedProps, key, isStaticChildren, source, self),
13
+ styles: ReactJSXRuntimeDev.jsxDEV(Styles, {}, undefined, true, source, self),
14
+ }, key, true, source, self);
15
+ }
16
+ return ReactJSXRuntimeDev.jsxDEV(type, parsedProps, key, isStaticChildren, source, self);
17
+ }
18
+ return ReactJSXRuntimeDev.jsxDEV(type, props, key, isStaticChildren, source, self);
19
+ }
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export * from './types';
3
+ export declare const Fragment: React.ExoticComponent<{
4
+ children?: React.ReactNode | undefined;
5
+ }>;
6
+ export declare function jsx(type: React.ElementType, props: Record<string, any>, key: string): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
7
+ export declare function jsxs(type: any, props: Record<string, any>, key: string): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
@@ -0,0 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import * as React from 'react';
3
+ import ReactJSXRuntime from 'react/jsx-runtime';
4
+ import { createRestyleProps } from './create-restyle-props';
5
+ import { ForwardRefWrapper } from './forward-ref-wrapper';
6
+ export * from './types';
7
+ export const Fragment = ReactJSXRuntime.Fragment;
8
+ export function jsx(type, props, key) {
9
+ if (props.css) {
10
+ const [parsedProps, Styles] = createRestyleProps(type, props);
11
+ if (Styles) {
12
+ return ReactJSXRuntime.jsx(ForwardRefWrapper, {
13
+ Fragment,
14
+ element: React.createElement(type, parsedProps),
15
+ styles: React.createElement(Styles),
16
+ }, key);
17
+ }
18
+ return ReactJSXRuntime.jsx(type, parsedProps, key);
19
+ }
20
+ return ReactJSXRuntime.jsx(type, props, key);
21
+ }
22
+ export function jsxs(type, props, key) {
23
+ if (props.css) {
24
+ const [parsedProps, Styles] = createRestyleProps(type, props);
25
+ if (Styles) {
26
+ return ReactJSXRuntime.jsx(ForwardRefWrapper, {
27
+ Fragment,
28
+ element: React.createElement(type, parsedProps),
29
+ styles: React.createElement(Styles),
30
+ }, key);
31
+ }
32
+ return ReactJSXRuntime.jsxs(type, parsedProps, key);
33
+ }
34
+ return ReactJSXRuntime.jsxs(type, props, key);
35
+ }
@@ -0,0 +1,14 @@
1
+ import { CSSObject } from 'restyle';
2
+ declare global {
3
+ namespace JSX {
4
+ interface IntrinsicAttributes {
5
+ css?: CSSObject;
6
+ }
7
+ }
8
+ namespace React {
9
+ interface Attributes {
10
+ css?: CSSObject;
11
+ }
12
+ }
13
+ }
14
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/jsx-dev-runtime.js",
3
+ "types": "../dist/jsx-dev-runtime.d.ts",
4
+ "sideEffects": false
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../dist/jsx-runtime.js",
3
+ "types": "../dist/jsx-runtime.d.ts",
4
+ "sideEffects": false
5
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@saunos/restyle-components",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "JSX source transformation for Restyle and React components",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "module": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./jsx-runtime": {
19
+ "import": {
20
+ "types": "./dist/jsx-runtime.d.ts",
21
+ "default": "./dist/jsx-runtime.js"
22
+ }
23
+ },
24
+ "./jsx-dev-runtime": {
25
+ "import": {
26
+ "types": "./dist/jsx-dev-runtime.d.ts",
27
+ "default": "./dist/jsx-dev-runtime.js"
28
+ }
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "jsx-runtime",
34
+ "jsx-dev-runtime"
35
+ ],
36
+ "sideEffects": false,
37
+ "keywords": [],
38
+ "author": "",
39
+ "license": "ISC",
40
+ "engines": {
41
+ "node": ">=18"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "^18.3.11",
45
+ "typescript": "^5.6.2"
46
+ },
47
+ "peerDependencies": {
48
+ "react": "^18.3.1",
49
+ "restyle": "^2.4.0"
50
+ }
51
+ }