@ndlib/component-library 1.0.21 → 1.0.23
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/README.md +26 -8
- package/dist/assets/index-3cfb730f.js +1 -0
- package/dist/components/composites/Card/Card.stories.js +2 -0
- package/dist/components/composites/Card/index.js +4 -3
- package/dist/components/composites/CardV2/CardV2.module.css +74 -0
- package/dist/components/composites/CardV2/CardV2.stories.d.ts +19 -0
- package/dist/components/composites/CardV2/CardV2.stories.js +187 -0
- package/dist/components/composites/CardV2/CardV2.test.js +67 -0
- package/dist/components/composites/CardV2/index.d.ts +43 -0
- package/dist/components/composites/CardV2/index.js +99 -0
- package/dist/components/composites/DragDropList/DragDropList.stories.js +3 -1
- package/dist/components/composites/DropdownLinks/DropdownLinks.stories.js +2 -0
- package/dist/components/composites/DropdownLinks/index.d.ts +1 -1
- package/dist/components/composites/EmptyState/EmptyState.stories.js +2 -0
- package/dist/components/composites/EmptyState/index.js +1 -1
- package/dist/components/composites/Modal/Modal.stories.js +5 -2
- package/dist/components/composites/Modal/index.js +3 -2
- package/dist/components/composites/ModalV2/ModalV2.stories.d.ts +6 -0
- package/dist/components/composites/ModalV2/ModalV2.stories.js +41 -0
- package/dist/components/composites/ModalV2/ModalV2.test.js +37 -0
- package/dist/components/composites/ModalV2/index.d.ts +20 -0
- package/dist/components/composites/ModalV2/index.js +65 -0
- package/dist/components/composites/NavMenu/NavMenu.stories.js +2 -0
- package/dist/components/composites/NavMenu/index.js +1 -1
- package/dist/components/composites/Seo/seo.stories.js +2 -0
- package/dist/components/composites/SnackBar/SnackBar.stories.js +2 -0
- package/dist/components/composites/StructuredData/StructuredData.stories.js +2 -0
- package/dist/components/elements/Alerts/Alert.stories.js +2 -0
- package/dist/components/elements/Alerts/Alerts.stories.js +2 -0
- package/dist/components/elements/Alerts/index.js +2 -1
- package/dist/components/elements/ArrowLink/ArrowLink.stories.js +2 -0
- package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/AutoComplete.stories.js +6 -4
- package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/AutoComplete.test.js +1 -1
- package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/index.js +3 -3
- package/dist/components/elements/BrandingBar/BrandingBar.stories.js +2 -0
- package/dist/components/elements/Button/Button.stories.js +4 -2
- package/dist/components/elements/ButtonV2/ButtonV2.module.css +25 -0
- package/dist/components/elements/ButtonV2/ButtonV2.stories.d.ts +15 -0
- package/dist/components/elements/ButtonV2/ButtonV2.stories.js +90 -0
- package/dist/components/elements/ButtonV2/ButtonV2.test.js +45 -0
- package/dist/components/elements/ButtonV2/index.d.ts +51 -0
- package/dist/components/elements/ButtonV2/index.js +137 -0
- package/dist/components/elements/{Fields/Checkbox → Checkbox}/Checkbox.stories.js +3 -1
- package/dist/components/elements/{Fields/Checkbox → Checkbox}/Checkbox.test.js +1 -1
- package/dist/components/elements/{Fields/Checkbox → Checkbox}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/Checkbox → Checkbox}/index.js +2 -2
- package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/CheckboxGroup.stories.js +3 -1
- package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/CheckboxGroup.test.js +1 -1
- package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/index.js +7 -7
- package/dist/components/elements/CheckboxGroupV2/CheckboxGroupV2.stories.d.ts +8 -0
- package/dist/components/elements/CheckboxGroupV2/CheckboxGroupV2.stories.js +31 -0
- package/dist/components/elements/CheckboxGroupV2/CheckboxGroupV2.test.js +34 -0
- package/dist/components/elements/CheckboxGroupV2/index.d.ts +17 -0
- package/dist/components/elements/CheckboxGroupV2/index.js +50 -0
- package/dist/components/elements/CheckboxV2/CheckboxV2.module.css +5 -0
- package/dist/components/elements/CheckboxV2/CheckboxV2.stories.d.ts +6 -0
- package/dist/components/elements/CheckboxV2/CheckboxV2.stories.js +19 -0
- package/dist/components/elements/CheckboxV2/CheckboxV2.test.js +35 -0
- package/dist/components/elements/CheckboxV2/index.d.ts +10 -0
- package/dist/components/elements/CheckboxV2/index.js +23 -0
- package/dist/components/elements/{Fields/DatePicker → DatePicker}/DatePicker.stories.js +3 -1
- package/dist/components/elements/{Fields/DatePicker → DatePicker}/DatePicker.test.js +1 -1
- package/dist/components/elements/{Fields/DatePicker → DatePicker}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/DatePicker → DatePicker}/index.js +2 -2
- package/dist/components/elements/Dropdown/Dropdown.stories.js +3 -1
- package/dist/components/elements/Dropdown/index.js +1 -1
- package/dist/components/elements/GroupV2/index.d.ts +22 -0
- package/dist/components/elements/GroupV2/index.js +71 -0
- package/dist/components/elements/{text/Heading → Heading}/Heading.stories.js +5 -3
- package/dist/components/elements/{text/Heading → Heading}/Heading.test.js +3 -3
- package/dist/components/elements/{text/Heading → Heading}/index.d.ts +3 -3
- package/dist/components/elements/{text/Heading → Heading}/index.js +10 -9
- package/dist/components/elements/HeadingV2/HeadingV2.module.css +8 -0
- package/dist/components/elements/HeadingV2/HeadingV2.stories.d.ts +8 -0
- package/dist/components/elements/HeadingV2/HeadingV2.stories.js +37 -0
- package/dist/components/elements/HeadingV2/HeadingV2.test.js +51 -0
- package/dist/components/elements/HeadingV2/index.d.ts +23 -0
- package/dist/components/elements/HeadingV2/index.js +101 -0
- package/dist/components/elements/Icon/Icon.stories.js +3 -1
- package/dist/components/elements/IconV2/IconV2.module.css +10 -0
- package/dist/components/elements/IconV2/IconV2.stories.d.ts +7 -0
- package/dist/components/elements/IconV2/IconV2.stories.js +31 -0
- package/dist/components/elements/IconV2/IconV2.test.js +62 -0
- package/dist/components/elements/IconV2/index.d.ts +11 -0
- package/dist/components/elements/IconV2/index.js +34 -0
- package/dist/components/elements/{text/Inline → Inline}/Inline.stories.js +2 -0
- package/dist/components/elements/{text/Inline → Inline}/index.d.ts +1 -1
- package/dist/components/elements/{text/Inline → Inline}/index.js +1 -1
- package/dist/components/elements/{text/Label → Label}/Label.stories.js +4 -2
- package/dist/components/elements/Label/Label.test.d.ts +1 -0
- package/dist/components/elements/{text/Label → Label}/Label.test.js +3 -3
- package/dist/components/elements/{text/Label → Label}/index.d.ts +2 -2
- package/dist/components/elements/{text/Label → Label}/index.js +3 -3
- package/dist/components/elements/LabelV2/LabelV2.stories.d.ts +6 -0
- package/dist/components/elements/LabelV2/LabelV2.stories.js +22 -0
- package/dist/components/elements/LabelV2/LabelV2.test.d.ts +1 -0
- package/dist/components/elements/LabelV2/LabelV2.test.js +56 -0
- package/dist/components/elements/LabelV2/index.d.ts +20 -0
- package/dist/components/elements/LabelV2/index.js +41 -0
- package/dist/components/elements/Link/Link.stories.js +3 -1
- package/dist/components/elements/List/List.stories.js +3 -1
- package/dist/components/elements/List/index.js +1 -1
- package/dist/components/elements/ListBox/Listbox.stories.js +2 -0
- package/dist/components/elements/ListBox/index.d.ts +1 -1
- package/dist/components/elements/ListBox/index.js +1 -1
- package/dist/components/elements/ListBoxV2/ListBoxV2.module.css +33 -0
- package/dist/components/elements/ListBoxV2/ListBoxV2.stories.d.ts +6 -0
- package/dist/components/elements/ListBoxV2/ListBoxV2.stories.js +19 -0
- package/dist/components/elements/ListBoxV2/index.d.ts +35 -0
- package/dist/components/elements/ListBoxV2/index.js +36 -0
- package/dist/components/elements/Markdown/Markdown.stories.js +2 -0
- package/dist/components/elements/Markdown/index.js +4 -4
- package/dist/components/elements/{Fields/MonthPicker → MonthPicker}/MonthPicker.stories.js +3 -1
- package/dist/components/elements/MonthPicker/MonthPicker.test.d.ts +1 -0
- package/dist/components/elements/{Fields/MonthPicker → MonthPicker}/MonthPicker.test.js +1 -1
- package/dist/components/elements/{Fields/MonthPicker → MonthPicker}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/MonthPicker → MonthPicker}/index.js +2 -2
- package/dist/components/elements/{text/Paragraph → Paragraph}/Paragraph.stories.js +5 -3
- package/dist/components/elements/Paragraph/Paragraph.test.d.ts +1 -0
- package/dist/components/elements/{text/Paragraph → Paragraph}/Paragraph.test.js +1 -1
- package/dist/components/elements/{text/Paragraph → Paragraph}/index.d.ts +2 -2
- package/dist/components/elements/{text/Paragraph → Paragraph}/index.js +6 -5
- package/dist/components/elements/ParagraphV2/ParagraphV2.stories.d.ts +7 -0
- package/dist/components/elements/ParagraphV2/ParagraphV2.stories.js +33 -0
- package/dist/components/elements/ParagraphV2/ParagraphV2.test.d.ts +1 -0
- package/dist/components/elements/ParagraphV2/ParagraphV2.test.js +9 -0
- package/dist/components/elements/ParagraphV2/index.d.ts +15 -0
- package/dist/components/elements/ParagraphV2/index.js +39 -0
- package/dist/components/elements/Pill/Pill.stories.js +3 -1
- package/dist/components/elements/Pill/index.js +2 -1
- package/dist/components/elements/{Fields/Radio → Radio}/Radio.stories.js +3 -1
- package/dist/components/elements/Radio/Radio.test.d.ts +1 -0
- package/dist/components/elements/{Fields/Radio → Radio}/Radio.test.js +3 -3
- package/dist/components/elements/{Fields/Radio → Radio}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/Radio → Radio}/index.js +1 -1
- package/dist/components/elements/{Fields/RadioGroup → RadioGroup}/RadioGroup.stories.js +3 -1
- package/dist/components/elements/{Fields/RadioGroup → RadioGroup}/RadioGroup.test.js +1 -1
- package/dist/components/elements/{Fields/RadioGroup → RadioGroup}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/RadioGroup → RadioGroup}/index.js +6 -6
- package/dist/components/elements/{text/ReadMore → ReadMore}/ReadMore.stories.js +5 -3
- package/dist/components/elements/ReadMore/ReadMore.test.d.ts +1 -0
- package/dist/components/elements/{text/ReadMore → ReadMore}/ReadMore.test.js +4 -9
- package/dist/components/elements/{text/ReadMore → ReadMore}/index.d.ts +2 -2
- package/dist/components/elements/{text/ReadMore → ReadMore}/index.js +10 -9
- package/dist/components/elements/ReadMoreV2/ReadMoreV2.module.css +19 -0
- package/dist/components/elements/ReadMoreV2/ReadMoreV2.stories.d.ts +8 -0
- package/dist/components/elements/ReadMoreV2/ReadMoreV2.stories.js +28 -0
- package/dist/components/elements/ReadMoreV2/ReadMoreV2.test.d.ts +1 -0
- package/dist/components/elements/ReadMoreV2/ReadMoreV2.test.js +30 -0
- package/dist/components/elements/ReadMoreV2/index.d.ts +13 -0
- package/dist/components/elements/ReadMoreV2/index.js +82 -0
- package/dist/components/elements/{Fields/Select → Select}/Select.stories.js +6 -4
- package/dist/components/elements/Select/Select.test.d.ts +1 -0
- package/dist/components/elements/{Fields/Select → Select}/Select.test.js +1 -1
- package/dist/components/elements/{Fields/Select → Select}/index.d.ts +1 -1
- package/dist/components/elements/{Fields/Select → Select}/index.js +9 -9
- package/dist/components/elements/SelectV2/SelectV2.module.css +27 -0
- package/dist/components/elements/SelectV2/SelectV2.stories.d.ts +8 -0
- package/dist/components/elements/SelectV2/SelectV2.stories.js +41 -0
- package/dist/components/elements/SelectV2/SelectV2.test.d.ts +1 -0
- package/dist/components/elements/SelectV2/SelectV2.test.js +52 -0
- package/dist/components/elements/SelectV2/index.d.ts +19 -0
- package/dist/components/elements/SelectV2/index.js +164 -0
- package/dist/components/elements/Spinner/Spinner.stories.js +2 -0
- package/dist/components/elements/Spinner/index.js +1 -1
- package/dist/components/elements/SpinnerV2/SpinnerV2.module.css +12 -0
- package/dist/components/elements/SpinnerV2/SpinnerV2.stories.d.ts +7 -0
- package/dist/components/elements/SpinnerV2/SpinnerV2.stories.js +29 -0
- package/dist/components/elements/SpinnerV2/SpinnerV2.test.d.ts +1 -0
- package/dist/components/elements/SpinnerV2/SpinnerV2.test.js +9 -0
- package/dist/components/elements/SpinnerV2/index.d.ts +15 -0
- package/dist/components/elements/SpinnerV2/index.js +36 -0
- package/dist/components/elements/TabList/TabList.stories.js +2 -0
- package/dist/components/elements/Table/Table.stories.js +2 -0
- package/dist/components/elements/{Fields/TextInput → TextInput}/TextInput.stories.js +6 -4
- package/dist/components/elements/TextInput/TextInput.test.d.ts +1 -0
- package/dist/components/elements/{Fields/TextInput → TextInput}/TextInput.test.js +2 -2
- package/dist/components/elements/{Fields/TextInput → TextInput}/index.d.ts +3 -3
- package/dist/components/elements/{Fields/TextInput → TextInput}/index.js +9 -8
- package/dist/components/elements/TextInputV2/TextInputV2.module.css +71 -0
- package/dist/components/elements/TextInputV2/TextInputV2.stories.d.ts +9 -0
- package/dist/components/elements/TextInputV2/TextInputV2.stories.js +37 -0
- package/dist/components/elements/TextInputV2/TextInputV2.test.d.ts +1 -0
- package/dist/components/elements/TextInputV2/TextInputV2.test.js +59 -0
- package/dist/components/elements/TextInputV2/index.d.ts +47 -0
- package/dist/components/elements/TextInputV2/index.js +98 -0
- package/dist/components/elements/layout/Box.stories.js +2 -0
- package/dist/components/elements/layout/Flex.stories.js +3 -1
- package/dist/components/elements/layoutV2/BoxV2.d.ts +9 -0
- package/dist/components/elements/layoutV2/BoxV2.js +19 -0
- package/dist/components/elements/layoutV2/BoxV2.stories.d.ts +6 -0
- package/dist/components/elements/layoutV2/BoxV2.stories.js +14 -0
- package/dist/components/elements/layoutV2/ColumnV2.d.ts +8 -0
- package/dist/components/elements/layoutV2/ColumnV2.js +21 -0
- package/dist/components/elements/layoutV2/RowV2.d.ts +19 -0
- package/dist/components/elements/layoutV2/RowV2.js +54 -0
- package/dist/components/providers/alerts.js +0 -1
- package/dist/components/providers/alerts.test.d.ts +1 -0
- package/dist/components/providers/alerts.test.js +115 -0
- package/dist/components/providers/componentConfigV2.d.ts +25 -0
- package/dist/components/providers/componentConfigV2.js +37 -0
- package/dist/components/providers/media.js +1 -1
- package/dist/components/providers/mediaV2.d.ts +11 -0
- package/dist/components/providers/mediaV2.js +48 -0
- package/dist/components/providers/uiV2.d.ts +20 -0
- package/dist/components/providers/uiV2.js +16 -0
- package/dist/index.d.ts +34 -14
- package/dist/index.html +14 -0
- package/dist/index.js +33 -13
- package/dist/theme/Color.stories.js +3 -1
- package/dist/theme/GlobalStylesV2.d.ts +2 -0
- package/dist/theme/GlobalStylesV2.js +212 -0
- package/dist/theme/Typography.stories.js +3 -1
- package/dist/theme/css-variables.css +57 -0
- package/dist/theme/index.d.ts +127 -1
- package/dist/theme/index.js +14 -0
- package/dist/theme/typography.js +2 -2
- package/dist/utils/decorators/UIVersion1.d.ts +2 -0
- package/dist/utils/decorators/UIVersion1.js +7 -0
- package/dist/utils/decorators/UIVersion2.d.ts +2 -0
- package/dist/utils/decorators/UIVersion2.js +7 -0
- package/dist/utils/hooks/useFocus.d.ts +7 -0
- package/dist/utils/hooks/useFocus.js +12 -0
- package/dist/utils/processSx.d.ts +3 -0
- package/dist/utils/processSx.js +135 -0
- package/package.json +8 -4
- /package/dist/components/{elements/Fields/Checkbox/Checkbox.test.d.ts → composites/CardV2/CardV2.test.d.ts} +0 -0
- /package/dist/components/{elements/Fields/CheckboxGroup/CheckboxGroup.test.d.ts → composites/ModalV2/ModalV2.test.d.ts} +0 -0
- /package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/AutoComplete.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/AutoComplete.test.d.ts +0 -0
- /package/dist/components/elements/{Fields/AutoComplete → AutoComplete}/index.d.ts +0 -0
- /package/dist/components/elements/{Fields/DatePicker/DatePicker.test.d.ts → ButtonV2/ButtonV2.test.d.ts} +0 -0
- /package/dist/components/elements/{text/Caption → Caption}/index.d.ts +0 -0
- /package/dist/components/elements/{text/Caption → Caption}/index.js +0 -0
- /package/dist/components/elements/{Fields/Checkbox → Checkbox}/Checkbox.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/MonthPicker/MonthPicker.test.d.ts → Checkbox/Checkbox.test.d.ts} +0 -0
- /package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/CheckboxGroup.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/Radio/Radio.test.d.ts → CheckboxGroup/CheckboxGroup.test.d.ts} +0 -0
- /package/dist/components/elements/{Fields/Select/Select.test.d.ts → CheckboxGroupV2/CheckboxGroupV2.test.d.ts} +0 -0
- /package/dist/components/elements/{text/Heading/Heading.test.d.ts → CheckboxV2/CheckboxV2.test.d.ts} +0 -0
- /package/dist/components/elements/{Fields/DatePicker → DatePicker}/DatePicker.stories.d.ts +0 -0
- /package/dist/components/elements/{text/Label/Label.test.d.ts → DatePicker/DatePicker.test.d.ts} +0 -0
- /package/dist/components/elements/{text/Heading → Heading}/Heading.stories.d.ts +0 -0
- /package/dist/components/elements/{text/Paragraph/Paragraph.test.d.ts → Heading/Heading.test.d.ts} +0 -0
- /package/dist/components/elements/{text/ReadMore/ReadMore.test.d.ts → HeadingV2/HeadingV2.test.d.ts} +0 -0
- /package/dist/components/elements/{Fields/RadioGroup/RadioGroup.test.d.ts → IconV2/IconV2.test.d.ts} +0 -0
- /package/dist/components/elements/{text/Inline → Inline}/Inline.stories.d.ts +0 -0
- /package/dist/components/elements/{text/Label → Label}/Label.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/MonthPicker → MonthPicker}/MonthPicker.stories.d.ts +0 -0
- /package/dist/components/elements/{text/Paragraph → Paragraph}/Paragraph.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/Radio → Radio}/Radio.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/RadioGroup → RadioGroup}/RadioGroup.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/TextInput/TextInput.test.d.ts → RadioGroup/RadioGroup.test.d.ts} +0 -0
- /package/dist/components/elements/{text/ReadMore → ReadMore}/ReadMore.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/Select → Select}/Select.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/TextInput → TextInput}/TextInput.stories.d.ts +0 -0
- /package/dist/components/elements/{Fields/option.d.ts → option.d.ts} +0 -0
- /package/dist/components/elements/{Fields/option.js → option.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { fireEvent } from '@testing-library/react';
|
|
3
|
+
import { vi } from 'vitest';
|
|
4
|
+
import { render } from '../../../utils/test';
|
|
5
|
+
import { ButtonV2 } from '.';
|
|
6
|
+
const MockPrimaryIcon = () => _jsx("div", { children: "Mock Primary Icon" });
|
|
7
|
+
const MockLeftIcon = () => _jsx("div", { children: "Mock Left Icon" });
|
|
8
|
+
const MockRightIcon = () => _jsx("div", { children: "Mock Right Icon" });
|
|
9
|
+
describe('Button', () => {
|
|
10
|
+
const mockClickHandler = vi.fn();
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.resetAllMocks();
|
|
13
|
+
});
|
|
14
|
+
it('renders without throwing an error', () => {
|
|
15
|
+
const { getByText } = render(_jsx(ButtonV2, { children: "Foo" }));
|
|
16
|
+
expect(getByText('Foo')).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
it('renders icon component passed to it', () => {
|
|
19
|
+
const { getByText } = render(_jsxs(_Fragment, { children: [_jsx(ButtonV2, Object.assign({ leftIcon: MockLeftIcon }, { children: "Click Me" })), _jsx(ButtonV2, Object.assign({ primaryIcon: MockPrimaryIcon }, { children: "Click Me" })), _jsx(ButtonV2, Object.assign({ rightIcon: MockRightIcon }, { children: "Click Me" }))] }));
|
|
20
|
+
expect(getByText('Mock Primary Icon')).toBeDefined();
|
|
21
|
+
expect(getByText('Mock Left Icon')).toBeDefined();
|
|
22
|
+
expect(getByText('Mock Right Icon')).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
it('renders without icons if not passed', () => {
|
|
25
|
+
const { queryByText } = render(_jsx(ButtonV2, { children: "Click Me" }));
|
|
26
|
+
expect(queryByText('Mock Primary Icon')).toBeNull();
|
|
27
|
+
expect(queryByText('Mock Left Icon')).toBeNull();
|
|
28
|
+
expect(queryByText('Mock Right Icon')).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
it('responds to click handlers', () => {
|
|
31
|
+
const { getByRole } = render(_jsx(ButtonV2, { onClick: mockClickHandler }));
|
|
32
|
+
fireEvent.click(getByRole('button'));
|
|
33
|
+
expect(mockClickHandler).toHaveBeenCalledTimes(1);
|
|
34
|
+
});
|
|
35
|
+
it('does not respond to click handler when disabled', () => {
|
|
36
|
+
const { getByRole } = render(_jsx(ButtonV2, { onClick: mockClickHandler, disabled: true }));
|
|
37
|
+
fireEvent.click(getByRole('button'));
|
|
38
|
+
expect(mockClickHandler).not.toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
it('does not respond to click handler when loading', () => {
|
|
41
|
+
const { getByRole } = render(_jsx(ButtonV2, { onClick: mockClickHandler, loading: true }));
|
|
42
|
+
fireEvent.click(getByRole('button'));
|
|
43
|
+
expect(mockClickHandler).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledElementPropsV2 } from '../../../theme';
|
|
3
|
+
import { COLOR } from '../../../theme/colors';
|
|
4
|
+
export declare enum BUTTONV2_SIZE {
|
|
5
|
+
SM = "sm",
|
|
6
|
+
MD = "md",
|
|
7
|
+
LG = "lg"
|
|
8
|
+
}
|
|
9
|
+
export declare enum BUTTONV2_TYPE {
|
|
10
|
+
DEFAULT = "default",
|
|
11
|
+
TEXT = "text",
|
|
12
|
+
OUTLINE = "outline"
|
|
13
|
+
}
|
|
14
|
+
export type ButtonV2Props = StyledElementPropsV2<HTMLButtonElement, {
|
|
15
|
+
size?: BUTTONV2_SIZE;
|
|
16
|
+
type?: BUTTONV2_TYPE;
|
|
17
|
+
color?: COLOR;
|
|
18
|
+
textColor?: COLOR;
|
|
19
|
+
customColor?: string;
|
|
20
|
+
primaryIcon?: React.FC<any>;
|
|
21
|
+
leftIcon?: React.FC<any>;
|
|
22
|
+
rightIcon?: React.FC<any>;
|
|
23
|
+
accessibleLabel?: string;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
disableFocusStyles?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const ButtonV2: React.ForwardRefExoticComponent<{
|
|
30
|
+
sx?: import("../../../theme").StylesPropV2 | undefined;
|
|
31
|
+
children?: React.ReactNode;
|
|
32
|
+
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children" | "onChange"> & {
|
|
33
|
+
size?: BUTTONV2_SIZE | undefined;
|
|
34
|
+
type?: BUTTONV2_TYPE | undefined;
|
|
35
|
+
color?: COLOR | undefined;
|
|
36
|
+
textColor?: COLOR | undefined;
|
|
37
|
+
customColor?: string | undefined;
|
|
38
|
+
primaryIcon?: React.FC<any> | undefined;
|
|
39
|
+
leftIcon?: React.FC<any> | undefined;
|
|
40
|
+
rightIcon?: React.FC<any> | undefined;
|
|
41
|
+
accessibleLabel?: string | undefined;
|
|
42
|
+
loading?: boolean | undefined;
|
|
43
|
+
disabled?: boolean | undefined;
|
|
44
|
+
disableFocusStyles?: boolean | undefined;
|
|
45
|
+
className?: string | undefined;
|
|
46
|
+
} & {
|
|
47
|
+
htmlFor?: string | undefined;
|
|
48
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
49
|
+
type LinkButtonV2Props = Omit<ButtonV2Props, 'type' | 'color' | 'textColor'>;
|
|
50
|
+
export declare const LinkButtonV2: React.FC<LinkButtonV2Props>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { COLOR } from '../../../theme/colors';
|
|
15
|
+
import { TYPOGRAPHY_TYPE, getIconSize, getTypographyStyles, } from '../../../theme/typography';
|
|
16
|
+
import { IconV2 } from '../IconV2';
|
|
17
|
+
import { useEnvironment } from '../../providers/env';
|
|
18
|
+
import { SPINNERV2_SIZE, SpinnerV2 } from '../SpinnerV2';
|
|
19
|
+
import { BOX_SHADOW } from '../../../theme/custom';
|
|
20
|
+
import { processSx } from '../../../utils/processSx';
|
|
21
|
+
import { useHover } from '../../../utils/hooks/useHover';
|
|
22
|
+
import { useFocus } from '../../../utils/hooks/useFocus';
|
|
23
|
+
import * as styles from './ButtonV2.module.css';
|
|
24
|
+
import clsx from 'clsx';
|
|
25
|
+
export var BUTTONV2_SIZE;
|
|
26
|
+
(function (BUTTONV2_SIZE) {
|
|
27
|
+
BUTTONV2_SIZE["SM"] = "sm";
|
|
28
|
+
BUTTONV2_SIZE["MD"] = "md";
|
|
29
|
+
BUTTONV2_SIZE["LG"] = "lg";
|
|
30
|
+
})(BUTTONV2_SIZE || (BUTTONV2_SIZE = {}));
|
|
31
|
+
const typographyMap = {
|
|
32
|
+
[BUTTONV2_SIZE.SM]: TYPOGRAPHY_TYPE.CONTROL_SMALL,
|
|
33
|
+
[BUTTONV2_SIZE.MD]: TYPOGRAPHY_TYPE.CONTROL_MEDIUM,
|
|
34
|
+
[BUTTONV2_SIZE.LG]: TYPOGRAPHY_TYPE.CONTROL_LARGE,
|
|
35
|
+
};
|
|
36
|
+
const defaultPaddingX = {
|
|
37
|
+
[BUTTONV2_SIZE.SM]: '0.5rem',
|
|
38
|
+
[BUTTONV2_SIZE.MD]: '0.75rem',
|
|
39
|
+
[BUTTONV2_SIZE.LG]: '1rem',
|
|
40
|
+
};
|
|
41
|
+
const defaultHeight = {
|
|
42
|
+
[BUTTONV2_SIZE.SM]: '2rem',
|
|
43
|
+
[BUTTONV2_SIZE.MD]: '2.5rem',
|
|
44
|
+
[BUTTONV2_SIZE.LG]: '3rem',
|
|
45
|
+
};
|
|
46
|
+
const iconMargin = {
|
|
47
|
+
[BUTTONV2_SIZE.SM]: '0.25rem',
|
|
48
|
+
[BUTTONV2_SIZE.MD]: '0.5rem',
|
|
49
|
+
[BUTTONV2_SIZE.LG]: '0.5rem',
|
|
50
|
+
};
|
|
51
|
+
export var BUTTONV2_TYPE;
|
|
52
|
+
(function (BUTTONV2_TYPE) {
|
|
53
|
+
BUTTONV2_TYPE["DEFAULT"] = "default";
|
|
54
|
+
BUTTONV2_TYPE["TEXT"] = "text";
|
|
55
|
+
BUTTONV2_TYPE["OUTLINE"] = "outline";
|
|
56
|
+
})(BUTTONV2_TYPE || (BUTTONV2_TYPE = {}));
|
|
57
|
+
const typeSafeStyles = styles;
|
|
58
|
+
export const ButtonV2 = React.forwardRef((_a, ref) => {
|
|
59
|
+
var { size: sizeParam, type: typeParam, color, customColor, textColor: textColorParam, primaryIcon, leftIcon, rightIcon, disabled: disabledParam, children, sx, loading, disableFocusStyles, className } = _a, rest = __rest(_a, ["size", "type", "color", "customColor", "textColor", "primaryIcon", "leftIcon", "rightIcon", "disabled", "children", "sx", "loading", "disableFocusStyles", "className"]);
|
|
60
|
+
const disabled = disabledParam || loading;
|
|
61
|
+
const { flagInDevelopment } = useEnvironment();
|
|
62
|
+
const { isHovered, anchorElementProps } = useHover();
|
|
63
|
+
const { isFocused } = useFocus();
|
|
64
|
+
let bg = COLOR.PRIMARY;
|
|
65
|
+
let borderColor = COLOR.TRANSPARENT;
|
|
66
|
+
let cursor = 'pointer';
|
|
67
|
+
let textColor = COLOR.BACKGROUND;
|
|
68
|
+
let hoverShadow = BOX_SHADOW.NORMAL;
|
|
69
|
+
let hoverDecoration = undefined;
|
|
70
|
+
let hoverTransform = 'scale(1.03)';
|
|
71
|
+
const isTextButton = typeParam === BUTTONV2_TYPE.TEXT;
|
|
72
|
+
const isIconButton = primaryIcon;
|
|
73
|
+
const type = typeParam || BUTTONV2_TYPE.DEFAULT;
|
|
74
|
+
const size = sizeParam || BUTTONV2_SIZE.MD;
|
|
75
|
+
const paddingX = isIconButton || isTextButton ? 0 : defaultPaddingX[size];
|
|
76
|
+
const height = isTextButton ? undefined : defaultHeight[size];
|
|
77
|
+
const width = primaryIcon ? height : undefined;
|
|
78
|
+
if (isIconButton && !rest['aria-label']) {
|
|
79
|
+
flagInDevelopment('Icon buttons should include aria-label prop for accessibility');
|
|
80
|
+
}
|
|
81
|
+
if (isIconButton) {
|
|
82
|
+
hoverTransform = 'scale(1.05)';
|
|
83
|
+
}
|
|
84
|
+
if (type === BUTTONV2_TYPE.DEFAULT) {
|
|
85
|
+
bg = color || COLOR.SECONDARY;
|
|
86
|
+
textColor = COLOR.BLACK;
|
|
87
|
+
}
|
|
88
|
+
if (type === BUTTONV2_TYPE.TEXT) {
|
|
89
|
+
bg = COLOR.TRANSPARENT;
|
|
90
|
+
textColor = color || COLOR.PRIMARY;
|
|
91
|
+
hoverShadow = undefined;
|
|
92
|
+
hoverDecoration = 'underline';
|
|
93
|
+
}
|
|
94
|
+
if (type === BUTTONV2_TYPE.OUTLINE) {
|
|
95
|
+
bg = COLOR.BACKGROUND;
|
|
96
|
+
textColor = color || COLOR.TEXT;
|
|
97
|
+
borderColor = textColor;
|
|
98
|
+
}
|
|
99
|
+
if (textColorParam) {
|
|
100
|
+
textColor = textColorParam;
|
|
101
|
+
}
|
|
102
|
+
if (disabled) {
|
|
103
|
+
cursor = 'not-allowed';
|
|
104
|
+
if (bg === COLOR.BACKGROUND || bg === COLOR.TRANSPARENT) {
|
|
105
|
+
textColor = COLOR.GRAY;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
bg = COLOR.GRAY;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const typography = typographyMap[size];
|
|
112
|
+
const typographyStyles = getTypographyStyles(typography);
|
|
113
|
+
let body = children;
|
|
114
|
+
if (primaryIcon) {
|
|
115
|
+
body = (_jsx(IconV2, { icon: primaryIcon, size: getIconSize(typographyStyles.fontSize), color: textColor }));
|
|
116
|
+
}
|
|
117
|
+
if (loading) {
|
|
118
|
+
body = (_jsxs("div", Object.assign({ className: typeSafeStyles.spinnerWrapper }, { children: [_jsx(SpinnerV2, { size: SPINNERV2_SIZE.SM, color: textColor, sx: { position: 'absolute' } }), _jsx("div", Object.assign({ style: { visibility: 'hidden' } }, { children: body }))] })));
|
|
119
|
+
}
|
|
120
|
+
const processedStyles = processSx(Object.assign(Object.assign({ bg: customColor ? customColor : bg }, typographyStyles), sx));
|
|
121
|
+
const hoverStyles = !disabled
|
|
122
|
+
? {
|
|
123
|
+
boxShadow: hoverShadow,
|
|
124
|
+
transform: hoverTransform,
|
|
125
|
+
textDecoration: hoverDecoration,
|
|
126
|
+
}
|
|
127
|
+
: undefined;
|
|
128
|
+
const appliedHoverStyles = !disableFocusStyles && isHovered ? hoverStyles : {};
|
|
129
|
+
const appliedFocusStyles = !disableFocusStyles && isFocused ? hoverStyles : {};
|
|
130
|
+
return (_jsxs("button", Object.assign({}, anchorElementProps, { ref: ref, tabIndex: disabled ? -1 : 0, disabled: disabled, className: clsx(typeSafeStyles.button, className), style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ cursor }, processSx({
|
|
131
|
+
color: textColor,
|
|
132
|
+
borderColor,
|
|
133
|
+
})), { paddingLeft: paddingX, paddingRight: paddingX, width: width, height: height }), appliedHoverStyles), appliedFocusStyles), processedStyles) }, rest, { children: [leftIcon && (_jsx(IconV2, { icon: leftIcon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: textColor })), _jsx("div", Object.assign({ className: typeSafeStyles.bodyWrapper }, { children: body })), rightIcon && (_jsx(IconV2, { icon: rightIcon, size: typographyStyles.fontSize, sx: { ml: iconMargin[size] }, color: textColor }))] })));
|
|
134
|
+
});
|
|
135
|
+
export const LinkButtonV2 = (props) => {
|
|
136
|
+
return (_jsx(ButtonV2, Object.assign({}, props, { color: COLOR.ND_BLUE_BRIGHT, textColor: COLOR.WHITE })));
|
|
137
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Checkbox } from './index';
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { Row } from '
|
|
4
|
+
import { Row } from '../layout/Row';
|
|
5
|
+
import { UIVersion1 } from '../../../utils/decorators/UIVersion1';
|
|
5
6
|
const meta = {
|
|
6
7
|
title: 'Elements/Fields/Checkbox',
|
|
7
8
|
component: Checkbox,
|
|
8
9
|
tags: ['autodocs'],
|
|
10
|
+
decorators: [UIVersion1],
|
|
9
11
|
};
|
|
10
12
|
export default meta;
|
|
11
13
|
const StatefulCheckbox = (props) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
-
import { Checkbox } from '
|
|
3
|
+
import { Checkbox } from '.';
|
|
4
4
|
import { vi } from 'vitest';
|
|
5
5
|
describe('Checkbox', () => {
|
|
6
6
|
it('renders unchecked checkbox', () => {
|
|
@@ -10,13 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
|
-
import { useTheme } from '
|
|
13
|
+
import { useTheme } from '../../../theme';
|
|
14
14
|
export const Checkbox = (_a) => {
|
|
15
15
|
var { checked, onChange, disabled, sx } = _a, rest = __rest(_a, ["checked", "onChange", "disabled", "sx"]);
|
|
16
16
|
const theme = useTheme();
|
|
17
17
|
return (_jsx("input", Object.assign({ type: "checkbox", onChange: (e) => {
|
|
18
18
|
onChange(e.target.checked);
|
|
19
19
|
}, checked: checked, sx: Object.assign({ margin: '0px', height: '1rem', width: '1rem', cursor: disabled ? 'not-allowed' : 'pointer', ':hover': {
|
|
20
|
-
boxShadow: theme.boxShadow,
|
|
20
|
+
boxShadow: theme === null || theme === void 0 ? void 0 : theme.boxShadow,
|
|
21
21
|
} }, sx), disabled: disabled }, rest)));
|
|
22
22
|
};
|
package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/CheckboxGroup.stories.js
RENAMED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { CheckboxGroup } from './index';
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { Row } from '
|
|
4
|
+
import { Row } from '../layout/Row';
|
|
5
|
+
import { UIVersion1 } from '../../../utils/decorators/UIVersion1';
|
|
5
6
|
const meta = {
|
|
6
7
|
title: 'Elements/Fields/CheckboxGroup',
|
|
7
8
|
component: CheckboxGroup,
|
|
8
9
|
tags: ['autodocs'],
|
|
10
|
+
decorators: [UIVersion1],
|
|
9
11
|
};
|
|
10
12
|
export default meta;
|
|
11
13
|
const options = [
|
package/dist/components/elements/{Fields/CheckboxGroup → CheckboxGroup}/CheckboxGroup.test.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
-
import { CheckboxGroup } from '
|
|
3
|
+
import { CheckboxGroup } from '.';
|
|
4
4
|
import { vi } from 'vitest';
|
|
5
5
|
const mockOptions = [
|
|
6
6
|
{ value: 'option1', label: 'Option 1' },
|
|
@@ -11,14 +11,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { useMemo } from 'react';
|
|
14
|
-
import { Row } from '
|
|
14
|
+
import { Row } from '../layout/Row';
|
|
15
15
|
import { Checkbox } from '../Checkbox';
|
|
16
|
-
import { Label } from '
|
|
17
|
-
import { Group } from '
|
|
18
|
-
import { GROUP_TYPE } from '
|
|
19
|
-
import { Column } from '
|
|
20
|
-
import { TYPOGRAPHY_TYPE, getTypographyStyles
|
|
21
|
-
import { COLOR } from '
|
|
16
|
+
import { Label } from '../Label';
|
|
17
|
+
import { Group } from '../Group';
|
|
18
|
+
import { GROUP_TYPE } from '../Group';
|
|
19
|
+
import { Column } from '../layout/Column';
|
|
20
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
21
|
+
import { COLOR } from '../../../theme/colors';
|
|
22
22
|
export function CheckboxGroup(_a) {
|
|
23
23
|
var { options, checkedOptions, columns: columnsProp, columnStyles, rowStyles, onChange } = _a, rest = __rest(_a, ["options", "checkedOptions", "columns", "columnStyles", "rowStyles", "onChange"]);
|
|
24
24
|
const columns = columnsProp || 1;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { CheckboxGroupV2 } from './index';
|
|
3
|
+
declare const meta: Meta<typeof CheckboxGroupV2>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof CheckboxGroupV2>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const Columns: Story;
|
|
8
|
+
export declare const Disabled: Story;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CheckboxGroupV2 } from './index';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { RowV2 } from '../layoutV2/RowV2';
|
|
5
|
+
import { UIVersion2 } from '../../../utils/decorators/UIVersion2';
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Elements/Fields/CheckboxGroupV2',
|
|
8
|
+
component: CheckboxGroupV2,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
decorators: [UIVersion2],
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
const options = [
|
|
14
|
+
{ value: 'orange', label: 'Orange', disabled: true },
|
|
15
|
+
{ value: 'apple', label: 'Apple' },
|
|
16
|
+
{ value: 'strawberry', label: 'Strawberry' },
|
|
17
|
+
{ value: 'pineapple', label: 'Pineapple' },
|
|
18
|
+
];
|
|
19
|
+
const StatefulCheckboxGroup = (props) => {
|
|
20
|
+
const [checked, setChecked] = useState(new Set(['orange']));
|
|
21
|
+
return (_jsx(CheckboxGroupV2, Object.assign({}, props, { checkedOptions: checked, options: props.options || options, onChange: setChecked })));
|
|
22
|
+
};
|
|
23
|
+
export const Default = {
|
|
24
|
+
render: () => (_jsx(RowV2, { children: _jsx(StatefulCheckboxGroup, {}) })),
|
|
25
|
+
};
|
|
26
|
+
export const Columns = {
|
|
27
|
+
render: () => (_jsx(RowV2, { children: _jsx(StatefulCheckboxGroup, { columns: 2 }) })),
|
|
28
|
+
};
|
|
29
|
+
export const Disabled = {
|
|
30
|
+
render: () => (_jsx(RowV2, { children: _jsx(StatefulCheckboxGroup, { options: options.map((option, i) => (Object.assign(Object.assign({}, option), { disabled: i === 1 ? true : false }))) }) })),
|
|
31
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { CheckboxGroupV2 } from '.';
|
|
4
|
+
import { vi } from 'vitest';
|
|
5
|
+
const mockOptions = [
|
|
6
|
+
{ value: 'option1', label: 'Option 1' },
|
|
7
|
+
{ value: 'option2', label: 'Option 2', disabled: true },
|
|
8
|
+
{ value: 'option3', label: 'Option 3' },
|
|
9
|
+
];
|
|
10
|
+
describe('CheckboxGroupV2', () => {
|
|
11
|
+
it('renders checkboxes with options correctly', () => {
|
|
12
|
+
const { getByText } = render(_jsx(CheckboxGroupV2, { options: mockOptions, onChange: () => { } }));
|
|
13
|
+
mockOptions.forEach((option) => {
|
|
14
|
+
const label = getByText(option.label);
|
|
15
|
+
expect(label).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it('calls onChange handler with correct value when checkbox is clicked', () => {
|
|
19
|
+
const onChangeMock = vi.fn();
|
|
20
|
+
const { getByLabelText } = render(_jsx(CheckboxGroupV2, { options: mockOptions, onChange: onChangeMock }));
|
|
21
|
+
const option1Checkbox = getByLabelText('Option 1');
|
|
22
|
+
fireEvent.click(option1Checkbox);
|
|
23
|
+
expect(onChangeMock).toHaveBeenCalledWith(new Set(['option1']));
|
|
24
|
+
});
|
|
25
|
+
it('disables checkboxes correctly', () => {
|
|
26
|
+
const { getByLabelText } = render(_jsx(CheckboxGroupV2, { options: mockOptions, onChange: () => { } }));
|
|
27
|
+
const option1Checkbox = getByLabelText('Option 1');
|
|
28
|
+
expect(option1Checkbox).not.toBeDisabled();
|
|
29
|
+
const option2Checkbox = getByLabelText('Option 2');
|
|
30
|
+
expect(option2Checkbox).toBeDisabled();
|
|
31
|
+
const option3Checkbox = getByLabelText('Option 3');
|
|
32
|
+
expect(option3Checkbox).not.toBeDisabled();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StyledElementPropsV2, StylesPropV2 } from '../../../theme';
|
|
2
|
+
import { Key } from '../option';
|
|
3
|
+
export type Option<K extends Key = string> = {
|
|
4
|
+
value: K;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type CheckboxGroupV2Props<K extends Key = string> = StyledElementPropsV2<HTMLDivElement, {
|
|
9
|
+
onChange: (value: Set<K>) => void;
|
|
10
|
+
options: Option<K>[];
|
|
11
|
+
checkedOptions?: Set<K>;
|
|
12
|
+
columnStyles?: StylesPropV2;
|
|
13
|
+
rowStyles?: StylesPropV2;
|
|
14
|
+
columns?: number;
|
|
15
|
+
}, string>;
|
|
16
|
+
export declare function CheckboxGroupV2<K extends Key>({ options, checkedOptions, columns: columnsProp, columnStyles, rowStyles, onChange, ...rest }: CheckboxGroupV2Props<K>): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from 'react';
|
|
14
|
+
import { RowV2 } from '../layoutV2/RowV2';
|
|
15
|
+
import { CheckboxV2 } from '../CheckboxV2';
|
|
16
|
+
import { LabelV2 } from '../LabelV2';
|
|
17
|
+
import { GroupV2 } from '../GroupV2';
|
|
18
|
+
import { GROUPV2_TYPE } from '../GroupV2';
|
|
19
|
+
import { ColumnV2 } from '../layoutV2/ColumnV2';
|
|
20
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
21
|
+
import { COLOR } from '../../../theme/colors';
|
|
22
|
+
export function CheckboxGroupV2(_a) {
|
|
23
|
+
var { options, checkedOptions, columns: columnsProp, columnStyles, rowStyles, onChange } = _a, rest = __rest(_a, ["options", "checkedOptions", "columns", "columnStyles", "rowStyles", "onChange"]);
|
|
24
|
+
const columns = columnsProp || 1;
|
|
25
|
+
const optionsByColumn = useMemo(() => {
|
|
26
|
+
const optionsByColumn = [];
|
|
27
|
+
for (let i = 0; i < options.length; i++) {
|
|
28
|
+
const maxPerColumn = Math.ceil(options.length / columns);
|
|
29
|
+
const columnIndex = Math.floor(i / maxPerColumn);
|
|
30
|
+
if (optionsByColumn[columnIndex] === undefined) {
|
|
31
|
+
optionsByColumn[columnIndex] = [];
|
|
32
|
+
}
|
|
33
|
+
optionsByColumn[columnIndex].push(options[i]);
|
|
34
|
+
}
|
|
35
|
+
return optionsByColumn;
|
|
36
|
+
}, [options, columns]);
|
|
37
|
+
return (_jsx(RowV2, Object.assign({}, rest, { children: optionsByColumn.map((options, index) => (_jsx(ColumnV2, Object.assign({ grow: 1, sx: Object.assign({ mr: 4 }, columnStyles) }, { children: options.map((option) => (_jsx(GroupV2, Object.assign({ type: GROUPV2_TYPE.RAW }, { children: ({ labelTargetId }) => (_jsxs(RowV2, Object.assign({ sx: Object.assign({ mb: 2, alignItems: 'center' }, rowStyles) }, { children: [_jsx(CheckboxV2, { onChange: (checked) => {
|
|
38
|
+
const updatedSet = new Set(checkedOptions || []);
|
|
39
|
+
if (checked) {
|
|
40
|
+
updatedSet.add(option.value);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
updatedSet.delete(option.value);
|
|
44
|
+
}
|
|
45
|
+
onChange(updatedSet);
|
|
46
|
+
}, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, disabled: option.disabled, sx: {
|
|
47
|
+
mr: 2,
|
|
48
|
+
flexShrink: 0,
|
|
49
|
+
} }), _jsx(LabelV2, Object.assign({ sx: Object.assign(Object.assign({ cursor: option.disabled ? 'not-allowed' : 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM)), { color: option.disabled ? COLOR.GRAY : undefined }) }, { children: option.label }))] }))) }), option.value))) }), index))) })));
|
|
50
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CheckboxV2 } from '.';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { RowV2 } from '../layoutV2/RowV2';
|
|
5
|
+
import { UIVersion2 } from '../../../utils/decorators/UIVersion2';
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Elements/Fields/CheckboxV2',
|
|
8
|
+
component: CheckboxV2,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
decorators: [UIVersion2],
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
const StatefulCheckbox = (props) => {
|
|
14
|
+
const [checked, setChecked] = useState(false);
|
|
15
|
+
return _jsx(CheckboxV2, Object.assign({}, props, { checked: checked, onChange: setChecked }));
|
|
16
|
+
};
|
|
17
|
+
export const Default = {
|
|
18
|
+
render: () => (_jsx(RowV2, { children: _jsx(StatefulCheckbox, {}) })),
|
|
19
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { CheckboxV2 } from '.';
|
|
4
|
+
import { vi } from 'vitest';
|
|
5
|
+
describe('CheckboxV2', () => {
|
|
6
|
+
it('renders unchecked checkbox', () => {
|
|
7
|
+
const { getByRole } = render(_jsx(CheckboxV2, { checked: false, onChange: () => { } }));
|
|
8
|
+
const checkbox = getByRole('checkbox');
|
|
9
|
+
expect(checkbox).toBeInTheDocument();
|
|
10
|
+
expect(checkbox).not.toBeChecked();
|
|
11
|
+
});
|
|
12
|
+
it('renders checked checkbox', () => {
|
|
13
|
+
const { getByRole } = render(_jsx(CheckboxV2, { checked: true, onChange: () => { } }));
|
|
14
|
+
const checkbox = getByRole('checkbox');
|
|
15
|
+
expect(checkbox).toBeInTheDocument();
|
|
16
|
+
expect(checkbox).toBeChecked();
|
|
17
|
+
});
|
|
18
|
+
it('calls onChange handler when checkbox is clicked', () => {
|
|
19
|
+
const onChangeMock = vi.fn();
|
|
20
|
+
const { getByRole } = render(_jsx(CheckboxV2, { checked: false, onChange: onChangeMock }));
|
|
21
|
+
const checkbox = getByRole('checkbox');
|
|
22
|
+
fireEvent.click(checkbox);
|
|
23
|
+
expect(onChangeMock).toHaveBeenCalledWith(true);
|
|
24
|
+
});
|
|
25
|
+
it('applies disabled styles when disabled', () => {
|
|
26
|
+
const { getByRole } = render(_jsx(CheckboxV2, { checked: false, onChange: () => { }, disabled: true }));
|
|
27
|
+
const checkbox = getByRole('checkbox');
|
|
28
|
+
expect(checkbox).toHaveStyle('cursor: not-allowed;');
|
|
29
|
+
});
|
|
30
|
+
it('applies pointer cursor style when not disabled', () => {
|
|
31
|
+
const { getByRole } = render(_jsx(CheckboxV2, { checked: false, onChange: () => { } }));
|
|
32
|
+
const checkbox = getByRole('checkbox');
|
|
33
|
+
expect(checkbox).toHaveStyle('cursor: pointer;');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledElementPropsV2 } from '../../../theme';
|
|
3
|
+
type CheckboxV2Props = StyledElementPropsV2<HTMLInputElement, {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
onChange: (value: boolean) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
}, string>;
|
|
9
|
+
export declare const CheckboxV2: React.FC<CheckboxV2Props>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { processSx } from '../../../utils/processSx';
|
|
14
|
+
import * as styles from './CheckboxV2.module.css';
|
|
15
|
+
import clsx from 'clsx';
|
|
16
|
+
const typeSafeStyles = styles;
|
|
17
|
+
export const CheckboxV2 = (_a) => {
|
|
18
|
+
var { checked, onChange, disabled, className, sx } = _a, rest = __rest(_a, ["checked", "onChange", "disabled", "className", "sx"]);
|
|
19
|
+
const processedStyles = processSx(sx);
|
|
20
|
+
return (_jsx("input", Object.assign({ type: "checkbox", onChange: (e) => {
|
|
21
|
+
onChange(e.target.checked);
|
|
22
|
+
}, checked: checked, className: clsx(typeSafeStyles.checkbox, className), style: Object.assign({ cursor: disabled ? 'not-allowed' : 'pointer' }, processedStyles), disabled: disabled }, rest)));
|
|
23
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { DatePicker } from '.';
|
|
4
|
-
import { Box } from '
|
|
4
|
+
import { Box } from '../layout/Box';
|
|
5
|
+
import { UIVersion1 } from '../../../utils/decorators/UIVersion1';
|
|
5
6
|
const meta = {
|
|
6
7
|
title: 'Elements/Fields/DatePicker',
|
|
7
8
|
component: DatePicker,
|
|
8
9
|
tags: ['autodocs'],
|
|
10
|
+
decorators: [UIVersion1],
|
|
9
11
|
};
|
|
10
12
|
export default meta;
|
|
11
13
|
const StatefulDatePicker = (props) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render, fireEvent, screen } from '@testing-library/react';
|
|
3
3
|
import { describe, it, expect, vi } from 'vitest';
|
|
4
|
-
import { DatePicker, areDatesEqual } from '
|
|
4
|
+
import { DatePicker, areDatesEqual } from '.';
|
|
5
5
|
describe('DatePicker Component', () => {
|
|
6
6
|
it('renders correctly', () => {
|
|
7
7
|
const mockDate = new Date(2023, 4, 23);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import 'react-datepicker/dist/react-datepicker.css';
|
|
3
3
|
import { TextInputProps } from '../TextInput';
|
|
4
|
-
import { BoxProps } from '
|
|
4
|
+
import { BoxProps } from '../layout/Box';
|
|
5
5
|
export declare const InputWrapper: React.ForwardRefExoticComponent<{
|
|
6
6
|
onChange?: ((e: React.ChangeEvent) => void) | undefined;
|
|
7
7
|
onClick?: ((e: React.MouseEvent) => void) | undefined;
|
|
@@ -15,8 +15,8 @@ import _ReactDatePicker from 'react-datepicker';
|
|
|
15
15
|
import 'react-datepicker/dist/react-datepicker.css';
|
|
16
16
|
import { TextInput } from '../TextInput';
|
|
17
17
|
import _CalendarIcon from '@mui/icons-material/CalendarMonth';
|
|
18
|
-
import { Box } from '
|
|
19
|
-
import { importedDefaultComponentShim } from '
|
|
18
|
+
import { Box } from '../layout/Box';
|
|
19
|
+
import { importedDefaultComponentShim } from '../../../utils/misc';
|
|
20
20
|
const CalendarIcon = importedDefaultComponentShim(_CalendarIcon);
|
|
21
21
|
const ReactDatePicker = importedDefaultComponentShim(_ReactDatePicker);
|
|
22
22
|
export const InputWrapper = React.forwardRef(({ onChange, value, children, onClick }, ref) => {
|