@zerops/web-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/README.md +117 -0
- package/chunks/browser-DeGg1Z-r.js +2927 -0
- package/chunks/register-C5_R6XU0.js +24212 -0
- package/package.json +24 -0
- package/recipe-card.d.ts +51 -0
- package/recipe-card.js +1 -0
- package/recipes/zerops-showcase.json +1 -0
- package/style.css +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @zerops/web-components
|
|
2
|
+
|
|
3
|
+
Zerops UI as framework-agnostic web components. Each element is a self-registering ES module entry — import it for its side effect and use the tag anywhere: plain HTML, React, Vue, Svelte, anything that renders DOM.
|
|
4
|
+
|
|
5
|
+
Angular is fully bundled inside (zoneless, shared across all elements on the page); the package has **no peer dependencies**.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Every page using the components needs the stylesheet and the fonts once:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<link href="https://fonts.googleapis.com/css2?family=Geologica:wght@100..900&display=swap" rel="stylesheet">
|
|
13
|
+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import '@zerops/web-components/style.css';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## `<zerops-recipe-card>`
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import '@zerops/web-components/recipe-card';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Self-fetching mode
|
|
27
|
+
|
|
28
|
+
The element fetches the recipe from the public Zerops API (CORS-open) at load:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<zerops-recipe-card slug="nestjs-minimal"></zerops-recipe-card>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Captured-data mode — no API call
|
|
35
|
+
|
|
36
|
+
Ship the recipe snapshot with your page and the card renders instantly:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import showcase from '@zerops/web-components/recipes/zerops-showcase.json';
|
|
40
|
+
|
|
41
|
+
const card = document.querySelector('zerops-recipe-card');
|
|
42
|
+
await customElements.whenDefined('zerops-recipe-card');
|
|
43
|
+
card.recipeData = showcase;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### React
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { useEffect, useRef } from 'react';
|
|
50
|
+
import '@zerops/web-components/recipe-card';
|
|
51
|
+
import '@zerops/web-components/style.css';
|
|
52
|
+
import type { ZeropsRecipeCardElement } from '@zerops/web-components/recipe-card';
|
|
53
|
+
|
|
54
|
+
export function ZeropsRecipeCard({ slug, recipeData, onDeployed }: {
|
|
55
|
+
slug?: string;
|
|
56
|
+
recipeData?: object;
|
|
57
|
+
onDeployed?: (appUrl: string) => void;
|
|
58
|
+
}) {
|
|
59
|
+
const ref = useRef<ZeropsRecipeCardElement>(null);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const el = ref.current;
|
|
63
|
+
if (!el) return;
|
|
64
|
+
const handler = (e: CustomEvent<string>) => onDeployed?.(e.detail);
|
|
65
|
+
el.addEventListener('deployed', handler);
|
|
66
|
+
return () => el.removeEventListener('deployed', handler);
|
|
67
|
+
}, [onDeployed]);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!recipeData) return;
|
|
71
|
+
customElements.whenDefined('zerops-recipe-card').then(() => {
|
|
72
|
+
if (ref.current) ref.current.recipeData = recipeData;
|
|
73
|
+
});
|
|
74
|
+
}, [recipeData]);
|
|
75
|
+
|
|
76
|
+
return <zerops-recipe-card ref={ref} slug={slug} />;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
With React 19 you can also set `recipeData` directly as a JSX prop (React assigns it as a DOM property); the wrapper above works on 18 and 19.
|
|
81
|
+
|
|
82
|
+
For TypeScript JSX, augment the intrinsic elements once:
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
declare module 'react' {
|
|
86
|
+
namespace JSX {
|
|
87
|
+
interface IntrinsicElements {
|
|
88
|
+
'zerops-recipe-card': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
89
|
+
slug?: string;
|
|
90
|
+
'api-base'?: string;
|
|
91
|
+
'app-url'?: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Attributes / properties
|
|
99
|
+
|
|
100
|
+
| Name | Attribute | Default | |
|
|
101
|
+
|------|-----------|---------|-|
|
|
102
|
+
| `slug` | `slug` | — | Catalog slug to self-fetch |
|
|
103
|
+
| `recipeData` | `recipe-data` (JSON string) | — | Captured recipe; wins over `slug` |
|
|
104
|
+
| `apiBase` | `api-base` | `https://api.zerops.io` | Public API origin |
|
|
105
|
+
| `appUrl` | `app-url` | `https://app.zerops.io` | Detail/deploy link origin |
|
|
106
|
+
|
|
107
|
+
### Events (CustomEvents on the element)
|
|
108
|
+
|
|
109
|
+
| Event | `detail` | |
|
|
110
|
+
|-------|----------|-|
|
|
111
|
+
| `deployed` | `string` | Deploy clicked; the app URL that was opened |
|
|
112
|
+
| `detailOpened` | — | A detail/title link was clicked |
|
|
113
|
+
|
|
114
|
+
## Known caveats
|
|
115
|
+
|
|
116
|
+
- The stylesheet includes a CSS-layered normalize that can nudge host-page base styles.
|
|
117
|
+
- Recipe snapshots under `recipes/` are frozen at package publish time; use `slug` mode for always-current data.
|