Repository navigation
Expand file tree
/
Copy patherror-page.ts
More file actions
140 lines (124 loc) · 4.58 KB
/
Copy patherror-page.ts
File metadata and controls
140 lines (124 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import { BaseElement } from '../internal/base-element'
import { arrowLeftIcon, refreshIcon, warningTriangleIcon } from '../icons'
import { toRelPath } from '../routing'
export type ErrorPageMode = 'back' | 'refresh'
export class ErrorPageBackEvent extends Event {
constructor() {
super('error-back', { bubbles: true, composed: true })
}
}
export class ErrorPageRefreshEvent extends Event {
constructor() {
super('error-refresh', { bubbles: true, composed: true })
}
}
@customElement('wg-error-page')
export class WgErrorPage extends BaseElement {
@property({ type: String }) mode: ErrorPageMode = 'back'
@property({ type: String }) title = 'Something went wrong'
@property({ type: String }) message =
'An unexpected error occurred while loading this page.'
@property({ type: String }) backHref = '/'
@property({ type: Boolean }) performDefaultAction = true
static styles = [
BaseElement.styles,
css`
:host {
display: block;
}
.error-page {
min-height: 280px;
display: grid;
place-items: center;
text-align: center;
padding: var(--wg-space-8) var(--wg-space-4);
color: var(--wg-text);
}
.error-card {
width: min(560px, 100%);
background: var(--wg-surface);
border: 1px solid var(--wg-border);
border-radius: var(--wg-radius-xl);
box-shadow: var(--wg-shadow-md);
padding: var(--wg-space-8);
}
.error-icon {
color: var(--wg-error);
display: inline-flex;
margin-bottom: var(--wg-space-3);
}
h1 {
margin: 0;
font-size: var(--wg-font-size-2xl);
font-weight: var(--wg-font-weight-bold);
line-height: var(--wg-line-height-tight);
}
p {
margin: var(--wg-space-3) 0 var(--wg-space-6);
color: var(--wg-text-secondary);
font-size: var(--wg-font-size-base);
}
.action-btn {
border: none;
border-radius: var(--wg-radius-full);
display: inline-flex;
align-items: center;
gap: var(--wg-space-2);
padding: 0.55rem 1rem;
font-size: var(--wg-font-size-sm);
font-weight: var(--wg-font-weight-semibold);
cursor: pointer;
color: var(--wg-accent);
background: rgba(124, 58, 237, 0.1);
transition: background-color 0.2s ease;
}
.action-btn:hover {
background: rgba(124, 58, 237, 0.16);
}
`,
]
private onBack() {
this.dispatchEvent(new ErrorPageBackEvent())
if (this.performDefaultAction) {
window.location.href = toRelPath(this.backHref)
}
}
private onRefresh() {
this.dispatchEvent(new ErrorPageRefreshEvent())
if (this.performDefaultAction) {
window.location.reload()
}
}
render() {
return html`
<section class="error-page">
<article class="error-card" role="alert" aria-live="polite">
<div class="error-icon">${warningTriangleIcon}</div>
<h1>${this.title}</h1>
<p>${this.message}</p>
${
this.mode === 'refresh'
? html`<button
type="button"
class="action-btn"
@click=${this.onRefresh}
>
${refreshIcon} Refresh
</button>`
: html`<button
type="button"
class="action-btn"
@click=${this.onBack}
>
${arrowLeftIcon} Back
</button>`
}
</article>
</section>
`
}
}