@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,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
FieldGroup as FieldGroupComponent,
|
|
6
|
+
FieldGroupProps,
|
|
7
|
+
} from './FieldGroup';
|
|
8
|
+
import { RadioButton } from '../RadioButton';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Forms (WIP)/Field Group',
|
|
12
|
+
component: FieldGroupComponent,
|
|
13
|
+
parameters: {
|
|
14
|
+
componentSubtitle: `
|
|
15
|
+
Use FieldGroup component to group elements and display it in nice layout (inline or stacked).
|
|
16
|
+
`,
|
|
17
|
+
},
|
|
18
|
+
} as ComponentMeta<typeof FieldGroupComponent>;
|
|
19
|
+
|
|
20
|
+
export const FieldGroup = ({
|
|
21
|
+
...args
|
|
22
|
+
}: FieldGroupProps): React.ReactElement => (
|
|
23
|
+
<FieldGroupComponent {...args}>
|
|
24
|
+
<RadioButton id="field-group-example-1">Radio button label</RadioButton>
|
|
25
|
+
<RadioButton id="field-group-example-2">Radio button label</RadioButton>
|
|
26
|
+
</FieldGroupComponent>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
FieldGroup.args = {
|
|
30
|
+
description: 'Field group description',
|
|
31
|
+
error: '',
|
|
32
|
+
stretch: false,
|
|
33
|
+
inline: false,
|
|
34
|
+
} as FieldGroupProps;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { FieldError } from '../FieldError';
|
|
4
|
+
import { FieldDescription } from '../FieldDescription';
|
|
5
|
+
|
|
6
|
+
import styles from './FieldGroup.module.scss';
|
|
7
|
+
|
|
8
|
+
export interface FieldGroupProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
error?: string;
|
|
11
|
+
inline?: boolean;
|
|
12
|
+
stretch?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const baseClass = 'field-group';
|
|
16
|
+
|
|
17
|
+
export const FieldGroup: React.FC<FieldGroupProps> = ({
|
|
18
|
+
className = '',
|
|
19
|
+
children,
|
|
20
|
+
description,
|
|
21
|
+
error,
|
|
22
|
+
inline,
|
|
23
|
+
stretch,
|
|
24
|
+
...props
|
|
25
|
+
}) => {
|
|
26
|
+
const mergedClassNames = cx(styles[baseClass], className, {
|
|
27
|
+
[styles[`${baseClass}--inline`]]: inline,
|
|
28
|
+
[styles[`${baseClass}--stretched`]]: stretch,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div {...props} className={mergedClassNames}>
|
|
33
|
+
{children}
|
|
34
|
+
{error && <FieldError>{error}</FieldError>}
|
|
35
|
+
{description && <FieldDescription>{description}</FieldDescription>}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldGroup } from './FieldGroup';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.form {
|
|
2
|
+
border: 0;
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
margin: 0;
|
|
5
|
+
padding: 0;
|
|
6
|
+
|
|
7
|
+
&__header,
|
|
8
|
+
&__footer {
|
|
9
|
+
margin-bottom: 32px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
&__label {
|
|
13
|
+
color: var(--content-default);
|
|
14
|
+
margin: 0;
|
|
15
|
+
margin-bottom: 16px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__helper {
|
|
19
|
+
color: var(--content-default);
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { render } from 'test-utils';
|
|
4
|
+
import noop from '../../utils/noop';
|
|
5
|
+
import { Form } from './Form';
|
|
6
|
+
|
|
7
|
+
describe('<Form /> component', () => {
|
|
8
|
+
it("should render 'labelText' heading", () => {
|
|
9
|
+
const { getByRole } = render(<Form labelText="Hello" />);
|
|
10
|
+
const heading = getByRole('heading');
|
|
11
|
+
expect(heading).toBeVisible();
|
|
12
|
+
expect(heading).toHaveTextContent('Hello');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should render 'helperText'", () => {
|
|
16
|
+
const { getByText } = render(<Form helperText="Hello" />);
|
|
17
|
+
expect(getByText('Hello')).toBeVisible();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should render nested elements as 'formFooter'", () => {
|
|
21
|
+
const { getByRole } = render(<Form formFooter={<button>Submit</button>} />);
|
|
22
|
+
const button = getByRole('button');
|
|
23
|
+
expect(button).toBeVisible();
|
|
24
|
+
expect(button).toHaveTextContent('Submit');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should render nested elements as 'children'", () => {
|
|
28
|
+
const { getByRole } = render(
|
|
29
|
+
<Form>
|
|
30
|
+
<input type="text" value="Hello" onChange={noop} />
|
|
31
|
+
</Form>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const input = getByRole('textbox');
|
|
35
|
+
expect(input).toBeVisible();
|
|
36
|
+
expect(input).toHaveValue('Hello');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta, Story } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { Form as FormComponenet, FormProps } from '../Form';
|
|
5
|
+
import { Button } from '..//Button';
|
|
6
|
+
import { RadioButton } from '../RadioButton';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'Forms (WIP)/Form',
|
|
10
|
+
component: FormComponenet,
|
|
11
|
+
} as ComponentMeta<typeof FormComponenet>;
|
|
12
|
+
|
|
13
|
+
export const Form: Story<FormProps> = (args) => {
|
|
14
|
+
return <FormComponenet {...args} />;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
Form.args = {
|
|
18
|
+
labelText: 'Settings',
|
|
19
|
+
helperText:
|
|
20
|
+
'Use form layout to arrange fields within a form using standard spacing. We recomme stacking fields vertically for easier scanning and faster completion, but you can also arrange them vertically.',
|
|
21
|
+
formFooter: (
|
|
22
|
+
<Button kind="primary" type="button">
|
|
23
|
+
Save changes
|
|
24
|
+
</Button>
|
|
25
|
+
),
|
|
26
|
+
children: (
|
|
27
|
+
// TODO: Expand the example with FormGroup, FieldGroup and InputField components
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'row',
|
|
32
|
+
marginBottom: '32px',
|
|
33
|
+
gap: '16px',
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<RadioButton checked id="gender-radio">
|
|
37
|
+
Male
|
|
38
|
+
</RadioButton>
|
|
39
|
+
<RadioButton id="gender-radio">Female</RadioButton>
|
|
40
|
+
</div>
|
|
41
|
+
),
|
|
42
|
+
} as FormProps;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
|
|
4
|
+
import { Text, Heading } from '../Typography';
|
|
5
|
+
|
|
6
|
+
import styles from './Form.module.scss';
|
|
7
|
+
|
|
8
|
+
export interface FormProps extends React.HTMLAttributes<HTMLFormElement> {
|
|
9
|
+
labelText?: string;
|
|
10
|
+
helperText?: string;
|
|
11
|
+
formFooter?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const baseClass = 'form';
|
|
15
|
+
|
|
16
|
+
export const Form: React.FC<FormProps> = ({
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
labelText,
|
|
20
|
+
helperText,
|
|
21
|
+
formFooter,
|
|
22
|
+
...restProps
|
|
23
|
+
}) => {
|
|
24
|
+
return (
|
|
25
|
+
<form className={cx(styles[baseClass], className)} {...restProps}>
|
|
26
|
+
{(labelText || helperText) && (
|
|
27
|
+
<div className={styles[`${baseClass}__header`]}>
|
|
28
|
+
{labelText && (
|
|
29
|
+
<Heading size="sm" className={styles[`${baseClass}__label`]}>
|
|
30
|
+
{labelText}
|
|
31
|
+
</Heading>
|
|
32
|
+
)}
|
|
33
|
+
{helperText && (
|
|
34
|
+
<Text as="p" size="sm" className={styles[`${baseClass}__helper`]}>
|
|
35
|
+
{helperText}
|
|
36
|
+
</Text>
|
|
37
|
+
)}
|
|
38
|
+
</div>
|
|
39
|
+
)}
|
|
40
|
+
{children}
|
|
41
|
+
{formFooter && (
|
|
42
|
+
<div className={styles[`${baseClass}__footer`]}>{formFooter}</div>
|
|
43
|
+
)}
|
|
44
|
+
</form>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.form-group {
|
|
2
|
+
border-style: none;
|
|
3
|
+
margin: 0 0 32px;
|
|
4
|
+
min-width: auto;
|
|
5
|
+
padding: 0;
|
|
6
|
+
|
|
7
|
+
&__header {
|
|
8
|
+
margin-bottom: 16px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&__label {
|
|
12
|
+
color: var(--content-default);
|
|
13
|
+
display: block;
|
|
14
|
+
margin-bottom: 4px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&__helper {
|
|
18
|
+
color: var(--content-subtle);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render } from 'test-utils';
|
|
3
|
+
import { FormGroup } from './FormGroup';
|
|
4
|
+
|
|
5
|
+
import styles from './FormGroup.module.scss';
|
|
6
|
+
|
|
7
|
+
const baseClass = 'form-group';
|
|
8
|
+
|
|
9
|
+
describe('<FormGroup> component', () => {
|
|
10
|
+
it('should allow for custom class', () => {
|
|
11
|
+
const { container } = render(
|
|
12
|
+
<FormGroup className="my-css-class">test</FormGroup>
|
|
13
|
+
);
|
|
14
|
+
expect(container.firstChild).toHaveClass('my-css-class');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should render label text', () => {
|
|
18
|
+
const text = 'Label text';
|
|
19
|
+
const { queryByText } = render(
|
|
20
|
+
<FormGroup labelText={text}>test</FormGroup>
|
|
21
|
+
);
|
|
22
|
+
expect(queryByText(text)).toBeTruthy();
|
|
23
|
+
expect(queryByText(text)).toHaveClass(styles[`${baseClass}__label`]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should render helper text', () => {
|
|
27
|
+
const text = 'Helper text';
|
|
28
|
+
const { queryByText } = render(
|
|
29
|
+
<FormGroup helperText={text}>test</FormGroup>
|
|
30
|
+
);
|
|
31
|
+
expect(queryByText(text)).toBeTruthy();
|
|
32
|
+
expect(queryByText(text)).toHaveClass(styles[`${baseClass}__helper`]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { FormGroup as FormGroupComponent, FormGroupProps } from './FormGroup';
|
|
5
|
+
import { RadioButton } from '../RadioButton';
|
|
6
|
+
import { FieldGroup } from '../FieldGroup';
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'Forms (WIP)/Form Group',
|
|
10
|
+
component: FormGroupComponent,
|
|
11
|
+
parameters: {
|
|
12
|
+
componentSubtitle: `
|
|
13
|
+
Use FormGroup component to group related fieldsets. Component provides label for group of fields which improves accessibility of your form.
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
} as ComponentMeta<typeof FormGroupComponent>;
|
|
17
|
+
|
|
18
|
+
export const FormGroup = ({ ...args }: FormGroupProps): React.ReactElement => (
|
|
19
|
+
<FormGroupComponent {...args}>
|
|
20
|
+
<FieldGroup>
|
|
21
|
+
<RadioButton id="field-group-example-1">Radio button label</RadioButton>
|
|
22
|
+
<RadioButton id="field-group-example-2">Radio button label</RadioButton>
|
|
23
|
+
</FieldGroup>
|
|
24
|
+
</FormGroupComponent>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
FormGroup.args = {
|
|
28
|
+
labelText: 'Form Group example',
|
|
29
|
+
helperText: 'Form Group helper text',
|
|
30
|
+
} as FormGroupProps;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { Text, Heading } from '../Typography';
|
|
4
|
+
|
|
5
|
+
import styles from './FormGroup.module.scss';
|
|
6
|
+
|
|
7
|
+
export interface FormGroupProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
8
|
+
className?: string;
|
|
9
|
+
labelText?: string;
|
|
10
|
+
helperText?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const baseClass = 'form-group';
|
|
14
|
+
|
|
15
|
+
export const FormGroup: React.FC<FormGroupProps> = ({
|
|
16
|
+
className = '',
|
|
17
|
+
children,
|
|
18
|
+
labelText,
|
|
19
|
+
helperText,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const mergedClassNames = cx(styles[baseClass], className);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
{...props}
|
|
27
|
+
role="group"
|
|
28
|
+
{...(labelText && { 'aria-label': labelText })}
|
|
29
|
+
className={mergedClassNames}
|
|
30
|
+
>
|
|
31
|
+
<div className={styles[`${baseClass}__header`]}>
|
|
32
|
+
<Heading as="div" size="sm" className={styles[`${baseClass}__label`]}>
|
|
33
|
+
{labelText}
|
|
34
|
+
</Heading>
|
|
35
|
+
{helperText && (
|
|
36
|
+
<Text as="div" size="sm" className={styles[`${baseClass}__helper`]}>
|
|
37
|
+
{helperText}
|
|
38
|
+
</Text>
|
|
39
|
+
)}
|
|
40
|
+
</div>
|
|
41
|
+
{children}
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FormGroup';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.icon {
|
|
2
|
+
align-items: center;
|
|
3
|
+
display: flex;
|
|
4
|
+
|
|
5
|
+
&--primary {
|
|
6
|
+
color: var(--content-default);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
&--subtle {
|
|
10
|
+
color: var(--content-subtle);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&--inverted {
|
|
14
|
+
color: var(--content-invert-default);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&--inverted-subtle {
|
|
18
|
+
color: var(--content-invert-subtle);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&--link {
|
|
22
|
+
color: var(--color-action-default);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&--success {
|
|
26
|
+
color: var(--color-positive-default);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&--warning {
|
|
30
|
+
color: var(--color-warning-default);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&--error {
|
|
34
|
+
color: var(--color-negative-default);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&--disabled {
|
|
38
|
+
&--primary {
|
|
39
|
+
color: var(--content-disabled);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&--subtle {
|
|
43
|
+
color: var(--content-disabled);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&--inverted {
|
|
47
|
+
color: var(--content-invert-disabled);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&--inverted-subtle {
|
|
51
|
+
color: var(--content-invert-disabled);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&--link {
|
|
55
|
+
color: var(--color-action-disabled);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&--success {
|
|
59
|
+
color: var(--color-positive-disabled);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&--warning {
|
|
63
|
+
color: var(--color-warning-default);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&--error {
|
|
67
|
+
color: var(--color-negative-disabled);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
import * as MaterialIcons from '@livechat/design-system-icons/react/material';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Icon as IconComponent,
|
|
7
|
+
IconSizeName,
|
|
8
|
+
IconTypeName,
|
|
9
|
+
IconProps,
|
|
10
|
+
} from './Icon';
|
|
11
|
+
|
|
12
|
+
const iterator = Object.keys(MaterialIcons);
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: 'Components/Icon',
|
|
16
|
+
component: IconComponent,
|
|
17
|
+
argTypes: {
|
|
18
|
+
source: {
|
|
19
|
+
options: iterator,
|
|
20
|
+
mapping: MaterialIcons,
|
|
21
|
+
control: {
|
|
22
|
+
type: 'select',
|
|
23
|
+
labels: iterator,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
table: {
|
|
28
|
+
defaultValue: {
|
|
29
|
+
summary: IconSizeName.Medium,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
iconType: {
|
|
34
|
+
table: {
|
|
35
|
+
defaultValue: {
|
|
36
|
+
summary: IconTypeName.Primary,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
} as ComponentMeta<typeof IconComponent>;
|
|
42
|
+
|
|
43
|
+
export const Icon = (args: IconProps): React.ReactElement => (
|
|
44
|
+
<div style={{ width: '300px' }}>
|
|
45
|
+
<IconComponent {...args} />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
Icon.args = {
|
|
50
|
+
source: MaterialIcons.Email,
|
|
51
|
+
size: IconSizeName.Medium,
|
|
52
|
+
iconType: IconTypeName.Primary,
|
|
53
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import styles from './Icon.module.scss';
|
|
4
|
+
|
|
5
|
+
export enum IconSizeName {
|
|
6
|
+
XSmall = 'xsmall',
|
|
7
|
+
Small = 'small',
|
|
8
|
+
Medium = 'medium',
|
|
9
|
+
Large = 'large',
|
|
10
|
+
XLarge = 'xlarge',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const IconSize = {
|
|
14
|
+
[IconSizeName.XSmall]: {
|
|
15
|
+
width: 12,
|
|
16
|
+
height: 12,
|
|
17
|
+
},
|
|
18
|
+
[IconSizeName.Small]: {
|
|
19
|
+
width: 16,
|
|
20
|
+
height: 16,
|
|
21
|
+
},
|
|
22
|
+
[IconSizeName.Medium]: {
|
|
23
|
+
width: 20,
|
|
24
|
+
height: 20,
|
|
25
|
+
},
|
|
26
|
+
[IconSizeName.Large]: {
|
|
27
|
+
width: 24,
|
|
28
|
+
height: 24,
|
|
29
|
+
},
|
|
30
|
+
[IconSizeName.XLarge]: {
|
|
31
|
+
width: 32,
|
|
32
|
+
height: 32,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export enum IconTypeName {
|
|
37
|
+
Primary = 'primary',
|
|
38
|
+
Subtle = 'subtle',
|
|
39
|
+
Inverted = 'inverted',
|
|
40
|
+
InvertedSubtle = 'inverted_subtle',
|
|
41
|
+
Link = 'link',
|
|
42
|
+
Success = 'success',
|
|
43
|
+
Warning = 'warning',
|
|
44
|
+
Error = 'error',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const IconColorMapper = {
|
|
48
|
+
[IconTypeName.Primary]: 'primary',
|
|
49
|
+
[IconTypeName.Subtle]: 'subtle',
|
|
50
|
+
[IconTypeName.Inverted]: 'inverted',
|
|
51
|
+
[IconTypeName.InvertedSubtle]: 'inverted-subtle',
|
|
52
|
+
[IconTypeName.Link]: 'link',
|
|
53
|
+
[IconTypeName.Success]: 'success',
|
|
54
|
+
[IconTypeName.Warning]: 'warning',
|
|
55
|
+
[IconTypeName.Error]: 'error',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const IconColorDisabledMapper = {
|
|
59
|
+
[IconTypeName.Primary]: 'disabled--primary',
|
|
60
|
+
[IconTypeName.Subtle]: 'disabled--subtle',
|
|
61
|
+
[IconTypeName.Inverted]: 'disabled--inverted',
|
|
62
|
+
[IconTypeName.InvertedSubtle]: 'disabled--inverted-subtle',
|
|
63
|
+
[IconTypeName.Link]: 'disabled--link',
|
|
64
|
+
[IconTypeName.Success]: 'disabled--success',
|
|
65
|
+
[IconTypeName.Warning]: 'disabled--warning',
|
|
66
|
+
[IconTypeName.Error]: 'disabled--error',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export interface IconProps {
|
|
70
|
+
source: React.FC<React.SVGProps<SVGSVGElement>> | string;
|
|
71
|
+
size?: IconSizeName;
|
|
72
|
+
iconType?: IconTypeName;
|
|
73
|
+
disabled?: boolean;
|
|
74
|
+
className?: string;
|
|
75
|
+
customColor?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const baseClass = 'icon';
|
|
79
|
+
|
|
80
|
+
export const Icon: React.FC<IconProps> = (props) => {
|
|
81
|
+
const {
|
|
82
|
+
source,
|
|
83
|
+
size = IconSizeName.Medium,
|
|
84
|
+
iconType,
|
|
85
|
+
disabled,
|
|
86
|
+
className,
|
|
87
|
+
customColor,
|
|
88
|
+
...restProps
|
|
89
|
+
} = props;
|
|
90
|
+
let filledColor;
|
|
91
|
+
|
|
92
|
+
if (iconType) {
|
|
93
|
+
filledColor = IconColorMapper[iconType];
|
|
94
|
+
|
|
95
|
+
if (disabled) {
|
|
96
|
+
filledColor = IconColorDisabledMapper[iconType];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const GeneratedIcon = React.createElement(source, {
|
|
101
|
+
...IconSize[size],
|
|
102
|
+
color: customColor,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const mergedClassNames = cx(
|
|
106
|
+
className,
|
|
107
|
+
styles[baseClass],
|
|
108
|
+
filledColor && styles[`${baseClass}--${filledColor}`]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<span {...restProps} className={mergedClassNames}>
|
|
113
|
+
{GeneratedIcon}
|
|
114
|
+
</span>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export default Icon;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Icon, IconSizeName, IconTypeName } from './Icon';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.input-field {
|
|
2
|
+
background-clip: padding-box;
|
|
3
|
+
border: 1px solid var(--border-default);
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
color: var(--content-default);
|
|
7
|
+
font-size: 15px;
|
|
8
|
+
line-height: 1.2;
|
|
9
|
+
padding: 8px 10px;
|
|
10
|
+
transition: border 0.25s ease-in-out;
|
|
11
|
+
width: 100%;
|
|
12
|
+
will-change: border-color;
|
|
13
|
+
|
|
14
|
+
&::placeholder {
|
|
15
|
+
color: var(--content-disabled);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&:hover {
|
|
19
|
+
border-color: var(--border-hover);
|
|
20
|
+
outline: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&:focus {
|
|
24
|
+
border-color: var(--color-action-default);
|
|
25
|
+
outline: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&--error,
|
|
29
|
+
&--error:focus {
|
|
30
|
+
border-color: var(--color-negative-default);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:disabled {
|
|
34
|
+
color: var(--content-disabled);
|
|
35
|
+
cursor: not-allowed;
|
|
36
|
+
}
|
|
37
|
+
}
|