weg-shared-layout 0.0.40 → 0.0.42
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 +449 -32
- package/dist/cjs/weg-shared-layout.cjs.js +1 -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 +263 -263
- package/dist/collection/components/weg-footer/weg-footer.js +2 -2
- package/dist/collection/components/weg-header/weg-header.css +533 -483
- package/dist/collection/components/weg-header/weg-header.js +348 -32
- package/dist/collection/styles/shared.css +104 -103
- package/dist/collection/utils/nav-active.js +121 -0
- 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 +449 -32
- package/dist/esm/weg-shared-layout.js +1 -1
- package/dist/types/components/weg-header/weg-header.d.ts +37 -0
- package/dist/types/components.d.ts +9 -0
- package/dist/types/utils/nav-active.d.ts +20 -0
- package/dist/weg-shared-layout/p-877ccc54.entry.js +1 -0
- package/dist/weg-shared-layout/weg-shared-layout.esm.js +1 -1
- package/docs/README.md +51 -49
- package/docs/angular.md +451 -400
- package/docs/nextjs.md +312 -302
- package/docs/publishing.md +65 -65
- package/docs/react.md +287 -257
- package/docs/vanilla.md +155 -124
- package/package.json +81 -81
- package/readme.md +108 -97
- package/src/constants/breakpoints.ts +7 -7
- package/src/styles/container.css +60 -60
- package/dist/weg-shared-layout/p-6f83b24a.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,124 +1,155 @@
|
|
|
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, menu, 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` and package **`exports`** (TypeScript: `resolveJsonModule` + `moduleResolution` `bundler` or `node16` — see [angular.md](./angular.md)):
|
|
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
|
-
|
|
27
|
-
defineCustomElements();
|
|
28
|
-
|
|
29
|
-
const header = document.getElementById('header');
|
|
30
|
-
const footer = document.getElementById('footer');
|
|
31
|
-
|
|
32
|
-
header.layout = layout;
|
|
33
|
-
footer.layout = layout;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
header.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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, menu, 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` and package **`exports`** (TypeScript: `resolveJsonModule` + `moduleResolution` `bundler` or `node16` — see [angular.md](./angular.md)):
|
|
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
|
+
|
|
27
|
+
defineCustomElements();
|
|
28
|
+
|
|
29
|
+
const header = document.getElementById('header');
|
|
30
|
+
const footer = document.getElementById('footer');
|
|
31
|
+
|
|
32
|
+
header.layout = layout;
|
|
33
|
+
footer.layout = layout;
|
|
34
|
+
|
|
35
|
+
function updateCurrentPath() {
|
|
36
|
+
const { pathname, search } = window.location;
|
|
37
|
+
header.currentPath = search ? `${pathname}${search}` : pathname;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
updateCurrentPath();
|
|
41
|
+
window.addEventListener('popstate', updateCurrentPath);
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Side-effect imports (no loader) if you only need specific tags:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import 'weg-shared-layout/weg-header';
|
|
49
|
+
import 'weg-shared-layout/weg-footer';
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## `layout` property vs attribute
|
|
53
|
+
|
|
54
|
+
Assign the **`layout` JavaScript property** (recommended):
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
element.layout = layoutObject;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Or pass a JSON **string** on the `layout` attribute:
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<weg-header layout='{"header":{"menu":[]}}'></weg-header>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Header layout fields (signed out)
|
|
67
|
+
|
|
68
|
+
| Field | Purpose |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `header.logoSrc` | Logo image URL (bundled if omitted) |
|
|
71
|
+
| `header.logoHref` | Logo link URL (WEG homepage if omitted) |
|
|
72
|
+
| `header.menu` | Unified nav — groups with `items[]`, flat links with `href` (incl. Sign in) |
|
|
73
|
+
|
|
74
|
+
See [`dummy-data.json`](../src/assets/dummy-data.json) for production URL examples.
|
|
75
|
+
|
|
76
|
+
## Header auth (Sign in / Sign out)
|
|
77
|
+
|
|
78
|
+
### Signed out
|
|
79
|
+
|
|
80
|
+
Renders `header.menu` from `layout`. Add sign-in as a normal link — `{ "label": "Sign in", "href": "…" }` — like Register. The header recognizes it by label or login URL and follows `href` on click.
|
|
81
|
+
|
|
82
|
+
### Signed in
|
|
83
|
+
|
|
84
|
+
Set **`signedIn`** and optionally **`userName`**. CMS nav is ignored; built-in links are shown (Find a job, Dashboard, Manage Account, Sign out). Set **`accountBaseUrl`** when account links should use a non-production portal.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
header.signedIn = true;
|
|
88
|
+
header.userName = 'Alex';
|
|
89
|
+
// header.accountBaseUrl = 'https://account-staging.example.com';
|
|
90
|
+
// or
|
|
91
|
+
header.setAttribute('signed-in', '');
|
|
92
|
+
header.setAttribute('user-name', 'Alex');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Listen for **`wegAuthClick`** to handle sign-out (call your logout API, then redirect):
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
header.addEventListener('wegAuthClick', async (event) => {
|
|
99
|
+
if (event.detail.action !== 'sign-out') return;
|
|
100
|
+
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
header.signedIn = false;
|
|
103
|
+
await logout();
|
|
104
|
+
window.location.assign('/');
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| `event.detail.action` | Default behaviour if not prevented |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `'sign-in'` | Browser follows the link's `href` |
|
|
111
|
+
| `'sign-out'` | Emits event only — no navigation (host handles logout) |
|
|
112
|
+
|
|
113
|
+
## Nav active state
|
|
114
|
+
|
|
115
|
+
Set **`currentPath`** (property) or **`current-path`** (attribute) to the current pathname. Include `?query` when dropdown links use search params.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
function syncCurrentPath() {
|
|
119
|
+
const { pathname, search } = window.location;
|
|
120
|
+
header.currentPath = search ? `${pathname}${search}` : pathname;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
syncCurrentPath();
|
|
124
|
+
window.addEventListener('popstate', syncCurrentPath);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
| Link type | Match rule |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| Flat nav link | Prefix match on pathname |
|
|
130
|
+
| Dropdown child | Exact pathname (+ query when href has `?`) |
|
|
131
|
+
| Dropdown parent | Active when any child matches |
|
|
132
|
+
| Sign in / Sign out | Never highlighted |
|
|
133
|
+
|
|
134
|
+
Active links use **`weg-purple-200`** (`#CDCFF8`).
|
|
135
|
+
|
|
136
|
+
Logo **image** uses `header.logoSrc` (bundled if omitted). Logo **link** uses `header.logoHref` when provided; otherwise it goes to the WEG homepage.
|
|
137
|
+
|
|
138
|
+
## Without a bundler
|
|
139
|
+
|
|
140
|
+
Copy `dummy-data.json` to your static assets, `fetch` it, parse JSON, then assign properties:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
const res = await fetch('/assets/dummy-data.json');
|
|
144
|
+
const layout = await res.json();
|
|
145
|
+
document.getElementById('header').layout = layout;
|
|
146
|
+
document.getElementById('footer').layout = layout;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## See also
|
|
150
|
+
|
|
151
|
+
- **[Documentation index](./README.md)**
|
|
152
|
+
- **[React SPA](./react.md)**
|
|
153
|
+
- **[Next.js App Router](./nextjs.md)**
|
|
154
|
+
- **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
|
|
155
|
+
- **[Package readme](../readme.md)**
|
package/package.json
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "weg-shared-layout",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Shared layout Web Components built with Stencil",
|
|
5
|
-
"main": "dist/index.cjs.js",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
|
-
"types": "dist/types/components.d.ts",
|
|
8
|
-
"collection": "dist/collection/collection-manifest.json",
|
|
9
|
-
"collection:main": "dist/collection/index.js",
|
|
10
|
-
"unpkg": "dist/weg-shared-layout/weg-shared-layout.esm.js",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"types": "./dist/types/components.d.ts",
|
|
14
|
-
"import": "./dist/weg-shared-layout/weg-shared-layout.esm.js",
|
|
15
|
-
"require": "./dist/weg-shared-layout/weg-shared-layout.cjs.js"
|
|
16
|
-
},
|
|
17
|
-
"./weg-footer": {
|
|
18
|
-
"types": "./dist/components/weg-footer.d.ts",
|
|
19
|
-
"import": "./dist/components/weg-footer.js"
|
|
20
|
-
},
|
|
21
|
-
"./weg-header": {
|
|
22
|
-
"types": "./dist/components/weg-header.d.ts",
|
|
23
|
-
"import": "./dist/components/weg-header.js"
|
|
24
|
-
},
|
|
25
|
-
"./loader": {
|
|
26
|
-
"types": "./loader/index.d.ts",
|
|
27
|
-
"import": "./loader/index.js",
|
|
28
|
-
"require": "./loader/index.cjs.js"
|
|
29
|
-
},
|
|
30
|
-
"./dummy-data.json": "./src/assets/dummy-data.json",
|
|
31
|
-
"./layout-data": {
|
|
32
|
-
"types": "./dist/types/types/layout-data.d.ts"
|
|
33
|
-
},
|
|
34
|
-
"./styles/container.css": "./src/styles/container.css"
|
|
35
|
-
},
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/jobsac/weg-shared-layout.git"
|
|
39
|
-
},
|
|
40
|
-
"bugs": {
|
|
41
|
-
"url": "https://github.com/jobsac/weg-shared-layout/issues"
|
|
42
|
-
},
|
|
43
|
-
"homepage": "https://github.com/jobsac/weg-shared-layout#readme",
|
|
44
|
-
"files": [
|
|
45
|
-
"dist/",
|
|
46
|
-
"docs/",
|
|
47
|
-
"loader/",
|
|
48
|
-
"src/assets/dummy-data.json",
|
|
49
|
-
"src/constants/",
|
|
50
|
-
"src/styles/container.css"
|
|
51
|
-
],
|
|
52
|
-
"scripts": {
|
|
53
|
-
"prepack": "
|
|
54
|
-
"build": "stencil build",
|
|
55
|
-
"start": "stencil build --dev --watch --serve",
|
|
56
|
-
"test": "stencil-test --prod",
|
|
57
|
-
"test:watch": "stencil-test --prod --watch",
|
|
58
|
-
"generate": "stencil generate",
|
|
59
|
-
"demo:angular16:install": "
|
|
60
|
-
"demo:angular16:build": "
|
|
61
|
-
"demo:angular16": "
|
|
62
|
-
},
|
|
63
|
-
"devDependencies": {
|
|
64
|
-
"@csstools/postcss-global-data": "~4.0.0",
|
|
65
|
-
"@stencil-community/postcss": "~2.2.0",
|
|
66
|
-
"@stencil/core": "~4.27.1 || ~5.0.0-0",
|
|
67
|
-
"@stencil/vitest": "~1.8.3",
|
|
68
|
-
"@types/node": "~22.13.5",
|
|
69
|
-
"@vitest/browser-playwright": "~4.0.0",
|
|
70
|
-
"axe-core": "~4.11.4",
|
|
71
|
-
"playwright": "~1.52.0",
|
|
72
|
-
"postcss-custom-media": "~12.0.1",
|
|
73
|
-
"vitest": "~4.0.0"
|
|
74
|
-
},
|
|
75
|
-
"license": "MIT",
|
|
76
|
-
"author": "WEG",
|
|
77
|
-
"contributors": [
|
|
78
|
-
"Tan Ahmed <tan.ahmed@warwick.ac.uk>",
|
|
79
|
-
"Rakin Ahmed <rakin.ahmed@warwick.ac.uk>"
|
|
80
|
-
]
|
|
81
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "weg-shared-layout",
|
|
3
|
+
"version": "0.0.42",
|
|
4
|
+
"description": "Shared layout Web Components built with Stencil",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/types/components.d.ts",
|
|
8
|
+
"collection": "dist/collection/collection-manifest.json",
|
|
9
|
+
"collection:main": "dist/collection/index.js",
|
|
10
|
+
"unpkg": "dist/weg-shared-layout/weg-shared-layout.esm.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/components.d.ts",
|
|
14
|
+
"import": "./dist/weg-shared-layout/weg-shared-layout.esm.js",
|
|
15
|
+
"require": "./dist/weg-shared-layout/weg-shared-layout.cjs.js"
|
|
16
|
+
},
|
|
17
|
+
"./weg-footer": {
|
|
18
|
+
"types": "./dist/components/weg-footer.d.ts",
|
|
19
|
+
"import": "./dist/components/weg-footer.js"
|
|
20
|
+
},
|
|
21
|
+
"./weg-header": {
|
|
22
|
+
"types": "./dist/components/weg-header.d.ts",
|
|
23
|
+
"import": "./dist/components/weg-header.js"
|
|
24
|
+
},
|
|
25
|
+
"./loader": {
|
|
26
|
+
"types": "./loader/index.d.ts",
|
|
27
|
+
"import": "./loader/index.js",
|
|
28
|
+
"require": "./loader/index.cjs.js"
|
|
29
|
+
},
|
|
30
|
+
"./dummy-data.json": "./src/assets/dummy-data.json",
|
|
31
|
+
"./layout-data": {
|
|
32
|
+
"types": "./dist/types/types/layout-data.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./styles/container.css": "./src/styles/container.css"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/jobsac/weg-shared-layout.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/jobsac/weg-shared-layout/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/jobsac/weg-shared-layout#readme",
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/",
|
|
46
|
+
"docs/",
|
|
47
|
+
"loader/",
|
|
48
|
+
"src/assets/dummy-data.json",
|
|
49
|
+
"src/constants/",
|
|
50
|
+
"src/styles/container.css"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"prepack": "pnpm run build",
|
|
54
|
+
"build": "stencil build",
|
|
55
|
+
"start": "stencil build --dev --watch --serve",
|
|
56
|
+
"test": "stencil-test --prod",
|
|
57
|
+
"test:watch": "stencil-test --prod --watch",
|
|
58
|
+
"generate": "stencil generate",
|
|
59
|
+
"demo:angular16:install": "pnpm install --dir demo/angular16",
|
|
60
|
+
"demo:angular16:build": "pnpm run build && pnpm run build --dir demo/angular16",
|
|
61
|
+
"demo:angular16": "pnpm run build && pnpm run start --dir demo/angular16"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@csstools/postcss-global-data": "~4.0.0",
|
|
65
|
+
"@stencil-community/postcss": "~2.2.0",
|
|
66
|
+
"@stencil/core": "~4.27.1 || ~5.0.0-0",
|
|
67
|
+
"@stencil/vitest": "~1.8.3",
|
|
68
|
+
"@types/node": "~22.13.5",
|
|
69
|
+
"@vitest/browser-playwright": "~4.0.0",
|
|
70
|
+
"axe-core": "~4.11.4",
|
|
71
|
+
"playwright": "~1.52.0",
|
|
72
|
+
"postcss-custom-media": "~12.0.1",
|
|
73
|
+
"vitest": "~4.0.0"
|
|
74
|
+
},
|
|
75
|
+
"license": "MIT",
|
|
76
|
+
"author": "WEG",
|
|
77
|
+
"contributors": [
|
|
78
|
+
"Tan Ahmed <tan.ahmed@warwick.ac.uk>",
|
|
79
|
+
"Rakin Ahmed <rakin.ahmed@warwick.ac.uk>"
|
|
80
|
+
]
|
|
81
|
+
}
|