@polarityio/pi-error 1.0.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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/component-registry.json +7 -0
- package/dist/error.d.ts +54 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +268 -0
- package/dist/styles/error.d.ts +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ThreatConnect, Inc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Polarity Integration Component Library
|
|
2
|
+
|
|
3
|
+
## Error Component
|
|
4
|
+
|
|
5
|
+
An error alert component that displays error information with a close button, optional title and icon, automatic message resolution from error objects, expandable JSON details, and clipboard copy.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @polarityio/pi-error
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer Dependencies
|
|
14
|
+
|
|
15
|
+
- [lit](https://lit.dev/) ^3.0.0
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import '@polarityio/pi-error';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Basic Error
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<pi-error open error-title="Error" message="An unexpected error occurred."></pi-error>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### No Title (Message-Only Header)
|
|
30
|
+
|
|
31
|
+
When no `error-title` is provided, the message is displayed inline in the header row. This is useful for compact, single-line error alerts.
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<pi-error open message="Something went wrong. Please try again."></pi-error>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### With an Error Object
|
|
38
|
+
|
|
39
|
+
When an `error` object is provided, the component resolves the message automatically:
|
|
40
|
+
|
|
41
|
+
1. If the error has a `detail` property, it is displayed as the message.
|
|
42
|
+
2. Otherwise, if the error has a `message` property, that is displayed.
|
|
43
|
+
|
|
44
|
+
The full error object is available in the expandable "View Details" section and can be copied to the clipboard.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { html } from 'lit';
|
|
48
|
+
|
|
49
|
+
html`
|
|
50
|
+
<pi-error
|
|
51
|
+
open
|
|
52
|
+
error-title="Request Failed"
|
|
53
|
+
.error=${{
|
|
54
|
+
status: 500,
|
|
55
|
+
detail: 'The upstream service returned an invalid response.',
|
|
56
|
+
requestId: 'abc-123-def-456'
|
|
57
|
+
}}
|
|
58
|
+
></pi-error>
|
|
59
|
+
`;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Explicit Message Override
|
|
63
|
+
|
|
64
|
+
When both a `message` property and an `error` object are provided, the explicit `message` takes priority over the error's `detail` or `message` fields.
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { html } from 'lit';
|
|
68
|
+
|
|
69
|
+
html`
|
|
70
|
+
<pi-error
|
|
71
|
+
open
|
|
72
|
+
error-title="API Error"
|
|
73
|
+
message="This explicit message overrides the error object."
|
|
74
|
+
.error=${{ detail: 'Original detail', status: 403 }}
|
|
75
|
+
></pi-error>
|
|
76
|
+
`;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Warning Variant
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<pi-error
|
|
83
|
+
open
|
|
84
|
+
variant="warning"
|
|
85
|
+
error-title="Warning"
|
|
86
|
+
message="This action may have unintended consequences."
|
|
87
|
+
></pi-error>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Custom Prefix Icon
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { html } from 'lit';
|
|
94
|
+
import { faBug } from '@fortawesome/free-solid-svg-icons';
|
|
95
|
+
|
|
96
|
+
html`
|
|
97
|
+
<pi-error open error-title="Bug Detected" message="An internal error was detected." .prefixIcon=${faBug}></pi-error>
|
|
98
|
+
`;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### No Prefix Icon
|
|
102
|
+
|
|
103
|
+
Set `prefixIcon` to `null` to hide the icon entirely.
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
import { html } from 'lit';
|
|
107
|
+
|
|
108
|
+
html` <pi-error open error-title="Error" message="No icon displayed." .prefixIcon=${null}></pi-error> `;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### No Title and No Icon
|
|
112
|
+
|
|
113
|
+
Combine both to show a minimal message-only alert with no icon.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { html } from 'lit';
|
|
117
|
+
|
|
118
|
+
html` <pi-error open message="Something went wrong. Please try again." .prefixIcon=${null}></pi-error> `;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## API Reference
|
|
122
|
+
|
|
123
|
+
### Properties
|
|
124
|
+
|
|
125
|
+
| Property | Attribute | Type | Default | Description |
|
|
126
|
+
| ------------ | ------------- | ------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
127
|
+
| `open` | `open` | `boolean` | `false` | Controls the visibility of the error component. |
|
|
128
|
+
| `variant` | `variant` | `'danger' \| 'warning'` | `'danger'` | Visual style variant. Controls background, border, and accent colors. |
|
|
129
|
+
| `errorTitle` | `error-title` | `string` | `''` | Title text displayed in the error header. Leave empty to show only the message in the header row. |
|
|
130
|
+
| `prefixIcon` | — | `IconDefinition \| null` | `faCircleExclamation` | FontAwesome icon displayed before the title. Set to `null` to hide. |
|
|
131
|
+
| `error` | — | `Record<string, unknown>` | `undefined` | The error object. If it has a `detail` property, that is used as the message. Otherwise `message` is used. The full object is shown in the expandable details section. |
|
|
132
|
+
| `message` | `message` | `string` | `''` | Explicit message text. Overrides any message derived from the error object. |
|
|
133
|
+
|
|
134
|
+
### Events
|
|
135
|
+
|
|
136
|
+
| Event Name | Detail | Description |
|
|
137
|
+
| ------------------------- | ----------------------- | -------------------------------------------------------- |
|
|
138
|
+
| `pi-error-close` | `{}` | Fired when the close button is clicked. |
|
|
139
|
+
| `pi-error-details-toggle` | `{ expanded: boolean }` | Fired when the details section is expanded or collapsed. |
|
|
140
|
+
|
|
141
|
+
### CSS Custom Properties
|
|
142
|
+
|
|
143
|
+
| Property | Default | Description |
|
|
144
|
+
| ------------------------------- | ------------------------------- | ------------------------------------------------------- |
|
|
145
|
+
| `--pi-error-background` | _(variant token)_ | Override the container background color. |
|
|
146
|
+
| `--pi-error-border-color` | _(variant token)_ | Override the container border color. |
|
|
147
|
+
| `--pi-error-border-radius` | `var(--pi-size-radius-lg, 8px)` | Container border radius. |
|
|
148
|
+
| `--pi-error-icon-size` | `1em` | Title icon size. |
|
|
149
|
+
| `--pi-error-icon-color` | _(variant token)_ | Override the title icon color. |
|
|
150
|
+
| `--pi-error-title-color` | _(variant token)_ | Override the title text color. |
|
|
151
|
+
| `--pi-error-message-color` | `var(--pi-color-font-primary)` | Message text color. |
|
|
152
|
+
| `--pi-error-details-max-height` | `300px` | Maximum height of the details section before scrolling. |
|
|
153
|
+
|
|
154
|
+
## Accessibility
|
|
155
|
+
|
|
156
|
+
- The error container has `role="alert"` to announce content to screen readers.
|
|
157
|
+
- The close button is a `pi-button` with `icon-only` and a `label` of "Close Error", providing full keyboard and screen reader accessibility.
|
|
158
|
+
- The View Details / Hide Details button is a standard `pi-button` with visible text.
|
|
159
|
+
- Copy button provides a "Copied error" success message.
|
|
160
|
+
|
|
161
|
+
## Theming
|
|
162
|
+
|
|
163
|
+
Customize the appearance using CSS custom properties or the `variant` property. This component uses design tokens from `@polarityio/pi-shared` for consistent theming across the component library.
|
|
164
|
+
|
|
165
|
+
The `danger` variant uses `--pi-color-*-danger` tokens and the `warning` variant uses `--pi-color-*-warning` tokens. You can override individual styles via the `--pi-error-*` CSS custom properties listed above.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LitElement, nothing } from 'lit';
|
|
2
|
+
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
3
|
+
export declare const CUSTOM_ELEMENT_NAME: string;
|
|
4
|
+
export type PiErrorVariant = 'danger' | 'warning';
|
|
5
|
+
export interface PiErrorProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
variant: PiErrorVariant;
|
|
8
|
+
errorTitle: string;
|
|
9
|
+
prefixIcon: IconDefinition | null;
|
|
10
|
+
error?: Record<string, unknown>;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An error alert component that displays error information with optional detail expansion and clipboard copy.
|
|
15
|
+
*
|
|
16
|
+
* @element pi-error
|
|
17
|
+
* @fires {CustomEvent} pi-error-close - Fired when the close button is clicked. detail: `{}`
|
|
18
|
+
* @fires {CustomEvent} pi-error-details-toggle - Fired when the details section is expanded or collapsed. detail: `{ expanded: boolean }`
|
|
19
|
+
* @cssproperty [--pi-error-background] - Override container background (defaults to variant token)
|
|
20
|
+
* @cssproperty [--pi-error-border-color] - Override container border color (defaults to variant token)
|
|
21
|
+
* @cssproperty [--pi-error-border-radius=var(--pi-size-radius-lg, 8px)] - Container border radius
|
|
22
|
+
* @cssproperty [--pi-error-icon-size=1em] - Title icon size
|
|
23
|
+
* @cssproperty [--pi-error-icon-color] - Override title icon color (defaults to variant token)
|
|
24
|
+
* @cssproperty [--pi-error-title-color] - Override title text color (defaults to variant token)
|
|
25
|
+
* @cssproperty [--pi-error-message-color=var(--pi-color-font-primary)] - Message text color
|
|
26
|
+
* @cssproperty [--pi-error-details-max-height=300px] - Maximum height of the details section before scrolling
|
|
27
|
+
*/
|
|
28
|
+
export declare class PiError extends LitElement {
|
|
29
|
+
/** Controls visibility of the error component. */
|
|
30
|
+
open: boolean;
|
|
31
|
+
/** Visual style variant. Controls background, border, and accent colors. */
|
|
32
|
+
variant: PiErrorVariant;
|
|
33
|
+
/** Title text displayed in the error header. Leave empty to show only the message in the header. */
|
|
34
|
+
errorTitle: string;
|
|
35
|
+
/** Icon displayed before the title. Defaults to exclamation-circle. Set to `null` to hide. */
|
|
36
|
+
prefixIcon: IconDefinition | null;
|
|
37
|
+
/**
|
|
38
|
+
* The error object to display. If the error has a `detail` property, it is shown as the message.
|
|
39
|
+
* Otherwise, if it has a `message` property, that is displayed. The full error object can be
|
|
40
|
+
* viewed in the expandable details section.
|
|
41
|
+
*/
|
|
42
|
+
error?: Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Explicit message text. When set, this overrides any message derived from the error object.
|
|
45
|
+
*/
|
|
46
|
+
message: string;
|
|
47
|
+
private _detailsExpanded;
|
|
48
|
+
static styles: import('lit').CSSResult;
|
|
49
|
+
private get _displayMessage();
|
|
50
|
+
private get _errorString();
|
|
51
|
+
private _handleClose;
|
|
52
|
+
private _handleDetailsToggle;
|
|
53
|
+
render(): typeof nothing | import('lit').TemplateResult;
|
|
54
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { css, LitElement, nothing } from "lit";
|
|
2
|
+
import { property, state } from "lit/decorators.js";
|
|
3
|
+
import { unsafeStatic, html } from "lit/static-html.js";
|
|
4
|
+
import { faCircleExclamation, faXmark, faChevronUp, faChevronDown } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import { libraryCustomElementName, defineCustomElementOnce } from "@polarityio/pi-shared";
|
|
6
|
+
import { CUSTOM_ELEMENT_NAME as CUSTOM_ELEMENT_NAME$1, PiIcon } from "@polarityio/pi-icon";
|
|
7
|
+
import { CUSTOM_ELEMENT_NAME as CUSTOM_ELEMENT_NAME$2, PiButton } from "@polarityio/pi-button";
|
|
8
|
+
import { CUSTOM_ELEMENT_NAME as CUSTOM_ELEMENT_NAME$3, PiCopyButton } from "@polarityio/pi-copy-button";
|
|
9
|
+
const version = "1.0.0";
|
|
10
|
+
const packageJson = {
|
|
11
|
+
version
|
|
12
|
+
};
|
|
13
|
+
const errorStyles = css`
|
|
14
|
+
:host {
|
|
15
|
+
display: block;
|
|
16
|
+
font-family: var(--pi-font-family-base, 'NotoSans', sans-serif);
|
|
17
|
+
font-size: var(--pi-size-font-base, 0.8125rem);
|
|
18
|
+
color: var(--pi-color-font-primary, #e2e3ea);
|
|
19
|
+
|
|
20
|
+
/* Variant tokens — components reference these, variants override them */
|
|
21
|
+
--_pi-error-accent: var(--pi-color-font-danger);
|
|
22
|
+
--_pi-error-bg: var(--pi-color-background-container-danger);
|
|
23
|
+
--_pi-error-border: var(--pi-color-border-danger);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:host([hidden]) {
|
|
27
|
+
display: none !important;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* ── Variant overrides ── */
|
|
31
|
+
|
|
32
|
+
:host([variant='danger']) {
|
|
33
|
+
--_pi-error-accent: var(--pi-color-font-danger);
|
|
34
|
+
--_pi-error-bg: var(--pi-color-background-container-danger);
|
|
35
|
+
--_pi-error-border: var(--pi-color-border-danger);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
:host([variant='warning']) {
|
|
39
|
+
--_pi-error-accent: var(--pi-color-font-warning);
|
|
40
|
+
--_pi-error-bg: var(--pi-color-background-container-warning);
|
|
41
|
+
--_pi-error-border: var(--pi-color-border-warning);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ── Layout ── */
|
|
45
|
+
|
|
46
|
+
.error-container {
|
|
47
|
+
background: var(--pi-error-background, var(--_pi-error-bg));
|
|
48
|
+
border: 1px solid var(--pi-error-border-color, var(--_pi-error-border));
|
|
49
|
+
border-radius: var(--pi-error-border-radius, var(--pi-size-radius-lg, 8px));
|
|
50
|
+
padding: var(--pi-size-spacing-md, 0.75rem);
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
gap: var(--pi-size-spacing-sm, 0.5rem);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.header {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: var(--pi-size-spacing-sm, 0.5rem);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.title-icon {
|
|
63
|
+
display: flex;
|
|
64
|
+
align-items: center;
|
|
65
|
+
flex-shrink: 0;
|
|
66
|
+
--pi-icon-size: var(--pi-error-icon-size, 1em);
|
|
67
|
+
--pi-icon-color: var(--pi-error-icon-color, var(--_pi-error-accent));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.title-content {
|
|
71
|
+
flex: 1;
|
|
72
|
+
min-width: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.title {
|
|
76
|
+
font-family: var(--pi-font-family-base, 'NotoSans', sans-serif);
|
|
77
|
+
font-size: var(--pi-size-font-sm, 0.875rem);
|
|
78
|
+
font-weight: var(--pi-font-weight-bold, 700);
|
|
79
|
+
color: var(--pi-error-title-color, var(--_pi-error-accent));
|
|
80
|
+
line-height: 1.3;
|
|
81
|
+
margin: 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.close-button {
|
|
85
|
+
flex-shrink: 0;
|
|
86
|
+
margin-left: auto;
|
|
87
|
+
--pi-button-icon-color: var(--pi-color-font-secondary, #9ba1b0);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.message {
|
|
91
|
+
color: var(--pi-error-message-color, var(--pi-color-font-primary, #e2e3ea));
|
|
92
|
+
font-size: var(--pi-size-font-base, 0.8125rem);
|
|
93
|
+
line-height: 1.5;
|
|
94
|
+
margin: 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.actions {
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
gap: var(--pi-size-spacing-sm, 0.5rem);
|
|
101
|
+
margin-top: var(--pi-size-spacing-xs, 0.25rem);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.details {
|
|
105
|
+
background: var(--pi-color-background-application-1, #1e2330);
|
|
106
|
+
border: 1px solid var(--pi-color-border-container, #3a3f4b);
|
|
107
|
+
border-radius: var(--pi-size-radius-base, 4px);
|
|
108
|
+
padding: var(--pi-size-spacing-sm, 0.5rem) var(--pi-size-spacing-md, 0.75rem);
|
|
109
|
+
margin-top: var(--pi-size-spacing-xs, 0.25rem);
|
|
110
|
+
overflow: auto;
|
|
111
|
+
max-height: var(--pi-error-details-max-height, 300px);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.details pre {
|
|
115
|
+
margin: 0;
|
|
116
|
+
font-family: var(--pi-font-family-mono, 'Courier New', monospace);
|
|
117
|
+
font-size: var(--pi-size-font-xs, 0.75rem);
|
|
118
|
+
color: var(--pi-color-font-secondary, #9ba1b0);
|
|
119
|
+
white-space: pre-wrap;
|
|
120
|
+
word-break: break-word;
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
var __defProp = Object.defineProperty;
|
|
124
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
125
|
+
var result = void 0;
|
|
126
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
127
|
+
if (decorator = decorators[i])
|
|
128
|
+
result = decorator(target, key, result) || result;
|
|
129
|
+
if (result) __defProp(target, key, result);
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
const CUSTOM_ELEMENT_NAME = libraryCustomElementName("error", packageJson.version);
|
|
133
|
+
defineCustomElementOnce(CUSTOM_ELEMENT_NAME$1, PiIcon);
|
|
134
|
+
defineCustomElementOnce(CUSTOM_ELEMENT_NAME$2, PiButton);
|
|
135
|
+
defineCustomElementOnce(CUSTOM_ELEMENT_NAME$3, PiCopyButton);
|
|
136
|
+
const iconTag = unsafeStatic(CUSTOM_ELEMENT_NAME$1);
|
|
137
|
+
const buttonTag = unsafeStatic(CUSTOM_ELEMENT_NAME$2);
|
|
138
|
+
const copyButtonTag = unsafeStatic(CUSTOM_ELEMENT_NAME$3);
|
|
139
|
+
const _PiError = class _PiError extends LitElement {
|
|
140
|
+
constructor() {
|
|
141
|
+
super(...arguments);
|
|
142
|
+
this.open = false;
|
|
143
|
+
this.variant = "danger";
|
|
144
|
+
this.errorTitle = "";
|
|
145
|
+
this.prefixIcon = faCircleExclamation;
|
|
146
|
+
this.message = "";
|
|
147
|
+
this._detailsExpanded = false;
|
|
148
|
+
this._handleClose = () => {
|
|
149
|
+
this.open = false;
|
|
150
|
+
this.dispatchEvent(
|
|
151
|
+
new CustomEvent("pi-error-close", {
|
|
152
|
+
detail: {},
|
|
153
|
+
bubbles: true,
|
|
154
|
+
composed: true
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
this._handleDetailsToggle = () => {
|
|
159
|
+
this._detailsExpanded = !this._detailsExpanded;
|
|
160
|
+
this.dispatchEvent(
|
|
161
|
+
new CustomEvent("pi-error-details-toggle", {
|
|
162
|
+
detail: { expanded: this._detailsExpanded },
|
|
163
|
+
bubbles: true,
|
|
164
|
+
composed: true
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
get _displayMessage() {
|
|
170
|
+
if (this.message) return this.message;
|
|
171
|
+
if (!this.error) return "";
|
|
172
|
+
if (typeof this.error.detail === "string") return this.error.detail;
|
|
173
|
+
if (typeof this.error.message === "string") return this.error.message;
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
get _errorString() {
|
|
177
|
+
if (!this.error) return "";
|
|
178
|
+
try {
|
|
179
|
+
return JSON.stringify(this.error, null, 2);
|
|
180
|
+
} catch {
|
|
181
|
+
return "[Unable to serialize error]";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
render() {
|
|
185
|
+
if (!this.open) return nothing;
|
|
186
|
+
const displayMessage = this._displayMessage;
|
|
187
|
+
const errorString = this._errorString;
|
|
188
|
+
const hasError = !!this.error;
|
|
189
|
+
return html`
|
|
190
|
+
<div class="error-container" role="alert">
|
|
191
|
+
<div class="header">
|
|
192
|
+
${this.prefixIcon ? html`
|
|
193
|
+
<span class="title-icon">
|
|
194
|
+
<${iconTag} .icon=${this.prefixIcon}></${iconTag}>
|
|
195
|
+
</span>
|
|
196
|
+
` : nothing}
|
|
197
|
+
<div class="title-content">
|
|
198
|
+
${this.errorTitle ? html`<h2 class="title">${this.errorTitle}</h2>` : displayMessage ? html`<p class="message">${displayMessage}</p>` : nothing}
|
|
199
|
+
</div>
|
|
200
|
+
<${buttonTag}
|
|
201
|
+
class="close-button"
|
|
202
|
+
type="tertiary"
|
|
203
|
+
icon-only
|
|
204
|
+
condensed
|
|
205
|
+
.prefixIcon=${faXmark}
|
|
206
|
+
label="Close Error"
|
|
207
|
+
@pi-click=${this._handleClose}
|
|
208
|
+
></${buttonTag}>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
${this.errorTitle && displayMessage ? html`<p class="message">${displayMessage}</p>` : nothing}
|
|
212
|
+
|
|
213
|
+
${hasError ? html`
|
|
214
|
+
<div class="actions">
|
|
215
|
+
<${buttonTag}
|
|
216
|
+
type="tertiary"
|
|
217
|
+
condensed
|
|
218
|
+
.prefixIcon=${this._detailsExpanded ? faChevronUp : faChevronDown}
|
|
219
|
+
@pi-click=${this._handleDetailsToggle}
|
|
220
|
+
>
|
|
221
|
+
${this._detailsExpanded ? "Hide Details" : "View Details"}
|
|
222
|
+
</${buttonTag}>
|
|
223
|
+
<${copyButtonTag}
|
|
224
|
+
.copyData=${errorString}
|
|
225
|
+
button-type="tertiary"
|
|
226
|
+
button-text=""
|
|
227
|
+
condensed
|
|
228
|
+
success-message="Copied error"
|
|
229
|
+
></${copyButtonTag}>
|
|
230
|
+
</div>
|
|
231
|
+
` : nothing}
|
|
232
|
+
|
|
233
|
+
${this._detailsExpanded && hasError ? html`
|
|
234
|
+
<div class="details">
|
|
235
|
+
<pre>${errorString}</pre>
|
|
236
|
+
</div>
|
|
237
|
+
` : nothing}
|
|
238
|
+
</div>
|
|
239
|
+
`;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
_PiError.styles = errorStyles;
|
|
243
|
+
let PiError = _PiError;
|
|
244
|
+
__decorateClass([
|
|
245
|
+
property({ type: Boolean, reflect: true })
|
|
246
|
+
], PiError.prototype, "open");
|
|
247
|
+
__decorateClass([
|
|
248
|
+
property({ type: String, reflect: true })
|
|
249
|
+
], PiError.prototype, "variant");
|
|
250
|
+
__decorateClass([
|
|
251
|
+
property({ type: String, attribute: "error-title" })
|
|
252
|
+
], PiError.prototype, "errorTitle");
|
|
253
|
+
__decorateClass([
|
|
254
|
+
property({ attribute: false })
|
|
255
|
+
], PiError.prototype, "prefixIcon");
|
|
256
|
+
__decorateClass([
|
|
257
|
+
property({ attribute: false })
|
|
258
|
+
], PiError.prototype, "error");
|
|
259
|
+
__decorateClass([
|
|
260
|
+
property({ type: String })
|
|
261
|
+
], PiError.prototype, "message");
|
|
262
|
+
__decorateClass([
|
|
263
|
+
state()
|
|
264
|
+
], PiError.prototype, "_detailsExpanded");
|
|
265
|
+
export {
|
|
266
|
+
CUSTOM_ELEMENT_NAME,
|
|
267
|
+
PiError
|
|
268
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const errorStyles: import('lit').CSSResult;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polarityio/pi-error",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Error alert component with dismissible behavior, detail expansion, and clipboard copy support",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/polarityio/integration-component-library.git",
|
|
12
|
+
"directory": "packages/error"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"source": "./src/index.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./component-registry.json": "./dist/component-registry.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@fortawesome/fontawesome-svg-core": "^7.0.0",
|
|
32
|
+
"@fortawesome/free-solid-svg-icons": "^7.0.0",
|
|
33
|
+
"@polarityio/pi-shared": "1.0.3",
|
|
34
|
+
"@polarityio/pi-icon": "1.0.3",
|
|
35
|
+
"@polarityio/pi-button": "1.0.4",
|
|
36
|
+
"@polarityio/pi-copy-button": "1.0.4"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"lit": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "vite build",
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
44
|
+
}
|
|
45
|
+
}
|