igniteui-cli 15.2.2 → 15.3.0
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/lib/commands/build.js +7 -12
- package/package.json +4 -4
- package/templates/blazor/igb/projects/ai-config/files/skills/AGENTS.md +0 -5
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/SKILL.md +2 -0
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/charts.md +7 -35
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/data-display.md +0 -54
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/feedback.md +0 -38
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/form-controls.md +0 -68
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/layout-manager.md +1 -124
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-components/references/layout.md +0 -62
- package/templates/blazor/igb/projects/ai-config/files/skills/igniteui-blazor-theming/SKILL.md +1 -1
- package/templates/react/igr-ts/projects/_base/files/package.json +1 -0
- package/templates/react/igr-ts/projects/_base/files/src/app/app.tsx +4 -2
- package/templates/react/igr-ts/projects/_base/files/src/setupTests.ts +12 -0
- package/templates/react/igr-ts/projects/_base/files/styles.css +6 -0
- package/templates/react/igr-ts/projects/_base_with_home/files/index.html +2 -1
- package/templates/react/igr-ts/projects/_base_with_home/files/src/app/home/home.tsx +60 -10
- package/templates/react/igr-ts/projects/_base_with_home/files/src/app/home/style.module.css +79 -20
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-components/SKILL.md +0 -8
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-components/reference/CHARTS-GRIDS.md +6 -36
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-components/reference/COMPONENT-CATALOGUE.md +8 -142
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-components/reference/EVENT-HANDLING.md +2 -0
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-customize-theme/SKILL.md +7 -14
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-customize-theme/reference/CSS-THEMING.md +2 -0
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-customize-theme/reference/MCP-SERVER.md +0 -8
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-generate-from-image-design/SKILL.md +2 -2
- package/templates/react/igr-ts/projects/ai-config/files/skills/igniteui-react-generate-from-image-design/reference/component-mapping.md +60 -74
- package/templates/react/igr-ts/projects/empty/index.js +2 -2
- package/templates/react/igr-ts/projects/side-nav/files/src/app/app-routes.tsx +5 -0
- package/templates/react/igr-ts/projects/side-nav/files/src/app/app.css +82 -0
- package/templates/react/igr-ts/projects/side-nav/files/src/app/app.tsx +104 -0
- package/templates/react/igr-ts/projects/side-nav/files/src/app/home/home.tsx +69 -0
- package/templates/react/igr-ts/projects/side-nav/files/src/app/home/style.module.css +105 -0
- package/templates/react/igr-ts/projects/{top-nav → side-nav}/index.d.ts +2 -2
- package/templates/react/igr-ts/projects/{top-nav → side-nav}/index.js +7 -7
- package/templates/react/igr-ts/projects/side-nav-auth/files/index.html +19 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/app-routes.tsx +24 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/app.css +84 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/app.tsx +124 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/AuthContext.tsx +73 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/AuthGuard.tsx +14 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/Login.module.css +93 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/Login.tsx +69 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/LoginBar.module.css +42 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/LoginBar.tsx +44 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/LoginDialog.module.css +14 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/LoginDialog.tsx +49 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/Register.module.css +74 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/components/Register.tsx +67 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/models/external-login.ts +10 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/models/login.ts +4 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/models/register-info.ts +6 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/models/user.ts +19 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/pages/Profile.module.css +87 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/pages/Profile.tsx +42 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/pages/RedirectFacebook.tsx +44 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/pages/RedirectGoogle.tsx +40 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/pages/RedirectMicrosoft.tsx +40 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/authentication.ts +37 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/external-auth-config.ts +44 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/externalAuth.ts +272 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/fakeBackend.ts +88 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/jwtUtil.ts +10 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/pkce.ts +29 -0
- package/templates/react/igr-ts/projects/side-nav-auth/files/src/app/authentication/services/userStore.ts +39 -0
- package/templates/react/igr-ts/projects/side-nav-auth/index.d.ts +15 -0
- package/templates/react/igr-ts/projects/side-nav-auth/index.js +46 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/app-routes.tsx +5 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/app.css +109 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/app.test.tsx +20 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/app.tsx +81 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/home/home.tsx +69 -0
- package/templates/react/igr-ts/projects/side-nav-mini/files/src/app/home/style.module.css +105 -0
- package/templates/react/igr-ts/projects/side-nav-mini/index.d.ts +15 -0
- package/templates/react/igr-ts/projects/side-nav-mini/index.js +46 -0
- package/templates/react/igr-ts/projects/side-nav-mini-auth/files/src/app/app.css +106 -0
- package/templates/react/igr-ts/projects/side-nav-mini-auth/files/src/app/app.tsx +101 -0
- package/templates/react/igr-ts/projects/side-nav-mini-auth/index.d.ts +15 -0
- package/templates/react/igr-ts/projects/side-nav-mini-auth/index.js +50 -0
- package/templates/webcomponents/igc-ts/projects/_base/files/src/app/app.ts +6 -1
- package/templates/webcomponents/igc-ts/projects/_base/files/styles.css +1 -0
- package/templates/webcomponents/igc-ts/projects/_base_with_home/files/index.html +2 -0
- package/templates/webcomponents/igc-ts/projects/_base_with_home/files/src/app/home/home.ts +103 -9
- package/templates/webcomponents/igc-ts/projects/_base_with_home/files/src/assets/wc.png +0 -0
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-choose-components/SKILL.md +122 -160
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-customize-component-theme/SKILL.md +83 -311
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-customize-component-theme/references/mcp-setup.md +69 -0
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-generate-from-image-design/SKILL.md +4 -1
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-generate-from-image-design/references/component-mapping.md +60 -61
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-generate-from-image-design/references/gotchas.md +15 -11
- package/templates/webcomponents/igc-ts/projects/ai-config/files/skills/igniteui-wc-optimize-bundle-size/SKILL.md +23 -274
- package/templates/webcomponents/igc-ts/projects/empty/index.js +1 -1
- package/templates/webcomponents/igc-ts/projects/side-nav/files/index.html +21 -0
- package/templates/webcomponents/igc-ts/projects/side-nav/files/src/app/app-routing.ts +9 -0
- package/templates/webcomponents/igc-ts/projects/side-nav/files/src/app/app.ts +192 -22
- package/templates/webcomponents/igc-ts/projects/side-nav/files/src/app/home/home.ts +175 -0
- package/templates/webcomponents/igc-ts/projects/side-nav/index.js +1 -1
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/index.html +25 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/app-routing.ts +37 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/app.ts +251 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/login-bar/login-bar.ts +124 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/login-dialog/login-dialog.ts +253 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/models/external-login.ts +10 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/models/login.ts +4 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/models/register-info.ts +6 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/models/user.ts +19 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/authentication.ts +37 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/external-auth-config.ts +44 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/externalAuth.ts +272 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/fakeBackend.ts +88 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/jwtUtil.ts +10 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/pkce.ts +29 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/authentication/services/userStore.ts +39 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/profile/profile.ts +142 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/redirect/redirect-facebook.ts +57 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/redirect/redirect-google.ts +53 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/files/src/app/redirect/redirect-microsoft.ts +53 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/index.d.ts +15 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-auth/index.js +46 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini/files/src/app/app-routing.ts +13 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini/files/src/app/app.ts +238 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini/index.d.ts +14 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini/index.js +45 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini-auth/files/src/app/app.ts +258 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini-auth/index.d.ts +15 -0
- package/templates/webcomponents/igc-ts/projects/side-nav-mini-auth/index.js +50 -0
- package/templates/react/igr-ts/projects/top-nav/files/src/app/app.css +0 -62
- package/templates/react/igr-ts/projects/top-nav/files/src/app/app.tsx +0 -18
- package/templates/react/igr-ts/projects/top-nav/files/src/components/navigation-header/index.tsx +0 -19
- /package/templates/react/igr-ts/projects/{top-nav → side-nav}/files/src/app/app.test.tsx +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Router } from '@vaadin/router';
|
|
2
|
+
import { css, html, LitElement } from 'lit';
|
|
3
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
4
|
+
import {
|
|
5
|
+
defineComponents,
|
|
6
|
+
IgcIconComponent,
|
|
7
|
+
IgcNavDrawerComponent,
|
|
8
|
+
IgcNavDrawerItemComponent,
|
|
9
|
+
registerIcon,
|
|
10
|
+
} from 'igniteui-webcomponents';
|
|
11
|
+
import { routes, type AppRoute } from './app-routing.js';
|
|
12
|
+
import { UserStore } from './authentication/services/userStore.js';
|
|
13
|
+
import './authentication/login-bar/login-bar.js';
|
|
14
|
+
|
|
15
|
+
defineComponents(
|
|
16
|
+
IgcIconComponent,
|
|
17
|
+
IgcNavDrawerComponent,
|
|
18
|
+
IgcNavDrawerItemComponent,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const materialIcons = [
|
|
22
|
+
['home', 'action/svg/production/ic_home_24px.svg'],
|
|
23
|
+
['menu', 'navigation/svg/production/ic_menu_24px.svg'],
|
|
24
|
+
['apps', 'navigation/svg/production/ic_apps_24px.svg'],
|
|
25
|
+
['code', 'action/svg/production/ic_code_24px.svg'],
|
|
26
|
+
['build', 'action/svg/production/ic_build_24px.svg'],
|
|
27
|
+
['palette', 'image/svg/production/ic_palette_24px.svg'],
|
|
28
|
+
['account_circle', 'action/svg/production/ic_account_circle_24px.svg'],
|
|
29
|
+
['lock', 'action/svg/production/ic_lock_24px.svg'],
|
|
30
|
+
['assignment_ind', 'action/svg/production/ic_assignment_ind_24px.svg'],
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
materialIcons.forEach(([name, path]) =>
|
|
34
|
+
registerIcon(name, `https://unpkg.com/material-design-icons@3.0.1/${path}`, 'material')
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
@customElement('app-root')
|
|
38
|
+
export default class App extends LitElement {
|
|
39
|
+
@state()
|
|
40
|
+
private drawerOpen = true;
|
|
41
|
+
|
|
42
|
+
@state()
|
|
43
|
+
private drawerPosition: 'relative' | 'start' = 'relative';
|
|
44
|
+
|
|
45
|
+
@state()
|
|
46
|
+
private currentPath = window.location.pathname;
|
|
47
|
+
|
|
48
|
+
@state()
|
|
49
|
+
private isLoggedIn = Boolean(UserStore.getUser());
|
|
50
|
+
|
|
51
|
+
private mediaQuery?: MediaQueryList;
|
|
52
|
+
|
|
53
|
+
static styles = css`
|
|
54
|
+
:host {
|
|
55
|
+
display: flex;
|
|
56
|
+
height: 100%;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.app {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-flow: column nowrap;
|
|
62
|
+
width: 100%;
|
|
63
|
+
height: 100%;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.app__navbar {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
flex: 0 0 auto;
|
|
71
|
+
height: 56px;
|
|
72
|
+
padding: 0 16px;
|
|
73
|
+
background: #239ef0;
|
|
74
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, .24);
|
|
75
|
+
box-sizing: border-box;
|
|
76
|
+
position: relative;
|
|
77
|
+
z-index: 10;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.app__menu-button {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
width: 40px;
|
|
85
|
+
height: 40px;
|
|
86
|
+
padding: 0;
|
|
87
|
+
color: #000;
|
|
88
|
+
border: 0;
|
|
89
|
+
background: transparent;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.app__menu-button igc-icon {
|
|
94
|
+
font-size: 24px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.app__title {
|
|
98
|
+
margin: 0 0 0 16px;
|
|
99
|
+
color: #000;
|
|
100
|
+
font-size: 1.25rem;
|
|
101
|
+
font-weight: 600;
|
|
102
|
+
line-height: 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.app__navbar-spacer {
|
|
106
|
+
flex: 1 1 auto;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.app__body {
|
|
110
|
+
display: flex;
|
|
111
|
+
flex: 1 1 auto;
|
|
112
|
+
min-height: 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.app__drawer {
|
|
116
|
+
flex: 0 0 auto;
|
|
117
|
+
height: 100%;
|
|
118
|
+
--menu-full-width: 280px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
igc-nav-drawer-item::part(base) {
|
|
122
|
+
min-height: 48px;
|
|
123
|
+
color: #2d2d2d;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
igc-nav-drawer-item[active]::part(base) {
|
|
127
|
+
background: #e0f2ff;
|
|
128
|
+
color: #0075d2;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
igc-nav-drawer-item[active] igc-icon {
|
|
132
|
+
color: #0075d2;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
igc-nav-drawer-item:not([active]) igc-icon {
|
|
136
|
+
color: #2d2d2d;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
router-outlet {
|
|
140
|
+
flex: 1 1 auto;
|
|
141
|
+
display: flex;
|
|
142
|
+
align-items: stretch;
|
|
143
|
+
justify-content: center;
|
|
144
|
+
min-width: 0;
|
|
145
|
+
overflow: auto;
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
render() {
|
|
150
|
+
const visibleRoutes = (routes as AppRoute[]).filter((route) => {
|
|
151
|
+
if (!route.name) return false;
|
|
152
|
+
if (route.requiresAuth && !this.isLoggedIn) return false;
|
|
153
|
+
return true;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return html`
|
|
157
|
+
<div class="app">
|
|
158
|
+
<header class="app__navbar">
|
|
159
|
+
<button
|
|
160
|
+
class="app__menu-button"
|
|
161
|
+
type="button"
|
|
162
|
+
aria-label="Toggle navigation"
|
|
163
|
+
@click=${this.toggleDrawer}
|
|
164
|
+
>
|
|
165
|
+
<igc-icon name="menu" collection="material"></igc-icon>
|
|
166
|
+
</button>
|
|
167
|
+
<h1 class="app__title">$(name)</h1>
|
|
168
|
+
<div class="app__navbar-spacer"></div>
|
|
169
|
+
<auth-login-bar @auth-change=${this.handleAuthChange}></auth-login-bar>
|
|
170
|
+
</header>
|
|
171
|
+
<div class="app__body">
|
|
172
|
+
<igc-nav-drawer
|
|
173
|
+
class="app__drawer"
|
|
174
|
+
?open=${this.drawerOpen}
|
|
175
|
+
position=${this.drawerPosition}
|
|
176
|
+
>
|
|
177
|
+
${visibleRoutes.map((route) => html`
|
|
178
|
+
<igc-nav-drawer-item
|
|
179
|
+
?active=${this.currentPath === route.path}
|
|
180
|
+
@click=${() => this.navigate(route.path)}
|
|
181
|
+
>
|
|
182
|
+
<igc-icon
|
|
183
|
+
slot="icon"
|
|
184
|
+
name=${route.icon || 'home'}
|
|
185
|
+
collection="material"
|
|
186
|
+
></igc-icon>
|
|
187
|
+
<span slot="content">${route.name}</span>
|
|
188
|
+
</igc-nav-drawer-item>
|
|
189
|
+
`)}
|
|
190
|
+
</igc-nav-drawer>
|
|
191
|
+
<router-outlet></router-outlet>
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
connectedCallback() {
|
|
198
|
+
super.connectedCallback();
|
|
199
|
+
|
|
200
|
+
this.mediaQuery = window.matchMedia('(min-width: 1025px)');
|
|
201
|
+
this.updateDrawerState();
|
|
202
|
+
this.mediaQuery.addEventListener('change', this.updateDrawerState);
|
|
203
|
+
window.addEventListener('popstate', this.updateCurrentPath);
|
|
204
|
+
// Listen globally so redirect components (Google/Facebook/Microsoft) in the router
|
|
205
|
+
// outlet can also trigger a shell state update after a successful OAuth redirect.
|
|
206
|
+
window.addEventListener('auth-change', this.handleAuthChange);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
disconnectedCallback() {
|
|
210
|
+
this.mediaQuery?.removeEventListener('change', this.updateDrawerState);
|
|
211
|
+
window.removeEventListener('popstate', this.updateCurrentPath);
|
|
212
|
+
window.removeEventListener('auth-change', this.handleAuthChange);
|
|
213
|
+
|
|
214
|
+
super.disconnectedCallback();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
firstUpdated() {
|
|
218
|
+
const outlet = this.shadowRoot?.querySelector('router-outlet');
|
|
219
|
+
const router = new Router(outlet);
|
|
220
|
+
router.setRoutes(routes);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private toggleDrawer = () => {
|
|
224
|
+
this.drawerOpen = !this.drawerOpen;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
private navigate(path: string) {
|
|
228
|
+
this.currentPath = path;
|
|
229
|
+
Router.go(path);
|
|
230
|
+
|
|
231
|
+
if (!this.mediaQuery?.matches) {
|
|
232
|
+
this.drawerOpen = false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private updateDrawerState = () => {
|
|
237
|
+
const pinned = Boolean(this.mediaQuery?.matches);
|
|
238
|
+
|
|
239
|
+
this.drawerOpen = pinned;
|
|
240
|
+
this.drawerPosition = pinned ? 'relative' : 'start';
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
private updateCurrentPath = () => {
|
|
244
|
+
this.currentPath = window.location.pathname;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
private handleAuthChange = () => {
|
|
248
|
+
this.isLoggedIn = Boolean(UserStore.getUser());
|
|
249
|
+
this.currentPath = window.location.pathname;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
3
|
+
import { Router } from '@vaadin/router';
|
|
4
|
+
import { defineComponents, IgcAvatarComponent, IgcButtonComponent, IgcDropdownComponent, IgcDropdownItemComponent } from 'igniteui-webcomponents';
|
|
5
|
+
import { UserStore } from '../services/userStore.js';
|
|
6
|
+
import { ExternalAuth } from '../services/externalAuth.js';
|
|
7
|
+
import type { User } from '../models/user.js';
|
|
8
|
+
import '../login-dialog/login-dialog.js';
|
|
9
|
+
|
|
10
|
+
defineComponents(IgcAvatarComponent, IgcButtonComponent, IgcDropdownComponent, IgcDropdownItemComponent);
|
|
11
|
+
|
|
12
|
+
@customElement('auth-login-bar')
|
|
13
|
+
export class LoginBarElement extends LitElement {
|
|
14
|
+
@state() private currentUser: User | null = UserStore.getUser();
|
|
15
|
+
|
|
16
|
+
static styles = css`
|
|
17
|
+
:host {
|
|
18
|
+
display: contents;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.login-btn::part(base) {
|
|
22
|
+
color: #0075d2;
|
|
23
|
+
background: #fff;
|
|
24
|
+
border-color: rgba(0, 117, 210, 0.35);
|
|
25
|
+
font-weight: 600;
|
|
26
|
+
white-space: nowrap;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.login-btn::part(base):hover {
|
|
30
|
+
background: #e8f3fc;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.profile-avatar {
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
color: #0075d2;
|
|
36
|
+
--ig-avatar-background: #fff;
|
|
37
|
+
--ig-avatar-color: #0075d2;
|
|
38
|
+
--ig-avatar-initials-font-size: 0.875rem;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
igc-dropdown-item:hover,
|
|
42
|
+
igc-dropdown-item[active]:hover {
|
|
43
|
+
background: #e8f3fc;
|
|
44
|
+
color: #0075d2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
igc-dropdown-item[active] {
|
|
48
|
+
background: #e8f3fc;
|
|
49
|
+
color: #0075d2;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
igc-dropdown-item[selected],
|
|
53
|
+
igc-dropdown-item[selected]:hover,
|
|
54
|
+
igc-dropdown-item[selected][active] {
|
|
55
|
+
background: #e8f3fc;
|
|
56
|
+
color: #0075d2;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.profile-avatar:focus-visible {
|
|
60
|
+
outline: 2px solid #fff;
|
|
61
|
+
outline-offset: 2px;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
connectedCallback() {
|
|
66
|
+
super.connectedCallback();
|
|
67
|
+
this.addEventListener('auth-change', this.handleAuthChange as EventListener);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
this.removeEventListener('auth-change', this.handleAuthChange as EventListener);
|
|
72
|
+
super.disconnectedCallback();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private handleAuthChange = () => {
|
|
76
|
+
this.currentUser = UserStore.getUser();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
private handleMenuSelect(e: CustomEvent) {
|
|
80
|
+
// igcChange detail is the selected IgcDropdownItemComponent element
|
|
81
|
+
const value = (e.detail as any)?.value;
|
|
82
|
+
if (value === 'profile') {
|
|
83
|
+
Router.go('/auth/profile');
|
|
84
|
+
} else if (value === 'logout') {
|
|
85
|
+
ExternalAuth.logout();
|
|
86
|
+
UserStore.clearUser();
|
|
87
|
+
this.currentUser = null;
|
|
88
|
+
Router.go('/');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
render() {
|
|
93
|
+
if (!this.currentUser) {
|
|
94
|
+
return html`
|
|
95
|
+
<igc-button variant="outlined" class="login-btn" @click=${() => (this.shadowRoot?.querySelector('auth-login-dialog') as any)?.open()}>Log In</igc-button>
|
|
96
|
+
<auth-login-dialog @auth-change=${this.handleAuthChange}></auth-login-dialog>
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const initials = UserStore.getInitials(this.currentUser);
|
|
101
|
+
|
|
102
|
+
return html`
|
|
103
|
+
<igc-dropdown placement="bottom-end" @igcChange=${this.handleMenuSelect}>
|
|
104
|
+
<igc-avatar
|
|
105
|
+
slot="target"
|
|
106
|
+
class="profile-avatar"
|
|
107
|
+
shape="circle"
|
|
108
|
+
size="small"
|
|
109
|
+
src=${this.currentUser.picture ?? ''}
|
|
110
|
+
tabindex="0"
|
|
111
|
+
aria-label="Open profile menu"
|
|
112
|
+
>${initials}</igc-avatar>
|
|
113
|
+
<igc-dropdown-item value="profile">Profile</igc-dropdown-item>
|
|
114
|
+
<igc-dropdown-item value="logout">Log Out</igc-dropdown-item>
|
|
115
|
+
</igc-dropdown>
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare global {
|
|
121
|
+
interface HTMLElementTagNameMap {
|
|
122
|
+
'auth-login-bar': LoginBarElement;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
3
|
+
import { Router } from '@vaadin/router';
|
|
4
|
+
import { defineComponents, IgcButtonComponent, IgcDialogComponent, IgcIconComponent, IgcInputComponent } from 'igniteui-webcomponents';
|
|
5
|
+
import { Authentication } from '../services/authentication.js';
|
|
6
|
+
import { ExternalAuth } from '../services/externalAuth.js';
|
|
7
|
+
import { UserStore } from '../services/userStore.js';
|
|
8
|
+
import type { User } from '../models/user.js';
|
|
9
|
+
|
|
10
|
+
defineComponents(IgcButtonComponent, IgcDialogComponent, IgcIconComponent, IgcInputComponent);
|
|
11
|
+
|
|
12
|
+
@customElement('auth-login-dialog')
|
|
13
|
+
export class LoginDialogElement extends LitElement {
|
|
14
|
+
@state() private showLogin = true;
|
|
15
|
+
@state() private error = '';
|
|
16
|
+
@state() private _loginValid = false;
|
|
17
|
+
@state() private _registerValid = false;
|
|
18
|
+
|
|
19
|
+
static styles = css`
|
|
20
|
+
igc-dialog::part(base) {
|
|
21
|
+
max-width: 24rem;
|
|
22
|
+
width: calc(100vw - 48px);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
igc-dialog::part(title) {
|
|
26
|
+
font-size: 1.125rem;
|
|
27
|
+
font-weight: 600;
|
|
28
|
+
color: #2d2d2d;
|
|
29
|
+
border-bottom: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.form {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-flow: column;
|
|
35
|
+
gap: 16px;
|
|
36
|
+
padding: 8px 0 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.form > * {
|
|
40
|
+
width: 100%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
igc-input {
|
|
44
|
+
--ig-input-group-focused-secondary-color: #239ef0;
|
|
45
|
+
--ig-input-group-focused-border-color: #239ef0;
|
|
46
|
+
--ig-input-group-filled-text-color: #2d2d2d;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
igc-input igc-icon {
|
|
50
|
+
color: #0075d2;
|
|
51
|
+
--ig-icon-size: 1.50rem;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.error {
|
|
55
|
+
margin: 0;
|
|
56
|
+
font-size: .875rem;
|
|
57
|
+
color: #d32f2f;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.submit-btn {
|
|
61
|
+
display: block;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.submit-btn::part(base) {
|
|
65
|
+
width: 100%;
|
|
66
|
+
min-height: 40px;
|
|
67
|
+
font-weight: 600;
|
|
68
|
+
text-transform: uppercase;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.submit-btn:not([disabled])::part(base) {
|
|
72
|
+
background: #239ef0;
|
|
73
|
+
color: #fff;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.submit-btn:not([disabled])::part(base):hover {
|
|
77
|
+
background: #1a8fd8;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.submit-btn[disabled]::part(base) {
|
|
81
|
+
background: #e0e0e0;
|
|
82
|
+
color: #767676;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.link-btn {
|
|
86
|
+
align-self: center;
|
|
87
|
+
text-align: center;
|
|
88
|
+
color: #0075d2;
|
|
89
|
+
font-size: .875rem;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
text-decoration: underline;
|
|
92
|
+
text-transform: none;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.link-btn:hover,
|
|
96
|
+
.link-btn:focus-visible {
|
|
97
|
+
color: #005da8;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.social-login {
|
|
101
|
+
display: grid;
|
|
102
|
+
gap: 8px;
|
|
103
|
+
padding-top: 16px;
|
|
104
|
+
border-top: 1px solid #d7d7d7;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.social-btn {
|
|
108
|
+
display: block;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.social-btn::part(base) {
|
|
112
|
+
width: 100%;
|
|
113
|
+
min-height: 40px;
|
|
114
|
+
color: #fff;
|
|
115
|
+
font-weight: 600;
|
|
116
|
+
text-transform: uppercase;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.google::part(base) { background: rgb(255, 19, 74); }
|
|
120
|
+
.facebook::part(base) { background: rgb(19, 119, 213); }
|
|
121
|
+
.microsoft::part(base) { background: rgb(27, 158, 245); }
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
private dialogRef: IgcDialogComponent | null = null;
|
|
125
|
+
|
|
126
|
+
public open() {
|
|
127
|
+
this.showLogin = true;
|
|
128
|
+
this.error = '';
|
|
129
|
+
this.dialogRef?.show();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
firstUpdated() {
|
|
133
|
+
this.dialogRef = this.shadowRoot?.querySelector('igc-dialog') ?? null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private checkLoginValidity = (e: Event) => {
|
|
137
|
+
this._loginValid = (e.currentTarget as HTMLFormElement).checkValidity();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
private checkRegisterValidity = (e: Event) => {
|
|
141
|
+
this._registerValid = (e.currentTarget as HTMLFormElement).checkValidity();
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
private handleLoginSubmit = async (e: Event) => {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
this.error = '';
|
|
147
|
+
const form = e.target as HTMLFormElement;
|
|
148
|
+
const data = new FormData(form);
|
|
149
|
+
const result = await Authentication.login({
|
|
150
|
+
email: data.get('email') as string,
|
|
151
|
+
password: data.get('password') as string,
|
|
152
|
+
});
|
|
153
|
+
if (result.user) {
|
|
154
|
+
form.reset();
|
|
155
|
+
this._loginValid = false;
|
|
156
|
+
UserStore.setUser(result.user as User);
|
|
157
|
+
this.dialogRef?.hide();
|
|
158
|
+
this.dispatchEvent(new CustomEvent('auth-change', { bubbles: true, composed: true }));
|
|
159
|
+
Router.go('/auth/profile');
|
|
160
|
+
} else {
|
|
161
|
+
this.error = result.error ?? 'Login failed';
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
private handleRegisterSubmit = async (e: Event) => {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
this.error = '';
|
|
168
|
+
const form = e.target as HTMLFormElement;
|
|
169
|
+
const data = new FormData(form);
|
|
170
|
+
const result = await Authentication.register({
|
|
171
|
+
given_name: data.get('given_name') as string,
|
|
172
|
+
family_name: data.get('family_name') as string,
|
|
173
|
+
email: data.get('email') as string,
|
|
174
|
+
password: data.get('password') as string,
|
|
175
|
+
});
|
|
176
|
+
if (result.user) {
|
|
177
|
+
form.reset();
|
|
178
|
+
this._registerValid = false;
|
|
179
|
+
UserStore.setUser(result.user as User);
|
|
180
|
+
this.dialogRef?.hide();
|
|
181
|
+
this.dispatchEvent(new CustomEvent('auth-change', { bubbles: true, composed: true }));
|
|
182
|
+
Router.go('/auth/profile');
|
|
183
|
+
} else {
|
|
184
|
+
this.error = result.error ?? 'Registration failed';
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
render() {
|
|
189
|
+
const title = this.showLogin ? 'Login' : 'Register';
|
|
190
|
+
|
|
191
|
+
const loginForm = html`
|
|
192
|
+
<form class="form" @submit=${this.handleLoginSubmit} @input=${this.checkLoginValidity} novalidate>
|
|
193
|
+
<igc-input outlined type="email" name="email" label="Email" autocomplete="email" required>
|
|
194
|
+
<igc-icon slot="suffix" name="account_circle" collection="material"></igc-icon>
|
|
195
|
+
</igc-input>
|
|
196
|
+
<igc-input outlined type="password" name="password" label="Password" autocomplete="current-password" required>
|
|
197
|
+
<igc-icon slot="suffix" name="lock" collection="material"></igc-icon>
|
|
198
|
+
</igc-input>
|
|
199
|
+
${this.error ? html`<p class="error">${this.error}</p>` : ''}
|
|
200
|
+
<igc-button class="submit-btn" variant="contained" type="submit" ?disabled=${!this._loginValid}>Log In</igc-button>
|
|
201
|
+
<a class="link-btn" @click=${() => { this.showLogin = false; this.error = ''; }} role="button" tabindex="0">Create new account</a>
|
|
202
|
+
${ExternalAuth.hasProvider() ? html`
|
|
203
|
+
<div class="social-login">
|
|
204
|
+
${ExternalAuth.hasProvider('google') ? html`
|
|
205
|
+
<igc-button class="social-btn google" variant="contained" type="button"
|
|
206
|
+
@click=${() => ExternalAuth.login('google')}>Sign in with Google</igc-button>
|
|
207
|
+
` : ''}
|
|
208
|
+
${ExternalAuth.hasProvider('facebook') ? html`
|
|
209
|
+
<igc-button class="social-btn facebook" variant="contained" type="button"
|
|
210
|
+
@click=${() => ExternalAuth.login('facebook')}>Sign in with Facebook</igc-button>
|
|
211
|
+
` : ''}
|
|
212
|
+
${ExternalAuth.hasProvider('microsoft') ? html`
|
|
213
|
+
<igc-button class="social-btn microsoft" variant="contained" type="button"
|
|
214
|
+
@click=${() => ExternalAuth.login('microsoft')}>Sign in with Microsoft</igc-button>
|
|
215
|
+
` : ''}
|
|
216
|
+
</div>
|
|
217
|
+
` : ''}
|
|
218
|
+
</form>
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
const registerForm = html`
|
|
222
|
+
<form class="form" @submit=${this.handleRegisterSubmit} @input=${this.checkRegisterValidity} novalidate>
|
|
223
|
+
<igc-input outlined type="text" name="given_name" label="First Name" autocomplete="given-name" required>
|
|
224
|
+
<igc-icon slot="suffix" name="assignment_ind" collection="material"></igc-icon>
|
|
225
|
+
</igc-input>
|
|
226
|
+
<igc-input outlined type="text" name="family_name" label="Last Name" autocomplete="family-name">
|
|
227
|
+
<igc-icon slot="suffix" name="assignment_ind" collection="material"></igc-icon>
|
|
228
|
+
</igc-input>
|
|
229
|
+
<igc-input outlined type="email" name="email" label="Email" autocomplete="email" required>
|
|
230
|
+
<igc-icon slot="suffix" name="account_circle" collection="material"></igc-icon>
|
|
231
|
+
</igc-input>
|
|
232
|
+
<igc-input outlined type="password" name="password" label="Password" autocomplete="new-password" required>
|
|
233
|
+
<igc-icon slot="suffix" name="lock" collection="material"></igc-icon>
|
|
234
|
+
</igc-input>
|
|
235
|
+
${this.error ? html`<p class="error">${this.error}</p>` : ''}
|
|
236
|
+
<igc-button class="submit-btn" variant="contained" type="submit" ?disabled=${!this._registerValid}>Sign Up</igc-button>
|
|
237
|
+
<a class="link-btn" @click=${() => { this.showLogin = true; this.error = ''; }} role="button" tabindex="0">Have an account?</a>
|
|
238
|
+
</form>
|
|
239
|
+
`;
|
|
240
|
+
return html`
|
|
241
|
+
<igc-dialog .title=${title} .closeOnOutsideClick=${true}>
|
|
242
|
+
<span slot="footer"></span>
|
|
243
|
+
${this.showLogin ? loginForm : registerForm}
|
|
244
|
+
</igc-dialog>
|
|
245
|
+
`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
declare global {
|
|
250
|
+
interface HTMLElementTagNameMap {
|
|
251
|
+
'auth-login-dialog': LoginDialogElement;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** User profile returned by a social (external) auth provider. */
|
|
2
|
+
export interface ExternalLogin {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
email?: string; // not always present use id as fallback key
|
|
6
|
+
given_name?: string;
|
|
7
|
+
family_name?: string;
|
|
8
|
+
picture?: string;
|
|
9
|
+
externalToken: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Data transfer model expected from backend API JWT-s */
|
|
2
|
+
export interface UserJWT {
|
|
3
|
+
exp: number;
|
|
4
|
+
name: string;
|
|
5
|
+
given_name: string;
|
|
6
|
+
family_name: string;
|
|
7
|
+
email: string;
|
|
8
|
+
picture?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Client user model */
|
|
12
|
+
export interface User extends UserJWT {
|
|
13
|
+
token: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface LoginResult {
|
|
17
|
+
user?: User;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|