weg-shared-layout 0.0.39 → 0.0.40
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 +21 -21
- package/dist/cjs/weg-footer_2.cjs.entry.js +9 -10
- package/dist/collection/components/weg-footer/icons/instagram.svg +5 -5
- package/dist/collection/components/weg-footer/icons/linkedin.svg +3 -3
- package/dist/collection/components/weg-footer/icons/tiktok.svg +3 -3
- package/dist/collection/components/weg-footer/icons/youtube.svg +4 -4
- package/dist/collection/components/weg-footer/weg-footer.css +263 -263
- package/dist/collection/components/weg-footer/weg-footer.js +2 -2
- package/dist/collection/components/weg-header/weg-header.css +483 -483
- package/dist/collection/components/weg-header/weg-header.js +9 -10
- package/dist/collection/styles/shared.css +103 -103
- package/dist/components/weg-footer.js +1 -1
- package/dist/components/weg-header.js +1 -1
- package/dist/esm/weg-footer_2.entry.js +9 -10
- package/dist/weg-shared-layout/p-6f83b24a.entry.js +1 -0
- package/dist/weg-shared-layout/weg-shared-layout.esm.js +1 -1
- package/docs/README.md +49 -49
- package/docs/angular.md +400 -395
- package/docs/nextjs.md +302 -307
- package/docs/publishing.md +65 -65
- package/docs/react.md +257 -262
- package/docs/vanilla.md +124 -125
- package/package.json +81 -81
- package/readme.md +97 -96
- package/src/constants/breakpoints.ts +7 -7
- package/src/styles/container.css +60 -60
- package/dist/weg-shared-layout/p-18d9facc.entry.js +0 -1
- /package/dist/types/Users/{rakin/Documents/WEG/repos → tan/Documents/code}/weg-shared-layout/.stencil/test-utils/axe.d.ts +0 -0
- /package/dist/types/Users/{rakin/Documents/WEG/repos → tan/Documents/code}/weg-shared-layout/.stencil/test-utils/viewport.d.ts +0 -0
package/docs/publishing.md
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
# Publishing to npm
|
|
2
|
-
|
|
3
|
-
## `npm publish` does not run your build by default
|
|
4
|
-
|
|
5
|
-
Publishing packs **whatever is already on disk** under the paths listed in [`package.json` `files`](../package.json) (for this package: `dist/`, `loader/`, and `dummy-data.json`). It does **not** automatically run `npm run build` unless a lifecycle script does.
|
|
6
|
-
|
|
7
|
-
If you publish with an empty, missing, or half-built `dist/`, consumers get a broken tarball (missing `loader/index.js`, missing `dist/components/*.js`, missing type declarations, etc.).
|
|
8
|
-
|
|
9
|
-
## What this repo does
|
|
10
|
-
|
|
11
|
-
The **`prepack`** script runs **`npm run build`** before every:
|
|
12
|
-
|
|
13
|
-
- `npm pack`
|
|
14
|
-
- `npm publish` (which packs first)
|
|
15
|
-
|
|
16
|
-
So the Stencil output and generated `loader/` are always fresh in the tarball.
|
|
17
|
-
|
|
18
|
-
```json
|
|
19
|
-
"scripts": {
|
|
20
|
-
"prepack": "npm run build",
|
|
21
|
-
"build": "stencil build"
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Release checklist
|
|
26
|
-
|
|
27
|
-
1. Bump **`version`** in `package.json`.
|
|
28
|
-
2. From the package root:
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm run build
|
|
32
|
-
npm test
|
|
33
|
-
npm pack --dry-run
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Inspect the dry-run file list and spot-check for:
|
|
37
|
-
|
|
38
|
-
- `loader/index.js`, `loader/index.d.ts`
|
|
39
|
-
- `dist/components/weg-header.js`, `dist/components/weg-footer.js`
|
|
40
|
-
- `src/assets/dummy-data.json` (via `exports["./dummy-data.json"]`)
|
|
41
|
-
- `dist/types/types/layout-data.d.ts` (via `exports["./layout-data"]`)
|
|
42
|
-
|
|
43
|
-
3. Smoke-test the Angular 16 demo (optional but recommended):
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm run demo:angular16:build
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
See [demo/angular16/README.md](../demo/angular16/README.md).
|
|
50
|
-
|
|
51
|
-
4. Publish (runs `prepack` → build again):
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
npm publish
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Use `npm publish --dry-run` if you want to exercise the full pack pipeline without uploading.
|
|
58
|
-
|
|
59
|
-
## What consumers import
|
|
60
|
-
|
|
61
|
-
Documented in [docs/README.md](./README.md): `loader`, `dummy-data.json`, `layout-data` (types), and per-tag subpaths. Angular 16 apps need modern `moduleResolution` or the loader-only pattern — [angular.md](./angular.md).
|
|
62
|
-
|
|
63
|
-
## CI
|
|
64
|
-
|
|
65
|
-
If you publish from CI, run **`npm run build`** (or rely on **`npm publish`**, which triggers **`prepack`**) in the same job before `npm publish`, and ensure **devDependencies** (e.g. `@stencil/core`) are installed so `stencil build` succeeds.
|
|
1
|
+
# Publishing to npm
|
|
2
|
+
|
|
3
|
+
## `npm publish` does not run your build by default
|
|
4
|
+
|
|
5
|
+
Publishing packs **whatever is already on disk** under the paths listed in [`package.json` `files`](../package.json) (for this package: `dist/`, `loader/`, and `dummy-data.json`). It does **not** automatically run `npm run build` unless a lifecycle script does.
|
|
6
|
+
|
|
7
|
+
If you publish with an empty, missing, or half-built `dist/`, consumers get a broken tarball (missing `loader/index.js`, missing `dist/components/*.js`, missing type declarations, etc.).
|
|
8
|
+
|
|
9
|
+
## What this repo does
|
|
10
|
+
|
|
11
|
+
The **`prepack`** script runs **`npm run build`** before every:
|
|
12
|
+
|
|
13
|
+
- `npm pack`
|
|
14
|
+
- `npm publish` (which packs first)
|
|
15
|
+
|
|
16
|
+
So the Stencil output and generated `loader/` are always fresh in the tarball.
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepack": "npm run build",
|
|
21
|
+
"build": "stencil build"
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Release checklist
|
|
26
|
+
|
|
27
|
+
1. Bump **`version`** in `package.json`.
|
|
28
|
+
2. From the package root:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run build
|
|
32
|
+
npm test
|
|
33
|
+
npm pack --dry-run
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Inspect the dry-run file list and spot-check for:
|
|
37
|
+
|
|
38
|
+
- `loader/index.js`, `loader/index.d.ts`
|
|
39
|
+
- `dist/components/weg-header.js`, `dist/components/weg-footer.js`
|
|
40
|
+
- `src/assets/dummy-data.json` (via `exports["./dummy-data.json"]`)
|
|
41
|
+
- `dist/types/types/layout-data.d.ts` (via `exports["./layout-data"]`)
|
|
42
|
+
|
|
43
|
+
3. Smoke-test the Angular 16 demo (optional but recommended):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run demo:angular16:build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
See [demo/angular16/README.md](../demo/angular16/README.md).
|
|
50
|
+
|
|
51
|
+
4. Publish (runs `prepack` → build again):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm publish
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Use `npm publish --dry-run` if you want to exercise the full pack pipeline without uploading.
|
|
58
|
+
|
|
59
|
+
## What consumers import
|
|
60
|
+
|
|
61
|
+
Documented in [docs/README.md](./README.md): `loader`, `dummy-data.json`, `layout-data` (types), and per-tag subpaths. Angular 16 apps need modern `moduleResolution` or the loader-only pattern — [angular.md](./angular.md).
|
|
62
|
+
|
|
63
|
+
## CI
|
|
64
|
+
|
|
65
|
+
If you publish from CI, run **`npm run build`** (or rely on **`npm publish`**, which triggers **`prepack`**) in the same job before `npm publish`, and ensure **devDependencies** (e.g. `@stencil/core`) are installed so `stencil build` succeeds.
|
package/docs/react.md
CHANGED
|
@@ -1,262 +1,257 @@
|
|
|
1
|
-
# React (SPA)
|
|
2
|
-
|
|
3
|
-
Guide for **client-rendered** React apps (Vite, Create React App, etc.). If you use **Next.js App Router**, see **[Next.js](./nextjs.md)** — SSR and Server Components require a different integration.
|
|
4
|
-
|
|
5
|
-
## Components
|
|
6
|
-
|
|
7
|
-
| Tag | Purpose |
|
|
8
|
-
| --- | --- |
|
|
9
|
-
| `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
|
|
10
|
-
| `<weg-footer>` | Site footer — social links, menu, credits, copyright |
|
|
11
|
-
|
|
12
|
-
Both are **presentational** [Stencil](https://stenciljs.com/) Web Components. They **do not fetch data** — your app passes a **`layout`** payload (API, CMS, or [`dummy-data.json`](../src/assets/dummy-data.json)).
|
|
13
|
-
|
|
14
|
-
`<weg-header>` additionally accepts **`signed-in`**, **`user-name`**, **`account-base-url`**, and emits **`wegAuthClick`**.
|
|
15
|
-
|
|
16
|
-
## Requirements
|
|
17
|
-
|
|
18
|
-
| Requirement | Notes |
|
|
19
|
-
| --- | --- |
|
|
20
|
-
| **React 19+** | React 19 maps custom-element props to DOM **properties** when possible. Older React often sets props as string **attributes**, which breaks object payloads. |
|
|
21
|
-
| **Bundler** | Must resolve `node_modules` ESM/CJS from `weg-shared-layout`. |
|
|
22
|
-
| **TypeScript (optional)** | `resolveJsonModule` + `moduleResolution` `bundler` / `node16` for JSON/subpath imports; module augmentation below. |
|
|
23
|
-
|
|
24
|
-
## Install
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm i weg-shared-layout
|
|
28
|
-
# or
|
|
29
|
-
pnpm add weg-shared-layout
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## 1. Register custom elements (once)
|
|
33
|
-
|
|
34
|
-
Call `defineCustomElements()` **once** before the first render — typically in `main.tsx` / `index.tsx`:
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import { defineCustomElements } from 'weg-shared-layout/loader';
|
|
38
|
-
|
|
39
|
-
defineCustomElements();
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
**Alternative** — side-effect imports per tag (requires modern `moduleResolution`; see [angular.md § Troubleshooting](./angular.md#troubleshooting)):
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
import 'weg-shared-layout/weg-header';
|
|
46
|
-
import 'weg-shared-layout/weg-footer';
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## 2. Layout shell
|
|
50
|
-
|
|
51
|
-
### Recommended: pass `layout` as an object (React 19+)
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
import 'weg-shared-layout/weg-header';
|
|
55
|
-
import 'weg-shared-layout/weg-footer';
|
|
56
|
-
import layout from 'weg-shared-layout/dummy-data.json';
|
|
57
|
-
|
|
58
|
-
export function SiteLayout({ children }: { children: React.ReactNode }) {
|
|
59
|
-
return (
|
|
60
|
-
<>
|
|
61
|
-
<weg-header layout={layout} />
|
|
62
|
-
{children}
|
|
63
|
-
<weg-footer layout={layout} />
|
|
64
|
-
</>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Fallback: `JSON.stringify` (React 18 or empty components)
|
|
70
|
-
|
|
71
|
-
```tsx
|
|
72
|
-
<weg-header layout={JSON.stringify(layout)} />
|
|
73
|
-
<weg-footer layout={JSON.stringify(layout)} />
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## 3. Header auth
|
|
77
|
-
|
|
78
|
-
Sign-in is a normal `header.menu` link — add it in your CMS like Register. The header recognizes **Sign in** by label or login URL and navigates to `href`.
|
|
79
|
-
|
|
80
|
-
### Signed in
|
|
81
|
-
|
|
82
|
-
Set **`signed-in`** and optionally **`user-name`**. The component **ignores CMS nav** and shows built-in links: Find a job, Dashboard, Manage Account, Sign out. Pass **`account-base-url`** when account links should use a non-production portal.
|
|
83
|
-
|
|
84
|
-
Handle **`wegAuthClick`**
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
|
247
|
-
|
|
|
248
|
-
|
|
|
249
|
-
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
- **[Documentation index](./README.md)**
|
|
259
|
-
- **[Next.js App Router](./nextjs.md)**
|
|
260
|
-
- **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
|
|
261
|
-
- **[Plain HTML / vanilla JS](./vanilla.md)**
|
|
262
|
-
- **[Package readme](../readme.md)**
|
|
1
|
+
# React (SPA)
|
|
2
|
+
|
|
3
|
+
Guide for **client-rendered** React apps (Vite, Create React App, etc.). If you use **Next.js App Router**, see **[Next.js](./nextjs.md)** — SSR and Server Components require a different integration.
|
|
4
|
+
|
|
5
|
+
## Components
|
|
6
|
+
|
|
7
|
+
| Tag | Purpose |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
|
|
10
|
+
| `<weg-footer>` | Site footer — social links, menu, credits, copyright |
|
|
11
|
+
|
|
12
|
+
Both are **presentational** [Stencil](https://stenciljs.com/) Web Components. They **do not fetch data** — your app passes a **`layout`** payload (API, CMS, or [`dummy-data.json`](../src/assets/dummy-data.json)).
|
|
13
|
+
|
|
14
|
+
`<weg-header>` additionally accepts **`signed-in`**, **`user-name`**, **`account-base-url`**, and emits **`wegAuthClick`**.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
| Requirement | Notes |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| **React 19+** | React 19 maps custom-element props to DOM **properties** when possible. Older React often sets props as string **attributes**, which breaks object payloads. |
|
|
21
|
+
| **Bundler** | Must resolve `node_modules` ESM/CJS from `weg-shared-layout`. |
|
|
22
|
+
| **TypeScript (optional)** | `resolveJsonModule` + `moduleResolution` `bundler` / `node16` for JSON/subpath imports; module augmentation below. |
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm i weg-shared-layout
|
|
28
|
+
# or
|
|
29
|
+
pnpm add weg-shared-layout
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 1. Register custom elements (once)
|
|
33
|
+
|
|
34
|
+
Call `defineCustomElements()` **once** before the first render — typically in `main.tsx` / `index.tsx`:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { defineCustomElements } from 'weg-shared-layout/loader';
|
|
38
|
+
|
|
39
|
+
defineCustomElements();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Alternative** — side-effect imports per tag (requires modern `moduleResolution`; see [angular.md § Troubleshooting](./angular.md#troubleshooting)):
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import 'weg-shared-layout/weg-header';
|
|
46
|
+
import 'weg-shared-layout/weg-footer';
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 2. Layout shell
|
|
50
|
+
|
|
51
|
+
### Recommended: pass `layout` as an object (React 19+)
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import 'weg-shared-layout/weg-header';
|
|
55
|
+
import 'weg-shared-layout/weg-footer';
|
|
56
|
+
import layout from 'weg-shared-layout/dummy-data.json';
|
|
57
|
+
|
|
58
|
+
export function SiteLayout({ children }: { children: React.ReactNode }) {
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<weg-header layout={layout} />
|
|
62
|
+
{children}
|
|
63
|
+
<weg-footer layout={layout} />
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Fallback: `JSON.stringify` (React 18 or empty components)
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
<weg-header layout={JSON.stringify(layout)} />
|
|
73
|
+
<weg-footer layout={JSON.stringify(layout)} />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 3. Header auth
|
|
77
|
+
|
|
78
|
+
Sign-in is a normal `header.menu` link — add it in your CMS like Register. The header recognizes **Sign in** by label or login URL and navigates to `href`.
|
|
79
|
+
|
|
80
|
+
### Signed in
|
|
81
|
+
|
|
82
|
+
Set **`signed-in`** and optionally **`user-name`**. The component **ignores CMS nav** and shows built-in links: Find a job, Dashboard, Manage Account, Sign out. Pass **`account-base-url`** when account links should use a non-production portal.
|
|
83
|
+
|
|
84
|
+
Handle **`wegAuthClick`** for sign-out (call your logout API, then redirect):
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { useCallback, useState } from 'react';
|
|
88
|
+
import 'weg-shared-layout/weg-header';
|
|
89
|
+
import layout from 'weg-shared-layout/dummy-data.json';
|
|
90
|
+
|
|
91
|
+
export function SiteHeader() {
|
|
92
|
+
const [signedIn, setSignedIn] = useState(false);
|
|
93
|
+
const userName = signedIn ? 'Alex' : undefined;
|
|
94
|
+
|
|
95
|
+
const onAuthClick = useCallback(async (event: CustomEvent<{ action: 'sign-in' | 'sign-out' }>) => {
|
|
96
|
+
if (event.detail.action !== 'sign-out') return;
|
|
97
|
+
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
await logout();
|
|
100
|
+
setSignedIn(false);
|
|
101
|
+
window.location.assign('/');
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<weg-header
|
|
106
|
+
layout={layout}
|
|
107
|
+
signedIn={signedIn}
|
|
108
|
+
{...(userName ? { userName } : {})}
|
|
109
|
+
onWegAuthClick={onAuthClick}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
| Prop / event | Purpose |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `signedIn={boolean}` | Switches to signed-in nav when `true` |
|
|
118
|
+
| `userName={string}` | First name beside profile icon on Manage Account |
|
|
119
|
+
| `accountBaseUrl={string}` | Account portal origin for signed-in links (optional) |
|
|
120
|
+
| `onWegAuthClick` | Required for sign-out — call logout API and redirect; sign-in follows link `href` |
|
|
121
|
+
|
|
122
|
+
**Ref fallback for the event** (if `onWegAuthClick` does not bind in your React version):
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import { useEffect, useRef } from 'react';
|
|
126
|
+
|
|
127
|
+
const ref = useRef<HTMLWegHeaderElement>(null);
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const el = ref.current;
|
|
131
|
+
if (!el) return;
|
|
132
|
+
|
|
133
|
+
const handler = (event: Event) => {
|
|
134
|
+
const e = event as CustomEvent<{ action: 'sign-in' | 'sign-out' }>;
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
// ...
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
el.addEventListener('wegAuthClick', handler);
|
|
140
|
+
return () => el.removeEventListener('wegAuthClick', handler);
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
return <weg-header ref={ref} layout={layout} signedIn={signedIn} userName="Alex" />;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 4. Production: fetch layout from your API
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { useEffect, useState } from 'react';
|
|
150
|
+
import 'weg-shared-layout/weg-header';
|
|
151
|
+
import 'weg-shared-layout/weg-footer';
|
|
152
|
+
import layoutFixture from 'weg-shared-layout/dummy-data.json';
|
|
153
|
+
|
|
154
|
+
type LayoutData = typeof layoutFixture;
|
|
155
|
+
|
|
156
|
+
const LAYOUT_URL = 'https://weg-payload-test.vercel.app/api/layout';
|
|
157
|
+
|
|
158
|
+
export function SiteLayout({ children }: { children: React.ReactNode }) {
|
|
159
|
+
const [layout, setLayout] = useState<LayoutData | null>(null);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
let cancelled = false;
|
|
163
|
+
fetch(LAYOUT_URL)
|
|
164
|
+
.then((res) => {
|
|
165
|
+
if (!res.ok) throw new Error(`layout fetch failed: ${res.status}`);
|
|
166
|
+
return res.json() as Promise<LayoutData>;
|
|
167
|
+
})
|
|
168
|
+
.then((data) => {
|
|
169
|
+
if (!cancelled) setLayout(data);
|
|
170
|
+
})
|
|
171
|
+
.catch(console.error);
|
|
172
|
+
return () => {
|
|
173
|
+
cancelled = true;
|
|
174
|
+
};
|
|
175
|
+
}, []);
|
|
176
|
+
|
|
177
|
+
if (!layout) return null;
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<>
|
|
181
|
+
<weg-header layout={layout} />
|
|
182
|
+
{children}
|
|
183
|
+
<weg-footer layout={layout} />
|
|
184
|
+
</>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Replace the URL with your CMS/API. Keep the object shape aligned with `dummy-data.json`.
|
|
190
|
+
|
|
191
|
+
## TypeScript
|
|
192
|
+
|
|
193
|
+
### JSON + package subpaths
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"compilerOptions": {
|
|
198
|
+
"resolveJsonModule": true,
|
|
199
|
+
"moduleResolution": "bundler"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import layoutFixture from 'weg-shared-layout/dummy-data.json';
|
|
206
|
+
export type LayoutData = typeof layoutFixture;
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Or types only: `import type { LayoutData } from 'weg-shared-layout/layout-data'`.
|
|
210
|
+
|
|
211
|
+
### JSX module augmentation
|
|
212
|
+
|
|
213
|
+
Add once (e.g. `src/types/weg-shared-layout-jsx.d.ts`):
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import type { JSX as WegSharedLayoutJSX } from 'weg-shared-layout';
|
|
217
|
+
import type { DetailedHTMLProps, HTMLAttributes } from 'react';
|
|
218
|
+
|
|
219
|
+
declare module 'react' {
|
|
220
|
+
namespace JSX {
|
|
221
|
+
interface IntrinsicElements extends WegSharedLayoutJSX.IntrinsicElements {
|
|
222
|
+
'weg-header': WegSharedLayoutJSX.IntrinsicElements['weg-header'] &
|
|
223
|
+
DetailedHTMLProps<HTMLAttributes<HTMLWegHeaderElement>, HTMLWegHeaderElement>;
|
|
224
|
+
'weg-footer': WegSharedLayoutJSX.IntrinsicElements['weg-footer'] &
|
|
225
|
+
DetailedHTMLProps<HTMLAttributes<HTMLWegFooterElement>, HTMLWegFooterElement>;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## `layout` prop vs attribute
|
|
232
|
+
|
|
233
|
+
| How data is set | Works with object? |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| **Property** `el.layout = obj` / React 19 `layout={obj}` | Yes |
|
|
236
|
+
| **Attribute** `layout="[object Object]"` / React 18 `layout={obj}` | No — components stay empty |
|
|
237
|
+
| **Attribute** `layout={JSON.stringify(obj)}` | Yes — component parses JSON |
|
|
238
|
+
|
|
239
|
+
## Troubleshooting
|
|
240
|
+
|
|
241
|
+
| Symptom | Likely cause | Fix |
|
|
242
|
+
| --- | --- | --- |
|
|
243
|
+
| Empty header/footer | Loader/tag import missing | `defineCustomElements()` + tag imports. |
|
|
244
|
+
| Empty despite correct data | React set `layout` as attribute | React 19+, or `JSON.stringify`, or ref assignment. |
|
|
245
|
+
| Logo missing on header | Old build without inlined logo | Upgrade package; logo is bundled in `logo-data.ts`. |
|
|
246
|
+
| Auth always Sign in | `signed-in` not set | Bind `signedIn={!!session}`. |
|
|
247
|
+
| Manage Account shows label not name | `user-name` not set | Pass `userName` when signed in. |
|
|
248
|
+
| `onWegAuthClick` not firing | React CE event binding | Use `addEventListener` on a ref. |
|
|
249
|
+
| TS: unknown element | No augmentation | Add `weg-shared-layout-jsx.d.ts`. |
|
|
250
|
+
|
|
251
|
+
## See also
|
|
252
|
+
|
|
253
|
+
- **[Documentation index](./README.md)**
|
|
254
|
+
- **[Next.js App Router](./nextjs.md)**
|
|
255
|
+
- **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
|
|
256
|
+
- **[Plain HTML / vanilla JS](./vanilla.md)**
|
|
257
|
+
- **[Package readme](../readme.md)**
|