@livechat/design-system-react-components 1.0.0-alpha.2 → 1.0.0-alpha.4
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/.eslintrc +9 -0
- package/.storybook/main.js +20 -0
- package/.storybook/preview-head.html +31 -0
- package/.storybook/preview.js +21 -0
- package/package.json +40 -37
- package/src/components/Alert/Alert.module.scss +88 -0
- package/src/components/Alert/Alert.spec.tsx +78 -0
- package/src/components/Alert/Alert.stories.tsx +73 -0
- package/src/components/Alert/Alert.tsx +94 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/Badge/Badge.module.scss +23 -0
- package/src/components/Badge/Badge.spec.tsx +12 -0
- package/src/components/Badge/Badge.stories.tsx +24 -0
- package/src/components/Badge/Badge.tsx +24 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Button/Button.module.scss +257 -0
- package/src/components/Button/Button.spec.tsx +110 -0
- package/src/components/Button/Button.stories.tsx +152 -0
- package/src/components/Button/Button.tsx +88 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/ButtonGroup/ButtonGroup.module.scss +31 -0
- package/src/components/ButtonGroup/ButtonGroup.spec.tsx +61 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +53 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +75 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Card/Card.module.scss +31 -0
- package/src/components/Card/Card.spec.tsx +38 -0
- package/src/components/Card/Card.stories.tsx +30 -0
- package/src/components/Card/Card.tsx +34 -0
- package/src/components/Card/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.module.scss +99 -0
- package/src/components/Checkbox/Checkbox.tsx +39 -0
- package/src/components/Checkbox/CheckboxField.spec.tsx +58 -0
- package/src/components/Checkbox/CheckboxField.stories.tsx +30 -0
- package/src/components/Checkbox/CheckboxField.tsx +46 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/FieldDescription/FieldDescription.module.scss +5 -0
- package/src/components/FieldDescription/FieldDescription.tsx +23 -0
- package/src/components/FieldDescription/index.ts +1 -0
- package/src/components/FieldError/FieldError.module.scss +5 -0
- package/src/components/FieldError/FieldError.tsx +23 -0
- package/src/components/FieldError/index.ts +1 -0
- package/src/components/FieldGroup/FieldGroup.module.scss +25 -0
- package/src/components/FieldGroup/FieldGroup.spec.tsx +42 -0
- package/src/components/FieldGroup/FieldGroup.stories.tsx +34 -0
- package/src/components/FieldGroup/FieldGroup.tsx +38 -0
- package/src/components/FieldGroup/index.ts +1 -0
- package/src/components/Form/Form.module.scss +22 -0
- package/src/components/Form/Form.spec.tsx +38 -0
- package/src/components/Form/Form.stories.tsx +42 -0
- package/src/components/Form/Form.tsx +46 -0
- package/src/components/Form/index.ts +2 -0
- package/src/components/FormGroup/FormGroup.module.scss +20 -0
- package/src/components/FormGroup/FormGroup.spec.tsx +34 -0
- package/src/components/FormGroup/FormGroup.stories.tsx +30 -0
- package/src/components/FormGroup/FormGroup.tsx +44 -0
- package/src/components/FormGroup/index.ts +1 -0
- package/src/components/Icon/Icon.module.scss +70 -0
- package/src/components/Icon/Icon.stories.tsx +53 -0
- package/src/components/Icon/Icon.tsx +118 -0
- package/src/components/Icon/index.ts +1 -0
- package/src/components/InputField/InputField.module.scss +37 -0
- package/src/components/InputField/InputField.spec.tsx +53 -0
- package/src/components/InputField/InputField.stories.tsx +73 -0
- package/src/components/InputField/InputField.tsx +72 -0
- package/src/components/InputField/index.ts +1 -0
- package/src/components/Link/Link.module.scss +18 -0
- package/src/components/Link/Link.stories.tsx +17 -0
- package/src/components/Link/Link.tsx +37 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/Loader/Loader.module.scss +66 -0
- package/src/components/Loader/Loader.spec.tsx +64 -0
- package/src/components/Loader/Loader.stories.tsx +25 -0
- package/src/components/Loader/Loader.tsx +48 -0
- package/src/components/Loader/index.ts +1 -0
- package/src/components/Modal/ActionModal.tsx +37 -0
- package/src/components/Modal/Modal.module.scss +131 -0
- package/src/components/Modal/Modal.stories.tsx +85 -0
- package/src/components/Modal/Modal.tsx +41 -0
- package/src/components/Modal/ModalBase.spec.tsx +58 -0
- package/src/components/Modal/ModalBase.tsx +66 -0
- package/src/components/Modal/ModalCloseButton.tsx +20 -0
- package/src/components/Modal/ModalPortal.tsx +35 -0
- package/src/components/Modal/index.ts +11 -0
- package/src/components/NumericInput/NumericInput.module.scss +110 -0
- package/src/components/NumericInput/NumericInput.spec.tsx +129 -0
- package/src/components/NumericInput/NumericInput.stories.tsx +56 -0
- package/src/components/NumericInput/NumericInput.tsx +161 -0
- package/src/components/NumericInput/NumericInputField.stories.tsx +58 -0
- package/src/components/NumericInput/NumericInputField.tsx +57 -0
- package/src/components/NumericInput/index.ts +2 -0
- package/src/components/Popover/Popover.module.scss +16 -0
- package/src/components/Popover/Popover.spec.tsx +39 -0
- package/src/components/Popover/Popover.stories.css +23 -0
- package/src/components/Popover/Popover.stories.tsx +164 -0
- package/src/components/Popover/Popover.tsx +124 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Progress/ProgressBar.module.scss +48 -0
- package/src/components/Progress/ProgressBar.spec.tsx +33 -0
- package/src/components/Progress/ProgressBar.stories.tsx +23 -0
- package/src/components/Progress/ProgressBar.tsx +62 -0
- package/src/components/Progress/ProgressCircle.module.scss +64 -0
- package/src/components/Progress/ProgressCircle.spec.tsx +34 -0
- package/src/components/Progress/ProgressCircle.stories.tsx +28 -0
- package/src/components/Progress/ProgressCircle.tsx +104 -0
- package/src/components/Progress/constants.ts +23 -0
- package/src/components/Progress/helpers.ts +23 -0
- package/src/components/Progress/index.ts +1 -0
- package/src/components/PromoBanner/PromoBanner.module.scss +121 -0
- package/src/components/PromoBanner/PromoBanner.spec.tsx +119 -0
- package/src/components/PromoBanner/PromoBanner.stories.tsx +125 -0
- package/src/components/PromoBanner/PromoBanner.tsx +99 -0
- package/src/components/PromoBanner/index.ts +1 -0
- package/src/components/RadioButton/RadioButton.module.scss +100 -0
- package/src/components/RadioButton/RadioButton.spec.tsx +70 -0
- package/src/components/RadioButton/RadioButton.stories.tsx +34 -0
- package/src/components/RadioButton/RadioButton.tsx +54 -0
- package/src/components/RadioButton/index.ts +1 -0
- package/src/components/Switch/Switch.module.scss +126 -0
- package/src/components/Switch/Switch.spec.tsx +40 -0
- package/src/components/Switch/Switch.stories.tsx +23 -0
- package/src/components/Switch/Switch.tsx +100 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Tab/Tab.module.scss +56 -0
- package/src/components/Tab/Tab.spec.tsx +34 -0
- package/src/components/Tab/Tab.stories.tsx +20 -0
- package/src/components/Tab/Tab.tsx +49 -0
- package/src/components/Tab/TabsWrapper.module.scss +11 -0
- package/src/components/Tab/TabsWrapper.spec.tsx +19 -0
- package/src/components/Tab/TabsWrapper.stories.tsx +46 -0
- package/src/components/Tab/TabsWrapper.tsx +24 -0
- package/src/components/Tab/index.ts +2 -0
- package/src/components/Tag/Tag.module.scss +131 -0
- package/src/components/Tag/Tag.spec.tsx +93 -0
- package/src/components/Tag/Tag.stories.tsx +151 -0
- package/src/components/Tag/Tag.tsx +129 -0
- package/src/components/Tag/index.ts +1 -0
- package/src/components/TagInput/EditableTag.tsx +54 -0
- package/src/components/TagInput/EditableTagContent.tsx +81 -0
- package/src/components/TagInput/EmailTagInput.tsx +31 -0
- package/src/components/TagInput/TagInput.module.scss +81 -0
- package/src/components/TagInput/TagInput.spec.tsx +58 -0
- package/src/components/TagInput/TagInput.stories.tsx +49 -0
- package/src/components/TagInput/TagInput.tsx +133 -0
- package/src/components/TagInput/index.ts +4 -0
- package/src/components/TextField/TextField.module.scss +90 -0
- package/src/components/TextField/TextField.spec.tsx +40 -0
- package/src/components/TextField/TextField.stories.tsx +60 -0
- package/src/components/TextField/TextField.tsx +100 -0
- package/src/components/TextField/index.ts +1 -0
- package/src/components/Toast/Toast.module.scss +218 -0
- package/src/components/Toast/Toast.spec.tsx +96 -0
- package/src/components/Toast/Toast.stories.tsx +64 -0
- package/src/components/Toast/Toast.tsx +121 -0
- package/src/components/Toast/ToastWrapper.spec.tsx +13 -0
- package/src/components/Toast/ToastWrapper.stories.tsx +55 -0
- package/src/components/Toast/ToastWrapper.tsx +87 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Typography/Heading.tsx +36 -0
- package/src/components/Typography/Text.tsx +49 -0
- package/src/components/Typography/Typography.module.scss +132 -0
- package/src/components/Typography/index.ts +2 -0
- package/src/index.scss +9 -0
- package/src/index.ts +32 -0
- package/src/stories/ColorTokens.stories.mdx +10 -0
- package/src/stories/Icons.stories.mdx +12 -0
- package/src/stories/Typography.stories.mdx +65 -0
- package/src/stories/components/ColorTokens.tsx +99 -0
- package/src/stories/components/IconsShowcase.tsx +25 -0
- package/src/stories/components/iconsShowcase.css +13 -0
- package/src/test/setup.ts +1 -0
- package/{dist/test-utils.d.ts → src/test/utils.ts} +3 -2
- package/src/themes/dark.scss +127 -0
- package/src/themes/designTokens.ts +126 -0
- package/src/themes/legacy.scss +128 -0
- package/src/themes/light.scss +127 -0
- package/src/utils/keyCodes.ts +12 -0
- package/src/utils/noop.ts +2 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +8 -0
- package/vite.config.ts +44 -0
- package/dist/components/Alert.d.ts +0 -19
- package/dist/components/Alert.spec.d.ts +0 -1
- package/dist/components/Badge.d.ts +0 -6
- package/dist/components/Badge.spec.d.ts +0 -1
- package/dist/components/Button.d.ts +0 -13
- package/dist/components/Button.spec.d.ts +0 -1
- package/dist/components/ButtonGroup.d.ts +0 -11
- package/dist/components/ButtonGroup.spec.d.ts +0 -1
- package/dist/components/Card.d.ts +0 -6
- package/dist/components/Card.spec.d.ts +0 -1
- package/dist/components/Checkbox.d.ts +0 -7
- package/dist/components/CheckboxField.d.ts +0 -7
- package/dist/components/CheckboxField.spec.d.ts +0 -1
- package/dist/components/FieldDescription.d.ts +0 -3
- package/dist/components/FieldError.d.ts +0 -3
- package/dist/components/FieldGroup.d.ts +0 -8
- package/dist/components/FieldGroup.spec.d.ts +0 -1
- package/dist/components/FieldLabel.d.ts +0 -3
- package/dist/components/Form.d.ts +0 -7
- package/dist/components/Form.spec.d.ts +0 -1
- package/dist/components/FormGroup.d.ts +0 -7
- package/dist/components/FormGroup.spec.d.ts +0 -1
- package/dist/components/Heading.d.ts +0 -11
- package/dist/components/Icon.d.ts +0 -69
- package/dist/components/Loader.d.ts +0 -10
- package/dist/components/Loader.spec.d.ts +0 -1
- package/dist/components/Modal/ActionModal.d.ts +0 -8
- package/dist/components/Modal/Modal.d.ts +0 -7
- package/dist/components/Modal/ModalBase.d.ts +0 -6
- package/dist/components/Modal/ModalBase.spec.d.ts +0 -1
- package/dist/components/Modal/ModalCloseButton.d.ts +0 -3
- package/dist/components/Modal/ModalPortal.d.ts +0 -7
- package/dist/components/ProgressBar.d.ts +0 -9
- package/dist/components/ProgressBar.spec.d.ts +0 -1
- package/dist/components/ProgressCircle.d.ts +0 -9
- package/dist/components/ProgressCircle.spec.d.ts +0 -1
- package/dist/components/PromoBanner.d.ts +0 -19
- package/dist/components/PromoBanner.spec.d.ts +0 -1
- package/dist/components/RadioButton.d.ts +0 -7
- package/dist/components/RadioButton.spec.d.ts +0 -1
- package/dist/components/Switch.d.ts +0 -17
- package/dist/components/Switch.spec.d.ts +0 -1
- package/dist/components/Tab.d.ts +0 -12
- package/dist/components/Tab.spec.d.ts +0 -1
- package/dist/components/TabsWrapper.d.ts +0 -3
- package/dist/components/TabsWrapper.spec.d.ts +0 -1
- package/dist/components/Text.d.ts +0 -15
- package/dist/components/Toast.d.ts +0 -22
- package/dist/components/Toast.spec.d.ts +0 -1
- package/dist/components/ToastWrapper.d.ts +0 -26
- package/dist/components/ToastWrapper.spec.d.ts +0 -1
- package/dist/components/constants.d.ts +0 -12
- package/dist/components/helpers.d.ts +0 -3
- package/dist/constants/keyCodes.d.ts +0 -3
- package/dist/index.css +0 -2
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/stories/Alert.stories.d.ts +0 -14
- package/dist/stories/Badge.stories.d.ts +0 -16
- package/dist/stories/Button.stories.d.ts +0 -20
- package/dist/stories/ButtonGroup.stories.d.ts +0 -18
- package/dist/stories/Card.stories.d.ts +0 -10
- package/dist/stories/CheckboxField.stories.d.ts +0 -9
- package/dist/stories/FieldGroup.stories.d.ts +0 -9
- package/dist/stories/Form.stories.d.ts +0 -6
- package/dist/stories/FormGroup.stories.d.ts +0 -9
- package/dist/stories/Icon.stories.d.ts +0 -14
- package/dist/stories/Loader.stories.d.ts +0 -8
- package/dist/stories/Modal.stories.d.ts +0 -19
- package/dist/stories/ProgressCircle.stories.d.ts +0 -13
- package/dist/stories/Progressbar.stories.d.ts +0 -13
- package/dist/stories/PromoBanner.stories.d.ts +0 -13
- package/dist/stories/RadioButton.stories.d.ts +0 -9
- package/dist/stories/Switch.stories.d.ts +0 -12
- package/dist/stories/Tab.stories.d.ts +0 -10
- package/dist/stories/TabsWrapper.stories.d.ts +0 -15
- package/dist/stories/Toast.stories.d.ts +0 -15
- package/dist/stories/ToastWrapper.stories.d.ts +0 -40
- package/dist/stories/foundations/components/ColorTokens.d.ts +0 -2
- package/dist/stories/foundations/components/IconsShowcase.d.ts +0 -6
- package/dist/utils/noop.d.ts +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from 'test-utils';
|
|
4
|
+
import { ProgressStatus } from './constants';
|
|
5
|
+
import { ProgressBar } from './ProgressBar';
|
|
6
|
+
|
|
7
|
+
import styles from './ProgressBar.module.scss';
|
|
8
|
+
|
|
9
|
+
describe('<ProgressBar /> component', () => {
|
|
10
|
+
it('should render normal ProgressBar by default', () => {
|
|
11
|
+
const { getByRole } = render(<ProgressBar percent={10} />);
|
|
12
|
+
expect(getByRole('progressbar')).toHaveClass(styles['progress-bar']);
|
|
13
|
+
expect(getByRole('progressbar')).toHaveClass(
|
|
14
|
+
styles['progress-bar--normal']
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should render success ProgressBar when success status is passed', () => {
|
|
19
|
+
const { getByRole } = render(
|
|
20
|
+
<ProgressBar status={ProgressStatus.Success} percent={10} />
|
|
21
|
+
);
|
|
22
|
+
expect(getByRole('progressbar')).toHaveClass(
|
|
23
|
+
styles['progress-bar--success']
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should render error ProgressBar when error status is passed', () => {
|
|
28
|
+
const { getByRole } = render(
|
|
29
|
+
<ProgressBar status={ProgressStatus.Error} percent={10} />
|
|
30
|
+
);
|
|
31
|
+
expect(getByRole('progressbar')).toHaveClass(styles['progress-bar--error']);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ProgressBar as ProgressBarComponent,
|
|
6
|
+
ProgressBarProps,
|
|
7
|
+
} from './ProgressBar';
|
|
8
|
+
import { ProgressSize, ProgressStatus } from './constants';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Components/Progress',
|
|
12
|
+
component: ProgressBarComponent,
|
|
13
|
+
} as ComponentMeta<typeof ProgressBarComponent>;
|
|
14
|
+
|
|
15
|
+
export const ProgressBar = (args: ProgressBarProps): React.ReactElement => {
|
|
16
|
+
return <ProgressBarComponent {...args} />;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
ProgressBar.args = {
|
|
20
|
+
percent: 10,
|
|
21
|
+
status: ProgressStatus.Normal,
|
|
22
|
+
size: ProgressSize.Medium,
|
|
23
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
|
|
4
|
+
import { ProgressSize, ProgressStatus } from './constants';
|
|
5
|
+
import { getPercentNumber, getProgressStatus } from './helpers';
|
|
6
|
+
|
|
7
|
+
import styles from './ProgressBar.module.scss';
|
|
8
|
+
|
|
9
|
+
const baseClass = 'progress-bar';
|
|
10
|
+
|
|
11
|
+
export interface ProgressBarProps {
|
|
12
|
+
className?: string;
|
|
13
|
+
percent: number;
|
|
14
|
+
status?: ProgressStatus;
|
|
15
|
+
size?: ProgressSize;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ProgressBar: React.ExoticComponent<
|
|
19
|
+
ProgressBarProps & React.RefAttributes<HTMLInputElement>
|
|
20
|
+
> = React.forwardRef(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
status = ProgressStatus.Normal,
|
|
24
|
+
percent,
|
|
25
|
+
size = ProgressSize.Medium,
|
|
26
|
+
className = '',
|
|
27
|
+
...restProps
|
|
28
|
+
},
|
|
29
|
+
ref: React.LegacyRef<HTMLInputElement>
|
|
30
|
+
) => {
|
|
31
|
+
const progressStatus = getProgressStatus(status, percent);
|
|
32
|
+
const percentNumber = getPercentNumber(progressStatus, percent);
|
|
33
|
+
|
|
34
|
+
const mergedClassNames = cx(
|
|
35
|
+
styles[baseClass],
|
|
36
|
+
{
|
|
37
|
+
[styles[`${baseClass}--${size}`]]: size,
|
|
38
|
+
[styles[`${baseClass}--error`]]:
|
|
39
|
+
progressStatus === ProgressStatus.Error,
|
|
40
|
+
[styles[`${baseClass}--success`]]:
|
|
41
|
+
progressStatus === ProgressStatus.Success,
|
|
42
|
+
[styles[`${baseClass}--normal`]]:
|
|
43
|
+
progressStatus === ProgressStatus.Normal,
|
|
44
|
+
},
|
|
45
|
+
className
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div
|
|
50
|
+
{...restProps}
|
|
51
|
+
className={mergedClassNames}
|
|
52
|
+
ref={ref}
|
|
53
|
+
role="progressbar"
|
|
54
|
+
>
|
|
55
|
+
<div
|
|
56
|
+
className={styles[`${baseClass}__indicator--${status}`]}
|
|
57
|
+
style={{ width: `${percentNumber}%` }}
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
.progress-circle {
|
|
2
|
+
height: 36px;
|
|
3
|
+
transform: rotate(-90deg);
|
|
4
|
+
width: 36px;
|
|
5
|
+
|
|
6
|
+
&--small {
|
|
7
|
+
height: 15px;
|
|
8
|
+
width: 15px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&--medium {
|
|
12
|
+
height: 36px;
|
|
13
|
+
width: 36px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&--large {
|
|
17
|
+
height: 56px;
|
|
18
|
+
width: 56px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&__bg-line--normal {
|
|
22
|
+
stroke: var(--color-action-disabled);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__bg-line--success {
|
|
26
|
+
stroke: var(--color-positive-disabled);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&__bg-line--error {
|
|
30
|
+
stroke: var(--color-negative-disabled);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&__indicator--normal {
|
|
34
|
+
stroke: var(--color-action-default);
|
|
35
|
+
transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&__indicator--success {
|
|
39
|
+
stroke: var(--color-positive-default);
|
|
40
|
+
transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&__indicator--error {
|
|
44
|
+
transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&--error {
|
|
48
|
+
.progress-circle__bg-line {
|
|
49
|
+
stroke: var(--color-negative-disabled);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&--success {
|
|
54
|
+
.progress-circle__bg-line {
|
|
55
|
+
stroke: var(--color-positive-disabled);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&--normal {
|
|
60
|
+
.progress-circle__bg-line {
|
|
61
|
+
stroke: var(--color-action-disabled);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render } from 'test-utils';
|
|
3
|
+
import { ProgressStatus } from './constants';
|
|
4
|
+
import { ProgressCircle } from './ProgressCircle';
|
|
5
|
+
|
|
6
|
+
import styles from './ProgressCircle.module.scss';
|
|
7
|
+
|
|
8
|
+
describe('<ProgressCircle /> component', () => {
|
|
9
|
+
it('should render ProgressCircle by default', () => {
|
|
10
|
+
const { getByRole } = render(<ProgressCircle percent={10} />);
|
|
11
|
+
expect(getByRole('progressbar')).toHaveClass(styles['progress-circle']);
|
|
12
|
+
expect(getByRole('progressbar')).toHaveClass(
|
|
13
|
+
styles['progress-circle--normal']
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should render success ProgressCircle when success status is passed', () => {
|
|
18
|
+
const { getByRole } = render(
|
|
19
|
+
<ProgressCircle status={ProgressStatus.Success} percent={10} />
|
|
20
|
+
);
|
|
21
|
+
expect(getByRole('progressbar')).toHaveClass(
|
|
22
|
+
styles['progress-circle--success']
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should render error ProgressCircle when error status is passed', () => {
|
|
27
|
+
const { getByRole } = render(
|
|
28
|
+
<ProgressCircle status={ProgressStatus.Error} percent={10} />
|
|
29
|
+
);
|
|
30
|
+
expect(getByRole('progressbar')).toHaveClass(
|
|
31
|
+
styles['progress-circle--error']
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ProgressCircle as ProgressCircleComponent,
|
|
6
|
+
ProgressCircleProps,
|
|
7
|
+
} from './ProgressCircle';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Components/Progress',
|
|
11
|
+
component: ProgressCircleComponent,
|
|
12
|
+
} as ComponentMeta<typeof ProgressCircleComponent>;
|
|
13
|
+
|
|
14
|
+
export const ProgressCircle = (
|
|
15
|
+
args: ProgressCircleProps
|
|
16
|
+
): React.ReactElement => {
|
|
17
|
+
return (
|
|
18
|
+
<div>
|
|
19
|
+
<ProgressCircleComponent {...args} />
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
ProgressCircle.args = {
|
|
25
|
+
percent: 10,
|
|
26
|
+
status: 'normal',
|
|
27
|
+
size: 'medium',
|
|
28
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { ProgressSize, ProgressStatus } from './constants';
|
|
4
|
+
import { getPercentNumber, getProgressStatus } from './helpers';
|
|
5
|
+
|
|
6
|
+
import styles from './ProgressCircle.module.scss';
|
|
7
|
+
|
|
8
|
+
const THICKNESS_FROM_SIZE = {
|
|
9
|
+
[ProgressSize.Small]: 2,
|
|
10
|
+
[ProgressSize.Medium]: 3,
|
|
11
|
+
[ProgressSize.Large]: 4,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const SIZE_VALUE_FROM_SIZE = {
|
|
15
|
+
[ProgressSize.Small]: 15,
|
|
16
|
+
[ProgressSize.Medium]: 36,
|
|
17
|
+
[ProgressSize.Large]: 56,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const baseClass = 'progress-circle';
|
|
21
|
+
|
|
22
|
+
export interface ProgressCircleProps {
|
|
23
|
+
className?: string;
|
|
24
|
+
percent: number;
|
|
25
|
+
status?: ProgressStatus;
|
|
26
|
+
size?: ProgressSize;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const ProgressCircle: React.ExoticComponent<
|
|
30
|
+
ProgressCircleProps & React.RefAttributes<HTMLInputElement>
|
|
31
|
+
> = React.forwardRef(
|
|
32
|
+
(
|
|
33
|
+
{
|
|
34
|
+
status = ProgressStatus.Normal,
|
|
35
|
+
percent,
|
|
36
|
+
className,
|
|
37
|
+
size = ProgressSize.Medium,
|
|
38
|
+
...restProps
|
|
39
|
+
},
|
|
40
|
+
ref: React.LegacyRef<HTMLInputElement>
|
|
41
|
+
) => {
|
|
42
|
+
const progressStatus = getProgressStatus(status, percent);
|
|
43
|
+
const percentNumber = getPercentNumber(progressStatus, percent);
|
|
44
|
+
const thickness = THICKNESS_FROM_SIZE[size];
|
|
45
|
+
const sizeValue = SIZE_VALUE_FROM_SIZE[size];
|
|
46
|
+
|
|
47
|
+
const mergedClassNames = cx(
|
|
48
|
+
styles[baseClass],
|
|
49
|
+
{
|
|
50
|
+
[styles[`${baseClass}--${size}`]]: size,
|
|
51
|
+
[styles[`${baseClass}--error`]]:
|
|
52
|
+
progressStatus === ProgressStatus.Error,
|
|
53
|
+
[styles[`${baseClass}--success`]]:
|
|
54
|
+
progressStatus === ProgressStatus.Success,
|
|
55
|
+
[styles[`${baseClass}--normal`]]:
|
|
56
|
+
progressStatus === ProgressStatus.Normal,
|
|
57
|
+
},
|
|
58
|
+
className
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const circumference = 2 * Math.PI * ((sizeValue - thickness) / 2);
|
|
62
|
+
|
|
63
|
+
const indicatorStyle = {
|
|
64
|
+
strokeDasharray: circumference.toFixed(3),
|
|
65
|
+
strokeDashoffset: `${(
|
|
66
|
+
((100 - percentNumber) / 100) *
|
|
67
|
+
circumference
|
|
68
|
+
).toFixed(3)}px`,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const svgViewBox = `${sizeValue / 2} ${
|
|
72
|
+
sizeValue / 2
|
|
73
|
+
} ${sizeValue} ${sizeValue}`;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div
|
|
77
|
+
className={mergedClassNames}
|
|
78
|
+
ref={ref}
|
|
79
|
+
role="progressbar"
|
|
80
|
+
{...restProps}
|
|
81
|
+
>
|
|
82
|
+
<svg viewBox={svgViewBox}>
|
|
83
|
+
<circle
|
|
84
|
+
className={styles[`${baseClass}__bg-line--${status}`]}
|
|
85
|
+
cx={sizeValue}
|
|
86
|
+
cy={sizeValue}
|
|
87
|
+
r={(sizeValue - thickness) / 2}
|
|
88
|
+
fill="none"
|
|
89
|
+
strokeWidth={thickness}
|
|
90
|
+
/>
|
|
91
|
+
<circle
|
|
92
|
+
className={styles[`${baseClass}__indicator--${status}`]}
|
|
93
|
+
style={indicatorStyle}
|
|
94
|
+
cx={sizeValue}
|
|
95
|
+
cy={sizeValue}
|
|
96
|
+
r={(sizeValue - thickness) / 2}
|
|
97
|
+
fill="none"
|
|
98
|
+
strokeWidth={thickness}
|
|
99
|
+
/>
|
|
100
|
+
</svg>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const enum ProgressStatus {
|
|
2
|
+
Normal = 'normal',
|
|
3
|
+
Error = 'error',
|
|
4
|
+
Success = 'success',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const enum ProgressSize {
|
|
8
|
+
Small = 'small',
|
|
9
|
+
Medium = 'medium',
|
|
10
|
+
Large = 'large',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const PROGRESS_STATUSES = [
|
|
14
|
+
ProgressStatus.Normal,
|
|
15
|
+
ProgressStatus.Error,
|
|
16
|
+
ProgressStatus.Success,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const PROGRESS_SIZES = [
|
|
20
|
+
ProgressSize.Small,
|
|
21
|
+
ProgressSize.Medium,
|
|
22
|
+
ProgressSize.Large,
|
|
23
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PROGRESS_STATUSES, ProgressStatus } from './constants';
|
|
2
|
+
|
|
3
|
+
const clampPercentage = (percent: number): number =>
|
|
4
|
+
Math.min(Math.max(percent, 0), 100);
|
|
5
|
+
|
|
6
|
+
export function getPercentNumber(status: ProgressStatus, percent = 0): number {
|
|
7
|
+
if (status === ProgressStatus.Error) {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return clampPercentage(parseInt(percent.toString(), 10));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getProgressStatus(
|
|
15
|
+
status: ProgressStatus,
|
|
16
|
+
percent: number
|
|
17
|
+
): ProgressStatus {
|
|
18
|
+
if (!PROGRESS_STATUSES.includes(status) && percent >= 100) {
|
|
19
|
+
return ProgressStatus.Normal;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return status || ProgressStatus.Normal;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProgressCircle } from './ProgressCircle';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
.promo-banner {
|
|
2
|
+
align-items: center;
|
|
3
|
+
background-color: var(--surface-basic-subtle);
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
color: var(--content-default);
|
|
7
|
+
display: flex;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
min-width: 180px;
|
|
11
|
+
padding: 20px;
|
|
12
|
+
position: relative;
|
|
13
|
+
width: 100%;
|
|
14
|
+
word-break: break-word;
|
|
15
|
+
|
|
16
|
+
b {
|
|
17
|
+
font-weight: 600;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&__content {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: row;
|
|
23
|
+
justify-content: flex-start;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&__wrapper {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&__header {
|
|
32
|
+
font-weight: 600;
|
|
33
|
+
margin-bottom: 8px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&__img {
|
|
37
|
+
height: 48px;
|
|
38
|
+
object-fit: contain;
|
|
39
|
+
width: 48px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&__button-text {
|
|
43
|
+
margin-right: 24px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&--light {
|
|
47
|
+
background-color: var(--surface-basic-default);
|
|
48
|
+
border: solid 1px var(--border-subtle);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&--small {
|
|
52
|
+
flex-wrap: wrap;
|
|
53
|
+
max-width: 400px;
|
|
54
|
+
|
|
55
|
+
.promo-banner__content {
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.promo-banner__img {
|
|
60
|
+
margin-bottom: 12px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.promo-banner__footer {
|
|
64
|
+
display: flex;
|
|
65
|
+
margin-top: 12px;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--medium {
|
|
70
|
+
flex-wrap: wrap;
|
|
71
|
+
max-width: 800px;
|
|
72
|
+
|
|
73
|
+
.promo-banner__img {
|
|
74
|
+
margin-right: 20px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.promo-banner__wrapper {
|
|
78
|
+
max-width: 680px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.promo-banner__footer {
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-shrink: 0;
|
|
84
|
+
margin-top: 12px;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&--large {
|
|
89
|
+
min-width: 600px;
|
|
90
|
+
|
|
91
|
+
.promo-banner__img {
|
|
92
|
+
margin-right: 20px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.promo-banner__wrapper {
|
|
96
|
+
max-width: 680px;
|
|
97
|
+
min-width: 180px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.promo-banner__footer {
|
|
101
|
+
align-items: center;
|
|
102
|
+
display: inline-flex;
|
|
103
|
+
flex-shrink: 0;
|
|
104
|
+
margin: 0 56px;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&__close-icon {
|
|
109
|
+
background-color: transparent;
|
|
110
|
+
border: 0;
|
|
111
|
+
box-shadow: none;
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
height: 24px;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
padding: 0;
|
|
116
|
+
position: absolute;
|
|
117
|
+
right: 12px;
|
|
118
|
+
top: 12px;
|
|
119
|
+
width: 24px;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, fireEvent, vi } from 'test-utils';
|
|
3
|
+
import { PromoBannerProps, PromoBanner, PromoBannerSize } from './PromoBanner';
|
|
4
|
+
|
|
5
|
+
import styles from './PromoBanner.module.scss';
|
|
6
|
+
|
|
7
|
+
const promoHeader = 'This example headline has 40 characters';
|
|
8
|
+
|
|
9
|
+
const renderComponent = (props: PromoBannerProps) => {
|
|
10
|
+
return render(<PromoBanner {...props}>This example content</PromoBanner>);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('<PromoBanner> component', () => {
|
|
14
|
+
it('should allow for custom class', () => {
|
|
15
|
+
const { container } = renderComponent({
|
|
16
|
+
header: promoHeader,
|
|
17
|
+
className: 'my-css-class',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(container.firstChild).toHaveClass('my-css-class');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should display button', () => {
|
|
24
|
+
const { getByText } = renderComponent({
|
|
25
|
+
header: promoHeader,
|
|
26
|
+
buttonText: 'Example text',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(getByText('Example text')).toBeVisible();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should display link', () => {
|
|
33
|
+
const { getByText } = renderComponent({
|
|
34
|
+
header: promoHeader,
|
|
35
|
+
linkText: 'Example text',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(getByText('Example text')).toBeVisible();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should display image', () => {
|
|
42
|
+
const { getByRole } = renderComponent({
|
|
43
|
+
header: promoHeader,
|
|
44
|
+
img: 'https://via.placeholder.com/100',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(getByRole('img')).toBeVisible();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should display with light mode', () => {
|
|
51
|
+
const { container } = renderComponent({
|
|
52
|
+
header: promoHeader,
|
|
53
|
+
light: true,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(container.firstChild).toHaveClass(styles['promo-banner--light']);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should display with small size by default', () => {
|
|
60
|
+
const { container } = renderComponent({
|
|
61
|
+
header: promoHeader,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(container.firstChild).toHaveClass(styles['promo-banner--small']);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should display with medium size', () => {
|
|
68
|
+
const { container } = renderComponent({
|
|
69
|
+
header: promoHeader,
|
|
70
|
+
size: PromoBannerSize.Medium,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(container.firstChild).toHaveClass(styles['promo-banner--medium']);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should display with large size', () => {
|
|
77
|
+
const { container } = renderComponent({
|
|
78
|
+
header: promoHeader,
|
|
79
|
+
size: PromoBannerSize.Large,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(container.firstChild).toHaveClass(styles['promo-banner--large']);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should call onClose function', () => {
|
|
86
|
+
const onClose = vi.fn();
|
|
87
|
+
const { getByRole } = renderComponent({
|
|
88
|
+
header: promoHeader,
|
|
89
|
+
onClose,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
fireEvent.click(getByRole('button'));
|
|
93
|
+
expect(onClose).toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should call onButtonClick function', () => {
|
|
97
|
+
const onButtonClick = vi.fn();
|
|
98
|
+
const { getByText } = renderComponent({
|
|
99
|
+
header: promoHeader,
|
|
100
|
+
buttonText: 'Example text',
|
|
101
|
+
onButtonClick,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
fireEvent.click(getByText('Example text'));
|
|
105
|
+
expect(onButtonClick).toHaveBeenCalled();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should call onLinkClick function', () => {
|
|
109
|
+
const onLinkClick = vi.fn();
|
|
110
|
+
const { getByText } = renderComponent({
|
|
111
|
+
header: promoHeader,
|
|
112
|
+
linkText: 'Example text',
|
|
113
|
+
onLinkClick,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
fireEvent.click(getByText('Example text'));
|
|
117
|
+
expect(onLinkClick).toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
});
|