weg-shared-layout 0.0.26 → 0.0.28

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.
Files changed (31) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/weg-footer_2.cjs.entry.js +7 -7
  3. package/dist/collection/components/weg-footer/icons/instagram.svg +5 -5
  4. package/dist/collection/components/weg-footer/icons/linkedin.svg +3 -3
  5. package/dist/collection/components/weg-footer/icons/tiktok.svg +3 -3
  6. package/dist/collection/components/weg-footer/icons/youtube.svg +4 -4
  7. package/dist/collection/components/weg-footer/weg-footer.css +263 -270
  8. package/dist/collection/components/weg-footer/weg-footer.js +2 -2
  9. package/dist/collection/components/weg-header/weg-header.css +475 -474
  10. package/dist/collection/components/weg-header/weg-header.js +4 -4
  11. package/dist/collection/styles/shared.css +96 -72
  12. package/dist/components/weg-footer.js +1 -1
  13. package/dist/components/weg-header.js +1 -1
  14. package/dist/esm/weg-footer_2.entry.js +7 -7
  15. package/dist/weg-shared-layout/p-9665af6f.entry.js +1 -0
  16. package/dist/weg-shared-layout/weg-shared-layout.esm.js +1 -1
  17. package/docs/README.md +51 -0
  18. package/docs/angular-16-compatibility.md +250 -235
  19. package/docs/angular-integration-guide.md +1035 -1008
  20. package/docs/angular.md +258 -232
  21. package/docs/nextjs.md +314 -306
  22. package/docs/publishing.md +65 -48
  23. package/docs/react.md +272 -261
  24. package/docs/vanilla.md +139 -138
  25. package/package.json +81 -76
  26. package/readme.md +97 -83
  27. package/src/constants/breakpoints.ts +7 -7
  28. package/src/styles/container.css +53 -0
  29. package/dist/weg-shared-layout/p-e6eadfa1.entry.js +0 -1
  30. /package/dist/types/Users/{tan/Documents/code → rakin/Documents/WEG/repos}/weg-shared-layout/.stencil/test-utils/axe.d.ts +0 -0
  31. /package/dist/types/Users/{tan/Documents/code → rakin/Documents/WEG/repos}/weg-shared-layout/.stencil/test-utils/viewport.d.ts +0 -0
@@ -1,48 +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 `dist/esm/loader.js`, missing `dist/components/*.js`, 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 `dist/esm/loader.js`, `dist/components/weg-footer.js`, and `loader/index.js`.
37
-
38
- 3. Publish (runs `prepack` → build again):
39
-
40
- ```bash
41
- npm publish
42
- ```
43
-
44
- Use `npm publish --dry-run` if you want to exercise the full pack pipeline without uploading.
45
-
46
- ## CI
47
-
48
- 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-16-compatibility.md](./angular-16-compatibility.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,261 +1,272 @@
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`**, 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)** | Module augmentation below; enable `resolveJsonModule` if you import `dummy-data.json`. |
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
- Side-effect import the tags your app uses:
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
- Define auth URLs once in your app:
79
-
80
- ```ts
81
- // auth.ts
82
- export const HEADER_SIGN_IN = {
83
- label: 'Sign in',
84
- href: 'https://account.warwickemploymentgroup.com/account/login',
85
- };
86
-
87
- export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
88
- ```
89
-
90
- ### Signed out
91
-
92
- Pass CMS/API layout with unified `header.menu`. Use [`dummy-data.json`](../src/assets/dummy-data.json) for the full shape — dropdown groups use `items`, flat links and Sign in use `href`. Keep auth URLs in a local file:
93
-
94
- ```ts
95
- // auth.ts (host app)
96
- export const HEADER_SIGN_IN = {
97
- label: 'Sign in',
98
- href: 'https://account.warwickemploymentgroup.com/account/login',
99
- };
100
-
101
- export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
102
- ```
103
-
104
- ### Signed in
105
-
106
- 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.
107
-
108
- ```tsx
109
- import { useCallback, useState } from 'react';
110
- import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth';
111
- import 'weg-shared-layout/weg-header';
112
- import layout from 'weg-shared-layout/dummy-data.json';
113
-
114
- export function SiteHeader() {
115
- const [signedIn, setSignedIn] = useState(false);
116
- const userName = signedIn ? 'Alex' : undefined;
117
-
118
- const onAuthClick = useCallback((event: CustomEvent<{ action: 'sign-in' | 'sign-out' }>) => {
119
- event.preventDefault();
120
-
121
- if (event.detail.action === 'sign-out') {
122
- setSignedIn(false);
123
- window.location.href = ACCOUNT_LOGIN_HREF;
124
- return;
125
- }
126
-
127
- window.location.href = HEADER_SIGN_IN.href;
128
- }, []);
129
-
130
- return (
131
- <weg-header
132
- layout={layout}
133
- signedIn={signedIn}
134
- {...(userName ? { userName } : {})}
135
- onWegAuthClick={onAuthClick}
136
- />
137
- );
138
- }
139
- ```
140
-
141
- | Prop / event | Purpose |
142
- | --- | --- |
143
- | `signedIn={boolean}` | Switches to signed-in nav when `true` |
144
- | `userName={string}` | First name beside profile icon on Manage Account |
145
- | `onWegAuthClick` | Host handles routing / logout; call `event.preventDefault()` to override defaults |
146
-
147
- **Ref fallback for the event** (if `onWegAuthClick` does not bind in your React version):
148
-
149
- ```tsx
150
- import { useEffect, useRef } from 'react';
151
-
152
- const ref = useRef<HTMLWegHeaderElement>(null);
153
-
154
- useEffect(() => {
155
- const el = ref.current;
156
- if (!el) return;
157
-
158
- const handler = (event: Event) => {
159
- const e = event as CustomEvent<{ action: 'sign-in' | 'sign-out' }>;
160
- e.preventDefault();
161
- // ...
162
- };
163
-
164
- el.addEventListener('wegAuthClick', handler);
165
- return () => el.removeEventListener('wegAuthClick', handler);
166
- }, []);
167
-
168
- return <weg-header ref={ref} layout={layout} signedIn={signedIn} userName="Alex" />;
169
- ```
170
-
171
- ## 4. Production: fetch layout from your API
172
-
173
- ```tsx
174
- import { useEffect, useState } from 'react';
175
- import 'weg-shared-layout/weg-header';
176
- import 'weg-shared-layout/weg-footer';
177
- import layoutFixture from 'weg-shared-layout/dummy-data.json';
178
-
179
- type LayoutData = typeof layoutFixture;
180
-
181
- const LAYOUT_URL = 'https://weg-payload-test.vercel.app/api/layout';
182
-
183
- export function SiteLayout({ children }: { children: React.ReactNode }) {
184
- const [layout, setLayout] = useState<LayoutData | null>(null);
185
-
186
- useEffect(() => {
187
- let cancelled = false;
188
- fetch(LAYOUT_URL)
189
- .then((res) => {
190
- if (!res.ok) throw new Error(`layout fetch failed: ${res.status}`);
191
- return res.json() as Promise<LayoutData>;
192
- })
193
- .then((data) => {
194
- if (!cancelled) setLayout(data);
195
- })
196
- .catch(console.error);
197
- return () => {
198
- cancelled = true;
199
- };
200
- }, []);
201
-
202
- if (!layout) return null;
203
-
204
- return (
205
- <>
206
- <weg-header layout={layout} />
207
- {children}
208
- <weg-footer layout={layout} />
209
- </>
210
- );
211
- }
212
- ```
213
-
214
- Replace the URL with your CMS/API. Keep the object shape aligned with `dummy-data.json`.
215
-
216
- ## TypeScript: module augmentation
217
-
218
- Add once (e.g. `src/types/weg-shared-layout-jsx.d.ts`):
219
-
220
- ```ts
221
- import type { JSX as WegSharedLayoutJSX } from 'weg-shared-layout';
222
- import type { DetailedHTMLProps, HTMLAttributes } from 'react';
223
-
224
- declare module 'react' {
225
- namespace JSX {
226
- interface IntrinsicElements extends WegSharedLayoutJSX.IntrinsicElements {
227
- 'weg-header': WegSharedLayoutJSX.IntrinsicElements['weg-header'] &
228
- DetailedHTMLProps<HTMLAttributes<HTMLWegHeaderElement>, HTMLWegHeaderElement>;
229
- 'weg-footer': WegSharedLayoutJSX.IntrinsicElements['weg-footer'] &
230
- DetailedHTMLProps<HTMLAttributes<HTMLWegFooterElement>, HTMLWegFooterElement>;
231
- }
232
- }
233
- }
234
- ```
235
-
236
- ## `layout` prop vs attribute
237
-
238
- | How data is set | Works with object? |
239
- | --- | --- |
240
- | **Property** `el.layout = obj` / React 19 `layout={obj}` | Yes |
241
- | **Attribute** `layout="[object Object]"` / React 18 `layout={obj}` | No — components stay empty |
242
- | **Attribute** `layout={JSON.stringify(obj)}` | Yes — component parses JSON |
243
-
244
- ## Troubleshooting
245
-
246
- | Symptom | Likely cause | Fix |
247
- | --- | --- | --- |
248
- | Empty header/footer | Loader/tag import missing | `defineCustomElements()` + tag imports. |
249
- | Empty despite correct data | React set `layout` as attribute | React 19+, or `JSON.stringify`, or ref assignment. |
250
- | Logo missing on header | Old build without inlined logo | Upgrade package; logo is bundled in `logo-data.ts`. |
251
- | Auth always Sign in | `signed-in` not set | Bind `signedIn={!!session}`. |
252
- | Manage Account shows label not name | `user-name` not set | Pass `userName` when signed in. |
253
- | `onWegAuthClick` not firing | React CE event binding | Use `addEventListener` on a ref. |
254
- | TS: unknown element | No augmentation | Add `weg-shared-layout-jsx.d.ts`. |
255
-
256
- ## See also
257
-
258
- - **[Next.js App Router](./nextjs.md)**
259
- - **[Angular](./angular.md)**
260
- - **[Plain HTML / vanilla JS](./vanilla.md)**
261
- - **[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`**, 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-16-compatibility](./angular-16-compatibility.md#error-2-cannot-find-module-weg-shared-layoutweg-header)):
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
+ Define auth URLs once in your app:
79
+
80
+ ```ts
81
+ // auth.ts
82
+ export const HEADER_SIGN_IN = {
83
+ label: 'Sign in',
84
+ href: 'https://account.warwickemploymentgroup.com/account/login',
85
+ };
86
+
87
+ export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
88
+ ```
89
+
90
+ ### Signed out
91
+
92
+ Pass CMS/API layout with unified **`header.menu`**. Use [`dummy-data.json`](../src/assets/dummy-data.json) for the full shape — nav groups use `items`, flat links and Sign in use `href`.
93
+
94
+ ### Signed in
95
+
96
+ 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.
97
+
98
+ ```tsx
99
+ import { useCallback, useState } from 'react';
100
+ import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth';
101
+ import 'weg-shared-layout/weg-header';
102
+ import layout from 'weg-shared-layout/dummy-data.json';
103
+
104
+ export function SiteHeader() {
105
+ const [signedIn, setSignedIn] = useState(false);
106
+ const userName = signedIn ? 'Alex' : undefined;
107
+
108
+ const onAuthClick = useCallback((event: CustomEvent<{ action: 'sign-in' | 'sign-out' }>) => {
109
+ event.preventDefault();
110
+
111
+ if (event.detail.action === 'sign-out') {
112
+ setSignedIn(false);
113
+ window.location.href = ACCOUNT_LOGIN_HREF;
114
+ return;
115
+ }
116
+
117
+ window.location.href = HEADER_SIGN_IN.href;
118
+ }, []);
119
+
120
+ return (
121
+ <weg-header
122
+ layout={layout}
123
+ signedIn={signedIn}
124
+ {...(userName ? { userName } : {})}
125
+ onWegAuthClick={onAuthClick}
126
+ />
127
+ );
128
+ }
129
+ ```
130
+
131
+ | Prop / event | Purpose |
132
+ | --- | --- |
133
+ | `signedIn={boolean}` | Switches to signed-in nav when `true` |
134
+ | `userName={string}` | First name beside profile icon on Manage Account |
135
+ | `onWegAuthClick` | Host handles routing / logout; call `event.preventDefault()` to override defaults |
136
+
137
+ **Ref fallback for the event** (if `onWegAuthClick` does not bind in your React version):
138
+
139
+ ```tsx
140
+ import { useEffect, useRef } from 'react';
141
+
142
+ const ref = useRef<HTMLWegHeaderElement>(null);
143
+
144
+ useEffect(() => {
145
+ const el = ref.current;
146
+ if (!el) return;
147
+
148
+ const handler = (event: Event) => {
149
+ const e = event as CustomEvent<{ action: 'sign-in' | 'sign-out' }>;
150
+ e.preventDefault();
151
+ // ...
152
+ };
153
+
154
+ el.addEventListener('wegAuthClick', handler);
155
+ return () => el.removeEventListener('wegAuthClick', handler);
156
+ }, []);
157
+
158
+ return <weg-header ref={ref} layout={layout} signedIn={signedIn} userName="Alex" />;
159
+ ```
160
+
161
+ ## 4. Production: fetch layout from your API
162
+
163
+ ```tsx
164
+ import { useEffect, useState } from 'react';
165
+ import 'weg-shared-layout/weg-header';
166
+ import 'weg-shared-layout/weg-footer';
167
+ import layoutFixture from 'weg-shared-layout/dummy-data.json';
168
+
169
+ type LayoutData = typeof layoutFixture;
170
+
171
+ const LAYOUT_URL = 'https://weg-payload-test.vercel.app/api/layout';
172
+
173
+ export function SiteLayout({ children }: { children: React.ReactNode }) {
174
+ const [layout, setLayout] = useState<LayoutData | null>(null);
175
+
176
+ useEffect(() => {
177
+ let cancelled = false;
178
+ fetch(LAYOUT_URL)
179
+ .then((res) => {
180
+ if (!res.ok) throw new Error(`layout fetch failed: ${res.status}`);
181
+ return res.json() as Promise<LayoutData>;
182
+ })
183
+ .then((data) => {
184
+ if (!cancelled) setLayout(data);
185
+ })
186
+ .catch(console.error);
187
+ return () => {
188
+ cancelled = true;
189
+ };
190
+ }, []);
191
+
192
+ if (!layout) return null;
193
+
194
+ return (
195
+ <>
196
+ <weg-header layout={layout} />
197
+ {children}
198
+ <weg-footer layout={layout} />
199
+ </>
200
+ );
201
+ }
202
+ ```
203
+
204
+ Replace the URL with your CMS/API. Keep the object shape aligned with `dummy-data.json`.
205
+
206
+ ## TypeScript
207
+
208
+ ### JSON + package subpaths
209
+
210
+ ```json
211
+ {
212
+ "compilerOptions": {
213
+ "resolveJsonModule": true,
214
+ "moduleResolution": "bundler"
215
+ }
216
+ }
217
+ ```
218
+
219
+ ```ts
220
+ import layoutFixture from 'weg-shared-layout/dummy-data.json';
221
+ export type LayoutData = typeof layoutFixture;
222
+ ```
223
+
224
+ Or types only: `import type { LayoutData } from 'weg-shared-layout/layout-data'`.
225
+
226
+ ### JSX module augmentation
227
+
228
+ Add once (e.g. `src/types/weg-shared-layout-jsx.d.ts`):
229
+
230
+ ```ts
231
+ import type { JSX as WegSharedLayoutJSX } from 'weg-shared-layout';
232
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react';
233
+
234
+ declare module 'react' {
235
+ namespace JSX {
236
+ interface IntrinsicElements extends WegSharedLayoutJSX.IntrinsicElements {
237
+ 'weg-header': WegSharedLayoutJSX.IntrinsicElements['weg-header'] &
238
+ DetailedHTMLProps<HTMLAttributes<HTMLWegHeaderElement>, HTMLWegHeaderElement>;
239
+ 'weg-footer': WegSharedLayoutJSX.IntrinsicElements['weg-footer'] &
240
+ DetailedHTMLProps<HTMLAttributes<HTMLWegFooterElement>, HTMLWegFooterElement>;
241
+ }
242
+ }
243
+ }
244
+ ```
245
+
246
+ ## `layout` prop vs attribute
247
+
248
+ | How data is set | Works with object? |
249
+ | --- | --- |
250
+ | **Property** `el.layout = obj` / React 19 `layout={obj}` | Yes |
251
+ | **Attribute** `layout="[object Object]"` / React 18 `layout={obj}` | No — components stay empty |
252
+ | **Attribute** `layout={JSON.stringify(obj)}` | Yes — component parses JSON |
253
+
254
+ ## Troubleshooting
255
+
256
+ | Symptom | Likely cause | Fix |
257
+ | --- | --- | --- |
258
+ | Empty header/footer | Loader/tag import missing | `defineCustomElements()` + tag imports. |
259
+ | Empty despite correct data | React set `layout` as attribute | React 19+, or `JSON.stringify`, or ref assignment. |
260
+ | Logo missing on header | Old build without inlined logo | Upgrade package; logo is bundled in `logo-data.ts`. |
261
+ | Auth always Sign in | `signed-in` not set | Bind `signedIn={!!session}`. |
262
+ | Manage Account shows label not name | `user-name` not set | Pass `userName` when signed in. |
263
+ | `onWegAuthClick` not firing | React CE event binding | Use `addEventListener` on a ref. |
264
+ | TS: unknown element | No augmentation | Add `weg-shared-layout-jsx.d.ts`. |
265
+
266
+ ## See also
267
+
268
+ - **[Documentation index](./README.md)**
269
+ - **[Next.js App Router](./nextjs.md)**
270
+ - **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
271
+ - **[Plain HTML / vanilla JS](./vanilla.md)**
272
+ - **[Package readme](../readme.md)**