weg-shared-layout 0.0.3 → 0.0.5

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 (49) hide show
  1. package/dist/types/components/weg-footer/weg-footer.d.ts +32 -47
  2. package/dist/types/components.d.ts +5 -79
  3. package/dist/weg-shared-layout/index-C8BdwtPR.js +4625 -0
  4. package/dist/weg-shared-layout/index-C8BdwtPR.js.map +1 -0
  5. package/dist/weg-shared-layout/index.esm.js +14 -1
  6. package/dist/weg-shared-layout/index.esm.js.map +1 -0
  7. package/dist/weg-shared-layout/my-component.entry.js +34 -0
  8. package/dist/weg-shared-layout/my-component.entry.js.map +1 -0
  9. package/dist/{cjs/index.cjs.js → weg-shared-layout/utils-DhW431pq.js} +4 -3
  10. package/dist/weg-shared-layout/utils-DhW431pq.js.map +1 -0
  11. package/dist/{esm/my-component_2.entry.js → weg-shared-layout/weg-footer.entry.js} +62 -138
  12. package/dist/weg-shared-layout/weg-footer.entry.js.map +1 -0
  13. package/dist/weg-shared-layout/weg-shared-layout.esm.js +50 -1
  14. package/dist/weg-shared-layout/weg-shared-layout.esm.js.map +1 -0
  15. package/package.json +5 -3
  16. package/readme.md +95 -95
  17. package/src/assets/dummy-data.json +20 -0
  18. package/dist/cjs/app-globals-V2Kpy_OQ.js +0 -5
  19. package/dist/cjs/index-CmiaQ_Dj.js +0 -1612
  20. package/dist/cjs/loader.cjs.js +0 -13
  21. package/dist/cjs/my-component_2.cjs.entry.js +0 -249
  22. package/dist/cjs/weg-shared-layout.cjs.js +0 -25
  23. package/dist/collection/collection-manifest.json +0 -14
  24. package/dist/collection/components/my-component/my-component.cmp.test.js +0 -27
  25. package/dist/collection/components/my-component/my-component.css +0 -3
  26. package/dist/collection/components/my-component/my-component.js +0 -95
  27. package/dist/collection/components/weg-footer/icons/instagram.svg +0 -5
  28. package/dist/collection/components/weg-footer/icons/linkedin.svg +0 -3
  29. package/dist/collection/components/weg-footer/icons/tiktok.svg +0 -3
  30. package/dist/collection/components/weg-footer/icons/youtube.svg +0 -4
  31. package/dist/collection/components/weg-footer/weg-footer.css +0 -236
  32. package/dist/collection/components/weg-footer/weg-footer.js +0 -412
  33. package/dist/collection/index.js +0 -10
  34. package/dist/collection/utils/utils.js +0 -3
  35. package/dist/collection/utils/utils.unit.test.js +0 -16
  36. package/dist/components/index.js +0 -1
  37. package/dist/components/my-component.js +0 -1
  38. package/dist/components/p-BTQYW5OR.js +0 -1
  39. package/dist/components/weg-footer.js +0 -1
  40. package/dist/esm/app-globals-DQuL1Twl.js +0 -3
  41. package/dist/esm/index-QiJxC4Ow.js +0 -1606
  42. package/dist/esm/index.js +0 -5
  43. package/dist/esm/loader.js +0 -11
  44. package/dist/esm/weg-shared-layout.js +0 -21
  45. package/dist/index.cjs.js +0 -1
  46. package/dist/index.js +0 -1
  47. package/dist/weg-shared-layout/p-67d9c345.entry.js +0 -1
  48. package/dist/weg-shared-layout/p-DQuL1Twl.js +0 -1
  49. package/dist/weg-shared-layout/p-QiJxC4Ow.js +0 -2
package/readme.md CHANGED
@@ -10,147 +10,147 @@ Install:
10
10
  npm i weg-shared-layout
11
11
  ```
12
12
 
13
+ ## How it works
14
+
15
+ `<weg-footer>` is a **presentational** Web Component: it does **not** fetch data. Your app loads layout data however you like (REST, GraphQL, SSR, etc.), then passes the object into the component via the **`data` property** (not a string HTML attribute).
16
+
17
+ The payload shape matches the sample file **`dummy-data.json`**, shipped with the package:
18
+
19
+ - **Import:** `import layout from 'weg-shared-layout/dummy-data.json'` (enable `resolveJsonModule` in TypeScript if needed).
20
+ - **In this repo:** [`src/assets/dummy-data.json`](src/assets/dummy-data.json)
21
+
22
+ Use that JSON as fixture data to see the footer working, or as a reference for your own API responses. Only `social.platform` values `LinkedIn`, `Instagram`, `TikTok`, and `YouTube` render an icon; items with missing or invalid fields are dropped.
23
+
13
24
  ## Using in Angular
14
25
 
15
- Register custom elements (recommended in `main.ts`):
26
+ Assumes Angular 17+ with **standalone** components (default for `ng new`).
27
+
28
+ ### 1. Install
29
+
30
+ ```bash
31
+ npm i weg-shared-layout
32
+ ```
33
+
34
+ ### 2. Register custom elements (once, before bootstrap)
35
+
36
+ In `src/main.ts`, call `defineCustomElements()` **before** `bootstrapApplication` so the browser recognises `<weg-footer>`.
16
37
 
17
38
  ```ts
39
+ import { bootstrapApplication } from '@angular/platform-browser';
18
40
  import { defineCustomElements } from 'weg-shared-layout/loader';
19
41
 
42
+ import { appConfig } from './app/app.config';
43
+ import { App } from './app/app';
44
+
20
45
  defineCustomElements();
46
+
47
+ bootstrapApplication(App, appConfig).catch((err) => console.error(err));
21
48
  ```
22
49
 
23
- Allow custom elements in the module that uses them:
50
+ ### 3. Allow custom elements in templates
24
51
 
25
- ```ts
26
- import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
52
+ Add `schemas: [CUSTOM_ELEMENTS_SCHEMA]` to every `@Component` whose template uses `<weg-footer>` (it does not cascade from the root through `router-outlet` children).
27
53
 
28
- @NgModule({
29
- // ...
30
- schemas: [CUSTOM_ELEMENTS_SCHEMA],
31
- })
32
- export class AppModule {}
33
- ```
54
+ ### 4. Pass data with property binding
34
55
 
35
- Use in a template (standard):
56
+ Use **`[data]="..."`** so Angular sets the element’s JavaScript `data` property (Stencil `@Prop()`), not an HTML attribute.
36
57
 
37
- ```html
38
- <weg-footer
39
- variant="standard"
40
- company-name="WEG"
41
- company-number="12345678"
42
- social-links-src="/assets/footer-social-links.json"
43
- standard-links-src="/assets/footer-standard-links.json"
44
- ></weg-footer>
45
- ```
58
+ Example with the bundled sample payload:
46
59
 
47
- Use in a template (additional):
60
+ ```ts
61
+ // src/app/app.ts
62
+ import { Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';
63
+ import { RouterOutlet } from '@angular/router';
64
+ import layoutFixture from 'weg-shared-layout/dummy-data.json';
65
+
66
+ @Component({
67
+ selector: 'app-root',
68
+ imports: [RouterOutlet],
69
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
70
+ templateUrl: './app.html',
71
+ styleUrl: './app.css',
72
+ })
73
+ export class App {
74
+ protected readonly layoutData = signal(layoutFixture);
75
+ }
76
+ ```
48
77
 
49
78
  ```html
50
- <weg-footer
51
- variant="additional"
52
- company-name="WEG"
53
- company-number="12345678"
54
- social-links-src="/assets/footer-social-links.json"
55
- additional-groups-src="/assets/footer-additional-groups.json"
56
- ></weg-footer>
79
+ <!-- src/app/app.html -->
80
+ <router-outlet />
81
+ <weg-footer [data]="layoutData()"></weg-footer>
57
82
  ```
58
83
 
59
- ## Using in React
84
+ In production, replace `layoutFixture` with data from your own services; keep the same object shape as `dummy-data.json`.
60
85
 
61
- Install:
86
+ ### Troubleshooting
62
87
 
63
- ```bash
64
- npm i weg-shared-layout
65
- ```
88
+ | Symptom | Cause / fix |
89
+ | --- | --- |
90
+ | `'weg-footer' is not a known element` | Add `schemas: [CUSTOM_ELEMENTS_SCHEMA]` on the component whose template contains `<weg-footer>`. |
91
+ | Footer missing or empty box | `defineCustomElements()` not called before bootstrap, or `data` not set / wrong shape — compare with `dummy-data.json`. |
92
+ | SSR: `document is not defined` | Guard `defineCustomElements()` with `typeof window !== 'undefined'` or `isPlatformBrowser`. |
66
93
 
67
- Register custom elements (pick one):
94
+ ### TypeScript typings
68
95
 
69
96
  ```ts
70
- // Option A (recommended): loader registers all components
71
- import { defineCustomElements } from 'weg-shared-layout/loader';
72
-
73
- defineCustomElements();
97
+ /// <reference types="weg-shared-layout/dist/types/components" />
74
98
  ```
75
99
 
76
- Or:
100
+ ### Legacy `NgModule`
77
101
 
78
- ```ts
79
- // Option B: import package bundle (also registers, depending on output target configuration)
80
- import 'weg-shared-layout';
81
- ```
102
+ Add `CUSTOM_ELEMENTS_SCHEMA` once on the module that declares components using `<weg-footer>`. `defineCustomElements()` in `main.ts` is still required.
82
103
 
83
- ### Next.js (App Router) note
104
+ ## Using in React
84
105
 
85
- Stencil custom elements must be registered **in the browser**. If you’re using Next.js `app/` (App Router), don’t import/register Stencil components from a Server Component.
106
+ Register once (for example in your app entry):
86
107
 
87
- Instead, register them in a Client Component, for example:
108
+ ```ts
109
+ import { defineCustomElements } from 'weg-shared-layout/loader';
88
110
 
89
- ```tsx
90
- // app/components/WegFooterClient.tsx
91
- "use client";
92
-
93
- import "weg-shared-layout/weg-footer";
94
-
95
- export function WegFooterClient() {
96
- return (
97
- <weg-footer
98
- variant="standard"
99
- company-name="WEG"
100
- company-number="12345678"
101
- social-links-src="/assets/footer-social-links.json"
102
- standard-links-src="/assets/footer-standard-links.json"
103
- />
104
- );
105
- }
111
+ defineCustomElements();
106
112
  ```
107
113
 
108
- Use the footer (standard):
114
+ Pass an object via a **ref** (or use React 19+ property handling) so you set the DOM property, not a string attribute:
109
115
 
110
116
  ```tsx
117
+ import { useEffect, useRef, useState } from 'react';
111
118
  import 'weg-shared-layout/weg-footer';
119
+ import layoutFixture from 'weg-shared-layout/dummy-data.json';
112
120
 
113
- export function App() {
114
- return (
115
- <weg-footer
116
- variant="standard"
117
- company-name="WEG"
118
- company-number="12345678"
119
- social-links-src="/assets/footer-social-links.json"
120
- standard-links-src="/assets/footer-standard-links.json"
121
- />
122
- );
123
- }
124
- ```
125
-
126
- Use the footer (additional):
121
+ export function SiteFooter() {
122
+ const ref = useRef<HTMLElement & { data?: unknown }>(null);
123
+ const [layout, setLayout] = useState(layoutFixture);
127
124
 
128
- ```tsx
129
- import 'weg-shared-layout/weg-footer';
125
+ useEffect(() => {
126
+ if (ref.current) ref.current.data = layout;
127
+ }, [layout]);
130
128
 
131
- export function App() {
132
- return (
133
- <weg-footer
134
- variant="additional"
135
- company-name="WEG"
136
- company-number="12345678"
137
- social-links-src="/assets/footer-social-links.json"
138
- additional-groups-src="/assets/footer-additional-groups.json"
139
- />
140
- );
129
+ return <weg-footer ref={ref} />;
141
130
  }
142
131
  ```
143
132
 
144
- ### React TypeScript typings
133
+ Swap `layoutFixture` / `setLayout` for your own data loading. **Next.js App Router:** register and assign `data` only in a Client Component (`"use client"`).
145
134
 
146
- Stencil generates `components.d.ts` in this repo, but React does not automatically pick up custom element typings. In consuming React apps, add a `global.d.ts` (or similar) that references your package’s generated types:
135
+ ### React TypeScript
147
136
 
148
137
  ```ts
149
138
  /// <reference types="weg-shared-layout/dist/types/components" />
150
139
  ```
151
140
 
152
- If your app still complains about JSX intrinsic elements, you can also augment `JSX.IntrinsicElements` in that same file (varies by React/TS setup).
141
+ ## Plain HTML / vanilla JS
153
142
 
154
- ### Note on `*-src` JSON URLs
143
+ With a bundler that resolves `node_modules` imports:
144
+
145
+ ```html
146
+ <weg-footer id="footer"></weg-footer>
147
+ <script type="module">
148
+ import { defineCustomElements } from 'weg-shared-layout/loader';
149
+ import layout from 'weg-shared-layout/dummy-data.json';
150
+
151
+ defineCustomElements();
152
+ document.getElementById('footer').data = layout;
153
+ </script>
154
+ ```
155
155
 
156
- `social-links-src`, `standard-links-src`, and `additional-groups-src` are fetched by the component at runtime, so the JSON files must be **served by the host app** (e.g. Angular’s `src/assets/`), or be a full `https://...` URL.
156
+ Otherwise, copy `dummy-data.json` to your static assets, `fetch` it, parse JSON, then assign **`element.data`**. You can also pass a JSON string on the **`data` attribute**; the component parses it the same way as an object `data` property.
@@ -0,0 +1,20 @@
1
+ {
2
+ "header": {},
3
+ "footer": {
4
+ "social": [
5
+ { "platform": "LinkedIn", "href": "https://www.linkedin.com/" },
6
+ { "platform": "Instagram", "href": "https://www.instagram.com/" },
7
+ { "platform": "TikTok", "href": "https://www.tiktok.com/" },
8
+ { "platform": "YouTube", "href": "https://www.youtube.com/" }
9
+ ],
10
+ "standardLinks": [
11
+ { "label": "About Us", "href": "/about" },
12
+ { "label": "Privacy Policy", "href": "/privacy" },
13
+ { "label": "Terms of Use", "href": "/terms" },
14
+ { "label": "Cookie Policy", "href": "/cookies" },
15
+ { "label": "Accessibility Statement", "href": "/accessibility" }
16
+ ],
17
+ "credits": "Warwick Employment Group is a department of the Campus and Commercial Services Group at the University of Warwick.",
18
+ "copyright": "Copyright © Warwick Employment Group."
19
+ }
20
+ }
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const globalScripts = () => {};
4
-
5
- exports.globalScripts = globalScripts;