@purpurds/notification-banner 0.0.1
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/dist/LICENSE.txt +59 -0
- package/dist/notification-banner.cjs.js +26 -0
- package/dist/notification-banner.cjs.js.map +1 -0
- package/dist/notification-banner.d.ts +27 -0
- package/dist/notification-banner.d.ts.map +1 -0
- package/dist/notification-banner.es.js +646 -0
- package/dist/notification-banner.es.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +63 -0
- package/readme.mdx +66 -0
- package/src/global.d.ts +4 -0
- package/src/notification-banner.module.scss +34 -0
- package/src/notification-banner.stories.tsx +60 -0
- package/src/notification-banner.test.tsx +16 -0
- package/src/notification-banner.tsx +105 -0
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._purpur-notification-banner_llblm_1{background-color:var(--purpur-color-background-tone-on-tone-quaternary);padding:var(--purpur-spacing-200) 0;position:relative}._purpur-notification-banner__container_llblm_6{display:flex;gap:var(--purpur-spacing-150);color:var(--purpur-color-text-tone-on-tone-tertiary)}._purpur-notification-banner__content_llblm_11{display:flex;flex-direction:column;gap:var(--purpur-spacing-50)}._purpur-notification-banner__icon_llblm_16{flex-shrink:0}._purpur-notification-banner__heading_llblm_19{color:var(--purpur-color-text-tone-on-tone-tertiary)}._purpur-notification-banner__heading--no-overlap_llblm_22{padding-right:var(--purpur-spacing-300)}._purpur-notification-banner__close-button_llblm_25{position:absolute;right:calc(var(--purpur-spacing-50) + var(--purpur-spacing-25));top:calc(var(--purpur-spacing-50) + var(--purpur-spacing-25))}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purpurds/notification-banner",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"main": "./dist/notification-banner.cjs.js",
|
|
6
|
+
"types": "./dist/notification-banner.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/notification-banner.cjs.js",
|
|
10
|
+
"types": "./dist/notification-banner.d.ts",
|
|
11
|
+
"default": "./dist/notification-banner.es.js"
|
|
12
|
+
},
|
|
13
|
+
"./styles": "./dist/styles.css"
|
|
14
|
+
},
|
|
15
|
+
"source": "src/notification-banner.tsx",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"classnames": "~2.5.0",
|
|
18
|
+
"@purpurds/grid": "5.5.0",
|
|
19
|
+
"@purpurds/button": "5.5.0",
|
|
20
|
+
"@purpurds/heading": "5.5.0",
|
|
21
|
+
"@purpurds/icon": "5.5.0",
|
|
22
|
+
"@purpurds/tokens": "5.5.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rushstack/eslint-patch": "~1.10.0",
|
|
26
|
+
"@storybook/blocks": "~7.6.0",
|
|
27
|
+
"@storybook/react": "~7.6.0",
|
|
28
|
+
"@telia/base-rig": "~8.2.0",
|
|
29
|
+
"@telia/react-rig": "~3.2.0",
|
|
30
|
+
"@testing-library/dom": "~9.3.3",
|
|
31
|
+
"@testing-library/jest-dom": "~6.4.0",
|
|
32
|
+
"@testing-library/react": "~14.3.0",
|
|
33
|
+
"@types/node": "20.12.12",
|
|
34
|
+
"@types/react-dom": "~18.3.0",
|
|
35
|
+
"@types/react": "~18.3.0",
|
|
36
|
+
"eslint-plugin-testing-library": "~6.2.0",
|
|
37
|
+
"eslint": "~8.57.0",
|
|
38
|
+
"jsdom": "~22.1.0",
|
|
39
|
+
"lint-staged": "~10.5.3",
|
|
40
|
+
"prettier": "~2.8.8",
|
|
41
|
+
"react-dom": "~18.3.0",
|
|
42
|
+
"react": "~18.3.0",
|
|
43
|
+
"typescript": "~5.4.2",
|
|
44
|
+
"vite": "~5.2.2",
|
|
45
|
+
"vitest": "~1.5.0",
|
|
46
|
+
"@purpurds/component-rig": "1.0.0",
|
|
47
|
+
"@purpurds/link": "5.5.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build:dev": "vite",
|
|
51
|
+
"build:watch": "vite build --watch",
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"ci:build": "rushx build",
|
|
54
|
+
"coverage": "vitest run --coverage",
|
|
55
|
+
"lint:fix": "eslint . --fix",
|
|
56
|
+
"lint": "lint-staged --no-stash 2>&1",
|
|
57
|
+
"sbdev": "rush sbdev",
|
|
58
|
+
"test:unit": "vitest run --passWithNoTests",
|
|
59
|
+
"test:watch": "vitest --watch",
|
|
60
|
+
"test": "rushx test:unit",
|
|
61
|
+
"typecheck": "tsc -p ./tsconfig.json"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/readme.mdx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Meta, Stories, ArgTypes, Primary, Subtitle } from "@storybook/blocks";
|
|
2
|
+
|
|
3
|
+
import * as NotificationBannerStories from "./src/notification-banner.stories";
|
|
4
|
+
import packageInfo from "./package.json";
|
|
5
|
+
|
|
6
|
+
<Meta name="Docs" title="Components/NotificationBanner" of={NotificationBannerStories} />
|
|
7
|
+
|
|
8
|
+
# NotificationBanner
|
|
9
|
+
|
|
10
|
+
<Subtitle>Version {packageInfo.version}</Subtitle>
|
|
11
|
+
|
|
12
|
+
### Showcase
|
|
13
|
+
|
|
14
|
+
<Primary />
|
|
15
|
+
|
|
16
|
+
### Properties
|
|
17
|
+
|
|
18
|
+
<ArgTypes />
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
#### Via NPM
|
|
23
|
+
|
|
24
|
+
Add the dependency to your consumer app like `"@purpurds/purpur": "^x.y.z"`
|
|
25
|
+
|
|
26
|
+
### Usage
|
|
27
|
+
|
|
28
|
+
In MyApp.tsx
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import "@purpurds/purpur/styles";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In MyComponent.tsx
|
|
35
|
+
|
|
36
|
+
#### With Link
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { NotificationBanner, Link } from "@purpurds/purpur";
|
|
40
|
+
|
|
41
|
+
export const MyComponent = () => (
|
|
42
|
+
<NotificationBanner
|
|
43
|
+
title="Lorem ipsum"
|
|
44
|
+
description="Donec placerat ornare neque sit amet euismod."
|
|
45
|
+
link={
|
|
46
|
+
<Link variant="text" href="http://purpur.telia.io">
|
|
47
|
+
Praesent pretium augue cursus
|
|
48
|
+
</Link>
|
|
49
|
+
}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### With custom icon and no Link
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { NotificationBanner, IconBattery } from "@purpurds/purpur";
|
|
58
|
+
|
|
59
|
+
export const MyComponent = () => (
|
|
60
|
+
<NotificationBanner
|
|
61
|
+
title="Low battery"
|
|
62
|
+
description="Please connect your device to a charger."
|
|
63
|
+
icon={<IconBattery size="sm" />}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
```
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
.purpur-notification-banner {
|
|
2
|
+
background-color: var(--purpur-color-background-tone-on-tone-quaternary);
|
|
3
|
+
padding: var(--purpur-spacing-200) 0;
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
&__container {
|
|
7
|
+
display: flex;
|
|
8
|
+
gap: var(--purpur-spacing-150);
|
|
9
|
+
color: var(--purpur-color-text-tone-on-tone-tertiary);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
&__content {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
gap: var(--purpur-spacing-50);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__icon {
|
|
19
|
+
flex-shrink: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&__heading {
|
|
23
|
+
color: var(--purpur-color-text-tone-on-tone-tertiary);
|
|
24
|
+
&--no-overlap {
|
|
25
|
+
padding-right: var(--purpur-spacing-300);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&__close-button {
|
|
30
|
+
position: absolute;
|
|
31
|
+
right: calc(var(--purpur-spacing-50) + var(--purpur-spacing-25));
|
|
32
|
+
top: calc(var(--purpur-spacing-50) + var(--purpur-spacing-25));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconBattery } from "@purpurds/icon";
|
|
3
|
+
import { Link } from "@purpurds/link";
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
|
|
6
|
+
import "@purpurds/link/styles";
|
|
7
|
+
import "@purpurds/button/styles";
|
|
8
|
+
import "@purpurds/grid/styles";
|
|
9
|
+
import "@purpurds/heading/styles";
|
|
10
|
+
import "@purpurds/icon/styles";
|
|
11
|
+
import { NotificationBanner } from "./notification-banner";
|
|
12
|
+
|
|
13
|
+
type Story = StoryObj<typeof NotificationBanner>;
|
|
14
|
+
|
|
15
|
+
const meta: Meta<typeof NotificationBanner> = {
|
|
16
|
+
title: "Components/NotificationBanner",
|
|
17
|
+
component: NotificationBanner,
|
|
18
|
+
parameters: {
|
|
19
|
+
design: [
|
|
20
|
+
{
|
|
21
|
+
name: "NotificationBanner",
|
|
22
|
+
type: "figma",
|
|
23
|
+
url: "https://www.figma.com/design/XEaIIFskrrxIBHMZDkIuIg/Purpur-DS---Component-library-%26-guidelines?node-id=37280-1900&m=dev",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
args: {
|
|
28
|
+
title: "Lorem ipsum",
|
|
29
|
+
hideIcon: false,
|
|
30
|
+
description: "Donec placerat ornare neque sit amet euismod.",
|
|
31
|
+
link: (
|
|
32
|
+
<Link variant="text" href="http://purpur.telia.io">
|
|
33
|
+
Praesent pretium augue cursus
|
|
34
|
+
</Link>
|
|
35
|
+
),
|
|
36
|
+
closeButtonAllyLabel: "Close notification",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Showcase: Story = {};
|
|
41
|
+
|
|
42
|
+
export const CustomIcon: Story = {
|
|
43
|
+
args: {
|
|
44
|
+
description: "Please connect your device to a charger.",
|
|
45
|
+
icon: <IconBattery size="sm" />,
|
|
46
|
+
link: undefined,
|
|
47
|
+
onClose: undefined,
|
|
48
|
+
title: "Low battery",
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const HideIcon: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
hideIcon: true,
|
|
55
|
+
link: undefined,
|
|
56
|
+
onClose: undefined,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default meta;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { NotificationBanner } from "./notification-banner";
|
|
7
|
+
|
|
8
|
+
expect.extend(matchers);
|
|
9
|
+
|
|
10
|
+
describe("NotificationBanner", () => {
|
|
11
|
+
it("should have title and description", () => {
|
|
12
|
+
render(<NotificationBanner title="abc" description="def" />);
|
|
13
|
+
expect(screen.getByRole("alert")).toHaveTextContent("abc");
|
|
14
|
+
expect(screen.getByRole("alert")).toHaveTextContent("def");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React, { ForwardedRef, forwardRef, ReactNode } from "react";
|
|
2
|
+
import { Button } from "@purpurds/button";
|
|
3
|
+
import { Grid } from "@purpurds/grid";
|
|
4
|
+
import { Heading, HeadingTagType } from "@purpurds/heading";
|
|
5
|
+
import { IconClose, IconInfo } from "@purpurds/icon";
|
|
6
|
+
import c from "classnames/bind";
|
|
7
|
+
|
|
8
|
+
import styles from "./notification-banner.module.scss";
|
|
9
|
+
const cx = c.bind(styles);
|
|
10
|
+
|
|
11
|
+
export type DefaultProps = {
|
|
12
|
+
["data-testid"]?: string;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
closeButtonAllyLabel?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
hideIcon?: boolean;
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
link?: ReactNode;
|
|
20
|
+
titleTag?: HeadingTagType;
|
|
21
|
+
title?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type CloseButtonProps = {
|
|
25
|
+
onClose: () => void;
|
|
26
|
+
closeButtonAllyLabel: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type NoCloseButtonProps = {
|
|
30
|
+
onClose?: never;
|
|
31
|
+
closeButtonAllyLabel?: never;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type NotificationBannerProps = DefaultProps & (CloseButtonProps | NoCloseButtonProps);
|
|
35
|
+
|
|
36
|
+
const rootClassName = "purpur-notification-banner";
|
|
37
|
+
|
|
38
|
+
export const NotificationBanner = forwardRef(
|
|
39
|
+
(
|
|
40
|
+
{
|
|
41
|
+
["data-testid"]: dataTestId,
|
|
42
|
+
children,
|
|
43
|
+
className,
|
|
44
|
+
closeButtonAllyLabel,
|
|
45
|
+
description,
|
|
46
|
+
hideIcon,
|
|
47
|
+
icon,
|
|
48
|
+
link,
|
|
49
|
+
onClose,
|
|
50
|
+
titleTag = "h4",
|
|
51
|
+
title,
|
|
52
|
+
...props
|
|
53
|
+
}: NotificationBannerProps,
|
|
54
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
55
|
+
) => {
|
|
56
|
+
const classes = cx([className, rootClassName]);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div {...props} className={classes} role="alert" ref={ref} data-testid={dataTestId}>
|
|
60
|
+
<Grid>
|
|
61
|
+
<div className={cx(`${rootClassName}__container`)}>
|
|
62
|
+
{!hideIcon ? (
|
|
63
|
+
icon ? (
|
|
64
|
+
icon
|
|
65
|
+
) : (
|
|
66
|
+
<IconInfo className={cx(`${rootClassName}__icon`)} size="sm" />
|
|
67
|
+
)
|
|
68
|
+
) : null}
|
|
69
|
+
<div className={cx(`${rootClassName}__content`)}>
|
|
70
|
+
<Heading
|
|
71
|
+
tag={titleTag}
|
|
72
|
+
variant="subsection-100"
|
|
73
|
+
className={cx([
|
|
74
|
+
`${rootClassName}__heading`,
|
|
75
|
+
{ [`${rootClassName}__heading--no-overlap`]: onClose },
|
|
76
|
+
])}
|
|
77
|
+
>
|
|
78
|
+
{title}
|
|
79
|
+
</Heading>
|
|
80
|
+
<div>
|
|
81
|
+
{description} {link}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
{children}
|
|
85
|
+
{onClose && (
|
|
86
|
+
<Button
|
|
87
|
+
data-testid={dataTestId ? `${dataTestId}-close-button` : undefined}
|
|
88
|
+
variant="tertiary-purple"
|
|
89
|
+
size="sm"
|
|
90
|
+
iconOnly
|
|
91
|
+
aria-label={closeButtonAllyLabel}
|
|
92
|
+
onClick={onClose}
|
|
93
|
+
className={cx(`${rootClassName}__close-button`)}
|
|
94
|
+
>
|
|
95
|
+
<IconClose size="sm" />
|
|
96
|
+
</Button>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
</Grid>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
NotificationBanner.displayName = "NotificationBanner";
|