@joralvmel/cosmos-react 0.0.0-stage → 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jorge Andrés Álvarez Melchor (joralvmel)
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 CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @joralvmel/cosmos-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React wrappers for [Cosmos UI](../../README.md).
4
+
5
+ React 19 wrappers of the Cosmos Web Components.
6
+
7
+ ```tsx
8
+ import '@joralvmel/cosmos-tokens/tokens.css';
9
+ import { Button } from '@joralvmel/cosmos-react';
10
+
11
+ export function Toolbar() {
12
+ return (
13
+ <Button variant="soft" onPress={event => console.log(event.detail.source)}>
14
+ Save
15
+ </Button>
16
+ );
17
+ }
18
+ ```
19
+
20
+ ## License
21
+
22
+ MIT
@@ -0,0 +1,17 @@
1
+ import type { ButtonPressDetail } from '@joralvmel/cosmos-core';
2
+ import { CosmButton } from '@joralvmel/cosmos-elements/button';
3
+ import { type EventName } from '@lit/react';
4
+ import * as React from 'react';
5
+ /** React event props of `Button`, mapped to the DOM events of `<cosm-button>`. */
6
+ export declare const buttonEvents: {
7
+ onPress: EventName<CustomEvent<ButtonPressDetail>>;
8
+ };
9
+ /**
10
+ * React wrapper of `<cosm-button>`. Props are set as element properties; `onPress` receives the
11
+ * original `CustomEvent` (`event.detail.source`).
12
+ */
13
+ export declare const Button: import("@lit/react").ReactWebComponent<CosmButton, {
14
+ onPress: EventName<CustomEvent<ButtonPressDetail>>;
15
+ }>;
16
+ export type ButtonProps = React.ComponentProps<typeof Button>;
17
+ //# sourceMappingURL=button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/components/button.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,kFAAkF;AAClF,eAAO,MAAM,YAAY;aACE,SAAS,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;CACnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,MAAM;aAPQ,SAAS,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;EAalE,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,MAAM,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { CosmButton } from '@joralvmel/cosmos-elements/button';
2
+ import { createComponent } from '@lit/react';
3
+ import * as React from 'react';
4
+ /** React event props of `Button`, mapped to the DOM events of `<cosm-button>`. */
5
+ export const buttonEvents = {
6
+ onPress: 'cosm-press',
7
+ };
8
+ /**
9
+ * React wrapper of `<cosm-button>`. Props are set as element properties; `onPress` receives the
10
+ * original `CustomEvent` (`event.detail.source`).
11
+ */
12
+ export const Button = createComponent({
13
+ tagName: 'cosm-button',
14
+ elementClass: CosmButton,
15
+ react: React,
16
+ events: buttonEvents,
17
+ displayName: 'Button',
18
+ });
19
+ //# sourceMappingURL=button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/components/button.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,YAAyD;CACnE,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC;IACpC,OAAO,EAAE,aAAa;IACtB,YAAY,EAAE,UAAU;IACxB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,YAAY;IACpB,WAAW,EAAE,QAAQ;CACtB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { ButtonPressDetail, PressSource } from '@joralvmel/cosmos-core';
2
+ export { Button, type ButtonProps, buttonEvents } from './components/button.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Button, buttonEvents } from './components/button.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAoB,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
package/llms.md ADDED
@@ -0,0 +1,135 @@
1
+ # @joralvmel/cosmos-react
2
+
3
+ React 19 wrappers of the Cosmos Web Components (Vite, Next.js). Props map to element properties; event props receive the original CustomEvent.
4
+
5
+ <!-- generated:start (npm run llms, do not edit this block by hand) -->
6
+
7
+ ## Setup: React (Vite)
8
+
9
+ ```bash
10
+ npm install @joralvmel/cosmos-react @joralvmel/cosmos-tokens
11
+ ```
12
+
13
+ **Load the tokens once** (`src/main.tsx`)
14
+
15
+ ```tsx
16
+ import '@joralvmel/cosmos-tokens/tokens.css';
17
+ ```
18
+
19
+ **Choose theme and mode** (`index.html`)
20
+
21
+ ```html
22
+ <html data-theme="cosmos" data-mode="system">
23
+ ```
24
+
25
+ **Use components** (`src/App.tsx`)
26
+
27
+ ```tsx
28
+ import { Button } from '@joralvmel/cosmos-react';
29
+
30
+ export default function App() {
31
+ return <Button onPress={event => console.log(event.detail.source)}>Save</Button>;
32
+ }
33
+ ```
34
+
35
+ - Event props (`onPress`, `onChange`…) receive the original CustomEvent: read `event.detail`.
36
+ - Change theme and mode at runtime with `setTheme()` / `setMode()` from `@joralvmel/cosmos-tokens/runtime`.
37
+
38
+ Guide: https://joralvmel.github.io/cosmos-ui/guides/react-vite/
39
+
40
+ ## Setup: Next.js (App Router)
41
+
42
+ ```bash
43
+ npm install @joralvmel/cosmos-react @joralvmel/cosmos-tokens
44
+ ```
45
+
46
+ **Load the tokens and avoid a theme flash** (`app/layout.tsx`)
47
+
48
+ ```tsx
49
+ import '@joralvmel/cosmos-tokens/tokens.css';
50
+ import { themeInitScript } from '@joralvmel/cosmos-tokens/runtime';
51
+ import Script from 'next/script';
52
+
53
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
54
+ return (
55
+ <html lang="en" data-theme="cosmos" data-mode="system" suppressHydrationWarning>
56
+ <body>
57
+ <Script id="cosmos-theme" strategy="beforeInteractive">
58
+ {themeInitScript()}
59
+ </Script>
60
+ {children}
61
+ </body>
62
+ </html>
63
+ );
64
+ }
65
+ ```
66
+
67
+ **Use components in Client Components** (`app/save-button.tsx`)
68
+
69
+ ```tsx
70
+ 'use client';
71
+
72
+ import { Button } from '@joralvmel/cosmos-react';
73
+
74
+ export function SaveButton() {
75
+ return <Button onPress={() => console.log('saved')}>Save</Button>;
76
+ }
77
+ ```
78
+
79
+ - Cosmos components are Web Components: render them from Client Components (`'use client'`). Server Components can render the Client Component that wraps them.
80
+ - The server HTML contains the custom element tag; it upgrades in the browser.
81
+
82
+ Guide: https://joralvmel.github.io/cosmos-ui/guides/nextjs/
83
+
84
+ ## Components
85
+
86
+ Every component of this package (status of planned ones: https://joralvmel.github.io/cosmos-ui/components/status/).
87
+
88
+ ### `Button`
89
+
90
+ Triggers an action or submits a form.
91
+
92
+ | Prop | Type | Default | Description |
93
+ | --- | --- | --- | --- |
94
+ | `variant` | 'solid' \| 'soft' \| 'outline' \| 'ghost' | `solid` | Visual emphasis, from highest (solid) to lowest (ghost). |
95
+ | `tone` | 'primary' \| 'neutral' \| 'danger' | `primary` | Color role. Use danger for destructive actions. |
96
+ | `size` | 'sm' \| 'md' \| 'lg' | `md` | Control height and padding. |
97
+ | `disabled` | boolean | `false` | Prevents interaction and removes the button from the tab order. |
98
+ | `loading` | boolean | `false` | Shows a spinner, sets aria-busy and ignores presses while keeping focus. |
99
+ | `fullWidth` | boolean | `false` | Stretches the button to the width of its container. |
100
+ | `type` | 'button' \| 'submit' \| 'reset' | `button` | Form behavior of the button. |
101
+ | `label` | string | — | Accessible name when the visible content is not descriptive (icon-only buttons). |
102
+
103
+ Events: `onPress` → `ButtonPressDetail`.
104
+
105
+ ```tsx
106
+ import { Button } from '@joralvmel/cosmos-react';
107
+
108
+ export function Example() {
109
+ return (
110
+ <Button onPress={event => console.log(event.detail)}>Button</Button>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ## Themes
116
+
117
+ Built-in themes: `cosmos`, `nebula` (default `cosmos`), each with `light` and `dark` modes; `system` follows the OS.
118
+
119
+ ```html
120
+ <html data-theme="nebula" data-mode="system">
121
+ <!-- runtime: setTheme(name), setMode(mode) from @joralvmel/cosmos-tokens/runtime -->
122
+ ```
123
+
124
+ Custom themes: `defineTheme()` in `@joralvmel/cosmos-tokens` (https://joralvmel.github.io/cosmos-ui/theming/themes/).
125
+
126
+ ## Rules for AI assistants
127
+
128
+ - Use Cosmos components before writing custom UI; check `list_components` / the component status page for what exists.
129
+ - Style with Cosmos tokens: `var(--cosm-*)` in CSS or the Tailwind theme utilities (`bg-primary`, `text-fg-muted`, `rounded-md`). Never hard-code colors.
130
+ - Set the theme and mode with `data-theme` and `data-mode` on the root element (or `CosmosThemeProvider` on React Native).
131
+ - Keep accessibility: give icon-only buttons a `label`, never rely on color alone, keep keyboard support.
132
+ - Never render untrusted HTML (`innerHTML`, `dangerouslySetInnerHTML`) and never build class names from user input.
133
+ - Import components from `@joralvmel/cosmos-react`; event props receive the CustomEvent (`event.detail`).
134
+
135
+ <!-- generated:end -->
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@joralvmel/cosmos-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "React wrappers for the Cosmos UI Web Components (React 19, Vite, Next.js).",
5
+ "keywords": [
6
+ "react",
7
+ "web-components",
8
+ "design-system",
9
+ "cosmos-ui"
10
+ ],
11
+ "type": "module",
12
+ "license": "MIT",
13
+ "author": "joralvmel",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/joralvmel/cosmos-ui.git",
17
+ "directory": "packages/react"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "sideEffects": true,
23
+ "files": [
24
+ "dist",
25
+ "llms.md"
26
+ ],
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./llms.md": "./llms.md",
35
+ "./package.json": "./package.json"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
40
+ "typecheck": "tsc -p tsconfig.json",
41
+ "test": "vitest run",
42
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
43
+ },
44
+ "dependencies": {
45
+ "@joralvmel/cosmos-core": "^0.0.0",
46
+ "@joralvmel/cosmos-elements": "^0.0.0",
47
+ "@lit/react": "^1.0.8"
48
+ },
49
+ "peerDependencies": {
50
+ "@types/react": "^19.0.0",
51
+ "react": "^19.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@types/react": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@types/react": "^19.3.0",
60
+ "@types/react-dom": "^19.3.0",
61
+ "react": "19.3.1",
62
+ "react-dom": "19.3.1"
63
+ }
64
+ }