@snack-uikit/alert 0.5.20-preview-85c5f47b.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/CHANGELOG.md +369 -0
- package/LICENSE +201 -0
- package/README.md +79 -0
- package/dist/components/Alert/Alert.d.ts +27 -0
- package/dist/components/Alert/Alert.js +28 -0
- package/dist/components/Alert/index.d.ts +1 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/Alert/styles.module.css +187 -0
- package/dist/components/AlertTop/AlertTop.d.ts +34 -0
- package/dist/components/AlertTop/AlertTop.js +30 -0
- package/dist/components/AlertTop/constants.d.ts +14 -0
- package/dist/components/AlertTop/constants.js +16 -0
- package/dist/components/AlertTop/index.d.ts +1 -0
- package/dist/components/AlertTop/index.js +1 -0
- package/dist/components/AlertTop/styles.module.css +237 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +16 -0
- package/dist/helperComponents/AlertTopButton/AlertTopButton.d.ts +9 -0
- package/dist/helperComponents/AlertTopButton/AlertTopButton.js +6 -0
- package/dist/helperComponents/AlertTopButton/index.d.ts +1 -0
- package/dist/helperComponents/AlertTopButton/index.js +1 -0
- package/dist/helperComponents/AlertTopButton/styles.module.css +58 -0
- package/dist/helperComponents/index.d.ts +1 -0
- package/dist/helperComponents/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +17 -0
- package/package.json +42 -0
- package/src/components/Alert/Alert.tsx +92 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/Alert/styles.module.scss +106 -0
- package/src/components/AlertTop/AlertTop.tsx +134 -0
- package/src/components/AlertTop/constants.ts +17 -0
- package/src/components/AlertTop/index.ts +1 -0
- package/src/components/AlertTop/styles.module.scss +157 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +17 -0
- package/src/helperComponents/AlertTopButton/AlertTopButton.tsx +25 -0
- package/src/helperComponents/AlertTopButton/index.ts +1 -0
- package/src/helperComponents/AlertTopButton/styles.module.scss +57 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/utils.tsx +18 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.alertTopButton{
|
|
2
|
+
height:var(--size-alert-top-button, 32px);
|
|
3
|
+
gap:var(--space-alert-top-button-gap, 4px);
|
|
4
|
+
border-radius:var(--radius-alert-top-button, 12px);
|
|
5
|
+
padding-left:var(--space-alert-top-button-horizontal-padding, 12px);
|
|
6
|
+
padding-right:var(--space-alert-top-button-horizontal-padding, 12px);
|
|
7
|
+
font-family:var(--sans-label-l-font-family, SB Sans Interface);
|
|
8
|
+
font-weight:var(--sans-label-l-font-weight, Semibold);
|
|
9
|
+
line-height:var(--sans-label-l-line-height, 20px);
|
|
10
|
+
font-size:var(--sans-label-l-font-size, 14px);
|
|
11
|
+
letter-spacing:var(--sans-label-l-letter-spacing, -0.1px);
|
|
12
|
+
paragraph-spacing:var(--sans-label-l-paragraph-spacing, 7.7px);
|
|
13
|
+
cursor:pointer;
|
|
14
|
+
display:flex;
|
|
15
|
+
align-items:center;
|
|
16
|
+
box-sizing:border-box;
|
|
17
|
+
margin:0;
|
|
18
|
+
margin-left:auto;
|
|
19
|
+
white-space:nowrap;
|
|
20
|
+
opacity:var(--opacity-a080, 0.8);
|
|
21
|
+
background:none;
|
|
22
|
+
border:0;
|
|
23
|
+
}
|
|
24
|
+
.alertTopButton svg{
|
|
25
|
+
width:var(--dimension-3m, 24px) !important;
|
|
26
|
+
height:var(--dimension-3m, 24px) !important;
|
|
27
|
+
}
|
|
28
|
+
.alertTopButton:hover{
|
|
29
|
+
opacity:unset;
|
|
30
|
+
background-color:var(--sys-opacity-hovered, rgba(253, 253, 253, 0.2392156863));
|
|
31
|
+
}
|
|
32
|
+
.alertTopButton:focus-visible{
|
|
33
|
+
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
34
|
+
outline-style:var(--border-state-focus-s-border-style, solid);
|
|
35
|
+
outline-color:var(--border-state-focus-s-border-color, );
|
|
36
|
+
opacity:unset;
|
|
37
|
+
background-color:var(--sys-opacity-hovered, rgba(253, 253, 253, 0.2392156863));
|
|
38
|
+
outline-color:var(--sys-available-on-complementary, #fdfdfd);
|
|
39
|
+
}
|
|
40
|
+
.alertTopButton:active{
|
|
41
|
+
opacity:var(--opacity-a080, 0.8);
|
|
42
|
+
background-color:var(--sys-opacity-activated, rgba(253, 253, 253, 0.3215686275));
|
|
43
|
+
}
|
|
44
|
+
.alertTopButton[data-color=invert-neutral]{
|
|
45
|
+
color:var(--sys-invert-neutral-text-main, #e7e7e7);
|
|
46
|
+
}
|
|
47
|
+
.alertTopButton[data-color=primary]{
|
|
48
|
+
color:var(--sys-primary-on-accent, #fdfbff);
|
|
49
|
+
}
|
|
50
|
+
.alertTopButton[data-color=red]{
|
|
51
|
+
color:var(--sys-red-on-accent, #fffbfa);
|
|
52
|
+
}
|
|
53
|
+
.alertTopButton[data-color=yellow]{
|
|
54
|
+
color:var(--sys-yellow-on-accent, #54290f);
|
|
55
|
+
}
|
|
56
|
+
.alertTopButton[data-color=green]{
|
|
57
|
+
color:var(--sys-green-on-accent, #1f392a);
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AlertTopButton';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AlertTopButton';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AlarmFilledSVG, CheckFilledSVG, CrossFilledSVG, InfoFilledSVG } from '@snack-uikit/icons';
|
|
3
|
+
import { Appearance } from './constants';
|
|
4
|
+
export function getIcon(appearance) {
|
|
5
|
+
switch (appearance) {
|
|
6
|
+
case Appearance.Success:
|
|
7
|
+
return _jsx(CheckFilledSVG, {});
|
|
8
|
+
case Appearance.Error:
|
|
9
|
+
return _jsx(CrossFilledSVG, {});
|
|
10
|
+
case Appearance.Warning:
|
|
11
|
+
return _jsx(AlarmFilledSVG, {});
|
|
12
|
+
case Appearance.Primary:
|
|
13
|
+
case Appearance.Neutral:
|
|
14
|
+
default:
|
|
15
|
+
return _jsx(InfoFilledSVG, {});
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snack-uikit/alert",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"title": "Alert",
|
|
7
|
+
"version": "0.5.20-preview-85c5f47b.0",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"*.css",
|
|
10
|
+
"*.woff",
|
|
11
|
+
"*.woff2"
|
|
12
|
+
],
|
|
13
|
+
"description": "",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/alert",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/cloud-ru-tech/snack-uikit.git",
|
|
20
|
+
"directory": "packages/alert"
|
|
21
|
+
},
|
|
22
|
+
"author": "Alexander Starodubtsev <avstarodubtsev@cloud.ru>",
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Alexander Starodubtsev <avstarodubtsev@cloud.ru>"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src",
|
|
29
|
+
"./CHANGELOG.md",
|
|
30
|
+
"./LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"scripts": {},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@snack-uikit/icons": "0.18.2-preview-85c5f47b.0",
|
|
36
|
+
"@snack-uikit/link": "0.7.1-preview-85c5f47b.0",
|
|
37
|
+
"@snack-uikit/truncate-string": "0.2.17-preview-85c5f47b.0",
|
|
38
|
+
"@snack-uikit/utils": "2.0.2-preview-85c5f47b.0",
|
|
39
|
+
"classnames": "2.3.2"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "6a7eef41d780d945f64f791448eaa72b9e0ae72d"
|
|
42
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
|
|
3
|
+
import { CrossSVG } from '@snack-uikit/icons';
|
|
4
|
+
import { Link } from '@snack-uikit/link';
|
|
5
|
+
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
6
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
7
|
+
|
|
8
|
+
import { Appearance, APPEARANCE_TO_COLOR_MAP } from '../../constants';
|
|
9
|
+
import { getIcon } from '../../utils';
|
|
10
|
+
import styles from './styles.module.scss';
|
|
11
|
+
|
|
12
|
+
export type AlertProps = WithSupportProps<{
|
|
13
|
+
/** Отображать иконку */
|
|
14
|
+
icon?: boolean;
|
|
15
|
+
/** Заголовок */
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Описание */
|
|
18
|
+
description: string;
|
|
19
|
+
/** Текст ссылки */
|
|
20
|
+
link?: string;
|
|
21
|
+
/** Ссылка */
|
|
22
|
+
href?: string;
|
|
23
|
+
/** Колбек закрытия */
|
|
24
|
+
onClose?: () => void;
|
|
25
|
+
/** Внешний вид */
|
|
26
|
+
appearance?: Appearance;
|
|
27
|
+
/** CSS-класс */
|
|
28
|
+
className?: string;
|
|
29
|
+
}>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Компонент для отображения уведомления.
|
|
33
|
+
*/
|
|
34
|
+
export function Alert({
|
|
35
|
+
icon = true,
|
|
36
|
+
title,
|
|
37
|
+
href,
|
|
38
|
+
link,
|
|
39
|
+
description,
|
|
40
|
+
onClose,
|
|
41
|
+
appearance = Alert.appearances.Neutral,
|
|
42
|
+
className,
|
|
43
|
+
...rest
|
|
44
|
+
}: AlertProps) {
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
className={cn(styles.alert, className)}
|
|
48
|
+
{...extractSupportProps(rest)}
|
|
49
|
+
data-color={APPEARANCE_TO_COLOR_MAP[appearance]}
|
|
50
|
+
>
|
|
51
|
+
{icon && (
|
|
52
|
+
<div className={styles.icon} data-color={APPEARANCE_TO_COLOR_MAP[appearance]} data-test-id='alert__icon'>
|
|
53
|
+
{getIcon(appearance)}
|
|
54
|
+
</div>
|
|
55
|
+
)}
|
|
56
|
+
<div className={styles.content}>
|
|
57
|
+
<div className={styles.textlayout}>
|
|
58
|
+
{title && <TruncateString text={title} maxLines={1} className={styles.title} data-test-id='alert__title' />}
|
|
59
|
+
<span data-test-id='alert__description' className={styles.description}>
|
|
60
|
+
{description}
|
|
61
|
+
</span>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
{link && (
|
|
65
|
+
<span>
|
|
66
|
+
<Link
|
|
67
|
+
href={href}
|
|
68
|
+
text={link}
|
|
69
|
+
onSurface={Link.onSurfaces.Decor}
|
|
70
|
+
external
|
|
71
|
+
onColor={APPEARANCE_TO_COLOR_MAP[appearance]}
|
|
72
|
+
size={Link.sizes.M}
|
|
73
|
+
data-test-id='alert__link'
|
|
74
|
+
/>
|
|
75
|
+
</span>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
{onClose && (
|
|
79
|
+
<button
|
|
80
|
+
onClick={onClose}
|
|
81
|
+
className={styles.closeButton}
|
|
82
|
+
data-color={APPEARANCE_TO_COLOR_MAP[appearance]}
|
|
83
|
+
data-test-id='alert__close-button'
|
|
84
|
+
>
|
|
85
|
+
<CrossSVG />
|
|
86
|
+
</button>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Alert.appearances = Appearance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Alert';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-alert';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
3
|
+
|
|
4
|
+
$colors: 'neutral', 'primary', 'red', 'yellow', 'green';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
.alert {
|
|
8
|
+
@include composite-var($alert-container-container);
|
|
9
|
+
|
|
10
|
+
display: flex;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
min-width: 256px;
|
|
13
|
+
border-style: solid;
|
|
14
|
+
|
|
15
|
+
@each $color in $colors {
|
|
16
|
+
&[data-color='#{$color}'] {
|
|
17
|
+
background-color: simple-var($theme-variables, 'sys', $color, 'background');
|
|
18
|
+
border-color: simple-var($theme-variables, 'sys', $color, 'decor-default');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.title {
|
|
24
|
+
@include composite-var($sans-title-s);
|
|
25
|
+
|
|
26
|
+
color: $sys-neutral-text-main;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.textlayout {
|
|
30
|
+
@include composite-var($alert-container-text-layout);
|
|
31
|
+
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.description {
|
|
36
|
+
@include composite-var($sans-body-m);
|
|
37
|
+
|
|
38
|
+
color: $sys-neutral-text-support;
|
|
39
|
+
word-wrap: break-word;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.content {
|
|
43
|
+
@include composite-var($alert-container-content-layout);
|
|
44
|
+
|
|
45
|
+
display: flex;
|
|
46
|
+
flex: 1;
|
|
47
|
+
flex-direction: column;
|
|
48
|
+
min-width: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.icon {
|
|
52
|
+
@each $color in $colors {
|
|
53
|
+
&[data-color='#{$color}'] {
|
|
54
|
+
color: simple-var($theme-variables, 'sys', $color, 'accent-default');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
svg {
|
|
59
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
60
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.closeButton {
|
|
65
|
+
@include composite-var($alert-button-button-close);
|
|
66
|
+
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
margin: 0;
|
|
75
|
+
margin-left: auto;
|
|
76
|
+
padding: 0;
|
|
77
|
+
|
|
78
|
+
background: none;
|
|
79
|
+
border: none;
|
|
80
|
+
|
|
81
|
+
svg {
|
|
82
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
83
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@each $color in $colors {
|
|
87
|
+
&[data-color='#{$color}'] {
|
|
88
|
+
color: simple-var($theme-variables, 'sys', $color, 'text-light');
|
|
89
|
+
|
|
90
|
+
&:hover {
|
|
91
|
+
color: simple-var($theme-variables, 'sys', $color, 'text-support');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&:focus-visible {
|
|
95
|
+
@include outline-var($container-focused-s);
|
|
96
|
+
|
|
97
|
+
color: simple-var($theme-variables, 'sys', $color, 'text-support');
|
|
98
|
+
outline-color: $sys-available-complementary;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
&:active {
|
|
102
|
+
color: simple-var($theme-variables, 'sys', $color, 'text-main');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { CrossSVG } from '@snack-uikit/icons';
|
|
5
|
+
import { Link } from '@snack-uikit/link';
|
|
6
|
+
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
7
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
8
|
+
|
|
9
|
+
import { Appearance, APPEARANCE_TO_COLOR_MAP } from '../../constants';
|
|
10
|
+
import { AlertTopButton } from '../../helperComponents';
|
|
11
|
+
import { getIcon } from '../../utils';
|
|
12
|
+
import { APPEARANCE_TO_COLOR_MAP_INVERT } from './constants';
|
|
13
|
+
import styles from './styles.module.scss';
|
|
14
|
+
|
|
15
|
+
export type AlertTopProps = WithSupportProps<{
|
|
16
|
+
/** Отображать иконку */
|
|
17
|
+
icon?: boolean;
|
|
18
|
+
/** Заголовок */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Описание */
|
|
21
|
+
description: string;
|
|
22
|
+
/** Текст ссылки */
|
|
23
|
+
link?: string;
|
|
24
|
+
/** Ссылка */
|
|
25
|
+
href?: string;
|
|
26
|
+
/** Колбек закрытия */
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
/** Внешний вид */
|
|
29
|
+
appearance?: Appearance;
|
|
30
|
+
/** Текст кнопки */
|
|
31
|
+
buttonText?: string;
|
|
32
|
+
/** Колбек клика по кнопке */
|
|
33
|
+
buttonOnClick?: () => void;
|
|
34
|
+
/** Иконка в кнопке */
|
|
35
|
+
buttonIcon?: ReactElement;
|
|
36
|
+
/** CSS-класс */
|
|
37
|
+
className?: string;
|
|
38
|
+
}>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Компонент для отображения уведомления вверху экрана.
|
|
42
|
+
*/
|
|
43
|
+
export function AlertTop({
|
|
44
|
+
icon = true,
|
|
45
|
+
title,
|
|
46
|
+
description,
|
|
47
|
+
link,
|
|
48
|
+
href,
|
|
49
|
+
onClose,
|
|
50
|
+
appearance = AlertTop.appearances.Neutral,
|
|
51
|
+
buttonText,
|
|
52
|
+
buttonOnClick,
|
|
53
|
+
buttonIcon,
|
|
54
|
+
className,
|
|
55
|
+
...rest
|
|
56
|
+
}: AlertTopProps) {
|
|
57
|
+
return (
|
|
58
|
+
<div
|
|
59
|
+
className={cn(styles.alertTop, className)}
|
|
60
|
+
{...extractSupportProps(rest)}
|
|
61
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
62
|
+
>
|
|
63
|
+
<div className={styles.contentWrapper}>
|
|
64
|
+
{icon && (
|
|
65
|
+
<div
|
|
66
|
+
className={styles.icon}
|
|
67
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
68
|
+
data-test-id='alert-top__icon'
|
|
69
|
+
>
|
|
70
|
+
{getIcon(appearance)}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
<div className={styles.contentLayout}>
|
|
75
|
+
<div className={styles.textLayout}>
|
|
76
|
+
{title && (
|
|
77
|
+
<div
|
|
78
|
+
className={styles.title}
|
|
79
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
80
|
+
data-test-id='alert-top__title'
|
|
81
|
+
>
|
|
82
|
+
<TruncateString text={title} maxLines={1} />
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
<span
|
|
87
|
+
className={styles.description}
|
|
88
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
89
|
+
data-test-id='alert-top__description'
|
|
90
|
+
>
|
|
91
|
+
{description}
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
{link && (
|
|
95
|
+
<span>
|
|
96
|
+
<Link
|
|
97
|
+
onSurface={Link.onSurfaces.Accent}
|
|
98
|
+
href={href}
|
|
99
|
+
text={link}
|
|
100
|
+
external
|
|
101
|
+
onColor={APPEARANCE_TO_COLOR_MAP[appearance]}
|
|
102
|
+
size={Link.sizes.M}
|
|
103
|
+
data-test-id='alert-top__link'
|
|
104
|
+
/>
|
|
105
|
+
</span>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<div className={styles.actions}>
|
|
110
|
+
{buttonText && (
|
|
111
|
+
<AlertTopButton
|
|
112
|
+
buttonIcon={buttonIcon}
|
|
113
|
+
buttonOnClick={buttonOnClick}
|
|
114
|
+
buttonText={buttonText}
|
|
115
|
+
appearance={appearance}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
|
|
119
|
+
{onClose && (
|
|
120
|
+
<button
|
|
121
|
+
onClick={onClose}
|
|
122
|
+
className={styles.closeButton}
|
|
123
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
124
|
+
data-test-id='alert-top__close-button'
|
|
125
|
+
>
|
|
126
|
+
<CrossSVG />
|
|
127
|
+
</button>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
AlertTop.appearances = Appearance;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Appearance } from '../../constants';
|
|
2
|
+
|
|
3
|
+
export enum Color {
|
|
4
|
+
InvertNeutral = 'invert-neutral',
|
|
5
|
+
Primary = 'primary',
|
|
6
|
+
Red = 'red',
|
|
7
|
+
Yellow = 'yellow',
|
|
8
|
+
Green = 'green',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const APPEARANCE_TO_COLOR_MAP_INVERT = {
|
|
12
|
+
[Appearance.Neutral]: Color.InvertNeutral,
|
|
13
|
+
[Appearance.Primary]: Color.Primary,
|
|
14
|
+
[Appearance.Error]: Color.Red,
|
|
15
|
+
[Appearance.Warning]: Color.Yellow,
|
|
16
|
+
[Appearance.Success]: Color.Green,
|
|
17
|
+
} as const;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AlertTop';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-alert-alertTop';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
3
|
+
|
|
4
|
+
$colors: 'invert-neutral', 'primary', 'red', 'yellow', 'green';
|
|
5
|
+
|
|
6
|
+
.alertTop {
|
|
7
|
+
@include composite-var($alert-top-container-container);
|
|
8
|
+
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
|
|
13
|
+
@each $color in $colors {
|
|
14
|
+
&[data-color='#{$color}'] {
|
|
15
|
+
@if $color == 'invert-neutral'{
|
|
16
|
+
background-color:$sys-invert-neutral-background;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@else {
|
|
20
|
+
background-color: simple-var($theme-variables, 'sys', $color, 'accent-default');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.icon {
|
|
27
|
+
@each $color in $colors {
|
|
28
|
+
&[data-color='#{$color}'] {
|
|
29
|
+
@if $color == 'invert-neutral'{
|
|
30
|
+
color:$sys-invert-neutral-text-main;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@else {
|
|
34
|
+
color: simple-var($theme-variables, 'sys', $color, 'on-accent');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
svg {
|
|
40
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
41
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.title {
|
|
46
|
+
@include composite-var($sans-title-s);
|
|
47
|
+
|
|
48
|
+
@each $color in $colors {
|
|
49
|
+
&[data-color='#{$color}'] {
|
|
50
|
+
@if $color == 'invert-neutral'{
|
|
51
|
+
color:$sys-invert-neutral-text-main;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@else {
|
|
55
|
+
color: simple-var($theme-variables, 'sys', $color, 'on-accent');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.description {
|
|
62
|
+
@include composite-var($sans-body-m);
|
|
63
|
+
|
|
64
|
+
word-wrap: break-word;
|
|
65
|
+
|
|
66
|
+
@each $color in $colors {
|
|
67
|
+
&[data-color='#{$color}'] {
|
|
68
|
+
@if $color == 'invert-neutral'{
|
|
69
|
+
color:$sys-invert-neutral-text-main;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@else {
|
|
73
|
+
color: simple-var($theme-variables, 'sys', $color, 'on-accent');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.contentWrapper {
|
|
80
|
+
display: flex;
|
|
81
|
+
gap: $dimension-2m;
|
|
82
|
+
align-items: center;
|
|
83
|
+
min-width: 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
.contentLayout {
|
|
88
|
+
@include composite-var($alert-top-container-content-layout);
|
|
89
|
+
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: column;
|
|
92
|
+
min-width: 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.textLayout {
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.closeButton {
|
|
100
|
+
@include composite-var($alert-top-button-button-close);
|
|
101
|
+
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
|
|
108
|
+
box-sizing: border-box;
|
|
109
|
+
margin: 0;
|
|
110
|
+
padding: 0;
|
|
111
|
+
|
|
112
|
+
background: none;
|
|
113
|
+
border: none;
|
|
114
|
+
|
|
115
|
+
svg {
|
|
116
|
+
width: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
117
|
+
height: $icon-s !important; /* stylelint-disable-line declaration-no-important */
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@each $color in $colors {
|
|
121
|
+
&[data-color='#{$color}'] {
|
|
122
|
+
@if $color == 'invert-neutral'{
|
|
123
|
+
color: $sys-invert-neutral-text-main;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@else {
|
|
127
|
+
color: simple-var($theme-variables, 'sys', $color, 'on-accent');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
opacity: $opacity-a080;
|
|
131
|
+
|
|
132
|
+
&:hover {
|
|
133
|
+
opacity: unset;
|
|
134
|
+
background-color: $sys-opacity-hovered;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&:focus-visible {
|
|
138
|
+
@include outline-var($container-focused-s);
|
|
139
|
+
|
|
140
|
+
opacity: unset;
|
|
141
|
+
background-color: $sys-opacity-hovered;
|
|
142
|
+
outline-color: $sys-available-on-complementary;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&:active {
|
|
146
|
+
opacity: $opacity-a080;
|
|
147
|
+
background-color: $sys-opacity-activated;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.actions {
|
|
154
|
+
display: flex;
|
|
155
|
+
gap: $dimension-2m;
|
|
156
|
+
align-items: center;
|
|
157
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OnColor } from '@snack-uikit/link';
|
|
2
|
+
|
|
3
|
+
export enum Appearance {
|
|
4
|
+
Neutral = 'neutral',
|
|
5
|
+
Primary = 'primary',
|
|
6
|
+
Error = 'error',
|
|
7
|
+
Warning = 'warning',
|
|
8
|
+
Success = 'success',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const APPEARANCE_TO_COLOR_MAP = {
|
|
12
|
+
[Appearance.Neutral]: OnColor.Neutral,
|
|
13
|
+
[Appearance.Primary]: OnColor.Primary,
|
|
14
|
+
[Appearance.Error]: OnColor.Red,
|
|
15
|
+
[Appearance.Warning]: OnColor.Yellow,
|
|
16
|
+
[Appearance.Success]: OnColor.Green,
|
|
17
|
+
} as const;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { APPEARANCE_TO_COLOR_MAP_INVERT } from '../../components/AlertTop/constants';
|
|
4
|
+
import { Appearance } from '../../constants';
|
|
5
|
+
import styles from './styles.module.scss';
|
|
6
|
+
|
|
7
|
+
export type AlertTopButtonProps = {
|
|
8
|
+
appearance: Appearance;
|
|
9
|
+
buttonText: string;
|
|
10
|
+
buttonIcon?: ReactElement;
|
|
11
|
+
buttonOnClick?: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function AlertTopButton({ appearance, buttonText, buttonIcon, buttonOnClick }: AlertTopButtonProps) {
|
|
15
|
+
return (
|
|
16
|
+
<button
|
|
17
|
+
onClick={buttonOnClick}
|
|
18
|
+
className={styles.alertTopButton}
|
|
19
|
+
data-color={APPEARANCE_TO_COLOR_MAP_INVERT[appearance]}
|
|
20
|
+
>
|
|
21
|
+
<span>{buttonText}</span>
|
|
22
|
+
{buttonIcon}
|
|
23
|
+
</button>
|
|
24
|
+
);
|
|
25
|
+
}
|