@plumeria/react 22.2.5 → 22.3.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/README.md ADDED
@@ -0,0 +1,99 @@
1
+ **@plumeria/react** adds `styled` to [Plumeria](https://www.npmjs.com/package/@plumeria/core). Use it for components whose job is to carry styles: a button, a text field, a layout primitive that the rest of the app reuses and extends for each use. When a component has its own logic and you only need to style part of what it renders, pass a `css.create` style to `sx` instead.
2
+
3
+ At build time, the compiler first rewrites a styled definition using `css.create` and the configured style prop (`sx` by default). Plumeria then compiles those styles as usual.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add -D @plumeria/react
9
+ ```
10
+
11
+ `@plumeria/react` contains type definitions only. It needs `@plumeria/core` and a bundler integration — see the [installation guide](https://plumeria.dev/docs/installation).
12
+
13
+ ## Example
14
+
15
+ Define a styled element at module scope and use it with the native element's props.
16
+
17
+ ```tsx
18
+ import { styled } from '@plumeria/react';
19
+
20
+ export const Button = styled.button({
21
+ padding: '8px',
22
+ color: 'navy',
23
+ });
24
+
25
+ export function SaveButton() {
26
+ return <Button type="submit">Save</Button>;
27
+ }
28
+ ```
29
+
30
+ ## Values from props
31
+
32
+ Read a prop directly in a style value. Its parameter type tells TypeScript which props the component requires.
33
+
34
+ ```tsx
35
+ import { styled } from '@plumeria/react';
36
+
37
+ const Swatch = styled.div({
38
+ width: '40px',
39
+ height: '40px',
40
+ backgroundColor: (props: { fill: string }) => props.fill,
41
+ });
42
+
43
+ export function ColorPreview({ color }: { color: string }) {
44
+ return <Swatch fill={color} aria-label={color} role="img" />;
45
+ }
46
+ ```
47
+
48
+ The compiler passes `fill` to the element through a CSS variable and omits the `fill` attribute. For a conditional color, choose the value where you render `Swatch`, for example `<Swatch fill={active ? 'teal' : 'gray'} />`.
49
+
50
+ ## Extending and overriding styles
51
+
52
+ Styles merge in order from the base component through each extension to the `sx` prop at the call site. When two styles set the same property, the later style wins. Within an `sx` array, the rightmost active style wins.
53
+
54
+ Here, `DeleteButton` keeps the padding from `Button` and changes its color to maroon. When `urgent` is true, `sx` changes the color to red.
55
+
56
+ ```tsx
57
+ import * as css from '@plumeria/core';
58
+ import { styled } from '@plumeria/react';
59
+ import { Button } from './Button';
60
+
61
+ const DeleteButton = styled(Button)({
62
+ color: 'maroon',
63
+ });
64
+
65
+ const styles = css.create({
66
+ urgent: {
67
+ color: 'red',
68
+ },
69
+ });
70
+
71
+ export function DeleteAction({ urgent }: { urgent: boolean }) {
72
+ return (
73
+ <DeleteButton type="button" sx={[urgent && styles.urgent]}>
74
+ Delete
75
+ </DeleteButton>
76
+ );
77
+ }
78
+ ```
79
+
80
+ A chain can be up to 16 levels deep.
81
+
82
+ ## Other JSX frameworks
83
+
84
+ `styled` takes its tags, props and return type from React by default. For Preact, Qwik and others, register the framework's `JSX` types once:
85
+
86
+ ```ts
87
+ import type { JSX } from '@builder.io/qwik';
88
+
89
+ declare module '@plumeria/react' {
90
+ interface JSXRegister {
91
+ IntrinsicElements: JSX.IntrinsicElements;
92
+ Element: JSX.Element;
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## License
98
+
99
+ Plumeria is [MIT licensed](https://github.com/zss-labs/plumeria/blob/main/LICENSE).
package/lib/styled.d.ts CHANGED
@@ -32,7 +32,9 @@ type Reads<R> =
32
32
  R extends AtomicClassNameFor<string, infer V>
33
33
  ? Reads<V>
34
34
  : R extends (props: infer A) => any
35
- ? A
35
+ ? 0 extends 1 & A
36
+ ? Record<string, any>
37
+ : A
36
38
  : R extends object
37
39
  ? { [K in keyof R]: Reads<R[K]> }[keyof R]
38
40
  : never;
@@ -85,7 +87,7 @@ type Known<T> = {
85
87
  export type StyledProps<T extends StyledTarget, P> = P &
86
88
  Omit<
87
89
  Framework['useReactProps'] extends true ? PropsOf<T> : Known<PropsOf<T>>,
88
- keyof P | 'sx'
90
+ keyof Known<P> | 'sx'
89
91
  > & {
90
92
  sx?: Style;
91
93
  };
@@ -101,7 +103,7 @@ export type StyledComponent<T extends StyledTarget, R> = ((
101
103
  };
102
104
 
103
105
  export type StyledFactory<T extends StyledTarget> = {
104
- <const R extends StyledRule<never>>(
106
+ <const R extends StyledRule<any>>(
105
107
  rule: R,
106
108
  ): StyledComponent<T, AtomicStyle<R>>;
107
109
  new (rule: never): never;
@@ -110,7 +112,7 @@ export type StyledFactory<T extends StyledTarget> = {
110
112
  export type styled = {
111
113
  <C extends ((props: any) => any) & Branded>(component: C): StyledFactory<C>;
112
114
  } & {
113
- [T in keyof Intrinsic & string]: StyledFactory<T>;
115
+ [T in keyof Intrinsic]: StyledFactory<T>;
114
116
  };
115
117
 
116
118
  export const styled: styled;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/react",
3
- "version": "22.2.5",
3
+ "version": "22.3.1",
4
4
  "description": "Styled components for Plumeria, compiled to the sx prop",
5
5
  "author": "zss-labs",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "keywords": [
17
17
  "plumeria",
18
18
  "react",
19
- "styled",
19
+ "styled-components",
20
20
  "css-in-js",
21
21
  "atomic-css",
22
22
  "zero-runtime",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "devDependencies": {
36
36
  "@types/react": "^19.3.0",
37
- "@plumeria/core": "22.3.0"
37
+ "@plumeria/core": "22.3.1"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public",