@sisense/sdk-shared-ui 0.1.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.ts +44 -0
- package/.storybook/preview-head.html +4 -0
- package/.storybook/preview.tsx +34 -0
- package/dist/index.js +40 -2
- package/package.json +99 -2
- package/src/lib/CheckableList/CheckableList.module.scss +13 -0
- package/src/lib/CheckableList/CheckableList.test.tsx +61 -0
- package/src/lib/CheckableList/CheckableList.tsx +41 -0
- package/src/lib/CheckableList/index.ts +4 -0
- package/src/lib/Checkbox/Checkbox.tsx +28 -0
- package/src/lib/Checkbox/index.ts +4 -0
- package/src/lib/Checkbox/themes/checkboxTheme.ts +42 -0
- package/src/lib/Checkbox/themes/index.ts +1 -0
- package/src/lib/Checkbox/themes/uiCustomization.ts +28 -0
- package/src/lib/DEPRECATED_Button/DEPRECATED_Button.module.scss +57 -0
- package/src/lib/DEPRECATED_Button/DEPRECATED_Button.stories.tsx +169 -0
- package/src/lib/DEPRECATED_Button/DEPRECATED_Button.test.tsx +154 -0
- package/src/lib/DEPRECATED_Button/DEPRECATED_Button.tsx +129 -0
- package/src/lib/DEPRECATED_Button/index.ts +4 -0
- package/src/lib/DEPRECATED_Checkbox/Checkbox.module.scss +49 -0
- package/src/lib/DEPRECATED_Checkbox/DEPRECATED_Checkbox.test.tsx +131 -0
- package/src/lib/DEPRECATED_Checkbox/DEPRECATED_Checkbox.tsx +103 -0
- package/src/lib/DEPRECATED_Checkbox/index.ts +4 -0
- package/src/lib/DEPRECATED_Icon/DEPRECATED_Icon.stories.tsx +27 -0
- package/src/lib/DEPRECATED_Icon/DEPRECATED_Icon.tsx +2 -0
- package/src/lib/DEPRECATED_Toggle/DEPRECATED_Toggle.tsx +49 -0
- package/src/lib/DEPRECATED_Toggle/index.ts +4 -0
- package/src/lib/DEPRECATED_Tooltip/DEPRECATED_Tooltip.module.scss +115 -0
- package/src/lib/DEPRECATED_Tooltip/DEPRECATED_Tooltip.tsx +68 -0
- package/src/lib/DEPRECATED_Tooltip/index.ts +4 -0
- package/src/lib/Dropdown/Dropdown.module.scss +9 -0
- package/src/lib/Dropdown/Dropdown.tsx +150 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButton.module.scss +49 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButton.tsx +81 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonBody/DropdownButtonBody.test.tsx +121 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonBody/DropdownButtonBody.tsx +39 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonBody/index.ts +2 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonSearch/DropdownButtonSearch.module.scss +20 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonSearch/DropdownButtonSearch.tsx +44 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonSearch/constants.ts +1 -0
- package/src/lib/Dropdown/DropdownButton/DropdownButtonSearch/index.ts +2 -0
- package/src/lib/Dropdown/DropdownButton/hooks/index.tsx +1 -0
- package/src/lib/Dropdown/DropdownButton/hooks/useDropdownButtonSearch.ts +51 -0
- package/src/lib/Dropdown/DropdownButton/index.ts +1 -0
- package/src/lib/Dropdown/hooks/index.tsx +1 -0
- package/src/lib/Dropdown/hooks/useDropdown.ts +29 -0
- package/src/lib/Dropdown/index.ts +5 -0
- package/src/lib/Dropdown/types.ts +17 -0
- package/src/lib/Icon/Icon.tsx +118 -0
- package/src/lib/Icon/index.ts +4 -0
- package/src/lib/Icon/themes/iconTheme.tsx +38 -0
- package/src/lib/Icon/themes/index.ts +1 -0
- package/src/lib/Icon/themes/uiCustomization.ts +9 -0
- package/src/lib/Input/Input.module.scss +97 -0
- package/src/lib/Input/Input.test.tsx +177 -0
- package/src/lib/Input/Input.tsx +134 -0
- package/src/lib/Input/index.ts +4 -0
- package/src/lib/LazyLoader/LazyLoader.module.scss +18 -0
- package/src/lib/LazyLoader/LazyLoader.tsx +42 -0
- package/src/lib/LazyLoader/index.ts +4 -0
- package/src/lib/Menu/Confirmation/Confirmation.module.scss +48 -0
- package/src/lib/Menu/Confirmation/Confirmation.tsx +45 -0
- package/src/lib/Menu/Confirmation/index.ts +1 -0
- package/src/lib/Menu/Confirmation/translation.ts +17 -0
- package/src/lib/Menu/Menu.module.scss +178 -0
- package/src/lib/Menu/Menu.tsx +363 -0
- package/src/lib/Menu/MenuItem/MenuItem.test.tsx +241 -0
- package/src/lib/Menu/MenuItem/MenuItem.tsx +186 -0
- package/src/lib/Menu/MenuItem/index.ts +2 -0
- package/src/lib/Menu/index.ts +6 -0
- package/src/lib/Menu/utils.ts +13 -0
- package/src/lib/Popover/Popover.module.scss +15 -0
- package/src/lib/Popover/Popover.tsx +92 -0
- package/src/lib/Popover/align.interface.ts +20 -0
- package/src/lib/Popover/index.ts +6 -0
- package/src/lib/RadioButton/RadioButton.module.scss +22 -0
- package/src/lib/RadioButton/RadioButton.tsx +89 -0
- package/src/lib/RadioButton/index.ts +4 -0
- package/src/lib/TablePagination/PaginationActionsComponent/PaginationActionsComponent.tsx +87 -0
- package/src/lib/TablePagination/PaginationActionsComponent/index.ts +4 -0
- package/src/lib/TablePagination/PaginationActionsComponent/themes/index.ts +4 -0
- package/src/lib/TablePagination/PaginationActionsComponent/themes/paginationActionsComponentTheme.tsx +70 -0
- package/src/lib/TablePagination/PaginationActionsComponent/themes/uiCustomization.ts +17 -0
- package/src/lib/TablePagination/TablePagination.tsx +148 -0
- package/src/lib/TablePagination/TablePaginationContext.ts +4 -0
- package/src/lib/TablePagination/index.ts +4 -0
- package/src/lib/TablePagination/themes/index.ts +1 -0
- package/src/lib/TablePagination/themes/tablePaginationResponsiveDesign.ts +33 -0
- package/src/lib/TablePagination/themes/tablePaginationTheme.tsx +128 -0
- package/src/lib/TablePagination/themes/uiCustomization.ts +50 -0
- package/src/lib/Tooltip/Tooltip.module.scss +125 -0
- package/src/lib/Tooltip/Tooltip.tsx +34 -0
- package/src/lib/Tooltip/index.ts +5 -0
- package/src/lib/Tooltip/themes/index.ts +1 -0
- package/src/lib/Tooltip/themes/tooltipTheme.ts +30 -0
- package/src/lib/Typography/Typography.tsx +28 -0
- package/src/lib/Typography/index.ts +5 -0
- package/src/lib/Typography/themes/index.ts +1 -0
- package/src/lib/Typography/themes/typographyTheme.tsx +170 -0
- package/src/lib/Typography/themes/uiCustomization.ts +10 -0
- package/src/lib/constants/styleguideConstants.ts +8 -0
- package/src/lib/index.ts +16 -0
- package/src/lib/styles/colors.module.scss +10 -0
- package/src/lib/styles/sisenseStyleguideReactColors.scss +57 -0
- package/src/lib/styles/style_styleguide_react/_variables.deprecated.scss +107 -0
- package/src/lib/styles/style_styleguide_react/_variables.scss +100 -0
- package/src/lib/styles/style_styleguide_react/base.scss +9 -0
- package/src/lib/styles/style_styleguide_react/colors.scss +71 -0
- package/src/lib/styles/style_styleguide_react/exports/colors.exports.scss +69 -0
- package/src/lib/styles/style_styleguide_react/exports/fonts.exports.scss +33 -0
- package/src/lib/styles/style_styleguide_react/fonts.scss +27 -0
- package/src/lib/styles/style_styleguide_react/mixins.scss +90 -0
- package/src/lib/themes/colors/index.ts +1 -0
- package/src/lib/themes/colors/siColors.ts +143 -0
- package/src/lib/themes/index.ts +2 -0
- package/src/lib/themes/types/SisenseTheme.ts +12 -0
- package/src/lib/themes/types/index.ts +1 -0
- package/tsconfig.lib.json +2 -1
- package/vite.config.ts +18 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { DEPRECATED_Button } from './DEPRECATED_Button';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'DEPRECATED/Button',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const Primary = () => (
|
|
10
|
+
<div
|
|
11
|
+
style={{
|
|
12
|
+
display: 'inline-flex',
|
|
13
|
+
justifyContent: 'space-between',
|
|
14
|
+
height: '175px',
|
|
15
|
+
padding: '20px 50px',
|
|
16
|
+
flexDirection: 'column',
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
<>
|
|
20
|
+
<DEPRECATED_Button text={'normal!'} />
|
|
21
|
+
<DEPRECATED_Button text={'hover!'} style={{ backgroundColor: '#f2b900' }} />
|
|
22
|
+
<DEPRECATED_Button text={'disable!'} disabled />
|
|
23
|
+
</>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const PrimaryWithIcon = () => (
|
|
28
|
+
<div
|
|
29
|
+
style={{
|
|
30
|
+
display: 'inline-flex',
|
|
31
|
+
justifyContent: 'space-between',
|
|
32
|
+
height: '175px',
|
|
33
|
+
padding: '20px 50px',
|
|
34
|
+
flexDirection: 'column',
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<>
|
|
38
|
+
<DEPRECATED_Button text={'normal!'} iconName="general-plus" />
|
|
39
|
+
<DEPRECATED_Button
|
|
40
|
+
text={'hover!'}
|
|
41
|
+
iconName="general-plus"
|
|
42
|
+
style={{ backgroundColor: '#f2b900' }}
|
|
43
|
+
/>
|
|
44
|
+
<DEPRECATED_Button text={'disable!'} iconName="general-plus" disabled />
|
|
45
|
+
</>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const Secondary = () => (
|
|
50
|
+
<div
|
|
51
|
+
style={{
|
|
52
|
+
display: 'inline-flex',
|
|
53
|
+
justifyContent: 'space-between',
|
|
54
|
+
height: '175px',
|
|
55
|
+
padding: '20px 50px',
|
|
56
|
+
flexDirection: 'column',
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<>
|
|
60
|
+
<DEPRECATED_Button text={'normal!'} secondary />
|
|
61
|
+
<DEPRECATED_Button text={'hover!'} secondary style={{ backgroundColor: '#F4F4F8' }} />
|
|
62
|
+
<DEPRECATED_Button text={'disable!'} secondary disabled />
|
|
63
|
+
</>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
export const SecondaryWithIcon = () => (
|
|
68
|
+
<div
|
|
69
|
+
style={{
|
|
70
|
+
display: 'inline-flex',
|
|
71
|
+
justifyContent: 'space-between',
|
|
72
|
+
height: '175px',
|
|
73
|
+
padding: '20px 50px',
|
|
74
|
+
flexDirection: 'column',
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<>
|
|
78
|
+
<DEPRECATED_Button text={'normal!'} iconName="general-plus" secondary />
|
|
79
|
+
<DEPRECATED_Button
|
|
80
|
+
text={'hover!'}
|
|
81
|
+
iconName="general-plus"
|
|
82
|
+
secondary
|
|
83
|
+
style={{ backgroundColor: '#F4F4F8' }}
|
|
84
|
+
/>
|
|
85
|
+
<DEPRECATED_Button text={'disable!'} iconName="general-plus" secondary disabled />
|
|
86
|
+
</>
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export const Cancel = () => (
|
|
91
|
+
<div
|
|
92
|
+
style={{
|
|
93
|
+
display: 'inline-flex',
|
|
94
|
+
justifyContent: 'space-between',
|
|
95
|
+
height: '175px',
|
|
96
|
+
padding: '20px 50px',
|
|
97
|
+
flexDirection: 'column',
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<>
|
|
101
|
+
<DEPRECATED_Button text={'normal!'} gray />
|
|
102
|
+
<DEPRECATED_Button text={'hover!'} style={{ backgroundColor: '#D1D1D7' }} />
|
|
103
|
+
<DEPRECATED_Button text={'disable!'} gray disabled />
|
|
104
|
+
</>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export const CancelWithIcon = () => (
|
|
109
|
+
<div
|
|
110
|
+
style={{
|
|
111
|
+
display: 'inline-flex',
|
|
112
|
+
justifyContent: 'space-between',
|
|
113
|
+
height: '175px',
|
|
114
|
+
padding: '20px 50px',
|
|
115
|
+
flexDirection: 'column',
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<>
|
|
119
|
+
<DEPRECATED_Button text={'normal!'} iconName="general-plus" gray />
|
|
120
|
+
<DEPRECATED_Button
|
|
121
|
+
text={'hover!'}
|
|
122
|
+
iconName="general-plus"
|
|
123
|
+
style={{ backgroundColor: '#D1D1D7' }}
|
|
124
|
+
/>
|
|
125
|
+
<DEPRECATED_Button text={'disable!'} iconName="general-plus" gray disabled />
|
|
126
|
+
</>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
export const Text = () => (
|
|
131
|
+
<div
|
|
132
|
+
style={{
|
|
133
|
+
display: 'inline-flex',
|
|
134
|
+
justifyContent: 'space-between',
|
|
135
|
+
height: '175px',
|
|
136
|
+
padding: '20px 50px',
|
|
137
|
+
flexDirection: 'column',
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<>
|
|
141
|
+
<DEPRECATED_Button text={'normal!'} dark />
|
|
142
|
+
<DEPRECATED_Button text={'hover!'} style={{ backgroundColor: '#f4f4f8' }} dark />
|
|
143
|
+
<DEPRECATED_Button text={'disable!'} disabled dark />
|
|
144
|
+
</>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
export const TextWithIcon = () => (
|
|
149
|
+
<div
|
|
150
|
+
style={{
|
|
151
|
+
display: 'inline-flex',
|
|
152
|
+
justifyContent: 'space-between',
|
|
153
|
+
height: '175px',
|
|
154
|
+
padding: '20px 50px',
|
|
155
|
+
flexDirection: 'column',
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
<>
|
|
159
|
+
<DEPRECATED_Button text={'normal!'} dark iconName={'general-edit'} />
|
|
160
|
+
<DEPRECATED_Button
|
|
161
|
+
text={'hover!'}
|
|
162
|
+
style={{ backgroundColor: '#f4f4f8' }}
|
|
163
|
+
iconName={'general-edit'}
|
|
164
|
+
dark
|
|
165
|
+
/>
|
|
166
|
+
<DEPRECATED_Button text={'disable!'} iconName={'general-edit'} disabled dark />
|
|
167
|
+
</>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
import { DEPRECATED_Button } from './DEPRECATED_Button';
|
|
6
|
+
|
|
7
|
+
import '@testing-library/jest-dom';
|
|
8
|
+
|
|
9
|
+
describe('Button Component', () => {
|
|
10
|
+
it('should render correctly with default props', () => {
|
|
11
|
+
render(<DEPRECATED_Button text="Click Me" />);
|
|
12
|
+
|
|
13
|
+
expect(screen.getByText('Click Me')).toBeInTheDocument();
|
|
14
|
+
expect(screen.getByRole('button')).toHaveClass('btn');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should apply custom className when provided as prop', () => {
|
|
18
|
+
render(<DEPRECATED_Button text="Click Me" className="custom-class" />);
|
|
19
|
+
|
|
20
|
+
expect(screen.getByRole('button')).toHaveClass('custom-class');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should render an DEPRECATED_Icon with correct props when provided', () => {
|
|
24
|
+
const iconName = 'icon-name';
|
|
25
|
+
const iconClassName = 'custom-icon-class';
|
|
26
|
+
const hoverSuffix = 'hover-suffix';
|
|
27
|
+
|
|
28
|
+
const { container } = render(
|
|
29
|
+
<DEPRECATED_Button
|
|
30
|
+
text="Button with Icon"
|
|
31
|
+
iconName={iconName}
|
|
32
|
+
iconClassName={iconClassName}
|
|
33
|
+
hoverSuffix={hoverSuffix}
|
|
34
|
+
disabled
|
|
35
|
+
/>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const icon = container.querySelector(`.${iconClassName}`);
|
|
39
|
+
expect(icon).toHaveClass('btn__icon');
|
|
40
|
+
expect(icon).toHaveClass(iconClassName);
|
|
41
|
+
expect(icon).toHaveAttribute('name', iconName);
|
|
42
|
+
expect(icon).toHaveAttribute('disabled');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render an DEPRECATED_Icon with correct hover suffix when provided', () => {
|
|
46
|
+
const iconName = 'icon-name';
|
|
47
|
+
const iconClassName = 'custom-icon-class';
|
|
48
|
+
const hoverSuffix = 'hover-suffix';
|
|
49
|
+
|
|
50
|
+
const { container } = render(
|
|
51
|
+
<DEPRECATED_Button
|
|
52
|
+
text="Button with Icon"
|
|
53
|
+
iconName={iconName}
|
|
54
|
+
iconClassName={iconClassName}
|
|
55
|
+
hoverSuffix={hoverSuffix}
|
|
56
|
+
/>,
|
|
57
|
+
);
|
|
58
|
+
let icon = container.querySelector(`.${iconClassName}`) as Element;
|
|
59
|
+
fireEvent.mouseEnter(icon);
|
|
60
|
+
icon = container.querySelector(`.${iconClassName}`) as Element;
|
|
61
|
+
|
|
62
|
+
expect(icon).toHaveClass('app-icon--icon-namehover-suffix');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should render a trailing DEPRECATED_Icon with correct props when trailingIconName is provided', () => {
|
|
66
|
+
const trailingIconName = 'trailing-icon';
|
|
67
|
+
const hoverSuffix = 'trailing-hover';
|
|
68
|
+
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<DEPRECATED_Button
|
|
71
|
+
text="Button with Trailing Icon"
|
|
72
|
+
trailingIconName={trailingIconName}
|
|
73
|
+
hoverSuffix={hoverSuffix}
|
|
74
|
+
/>,
|
|
75
|
+
);
|
|
76
|
+
const trailingIcon = container.querySelector('.app-icon.app-icon--trailing-icon.btn__icon');
|
|
77
|
+
|
|
78
|
+
expect(trailingIcon).toBeInTheDocument();
|
|
79
|
+
expect(trailingIcon).toHaveAttribute('name', trailingIconName);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should render only an DEPRECATED_Icon when no text is provided and passes correct props', () => {
|
|
83
|
+
const iconName = 'icon-only';
|
|
84
|
+
const { container } = render(<DEPRECATED_Button iconName={iconName} disabled />);
|
|
85
|
+
|
|
86
|
+
const button = screen.getByRole('button');
|
|
87
|
+
const icon = container.querySelector(".app-icon[class~='app-icon--icon-only']");
|
|
88
|
+
|
|
89
|
+
expect(button).toHaveClass('btn--icon');
|
|
90
|
+
expect(icon).toBeInTheDocument();
|
|
91
|
+
expect(icon).toHaveAttribute('name', iconName);
|
|
92
|
+
expect(icon).toHaveAttribute('disabled');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should render both text and DEPRECATED_Icon with proper spacing', () => {
|
|
96
|
+
const { container } = render(<DEPRECATED_Button text="Text with Icon" iconName="icon-name" />);
|
|
97
|
+
|
|
98
|
+
const button = screen.getByRole('button');
|
|
99
|
+
const icon = container.querySelector('.app-icon.app-icon--icon-name.btn__icon');
|
|
100
|
+
|
|
101
|
+
expect(icon).toBeInTheDocument();
|
|
102
|
+
expect(button).toHaveTextContent('Text with Icon');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should disable the button when disabled is true', () => {
|
|
106
|
+
render(<DEPRECATED_Button text="Disabled" disabled />);
|
|
107
|
+
|
|
108
|
+
const button = screen.getByRole('button');
|
|
109
|
+
|
|
110
|
+
expect(button).toBeDisabled();
|
|
111
|
+
expect(button).toHaveClass('btn--disabled');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should call the onClick handler when clicked', () => {
|
|
115
|
+
const handleClick = vi.fn();
|
|
116
|
+
render(<DEPRECATED_Button text="Click Me" onClick={handleClick} />);
|
|
117
|
+
const button = screen.getByRole('button');
|
|
118
|
+
|
|
119
|
+
button.click();
|
|
120
|
+
|
|
121
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should apply the correct aria-label', () => {
|
|
125
|
+
render(<DEPRECATED_Button text="Aria Test" ariaLabel="custom-label" />);
|
|
126
|
+
|
|
127
|
+
const button = screen.getByRole('button');
|
|
128
|
+
|
|
129
|
+
expect(button).toHaveAttribute('aria-label', 'custom-label');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should set the title when button is disabled and allowDisabledTitle is true', () => {
|
|
133
|
+
render(
|
|
134
|
+
<DEPRECATED_Button
|
|
135
|
+
title="Disabled Button Allowed"
|
|
136
|
+
disabled
|
|
137
|
+
allowDisabledTitle
|
|
138
|
+
dataTestId="button"
|
|
139
|
+
/>,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const button = screen.getByTestId('button');
|
|
143
|
+
|
|
144
|
+
expect(button).toHaveAttribute('title', 'Disabled Button Allowed');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should not set the title when button is disabled and allowDisabledTitle is false', () => {
|
|
148
|
+
render(<DEPRECATED_Button title="Disabled Button" disabled dataTestId="button" />);
|
|
149
|
+
|
|
150
|
+
const button = screen.getByTestId('button');
|
|
151
|
+
|
|
152
|
+
expect(button).not.toHaveAttribute('title');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
|
|
5
|
+
import { DEPRECATED_Icon } from '../DEPRECATED_Icon';
|
|
6
|
+
|
|
7
|
+
import styles from './DEPRECATED_Button.module.scss';
|
|
8
|
+
|
|
9
|
+
export type ButtonProps = {
|
|
10
|
+
allowDisabledTitle?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
hoverSuffix?: string;
|
|
14
|
+
iconClassName?: string;
|
|
15
|
+
iconName?: string;
|
|
16
|
+
transparent?: boolean;
|
|
17
|
+
text?: string;
|
|
18
|
+
trailingIconName?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
dark?: boolean;
|
|
21
|
+
gray?: boolean;
|
|
22
|
+
secondary?: boolean;
|
|
23
|
+
dataTestId?: string;
|
|
24
|
+
ariaLabel?: React.AriaAttributes['aria-label'];
|
|
25
|
+
} & React.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
26
|
+
|
|
27
|
+
// Used since in sisense-styleguide repo, there is a new line between the icon span and the text span
|
|
28
|
+
// The browser shows this new line as a space between the button spans and the text,
|
|
29
|
+
// so we are doing it as well until the styleguide will be changed
|
|
30
|
+
const SPACE = ' ';
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
33
|
+
const DEPRECATED_Button = (props: ButtonProps) => {
|
|
34
|
+
const {
|
|
35
|
+
allowDisabledTitle,
|
|
36
|
+
className,
|
|
37
|
+
disabled,
|
|
38
|
+
hoverSuffix,
|
|
39
|
+
iconClassName,
|
|
40
|
+
iconName,
|
|
41
|
+
transparent,
|
|
42
|
+
text,
|
|
43
|
+
trailingIconName,
|
|
44
|
+
title,
|
|
45
|
+
dark,
|
|
46
|
+
gray,
|
|
47
|
+
secondary,
|
|
48
|
+
dataTestId,
|
|
49
|
+
ariaLabel = 'button',
|
|
50
|
+
...otherProps
|
|
51
|
+
} = props;
|
|
52
|
+
|
|
53
|
+
const isIconOnlyComponent = !text;
|
|
54
|
+
|
|
55
|
+
const buttonClass = classNames(
|
|
56
|
+
'btn',
|
|
57
|
+
{
|
|
58
|
+
'btn--disabled': disabled,
|
|
59
|
+
'btn--transp': transparent,
|
|
60
|
+
'btn--dark': dark,
|
|
61
|
+
'btn--icon': isIconOnlyComponent,
|
|
62
|
+
'btn--gray': gray,
|
|
63
|
+
[styles.btnSecondary]: secondary,
|
|
64
|
+
},
|
|
65
|
+
styles.sharedComponentsButton,
|
|
66
|
+
className,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const iconClass = classNames('btn__icon', iconClassName);
|
|
70
|
+
const iconComponent = iconName && (
|
|
71
|
+
<DEPRECATED_Icon
|
|
72
|
+
className={iconClass}
|
|
73
|
+
name={iconName}
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
hoverSuffix={hoverSuffix}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const textClass = classNames('btn__text', styles.sharedComponentsButtonText);
|
|
80
|
+
const textComponent = text && <span className={textClass}>{text}</span>;
|
|
81
|
+
|
|
82
|
+
const spaceComponent = iconComponent && textComponent && SPACE;
|
|
83
|
+
const trailingIconComponent = trailingIconName && (
|
|
84
|
+
<DEPRECATED_Icon
|
|
85
|
+
className={iconClass}
|
|
86
|
+
name={trailingIconName}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
hoverSuffix={hoverSuffix}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const extraProps = {
|
|
93
|
+
disabled,
|
|
94
|
+
title: title && (!disabled || allowDisabledTitle) ? title : undefined,
|
|
95
|
+
...otherProps,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<button {...extraProps} className={buttonClass} data-testid={dataTestId} aria-label={ariaLabel}>
|
|
100
|
+
{iconComponent}
|
|
101
|
+
{spaceComponent}
|
|
102
|
+
{textComponent}
|
|
103
|
+
{trailingIconComponent}
|
|
104
|
+
</button>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
DEPRECATED_Button.propTypes = {
|
|
109
|
+
allowDisabledTitle: PropTypes.bool,
|
|
110
|
+
className: PropTypes.string,
|
|
111
|
+
disabled: PropTypes.bool,
|
|
112
|
+
hoverSuffix: PropTypes.string,
|
|
113
|
+
iconClassName: PropTypes.string,
|
|
114
|
+
iconName: PropTypes.string,
|
|
115
|
+
onClick: PropTypes.func.isRequired,
|
|
116
|
+
text: PropTypes.string,
|
|
117
|
+
title: PropTypes.string,
|
|
118
|
+
trailingIconName: PropTypes.string,
|
|
119
|
+
transparent: PropTypes.bool,
|
|
120
|
+
dark: PropTypes.bool,
|
|
121
|
+
gray: PropTypes.bool,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
DEPRECATED_Button.defaultProps = {
|
|
125
|
+
allowDisabledTitle: false,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default DEPRECATED_Button;
|
|
129
|
+
export { DEPRECATED_Button }; // Named export
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
:global(.sis-scope) {
|
|
2
|
+
:global(.custom-checkbox__icon.app-icon) {
|
|
3
|
+
&.transparent {
|
|
4
|
+
background: transparent !important;
|
|
5
|
+
color: transparent;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:global(.custom-checkbox__input:checked + .custom-checkbox__icon) {
|
|
10
|
+
&.transparent {
|
|
11
|
+
color: #3a4356;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:global(.custom-checkbox__text) {
|
|
16
|
+
padding-left: 4px;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.icon {
|
|
21
|
+
margin: 0 -5px 0 0px;
|
|
22
|
+
// If there is not a onDescriptionClick, the icon will not have
|
|
23
|
+
// onClick set, and thus would not show a pointer but should.
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.disabled {
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
// sis-scope uses an adjacency selector to style the span,
|
|
30
|
+
// but the optional icon is between the checkbox and text.
|
|
31
|
+
:global(.custom-checkbox__text) {
|
|
32
|
+
color: rgba(91, 99, 114, 0.4);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:global(.app-icon) {
|
|
36
|
+
opacity: 0.4;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.sharedComponentsInputCheckbox {
|
|
41
|
+
width: 28px;
|
|
42
|
+
height: 28px;
|
|
43
|
+
padding: 8px;
|
|
44
|
+
|
|
45
|
+
&:hover {
|
|
46
|
+
background-color: rgba(91, 99, 114, 0.1);
|
|
47
|
+
border-radius: 50%;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { DEPRECATED_Checkbox } from './DEPRECATED_Checkbox';
|
|
6
|
+
|
|
7
|
+
import '@testing-library/jest-dom';
|
|
8
|
+
|
|
9
|
+
describe('DEPRECATED_Checkbox', () => {
|
|
10
|
+
it('should render the checkbox with the provided text', () => {
|
|
11
|
+
render(<DEPRECATED_Checkbox checked={false} text="Checkbox Label" onChange={vi.fn()} />);
|
|
12
|
+
|
|
13
|
+
expect(screen.getByText('Checkbox Label')).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should render as checked when the checked prop is true', () => {
|
|
17
|
+
render(<DEPRECATED_Checkbox checked={true} text="Checked Checkbox" onChange={vi.fn()} />);
|
|
18
|
+
|
|
19
|
+
const checkbox = screen.getByRole('checkbox');
|
|
20
|
+
|
|
21
|
+
expect(checkbox).toBeChecked();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should trigger onChange when clicked', () => {
|
|
25
|
+
const handleChange = vi.fn();
|
|
26
|
+
render(<DEPRECATED_Checkbox checked={false} onChange={handleChange} dataTestId="checkbox" />);
|
|
27
|
+
|
|
28
|
+
const checkbox = screen.getByTestId('checkbox');
|
|
29
|
+
fireEvent.click(checkbox);
|
|
30
|
+
|
|
31
|
+
expect(handleChange).toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should render the title when provided and not disabled', () => {
|
|
35
|
+
render(<DEPRECATED_Checkbox checked={false} title="Checkbox Title" onChange={vi.fn()} />);
|
|
36
|
+
|
|
37
|
+
const checkbox = screen.getByRole('checkbox');
|
|
38
|
+
|
|
39
|
+
expect(checkbox).toHaveAttribute('title', 'Checkbox Title');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should not render the title when disabled', () => {
|
|
43
|
+
render(
|
|
44
|
+
<DEPRECATED_Checkbox checked={false} title="Checkbox Title" disabled onChange={vi.fn()} />,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const checkbox = screen.getByRole('checkbox');
|
|
48
|
+
|
|
49
|
+
expect(checkbox).not.toHaveAttribute('title');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should apply the correct classes for inline and transparent props', () => {
|
|
53
|
+
const { container } = render(
|
|
54
|
+
<DEPRECATED_Checkbox
|
|
55
|
+
checked={false}
|
|
56
|
+
inline
|
|
57
|
+
transparent
|
|
58
|
+
onChange={vi.fn()}
|
|
59
|
+
className="custom-class"
|
|
60
|
+
/>,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const checkboxContainer = container.querySelector(`.custom-checkbox--inline`);
|
|
64
|
+
|
|
65
|
+
expect(checkboxContainer).toHaveClass('custom-checkbox');
|
|
66
|
+
expect(checkboxContainer).toHaveClass('custom-checkbox--inline');
|
|
67
|
+
expect(checkboxContainer).toHaveClass('custom-class');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should call onDescriptionClick when the description is clicked', () => {
|
|
71
|
+
const handleDescriptionClick = vi.fn();
|
|
72
|
+
render(
|
|
73
|
+
<DEPRECATED_Checkbox
|
|
74
|
+
checked={false}
|
|
75
|
+
text="Clickable Description"
|
|
76
|
+
onChange={vi.fn()}
|
|
77
|
+
onDescriptionClick={handleDescriptionClick}
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
fireEvent.click(screen.getByText('Clickable Description'));
|
|
82
|
+
|
|
83
|
+
expect(handleDescriptionClick).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should render an icon if iconName is provided', () => {
|
|
87
|
+
const { container } = render(
|
|
88
|
+
<DEPRECATED_Checkbox
|
|
89
|
+
checked={false}
|
|
90
|
+
iconName="test-icon"
|
|
91
|
+
onChange={vi.fn()}
|
|
92
|
+
dataTestId="checkbox"
|
|
93
|
+
/>,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const icon = container.querySelector(`.app-icon.app-icon--test-icon`);
|
|
97
|
+
|
|
98
|
+
expect(icon).toBeInTheDocument();
|
|
99
|
+
expect(icon).toHaveClass('app-icon app-icon--test-icon');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should call onDescriptionClick when the icon is clicked', () => {
|
|
103
|
+
const handleDescriptionClick = vi.fn();
|
|
104
|
+
const { container } = render(
|
|
105
|
+
<DEPRECATED_Checkbox
|
|
106
|
+
checked={false}
|
|
107
|
+
iconName="test-icon"
|
|
108
|
+
onChange={vi.fn()}
|
|
109
|
+
onDescriptionClick={handleDescriptionClick}
|
|
110
|
+
/>,
|
|
111
|
+
);
|
|
112
|
+
const icon = container.querySelector(`.app-icon.app-icon--test-icon`);
|
|
113
|
+
|
|
114
|
+
fireEvent.click(icon as Element);
|
|
115
|
+
|
|
116
|
+
expect(handleDescriptionClick).toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should apply additional class names to the input checkbox element', () => {
|
|
120
|
+
render(
|
|
121
|
+
<DEPRECATED_Checkbox
|
|
122
|
+
checked={false}
|
|
123
|
+
inputCheckboxClassName="additional-input-class"
|
|
124
|
+
onChange={vi.fn()}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
const inputWrapper = screen.getByRole('checkbox').closest('div');
|
|
128
|
+
|
|
129
|
+
expect(inputWrapper).toHaveClass('additional-input-class');
|
|
130
|
+
});
|
|
131
|
+
});
|