weg-shared-layout 0.0.23 → 0.0.24
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/loader.cjs.js +1 -1
- package/dist/cjs/weg-footer_2.cjs.entry.js +121 -58
- package/dist/cjs/weg-shared-layout.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +0 -1
- 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 +218 -201
- package/dist/collection/components/weg-footer/weg-footer.js +2 -2
- package/dist/collection/components/weg-header/weg-header.css +473 -365
- package/dist/collection/components/weg-header/weg-header.js +114 -58
- package/dist/collection/constants/breakpoints.js +6 -0
- package/dist/collection/styles/shared.css +72 -78
- package/dist/components/weg-footer.js +1 -1
- package/dist/components/weg-header.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/weg-footer_2.entry.js +121 -58
- package/dist/esm/weg-shared-layout.js +1 -1
- package/dist/types/components/weg-header/weg-header.d.ts +20 -7
- package/dist/types/components.d.ts +0 -42
- package/dist/types/constants/breakpoints.d.ts +6 -0
- package/dist/weg-shared-layout/p-c6ec3888.entry.js +1 -0
- package/dist/weg-shared-layout/weg-shared-layout.esm.js +1 -1
- package/docs/angular-integration-guide.md +1026 -0
- package/docs/angular.md +247 -138
- package/docs/nextjs.md +305 -305
- package/docs/publishing.md +48 -48
- package/docs/react.md +261 -261
- package/docs/vanilla.md +140 -140
- package/package.json +12 -8
- package/readme.md +108 -107
- package/src/assets/dummy-data.json +147 -147
- package/src/constants/breakpoints.ts +7 -0
- package/src/constants/weg-urls.ts +23 -23
- package/dist/cjs/my-component.cjs.entry.js +0 -33
- package/dist/collection/components/my-component/my-component.css +0 -3
- package/dist/collection/components/my-component/my-component.js +0 -95
- package/dist/components/my-component.d.ts +0 -11
- package/dist/components/my-component.js +0 -1
- package/dist/esm/my-component.entry.js +0 -31
- package/dist/types/components/my-component/my-component.d.ts +0 -16
- package/dist/weg-shared-layout/p-80fa529c.entry.js +0 -1
- package/dist/weg-shared-layout/p-d61033bd.entry.js +0 -1
- /package/dist/types/Users/{tan/Documents/code → rakin/Documents/WEG/repos}/weg-shared-layout/.stencil/test-utils/axe.d.ts +0 -0
- /package/dist/types/Users/{tan/Documents/code → rakin/Documents/WEG/repos}/weg-shared-layout/.stencil/test-utils/viewport.d.ts +0 -0
package/docs/vanilla.md
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
# Plain HTML / vanilla JS
|
|
2
|
-
|
|
3
|
-
## What you get
|
|
4
|
-
|
|
5
|
-
| Tag | Purpose |
|
|
6
|
-
| --- | --- |
|
|
7
|
-
| `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
|
|
8
|
-
| `<weg-footer>` | Site footer — social links, columns, credits, copyright |
|
|
9
|
-
|
|
10
|
-
Both components are **presentational**: they do **not** fetch data. Pass the same `layout` payload to each.
|
|
11
|
-
|
|
12
|
-
Payload shape: [`dummy-data.json`](../src/assets/dummy-data.json) (see [readme](../readme.md#how-it-works)).
|
|
13
|
-
|
|
14
|
-
## Install & register
|
|
15
|
-
|
|
16
|
-
With a bundler that resolves `node_modules` imports:
|
|
17
|
-
|
|
18
|
-
```html
|
|
19
|
-
<weg-header id="header"></weg-header>
|
|
20
|
-
<main><!-- your content --></main>
|
|
21
|
-
<weg-footer id="footer"></weg-footer>
|
|
22
|
-
|
|
23
|
-
<script type="module">
|
|
24
|
-
import { defineCustomElements } from 'weg-shared-layout/loader';
|
|
25
|
-
import layout from 'weg-shared-layout/dummy-data.json';
|
|
26
|
-
import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth.js';
|
|
27
|
-
|
|
28
|
-
defineCustomElements();
|
|
29
|
-
|
|
30
|
-
const header = document.getElementById('header');
|
|
31
|
-
const footer = document.getElementById('footer');
|
|
32
|
-
|
|
33
|
-
header.layout = layout;
|
|
34
|
-
footer.layout = layout;
|
|
35
|
-
</script>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Side-effect imports (no loader) if you only need specific tags:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import 'weg-shared-layout/weg-header';
|
|
42
|
-
import 'weg-shared-layout/weg-footer';
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## `layout` property vs attribute
|
|
46
|
-
|
|
47
|
-
Assign the **`layout` JavaScript property** (recommended):
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
element.layout = layoutObject;
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Or pass a JSON **string** on the `layout` attribute:
|
|
54
|
-
|
|
55
|
-
```html
|
|
56
|
-
<weg-header layout='{"header":{"links":[]}}'></weg-header>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Header layout fields (signed out)
|
|
60
|
-
|
|
61
|
-
| Field | Purpose |
|
|
62
|
-
| --- | --- |
|
|
63
|
-
| `header.logoHref` | Logo link target (defaults to WEG home) |
|
|
64
|
-
| `header.dropdowns` | Dropdown menus from CMS |
|
|
65
|
-
| `header.links` | Flat nav links from CMS |
|
|
66
|
-
| `header.signIn` | Sign in button `{ label, href }` |
|
|
67
|
-
|
|
68
|
-
See [`dummy-data.json`](../src/assets/dummy-data.json) for production URL examples.
|
|
69
|
-
|
|
70
|
-
## Header auth (Sign in / Sign out)
|
|
71
|
-
|
|
72
|
-
Define auth URLs in `./auth.js`:
|
|
73
|
-
|
|
74
|
-
```js
|
|
75
|
-
export const HEADER_SIGN_IN = {
|
|
76
|
-
label: 'Sign in',
|
|
77
|
-
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Signed out
|
|
84
|
-
|
|
85
|
-
Renders `dropdowns`, `links`, and `signIn` from `layout`.
|
|
86
|
-
|
|
87
|
-
### Signed in
|
|
88
|
-
|
|
89
|
-
Set **`signedIn`** and optionally **`userName`**. CMS nav is ignored; built-in links are shown (Find a job, Dashboard, Manage Account, Sign out).
|
|
90
|
-
|
|
91
|
-
```js
|
|
92
|
-
header.signedIn = true;
|
|
93
|
-
header.userName = 'Alex';
|
|
94
|
-
// or
|
|
95
|
-
header.setAttribute('signed-in', '');
|
|
96
|
-
header.setAttribute('user-name', 'Alex');
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Listen for **`wegAuthClick`**:
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth.js';
|
|
103
|
-
|
|
104
|
-
header.addEventListener('wegAuthClick', (event) => {
|
|
105
|
-
event.preventDefault();
|
|
106
|
-
|
|
107
|
-
if (event.detail.action === 'sign-out') {
|
|
108
|
-
header.signedIn = false;
|
|
109
|
-
window.location.href = ACCOUNT_LOGIN_HREF;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
window.location.href = layout.header.signIn?.href ?? HEADER_SIGN_IN.href;
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
| `event.detail.action` | Default behaviour if not prevented |
|
|
118
|
-
| --- | --- |
|
|
119
|
-
| `'sign-in'` | Browser follows `signIn.href` |
|
|
120
|
-
| `'sign-out'` | Redirects to built-in sign-out URL |
|
|
121
|
-
|
|
122
|
-
Logo **image** is bundled. Logo **link** uses `layout.header.logoHref` when signed out.
|
|
123
|
-
|
|
124
|
-
## Without a bundler
|
|
125
|
-
|
|
126
|
-
Copy `dummy-data.json` to your static assets, `fetch` it, parse JSON, then assign properties:
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
const res = await fetch('/assets/dummy-data.json');
|
|
130
|
-
const layout = await res.json();
|
|
131
|
-
document.getElementById('header').layout = layout;
|
|
132
|
-
document.getElementById('footer').layout = layout;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## See also
|
|
136
|
-
|
|
137
|
-
- **[React SPA](./react.md)**
|
|
138
|
-
- **[Next.js App Router](./nextjs.md)**
|
|
139
|
-
- **[Angular](./angular.md)**
|
|
140
|
-
- **[Package readme](../readme.md)**
|
|
1
|
+
# Plain HTML / vanilla JS
|
|
2
|
+
|
|
3
|
+
## What you get
|
|
4
|
+
|
|
5
|
+
| Tag | Purpose |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
|
|
8
|
+
| `<weg-footer>` | Site footer — social links, columns, credits, copyright |
|
|
9
|
+
|
|
10
|
+
Both components are **presentational**: they do **not** fetch data. Pass the same `layout` payload to each.
|
|
11
|
+
|
|
12
|
+
Payload shape: [`dummy-data.json`](../src/assets/dummy-data.json) (see [readme](../readme.md#how-it-works)).
|
|
13
|
+
|
|
14
|
+
## Install & register
|
|
15
|
+
|
|
16
|
+
With a bundler that resolves `node_modules` imports:
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<weg-header id="header"></weg-header>
|
|
20
|
+
<main><!-- your content --></main>
|
|
21
|
+
<weg-footer id="footer"></weg-footer>
|
|
22
|
+
|
|
23
|
+
<script type="module">
|
|
24
|
+
import { defineCustomElements } from 'weg-shared-layout/loader';
|
|
25
|
+
import layout from 'weg-shared-layout/dummy-data.json';
|
|
26
|
+
import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth.js';
|
|
27
|
+
|
|
28
|
+
defineCustomElements();
|
|
29
|
+
|
|
30
|
+
const header = document.getElementById('header');
|
|
31
|
+
const footer = document.getElementById('footer');
|
|
32
|
+
|
|
33
|
+
header.layout = layout;
|
|
34
|
+
footer.layout = layout;
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Side-effect imports (no loader) if you only need specific tags:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import 'weg-shared-layout/weg-header';
|
|
42
|
+
import 'weg-shared-layout/weg-footer';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## `layout` property vs attribute
|
|
46
|
+
|
|
47
|
+
Assign the **`layout` JavaScript property** (recommended):
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
element.layout = layoutObject;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or pass a JSON **string** on the `layout` attribute:
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<weg-header layout='{"header":{"links":[]}}'></weg-header>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Header layout fields (signed out)
|
|
60
|
+
|
|
61
|
+
| Field | Purpose |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `header.logoHref` | Logo link target (defaults to WEG home) |
|
|
64
|
+
| `header.dropdowns` | Dropdown menus from CMS |
|
|
65
|
+
| `header.links` | Flat nav links from CMS |
|
|
66
|
+
| `header.signIn` | Sign in button `{ label, href }` |
|
|
67
|
+
|
|
68
|
+
See [`dummy-data.json`](../src/assets/dummy-data.json) for production URL examples.
|
|
69
|
+
|
|
70
|
+
## Header auth (Sign in / Sign out)
|
|
71
|
+
|
|
72
|
+
Define auth URLs in `./auth.js`:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
export const HEADER_SIGN_IN = {
|
|
76
|
+
label: 'Sign in',
|
|
77
|
+
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Signed out
|
|
84
|
+
|
|
85
|
+
Renders `dropdowns`, `links`, and `signIn` from `layout`.
|
|
86
|
+
|
|
87
|
+
### Signed in
|
|
88
|
+
|
|
89
|
+
Set **`signedIn`** and optionally **`userName`**. CMS nav is ignored; built-in links are shown (Find a job, Dashboard, Manage Account, Sign out).
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
header.signedIn = true;
|
|
93
|
+
header.userName = 'Alex';
|
|
94
|
+
// or
|
|
95
|
+
header.setAttribute('signed-in', '');
|
|
96
|
+
header.setAttribute('user-name', 'Alex');
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Listen for **`wegAuthClick`**:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { ACCOUNT_LOGIN_HREF, HEADER_SIGN_IN } from './auth.js';
|
|
103
|
+
|
|
104
|
+
header.addEventListener('wegAuthClick', (event) => {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
|
|
107
|
+
if (event.detail.action === 'sign-out') {
|
|
108
|
+
header.signedIn = false;
|
|
109
|
+
window.location.href = ACCOUNT_LOGIN_HREF;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
window.location.href = layout.header.signIn?.href ?? HEADER_SIGN_IN.href;
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| `event.detail.action` | Default behaviour if not prevented |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `'sign-in'` | Browser follows `signIn.href` |
|
|
120
|
+
| `'sign-out'` | Redirects to built-in sign-out URL |
|
|
121
|
+
|
|
122
|
+
Logo **image** is bundled. Logo **link** uses `layout.header.logoHref` when signed out.
|
|
123
|
+
|
|
124
|
+
## Without a bundler
|
|
125
|
+
|
|
126
|
+
Copy `dummy-data.json` to your static assets, `fetch` it, parse JSON, then assign properties:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const res = await fetch('/assets/dummy-data.json');
|
|
130
|
+
const layout = await res.json();
|
|
131
|
+
document.getElementById('header').layout = layout;
|
|
132
|
+
document.getElementById('footer').layout = layout;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## See also
|
|
136
|
+
|
|
137
|
+
- **[React SPA](./react.md)**
|
|
138
|
+
- **[Next.js App Router](./nextjs.md)**
|
|
139
|
+
- **[Angular](./angular.md)**
|
|
140
|
+
- **[Package readme](../readme.md)**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weg-shared-layout",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Shared layout Web Components built with Stencil",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"import": "./dist/weg-shared-layout/weg-shared-layout.esm.js",
|
|
15
15
|
"require": "./dist/weg-shared-layout/weg-shared-layout.cjs.js"
|
|
16
16
|
},
|
|
17
|
-
"./my-component": {
|
|
18
|
-
"types": "./dist/components/my-component.d.ts",
|
|
19
|
-
"import": "./dist/components/my-component.js"
|
|
20
|
-
},
|
|
21
17
|
"./weg-footer": {
|
|
22
18
|
"types": "./dist/components/weg-footer.d.ts",
|
|
23
19
|
"import": "./dist/components/weg-footer.js"
|
|
@@ -57,13 +53,21 @@
|
|
|
57
53
|
"generate": "stencil generate"
|
|
58
54
|
},
|
|
59
55
|
"devDependencies": {
|
|
56
|
+
"@csstools/postcss-global-data": "^4.0.0",
|
|
57
|
+
"@stencil-community/postcss": "^2.2.0",
|
|
60
58
|
"@stencil/core": "^4.27.1 || ^5.0.0-0",
|
|
61
59
|
"@stencil/vitest": "^1.8.3",
|
|
62
60
|
"@types/node": "^22.13.5",
|
|
63
61
|
"@vitest/browser-playwright": "^4.0.0",
|
|
62
|
+
"axe-core": "^4.11.4",
|
|
64
63
|
"playwright": "^1.52.0",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
64
|
+
"postcss-custom-media": "^12.0.1",
|
|
65
|
+
"vitest": "^4.0.0"
|
|
67
66
|
},
|
|
68
|
-
"license": "MIT"
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"author": "WEG",
|
|
69
|
+
"contributors": [
|
|
70
|
+
"Tan Ahmed <tan.ahmed@warwick.ac.uk>",
|
|
71
|
+
"Rakin Ahmed <rakin.ahmed@warwick.ac.uk>"
|
|
72
|
+
]
|
|
69
73
|
}
|
package/readme.md
CHANGED
|
@@ -1,107 +1,108 @@
|
|
|
1
|
-
[](https://stenciljs.com)
|
|
2
|
-
|
|
3
|
-
# weg-shared-layout
|
|
4
|
-
|
|
5
|
-
> Shared layout Web Components.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm i weg-shared-layout
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## How it works
|
|
14
|
-
|
|
15
|
-
`<weg-header>` and `<weg-footer>` are **presentational** Web Components: they do **not** fetch data.
|
|
16
|
-
|
|
17
|
-
Load layout JSON from your CMS/API (e.g. [`GET /api/layout`](https://weg-payload-test.vercel.app/api/layout) from WEG CMS) or import [`dummy-data.json`](src/assets/dummy-data.json), then pass it to `layout` on each tag.
|
|
18
|
-
|
|
19
|
-
### Layout shape (abbreviated)
|
|
20
|
-
|
|
21
|
-
Full reference: [`src/assets/dummy-data.json`](src/assets/dummy-data.json). This package keeps auth URLs in [`src/constants/weg-urls.ts`](src/constants/weg-urls.ts) for the signed-in nav and docs — **host apps should define their own constants file** (e.g. `auth.ts`) rather than importing from the package.
|
|
22
|
-
|
|
23
|
-
```json
|
|
24
|
-
{
|
|
25
|
-
"header": {
|
|
26
|
-
"logoHref": "…",
|
|
27
|
-
"dropdowns": [{ "label": "Find a job", "items": [{ "label": "Graduates", "href": "…" }] }],
|
|
28
|
-
"links": [{ "label": "Career advice", "href": "…" }, { "label": "Register", "href": "…" }],
|
|
29
|
-
"signIn": { "label": "Sign in", "href": "…" }
|
|
30
|
-
},
|
|
31
|
-
"footer": {
|
|
32
|
-
"social": [{ "platform": "LinkedIn", "href": "…" }],
|
|
33
|
-
"columns": [{ "links": [{ "label": "About WEG", "href": "…" }] }],
|
|
34
|
-
"credits": "…",
|
|
35
|
-
"copyright": "…"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Use **`dummy-data.json`** for full production URLs. In your app, keep sign-in/out URLs in a local constants file:
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
// auth.ts (host app — example)
|
|
44
|
-
export const HEADER_SIGN_IN = {
|
|
45
|
-
label: 'Sign in',
|
|
46
|
-
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
| Field | Used when | Notes |
|
|
53
|
-
| --- | --- | --- |
|
|
54
|
-
| `header.logoHref` | Always (signed out) | Logo link target. Defaults to WEG home if omitted. Logo image is bundled. |
|
|
55
|
-
| `header.dropdowns` | Signed out | CMS-managed dropdown menus |
|
|
56
|
-
| `header.links` | Signed out | CMS-managed flat nav links |
|
|
57
|
-
| `header.signIn` | Signed out | Sign in button label + href |
|
|
58
|
-
| `footer.*` | Always | Social, columns, credits, copyright |
|
|
59
|
-
|
|
60
|
-
### Auth (Sign in / Sign out)
|
|
61
|
-
|
|
62
|
-
**Signed out** (`signed-in` false): renders `dropdowns`, `links`, and `signIn` from `layout`.
|
|
63
|
-
|
|
64
|
-
**Signed in** (`signed-in` true): **ignores** CMS nav and shows built-in links:
|
|
65
|
-
|
|
66
|
-
- Find a job
|
|
67
|
-
- Dashboard
|
|
68
|
-
- Manage Account (profile icon + `user-name`, or "Manage Account" if omitted)
|
|
69
|
-
- Sign out (with icon)
|
|
70
|
-
|
|
71
|
-
Set **`signed-in`** from your app session state. Pass **`user-name`** with the user's first name for Manage Account.
|
|
72
|
-
|
|
73
|
-
Listen for **`wegAuthClick`** to handle sign-in routing or sign-out logic. Call `event.preventDefault()` to stop default navigation.
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
// auth.ts
|
|
77
|
-
const HEADER_SIGN_IN = {
|
|
78
|
-
label: 'Sign in',
|
|
79
|
-
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
header.signedIn = true;
|
|
83
|
-
header.userName = 'Alex';
|
|
84
|
-
header.addEventListener('wegAuthClick', (event) => {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
if (event.detail.action === 'sign-out') logout();
|
|
87
|
-
else window.location.href = layout.header.signIn?.href ?? HEADER_SIGN_IN.href;
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
- **From npm:** `import layout from 'weg-shared-layout/dummy-data.json'` (enable `resolveJsonModule` in TypeScript if needed).
|
|
92
|
-
- **In this repo:** [`src/assets/dummy-data.json`](src/assets/dummy-data.json)
|
|
93
|
-
|
|
94
|
-
## Framework guides
|
|
95
|
-
|
|
96
|
-
| Guide | Doc |
|
|
97
|
-
| --- | --- |
|
|
98
|
-
| Angular | [docs/angular.md](./docs/angular.md) |
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
[](https://stenciljs.com)
|
|
2
|
+
|
|
3
|
+
# weg-shared-layout
|
|
4
|
+
|
|
5
|
+
> Shared layout Web Components.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i weg-shared-layout
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
`<weg-header>` and `<weg-footer>` are **presentational** Web Components: they do **not** fetch data.
|
|
16
|
+
|
|
17
|
+
Load layout JSON from your CMS/API (e.g. [`GET /api/layout`](https://weg-payload-test.vercel.app/api/layout) from WEG CMS) or import [`dummy-data.json`](src/assets/dummy-data.json), then pass it to `layout` on each tag.
|
|
18
|
+
|
|
19
|
+
### Layout shape (abbreviated)
|
|
20
|
+
|
|
21
|
+
Full reference: [`src/assets/dummy-data.json`](src/assets/dummy-data.json). This package keeps auth URLs in [`src/constants/weg-urls.ts`](src/constants/weg-urls.ts) for the signed-in nav and docs — **host apps should define their own constants file** (e.g. `auth.ts`) rather than importing from the package.
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"header": {
|
|
26
|
+
"logoHref": "…",
|
|
27
|
+
"dropdowns": [{ "label": "Find a job", "items": [{ "label": "Graduates", "href": "…" }] }],
|
|
28
|
+
"links": [{ "label": "Career advice", "href": "…" }, { "label": "Register", "href": "…" }],
|
|
29
|
+
"signIn": { "label": "Sign in", "href": "…" }
|
|
30
|
+
},
|
|
31
|
+
"footer": {
|
|
32
|
+
"social": [{ "platform": "LinkedIn", "href": "…" }],
|
|
33
|
+
"columns": [{ "links": [{ "label": "About WEG", "href": "…" }] }],
|
|
34
|
+
"credits": "…",
|
|
35
|
+
"copyright": "…"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Use **`dummy-data.json`** for full production URLs. In your app, keep sign-in/out URLs in a local constants file:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// auth.ts (host app — example)
|
|
44
|
+
export const HEADER_SIGN_IN = {
|
|
45
|
+
label: 'Sign in',
|
|
46
|
+
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const ACCOUNT_LOGIN_HREF = HEADER_SIGN_IN.href;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Field | Used when | Notes |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `header.logoHref` | Always (signed out) | Logo link target. Defaults to WEG home if omitted. Logo image is bundled. |
|
|
55
|
+
| `header.dropdowns` | Signed out | CMS-managed dropdown menus |
|
|
56
|
+
| `header.links` | Signed out | CMS-managed flat nav links |
|
|
57
|
+
| `header.signIn` | Signed out | Sign in button label + href |
|
|
58
|
+
| `footer.*` | Always | Social, columns, credits, copyright |
|
|
59
|
+
|
|
60
|
+
### Auth (Sign in / Sign out)
|
|
61
|
+
|
|
62
|
+
**Signed out** (`signed-in` false): renders `dropdowns`, `links`, and `signIn` from `layout`.
|
|
63
|
+
|
|
64
|
+
**Signed in** (`signed-in` true): **ignores** CMS nav and shows built-in links:
|
|
65
|
+
|
|
66
|
+
- Find a job
|
|
67
|
+
- Dashboard
|
|
68
|
+
- Manage Account (profile icon + `user-name`, or "Manage Account" if omitted)
|
|
69
|
+
- Sign out (with icon)
|
|
70
|
+
|
|
71
|
+
Set **`signed-in`** from your app session state. Pass **`user-name`** with the user's first name for Manage Account.
|
|
72
|
+
|
|
73
|
+
Listen for **`wegAuthClick`** to handle sign-in routing or sign-out logic. Call `event.preventDefault()` to stop default navigation.
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
// auth.ts
|
|
77
|
+
const HEADER_SIGN_IN = {
|
|
78
|
+
label: 'Sign in',
|
|
79
|
+
href: 'https://account.warwickemploymentgroup.com/account/login',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
header.signedIn = true;
|
|
83
|
+
header.userName = 'Alex';
|
|
84
|
+
header.addEventListener('wegAuthClick', (event) => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
if (event.detail.action === 'sign-out') logout();
|
|
87
|
+
else window.location.href = layout.header.signIn?.href ?? HEADER_SIGN_IN.href;
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **From npm:** `import layout from 'weg-shared-layout/dummy-data.json'` (enable `resolveJsonModule` in TypeScript if needed).
|
|
92
|
+
- **In this repo:** [`src/assets/dummy-data.json`](src/assets/dummy-data.json)
|
|
93
|
+
|
|
94
|
+
## Framework guides
|
|
95
|
+
|
|
96
|
+
| Guide | Doc |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| Angular (quick start) | [docs/angular.md](./docs/angular.md) |
|
|
99
|
+
| Angular (step-by-step integration) | [docs/angular-integration-guide.md](./docs/angular-integration-guide.md) |
|
|
100
|
+
| React (SPA, client-only) | [docs/react.md](./docs/react.md) |
|
|
101
|
+
| Next.js (App Router) | [docs/nextjs.md](./docs/nextjs.md) |
|
|
102
|
+
| Plain HTML / vanilla JS | [docs/vanilla.md](./docs/vanilla.md) |
|
|
103
|
+
|
|
104
|
+
## Publishing (maintainers)
|
|
105
|
+
|
|
106
|
+
**`npm publish` does not run `npm run build` by itself** — it packs what is on disk. This package uses a **`prepack`** script so a full Stencil build runs before every `npm pack` / `npm publish`, avoiding incomplete tarballs.
|
|
107
|
+
|
|
108
|
+
Details, checklist, and CI notes: **[docs/publishing.md](./docs/publishing.md)**.
|