@seeqdev/qomponents 0.0.41 → 0.0.43
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 +135 -135
- package/dist/Button/Button.js +86 -86
- package/dist/Button/Button.stories.js +76 -76
- package/dist/Button/Button.test.js +48 -48
- package/dist/Button/Button.types.js +3 -3
- package/dist/Button/index.js +1 -1
- package/dist/Checkbox/Checkbox.js +23 -23
- package/dist/Checkbox/Checkbox.stories.js +31 -31
- package/dist/Checkbox/Checkbox.test.js +93 -93
- package/dist/Checkbox/Checkbox.types.js +1 -1
- package/dist/Checkbox/index.js +1 -1
- package/dist/FontCustom.woff +0 -0
- package/dist/FontCustom.woff2 +0 -0
- package/dist/Icon/Icon.js +62 -62
- package/dist/Icon/Icon.stories.js +39 -39
- package/dist/Icon/Icon.test.js +54 -54
- package/dist/Icon/Icon.types.js +15 -15
- package/dist/Icon/index.js +1 -1
- package/dist/Select/Select.js +167 -167
- package/dist/Select/Select.stories.js +71 -71
- package/dist/Select/Select.test.js +160 -160
- package/dist/Select/Select.types.js +1 -1
- package/dist/Select/index.js +1 -1
- package/dist/Tabs/Tabs.d.ts +4 -0
- package/dist/Tabs/Tabs.js +23 -0
- package/dist/Tabs/Tabs.js.map +1 -0
- package/dist/Tabs/Tabs.stories.d.ts +5 -0
- package/dist/Tabs/Tabs.stories.js +63 -0
- package/dist/Tabs/Tabs.stories.js.map +1 -0
- package/dist/Tabs/Tabs.test.d.ts +1 -0
- package/dist/Tabs/Tabs.test.js +91 -0
- package/dist/Tabs/Tabs.test.js.map +1 -0
- package/dist/Tabs/Tabs.types.d.ts +18 -0
- package/dist/Tabs/Tabs.types.js +2 -0
- package/dist/Tabs/Tabs.types.js.map +1 -0
- package/dist/Tabs/index.d.ts +1 -0
- package/dist/Tabs/index.js +2 -0
- package/dist/Tabs/index.js.map +1 -0
- package/dist/TextArea/TextArea.js +22 -22
- package/dist/TextArea/TextArea.stories.js +38 -38
- package/dist/TextArea/TextArea.test.js +67 -67
- package/dist/TextArea/TextArea.types.js +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/TextField/TextField.js +63 -63
- package/dist/TextField/TextField.stories.js +40 -40
- package/dist/TextField/TextField.test.js +34 -34
- package/dist/TextField/TextField.types.js +1 -1
- package/dist/TextField/index.js +1 -1
- package/dist/ToolbarButton/ToolbarButton.js +73 -73
- package/dist/ToolbarButton/ToolbarButton.stories.js +78 -78
- package/dist/ToolbarButton/ToolbarButton.test.js +92 -92
- package/dist/ToolbarButton/ToolbarButton.types.js +1 -1
- package/dist/ToolbarButton/index.js +1 -1
- package/dist/Tooltip/QTip.stories.js +39 -39
- package/dist/Tooltip/QTip.types.js +1 -1
- package/dist/Tooltip/QTipPerformance.stories.js +29 -29
- package/dist/Tooltip/Qtip.js +147 -147
- package/dist/Tooltip/Tooltip.js +35 -35
- package/dist/Tooltip/Tooltip.stories.js +31 -31
- package/dist/Tooltip/Tooltip.types.js +2 -2
- package/dist/Tooltip/TooltipPerformance.stories.js +29 -29
- package/dist/Tooltip/index.js +2 -2
- package/dist/example/.eslintrc.cjs +14 -14
- package/dist/example/README.md +33 -33
- package/dist/example/index.html +13 -13
- package/dist/example/package.json +30 -30
- package/dist/example/src/ComplexSelectExample.tsx +81 -81
- package/dist/example/src/Example.tsx +167 -167
- package/dist/example/src/index.css +102 -102
- package/dist/example/src/main.tsx +10 -10
- package/dist/example/src/vite-env.d.ts +1 -1
- package/dist/example/tsconfig.json +33 -33
- package/dist/example/tsconfig.node.json +12 -12
- package/dist/example/vite.config.ts +12 -12
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +486 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +486 -6
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2730 -2644
- package/dist/types.js +1 -1
- package/dist/utils/browserId.js +28 -28
- package/package.json +80 -79
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Icon from './Icon';
|
|
3
|
-
import { iconTypes } from './Icon.types';
|
|
4
|
-
export default {
|
|
5
|
-
title: 'Icons',
|
|
6
|
-
};
|
|
7
|
-
export const AllIcons = () => {
|
|
8
|
-
const renderAllVariations = () => {
|
|
9
|
-
return (React.createElement(React.Fragment, null,
|
|
10
|
-
React.createElement("br", null),
|
|
11
|
-
React.createElement("br", null),
|
|
12
|
-
iconTypes.map((iconType) => {
|
|
13
|
-
return (React.createElement("div", { key: `${iconType}` },
|
|
14
|
-
React.createElement("b", null,
|
|
15
|
-
"type=",
|
|
16
|
-
iconType),
|
|
17
|
-
React.createElement("br", null),
|
|
18
|
-
React.createElement("div", null,
|
|
19
|
-
React.createElement(Icon, { icon: "fc-announcements", small: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'purple' : undefined }),
|
|
20
|
-
React.createElement(Icon, { icon: "fc-announcements", extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? '#928378' : undefined }),
|
|
21
|
-
React.createElement(Icon, { icon: "fc-announcements", large: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'pink' : undefined })),
|
|
22
|
-
React.createElement("div", { className: "tw-dark tw-bg-sq-dark-background" },
|
|
23
|
-
React.createElement(Icon, { icon: "fc-announcements", small: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'purple' : undefined }),
|
|
24
|
-
React.createElement(Icon, { icon: "fc-announcements", extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? '#928378' : undefined }),
|
|
25
|
-
React.createElement(Icon, { icon: "fc-announcements", large: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'pink' : undefined })),
|
|
26
|
-
React.createElement("br", null)));
|
|
27
|
-
})));
|
|
28
|
-
};
|
|
29
|
-
return (React.createElement("div", { className: "tw-grid tw-grid-cols-3 tw-gap-4" },
|
|
30
|
-
React.createElement("div", { className: "color_topic" },
|
|
31
|
-
React.createElement("b", null, "Topic Colors"),
|
|
32
|
-
renderAllVariations()),
|
|
33
|
-
React.createElement("div", { className: "color_analysis" },
|
|
34
|
-
React.createElement("b", null, "Analysis Colors"),
|
|
35
|
-
renderAllVariations()),
|
|
36
|
-
React.createElement("div", { className: "color_datalab" },
|
|
37
|
-
React.createElement("b", null, "Datalab Colors"),
|
|
38
|
-
renderAllVariations())));
|
|
39
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Icon from './Icon';
|
|
3
|
+
import { iconTypes } from './Icon.types';
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Icons',
|
|
6
|
+
};
|
|
7
|
+
export const AllIcons = () => {
|
|
8
|
+
const renderAllVariations = () => {
|
|
9
|
+
return (React.createElement(React.Fragment, null,
|
|
10
|
+
React.createElement("br", null),
|
|
11
|
+
React.createElement("br", null),
|
|
12
|
+
iconTypes.map((iconType) => {
|
|
13
|
+
return (React.createElement("div", { key: `${iconType}` },
|
|
14
|
+
React.createElement("b", null,
|
|
15
|
+
"type=",
|
|
16
|
+
iconType),
|
|
17
|
+
React.createElement("br", null),
|
|
18
|
+
React.createElement("div", null,
|
|
19
|
+
React.createElement(Icon, { icon: "fc-announcements", small: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'purple' : undefined }),
|
|
20
|
+
React.createElement(Icon, { icon: "fc-announcements", extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? '#928378' : undefined }),
|
|
21
|
+
React.createElement(Icon, { icon: "fc-announcements", large: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'pink' : undefined })),
|
|
22
|
+
React.createElement("div", { className: "tw-dark tw-bg-sq-dark-background" },
|
|
23
|
+
React.createElement(Icon, { icon: "fc-announcements", small: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'purple' : undefined }),
|
|
24
|
+
React.createElement(Icon, { icon: "fc-announcements", extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? '#928378' : undefined }),
|
|
25
|
+
React.createElement(Icon, { icon: "fc-announcements", large: true, extraClassNames: 'tw-p-2', type: iconType, color: iconType === 'color' ? 'pink' : undefined })),
|
|
26
|
+
React.createElement("br", null)));
|
|
27
|
+
})));
|
|
28
|
+
};
|
|
29
|
+
return (React.createElement("div", { className: "tw-grid tw-grid-cols-3 tw-gap-4" },
|
|
30
|
+
React.createElement("div", { className: "color_topic" },
|
|
31
|
+
React.createElement("b", null, "Topic Colors"),
|
|
32
|
+
renderAllVariations()),
|
|
33
|
+
React.createElement("div", { className: "color_analysis" },
|
|
34
|
+
React.createElement("b", null, "Analysis Colors"),
|
|
35
|
+
renderAllVariations()),
|
|
36
|
+
React.createElement("div", { className: "color_datalab" },
|
|
37
|
+
React.createElement("b", null, "Datalab Colors"),
|
|
38
|
+
renderAllVariations())));
|
|
39
|
+
};
|
|
40
40
|
//# sourceMappingURL=Icon.stories.js.map
|
package/dist/Icon/Icon.test.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import Icon from './Icon';
|
|
5
|
-
describe('Icon', () => {
|
|
6
|
-
class Context {
|
|
7
|
-
testId = 'iconTestId';
|
|
8
|
-
icon = 'testIcon';
|
|
9
|
-
props = {
|
|
10
|
-
icon: this.icon,
|
|
11
|
-
onClick: jest.fn(),
|
|
12
|
-
testId: this.testId,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
let tc;
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
tc = new Context();
|
|
18
|
-
});
|
|
19
|
-
const renderIcon = (props) => render(React.createElement(Icon, { ...props }));
|
|
20
|
-
it('renders icon', () => {
|
|
21
|
-
renderIcon(tc.props);
|
|
22
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass(tc.icon);
|
|
23
|
-
});
|
|
24
|
-
it('renders large icon', () => {
|
|
25
|
-
renderIcon({ ...tc.props, large: true });
|
|
26
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass('fa-lg');
|
|
27
|
-
});
|
|
28
|
-
it('renders small icon', () => {
|
|
29
|
-
renderIcon({ ...tc.props, small: true });
|
|
30
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass('fa-sm');
|
|
31
|
-
});
|
|
32
|
-
describe('icon types', () => {
|
|
33
|
-
it('renders the theme type by default', () => {
|
|
34
|
-
renderIcon(tc.props);
|
|
35
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-sq-color-dark');
|
|
36
|
-
});
|
|
37
|
-
it('renders the white icon', () => {
|
|
38
|
-
renderIcon({ ...tc.props, type: 'white' });
|
|
39
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-white');
|
|
40
|
-
});
|
|
41
|
-
it('renders the text-type icon', () => {
|
|
42
|
-
renderIcon({ ...tc.props, type: 'text' });
|
|
43
|
-
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-sq-text-color');
|
|
44
|
-
});
|
|
45
|
-
it('renders the color-type icon', () => {
|
|
46
|
-
renderIcon({ ...tc.props, type: 'color', color: '#AABBFF' });
|
|
47
|
-
expect(screen.getByTestId(tc.testId)).toHaveStyle('color: #AABBFF');
|
|
48
|
-
});
|
|
49
|
-
it('renders a warning if type=color and no color is provided', () => {
|
|
50
|
-
renderIcon({ ...tc.props, type: 'color' });
|
|
51
|
-
expect(screen.getByText('Icon with type="color" must have prop color specified.')).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import Icon from './Icon';
|
|
5
|
+
describe('Icon', () => {
|
|
6
|
+
class Context {
|
|
7
|
+
testId = 'iconTestId';
|
|
8
|
+
icon = 'testIcon';
|
|
9
|
+
props = {
|
|
10
|
+
icon: this.icon,
|
|
11
|
+
onClick: jest.fn(),
|
|
12
|
+
testId: this.testId,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
let tc;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
tc = new Context();
|
|
18
|
+
});
|
|
19
|
+
const renderIcon = (props) => render(React.createElement(Icon, { ...props }));
|
|
20
|
+
it('renders icon', () => {
|
|
21
|
+
renderIcon(tc.props);
|
|
22
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass(tc.icon);
|
|
23
|
+
});
|
|
24
|
+
it('renders large icon', () => {
|
|
25
|
+
renderIcon({ ...tc.props, large: true });
|
|
26
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass('fa-lg');
|
|
27
|
+
});
|
|
28
|
+
it('renders small icon', () => {
|
|
29
|
+
renderIcon({ ...tc.props, small: true });
|
|
30
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass('fa-sm');
|
|
31
|
+
});
|
|
32
|
+
describe('icon types', () => {
|
|
33
|
+
it('renders the theme type by default', () => {
|
|
34
|
+
renderIcon(tc.props);
|
|
35
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-sq-color-dark');
|
|
36
|
+
});
|
|
37
|
+
it('renders the white icon', () => {
|
|
38
|
+
renderIcon({ ...tc.props, type: 'white' });
|
|
39
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-white');
|
|
40
|
+
});
|
|
41
|
+
it('renders the text-type icon', () => {
|
|
42
|
+
renderIcon({ ...tc.props, type: 'text' });
|
|
43
|
+
expect(screen.getByTestId(tc.testId)).toHaveClass('tw-text-sq-text-color');
|
|
44
|
+
});
|
|
45
|
+
it('renders the color-type icon', () => {
|
|
46
|
+
renderIcon({ ...tc.props, type: 'color', color: '#AABBFF' });
|
|
47
|
+
expect(screen.getByTestId(tc.testId)).toHaveStyle('color: #AABBFF');
|
|
48
|
+
});
|
|
49
|
+
it('renders a warning if type=color and no color is provided', () => {
|
|
50
|
+
renderIcon({ ...tc.props, type: 'color' });
|
|
51
|
+
expect(screen.getByText('Icon with type="color" must have prop color specified.')).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
55
|
//# sourceMappingURL=Icon.test.js.map
|
package/dist/Icon/Icon.types.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export const iconTypes = [
|
|
2
|
-
'theme',
|
|
3
|
-
'white',
|
|
4
|
-
'dark-gray',
|
|
5
|
-
'darkish-gray',
|
|
6
|
-
'gray',
|
|
7
|
-
'color',
|
|
8
|
-
'info',
|
|
9
|
-
'text',
|
|
10
|
-
'warning',
|
|
11
|
-
'inherit',
|
|
12
|
-
'danger',
|
|
13
|
-
'theme-light',
|
|
14
|
-
'success',
|
|
15
|
-
];
|
|
1
|
+
export const iconTypes = [
|
|
2
|
+
'theme',
|
|
3
|
+
'white',
|
|
4
|
+
'dark-gray',
|
|
5
|
+
'darkish-gray',
|
|
6
|
+
'gray',
|
|
7
|
+
'color',
|
|
8
|
+
'info',
|
|
9
|
+
'text',
|
|
10
|
+
'warning',
|
|
11
|
+
'inherit',
|
|
12
|
+
'danger',
|
|
13
|
+
'theme-light',
|
|
14
|
+
'success',
|
|
15
|
+
];
|
|
16
16
|
//# sourceMappingURL=Icon.types.js.map
|
package/dist/Icon/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './Icon';
|
|
1
|
+
export { default } from './Icon';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/Select/Select.js
CHANGED
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '../styles.css';
|
|
3
|
-
import { createFilter, default as ReactSelect } from 'react-select';
|
|
4
|
-
import CreatableSelect from 'react-select/creatable';
|
|
5
|
-
const baseClasses = ['focus:tw-ring-0', 'disabled:tw-cursor-not-allowed'].join(' ');
|
|
6
|
-
const containerStyles = ['tw-bg-white', 'dark:tw-bg-sq-dark-background'].join(' ');
|
|
7
|
-
const errorClasses = 'tw-border-sq-danger-color';
|
|
8
|
-
const borderColorClasses = ['tw-border-sq-disabled-gray', 'dark:tw-border-sq-dark-disabled-gray'].join(' ');
|
|
9
|
-
const borderStyles = [
|
|
10
|
-
'tw-border-solid',
|
|
11
|
-
'tw-border',
|
|
12
|
-
'hover:tw-border-sq-color-dark',
|
|
13
|
-
'focus:tw-border-sq-color-dark',
|
|
14
|
-
'active:tw-border-sq-color-dark',
|
|
15
|
-
'dark:hover:tw-border-sq-color-dark-dark',
|
|
16
|
-
'dark:focus:tw-border-sq-color-dark-dark',
|
|
17
|
-
'dark:active:tw-border-sq-color-dark-dark',
|
|
18
|
-
].join(' ');
|
|
19
|
-
const textStyles = ['tw-text-sq-text-color', 'dark:tw-text-sq-dark-text', 'tw-text-sm'].join(' ');
|
|
20
|
-
const textActiveStyles = [
|
|
21
|
-
'hover:tw-text-sq-color-dark',
|
|
22
|
-
'focus:tw-text-sq-color-dark',
|
|
23
|
-
'active:tw-text-sq-color-dark',
|
|
24
|
-
'dark:tw-text-sq-dark-disabled-gray',
|
|
25
|
-
'dark:hover:tw-text-sq-color-dark-dark',
|
|
26
|
-
'dark:focus:tw-text-sq-color-dark-dark',
|
|
27
|
-
'dark:active:tw-text-sq-color-dark-dark',
|
|
28
|
-
].join(' ');
|
|
29
|
-
const menuStyles = [
|
|
30
|
-
'tw-border-solid',
|
|
31
|
-
'tw-border',
|
|
32
|
-
'tw-rounded-b',
|
|
33
|
-
'tw-border-sq-disabled-gray',
|
|
34
|
-
'dark:tw-border-sq-dark-disabled-gray',
|
|
35
|
-
'tw-whitespace-nowrap',
|
|
36
|
-
'tw-min-w-fit',
|
|
37
|
-
'!tw-z-[9999]',
|
|
38
|
-
].join(' ');
|
|
39
|
-
const menuListStyles = [
|
|
40
|
-
'tw-rounded-b',
|
|
41
|
-
'tw-bg-white',
|
|
42
|
-
'dark:tw-bg-sq-dark-background',
|
|
43
|
-
'tw-min-w-fit',
|
|
44
|
-
'!tw-z-[9999]',
|
|
45
|
-
'specSelectMenu',
|
|
46
|
-
].join(' ');
|
|
47
|
-
const groupHeadingStyles = [
|
|
48
|
-
'tw-bg-sq-light-gray',
|
|
49
|
-
'dark:tw-bg-sq-dark-disabled-gray',
|
|
50
|
-
'tw-text-sq-darkish-gray',
|
|
51
|
-
'tw-py-1',
|
|
52
|
-
'tw-px-2.5',
|
|
53
|
-
'specSelectGroupHeading',
|
|
54
|
-
].join(' ');
|
|
55
|
-
const optionStyles = [
|
|
56
|
-
'hover:tw-bg-sq-gray-highlight',
|
|
57
|
-
'hover:tw-cursor-pointer',
|
|
58
|
-
'dark:hover:tw-bg-sq-gray-highlight-dark',
|
|
59
|
-
'tw-py-1',
|
|
60
|
-
'tw-px-2.5',
|
|
61
|
-
'specSelectOption',
|
|
62
|
-
].join(' ');
|
|
63
|
-
const disabledClasses = ['tw-bg-sq-field-disabled-gray', 'tw-cursor-not-allowed'].join(' ');
|
|
64
|
-
const dropDownIndicatorStyles = `tw-text-sq-disabled-gray ${textActiveStyles} specOpenIt`;
|
|
65
|
-
const placeholderStyles = ['tw-text-gray-400', 'dark:tw-text-sq-dark-text-lighter', 'specOpenSelect'].join(' ');
|
|
66
|
-
const multiValueStyles = [
|
|
67
|
-
'tw-bg-sq-disabled-gray',
|
|
68
|
-
'dark:tw-bg-sq-multi-gray-dark',
|
|
69
|
-
'tw-text-sm',
|
|
70
|
-
'tw-py-0.5',
|
|
71
|
-
'tw-px-1',
|
|
72
|
-
'tw-m-0.5',
|
|
73
|
-
'tw-rounded-sm',
|
|
74
|
-
'specOpenSelect',
|
|
75
|
-
].join(' ');
|
|
76
|
-
/**
|
|
77
|
-
* Select Component
|
|
78
|
-
* - based on react-select (https://react-select.com/)
|
|
79
|
-
*
|
|
80
|
-
* For ease of testing most of the elements of this select can be identified by classNames prefixed with "spec".
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
const Select = ({ options, value, placeholder = 'select', noOptionsMessage = 'no matching options', isSearchable = true, creatable = false, isMulti = false, isClearable = false, closeMenuOnSelect = true, id, inputId, menuPortalTarget, getOptionLabel, getSelectedValueLabel, getOptionValue, onChange, menuIsOpen, menuPlacement = 'auto', extraClassNames, inputGroup, filterConfig, filterOption, small = false, isDisabled = false, showError = false, isLoading = false, formatGroupLabel, onRemove, defaultValue, }) => {
|
|
84
|
-
const getOptionOrSelectedLabel = (option, { context }) => {
|
|
85
|
-
const getSelectedOptionLabel = getSelectedValueLabel ? getSelectedValueLabel : getOptionLabel;
|
|
86
|
-
if (getOptionLabel || getSelectedValueLabel) {
|
|
87
|
-
if (context === 'value') {
|
|
88
|
-
return getSelectedOptionLabel ? getSelectedOptionLabel(option) : option.label;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return getOptionLabel ? getOptionLabel(option) : option.label;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return option.label;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const interceptOnChange = (newValue, actionMeta) => {
|
|
99
|
-
if (isMulti && onRemove && actionMeta.action === 'remove-value') {
|
|
100
|
-
onRemove({ id: actionMeta.removedValue });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
onChange(newValue);
|
|
104
|
-
};
|
|
105
|
-
const props = {
|
|
106
|
-
id,
|
|
107
|
-
value,
|
|
108
|
-
inputId,
|
|
109
|
-
placeholder,
|
|
110
|
-
closeMenuOnSelect,
|
|
111
|
-
blurInputOnSelect: closeMenuOnSelect,
|
|
112
|
-
isSearchable: creatable ? true : isSearchable,
|
|
113
|
-
isMulti,
|
|
114
|
-
isClearable,
|
|
115
|
-
isLoading,
|
|
116
|
-
defaultValue,
|
|
117
|
-
noOptionsMessage: () => noOptionsMessage,
|
|
118
|
-
menuPortalTarget,
|
|
119
|
-
menuIsOpen,
|
|
120
|
-
onChange: interceptOnChange,
|
|
121
|
-
unstyled: true,
|
|
122
|
-
menuPlacement,
|
|
123
|
-
formatOptionLabel: getOptionOrSelectedLabel,
|
|
124
|
-
formatGroupLabel,
|
|
125
|
-
getOptionValue,
|
|
126
|
-
options,
|
|
127
|
-
isDisabled,
|
|
128
|
-
hideSelectedOptions: isMulti,
|
|
129
|
-
filterOption: filterOption ? filterOption : filterConfig ? createFilter(filterConfig) : undefined,
|
|
130
|
-
classNames: {
|
|
131
|
-
control: ({ menuIsOpen }) => {
|
|
132
|
-
let border = menuIsOpen ? 'tw-rounded-t-sm' : 'tw-rounded-sm';
|
|
133
|
-
// if it's on the left side of the input group make sure the right side is straight and not curved
|
|
134
|
-
if (inputGroup === 'left') {
|
|
135
|
-
border = menuIsOpen ? 'tw-rounded-tl-sm' : 'tw-rounded-l-sm';
|
|
136
|
-
}
|
|
137
|
-
else if (inputGroup === 'right') {
|
|
138
|
-
border = menuIsOpen ? 'tw-rounded-tr-sm' : 'tw-rounded-r-sm';
|
|
139
|
-
}
|
|
140
|
-
const appliedClasses = `${borderStyles} ${border} ${showError ? errorClasses : borderColorClasses} ${small ? 'reactSelectMinHeightSmall' : 'reactSelectMinHeight'} `;
|
|
141
|
-
return `${appliedClasses} ${baseClasses} specSelectControl ${isDisabled ? disabledClasses : ''} ${small ? 'tw-pl-2 tw-pr-1' : 'tw-pl-2.5 tw-pr-1.5'}`;
|
|
142
|
-
},
|
|
143
|
-
placeholder: () => placeholderStyles,
|
|
144
|
-
container: () => `${textStyles} ${containerStyles} ${extraClassNames}`,
|
|
145
|
-
input: () => textStyles + ' specSelectInput',
|
|
146
|
-
menuList: () => menuListStyles,
|
|
147
|
-
menu: () => menuStyles,
|
|
148
|
-
menuPortal: () => '!tw-z-[9000]',
|
|
149
|
-
dropdownIndicator: () => dropDownIndicatorStyles,
|
|
150
|
-
option: ({ isSelected, isDisabled }) => {
|
|
151
|
-
let classes = optionStyles;
|
|
152
|
-
if (isDisabled) {
|
|
153
|
-
classes += ' specDisabledOption ';
|
|
154
|
-
}
|
|
155
|
-
return isSelected ? classes + ' tw-bg-sq-colored-hover dark:tw-bg-sq-colored-hover-dark' : classes;
|
|
156
|
-
},
|
|
157
|
-
singleValue: () => 'specOpenSelect',
|
|
158
|
-
multiValue: () => multiValueStyles,
|
|
159
|
-
multiValueRemove: () => 'hover:tw-text-sq-danger-color specSelectMultiValueRemove',
|
|
160
|
-
clearIndicator: () => 'tw-text-sq-disabled-gray hover:tw-text-sq-danger-color specClearSelect',
|
|
161
|
-
group: () => 'specSelectGroup',
|
|
162
|
-
groupHeading: () => groupHeadingStyles,
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
return creatable ? React.createElement(CreatableSelect, { ...props }) : React.createElement(ReactSelect, { ...props });
|
|
166
|
-
};
|
|
167
|
-
export default Select;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '../styles.css';
|
|
3
|
+
import { createFilter, default as ReactSelect } from 'react-select';
|
|
4
|
+
import CreatableSelect from 'react-select/creatable';
|
|
5
|
+
const baseClasses = ['focus:tw-ring-0', 'disabled:tw-cursor-not-allowed'].join(' ');
|
|
6
|
+
const containerStyles = ['tw-bg-white', 'dark:tw-bg-sq-dark-background'].join(' ');
|
|
7
|
+
const errorClasses = 'tw-border-sq-danger-color';
|
|
8
|
+
const borderColorClasses = ['tw-border-sq-disabled-gray', 'dark:tw-border-sq-dark-disabled-gray'].join(' ');
|
|
9
|
+
const borderStyles = [
|
|
10
|
+
'tw-border-solid',
|
|
11
|
+
'tw-border',
|
|
12
|
+
'hover:tw-border-sq-color-dark',
|
|
13
|
+
'focus:tw-border-sq-color-dark',
|
|
14
|
+
'active:tw-border-sq-color-dark',
|
|
15
|
+
'dark:hover:tw-border-sq-color-dark-dark',
|
|
16
|
+
'dark:focus:tw-border-sq-color-dark-dark',
|
|
17
|
+
'dark:active:tw-border-sq-color-dark-dark',
|
|
18
|
+
].join(' ');
|
|
19
|
+
const textStyles = ['tw-text-sq-text-color', 'dark:tw-text-sq-dark-text', 'tw-text-sm'].join(' ');
|
|
20
|
+
const textActiveStyles = [
|
|
21
|
+
'hover:tw-text-sq-color-dark',
|
|
22
|
+
'focus:tw-text-sq-color-dark',
|
|
23
|
+
'active:tw-text-sq-color-dark',
|
|
24
|
+
'dark:tw-text-sq-dark-disabled-gray',
|
|
25
|
+
'dark:hover:tw-text-sq-color-dark-dark',
|
|
26
|
+
'dark:focus:tw-text-sq-color-dark-dark',
|
|
27
|
+
'dark:active:tw-text-sq-color-dark-dark',
|
|
28
|
+
].join(' ');
|
|
29
|
+
const menuStyles = [
|
|
30
|
+
'tw-border-solid',
|
|
31
|
+
'tw-border',
|
|
32
|
+
'tw-rounded-b',
|
|
33
|
+
'tw-border-sq-disabled-gray',
|
|
34
|
+
'dark:tw-border-sq-dark-disabled-gray',
|
|
35
|
+
'tw-whitespace-nowrap',
|
|
36
|
+
'tw-min-w-fit',
|
|
37
|
+
'!tw-z-[9999]',
|
|
38
|
+
].join(' ');
|
|
39
|
+
const menuListStyles = [
|
|
40
|
+
'tw-rounded-b',
|
|
41
|
+
'tw-bg-white',
|
|
42
|
+
'dark:tw-bg-sq-dark-background',
|
|
43
|
+
'tw-min-w-fit',
|
|
44
|
+
'!tw-z-[9999]',
|
|
45
|
+
'specSelectMenu',
|
|
46
|
+
].join(' ');
|
|
47
|
+
const groupHeadingStyles = [
|
|
48
|
+
'tw-bg-sq-light-gray',
|
|
49
|
+
'dark:tw-bg-sq-dark-disabled-gray',
|
|
50
|
+
'tw-text-sq-darkish-gray',
|
|
51
|
+
'tw-py-1',
|
|
52
|
+
'tw-px-2.5',
|
|
53
|
+
'specSelectGroupHeading',
|
|
54
|
+
].join(' ');
|
|
55
|
+
const optionStyles = [
|
|
56
|
+
'hover:tw-bg-sq-gray-highlight',
|
|
57
|
+
'hover:tw-cursor-pointer',
|
|
58
|
+
'dark:hover:tw-bg-sq-gray-highlight-dark',
|
|
59
|
+
'tw-py-1',
|
|
60
|
+
'tw-px-2.5',
|
|
61
|
+
'specSelectOption',
|
|
62
|
+
].join(' ');
|
|
63
|
+
const disabledClasses = ['tw-bg-sq-field-disabled-gray', 'tw-cursor-not-allowed'].join(' ');
|
|
64
|
+
const dropDownIndicatorStyles = `tw-text-sq-disabled-gray ${textActiveStyles} specOpenIt`;
|
|
65
|
+
const placeholderStyles = ['tw-text-gray-400', 'dark:tw-text-sq-dark-text-lighter', 'specOpenSelect'].join(' ');
|
|
66
|
+
const multiValueStyles = [
|
|
67
|
+
'tw-bg-sq-disabled-gray',
|
|
68
|
+
'dark:tw-bg-sq-multi-gray-dark',
|
|
69
|
+
'tw-text-sm',
|
|
70
|
+
'tw-py-0.5',
|
|
71
|
+
'tw-px-1',
|
|
72
|
+
'tw-m-0.5',
|
|
73
|
+
'tw-rounded-sm',
|
|
74
|
+
'specOpenSelect',
|
|
75
|
+
].join(' ');
|
|
76
|
+
/**
|
|
77
|
+
* Select Component
|
|
78
|
+
* - based on react-select (https://react-select.com/)
|
|
79
|
+
*
|
|
80
|
+
* For ease of testing most of the elements of this select can be identified by classNames prefixed with "spec".
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
const Select = ({ options, value, placeholder = 'select', noOptionsMessage = 'no matching options', isSearchable = true, creatable = false, isMulti = false, isClearable = false, closeMenuOnSelect = true, id, inputId, menuPortalTarget, getOptionLabel, getSelectedValueLabel, getOptionValue, onChange, menuIsOpen, menuPlacement = 'auto', extraClassNames, inputGroup, filterConfig, filterOption, small = false, isDisabled = false, showError = false, isLoading = false, formatGroupLabel, onRemove, defaultValue, }) => {
|
|
84
|
+
const getOptionOrSelectedLabel = (option, { context }) => {
|
|
85
|
+
const getSelectedOptionLabel = getSelectedValueLabel ? getSelectedValueLabel : getOptionLabel;
|
|
86
|
+
if (getOptionLabel || getSelectedValueLabel) {
|
|
87
|
+
if (context === 'value') {
|
|
88
|
+
return getSelectedOptionLabel ? getSelectedOptionLabel(option) : option.label;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return getOptionLabel ? getOptionLabel(option) : option.label;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return option.label;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const interceptOnChange = (newValue, actionMeta) => {
|
|
99
|
+
if (isMulti && onRemove && actionMeta.action === 'remove-value') {
|
|
100
|
+
onRemove({ id: actionMeta.removedValue });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
onChange(newValue);
|
|
104
|
+
};
|
|
105
|
+
const props = {
|
|
106
|
+
id,
|
|
107
|
+
value,
|
|
108
|
+
inputId,
|
|
109
|
+
placeholder,
|
|
110
|
+
closeMenuOnSelect,
|
|
111
|
+
blurInputOnSelect: closeMenuOnSelect,
|
|
112
|
+
isSearchable: creatable ? true : isSearchable,
|
|
113
|
+
isMulti,
|
|
114
|
+
isClearable,
|
|
115
|
+
isLoading,
|
|
116
|
+
defaultValue,
|
|
117
|
+
noOptionsMessage: () => noOptionsMessage,
|
|
118
|
+
menuPortalTarget,
|
|
119
|
+
menuIsOpen,
|
|
120
|
+
onChange: interceptOnChange,
|
|
121
|
+
unstyled: true,
|
|
122
|
+
menuPlacement,
|
|
123
|
+
formatOptionLabel: getOptionOrSelectedLabel,
|
|
124
|
+
formatGroupLabel,
|
|
125
|
+
getOptionValue,
|
|
126
|
+
options,
|
|
127
|
+
isDisabled,
|
|
128
|
+
hideSelectedOptions: isMulti,
|
|
129
|
+
filterOption: filterOption ? filterOption : filterConfig ? createFilter(filterConfig) : undefined,
|
|
130
|
+
classNames: {
|
|
131
|
+
control: ({ menuIsOpen }) => {
|
|
132
|
+
let border = menuIsOpen ? 'tw-rounded-t-sm' : 'tw-rounded-sm';
|
|
133
|
+
// if it's on the left side of the input group make sure the right side is straight and not curved
|
|
134
|
+
if (inputGroup === 'left') {
|
|
135
|
+
border = menuIsOpen ? 'tw-rounded-tl-sm' : 'tw-rounded-l-sm';
|
|
136
|
+
}
|
|
137
|
+
else if (inputGroup === 'right') {
|
|
138
|
+
border = menuIsOpen ? 'tw-rounded-tr-sm' : 'tw-rounded-r-sm';
|
|
139
|
+
}
|
|
140
|
+
const appliedClasses = `${borderStyles} ${border} ${showError ? errorClasses : borderColorClasses} ${small ? 'reactSelectMinHeightSmall' : 'reactSelectMinHeight'} `;
|
|
141
|
+
return `${appliedClasses} ${baseClasses} specSelectControl ${isDisabled ? disabledClasses : ''} ${small ? 'tw-pl-2 tw-pr-1' : 'tw-pl-2.5 tw-pr-1.5'}`;
|
|
142
|
+
},
|
|
143
|
+
placeholder: () => placeholderStyles,
|
|
144
|
+
container: () => `${textStyles} ${containerStyles} ${extraClassNames}`,
|
|
145
|
+
input: () => textStyles + ' specSelectInput',
|
|
146
|
+
menuList: () => menuListStyles,
|
|
147
|
+
menu: () => menuStyles,
|
|
148
|
+
menuPortal: () => '!tw-z-[9000]',
|
|
149
|
+
dropdownIndicator: () => dropDownIndicatorStyles,
|
|
150
|
+
option: ({ isSelected, isDisabled }) => {
|
|
151
|
+
let classes = optionStyles;
|
|
152
|
+
if (isDisabled) {
|
|
153
|
+
classes += ' specDisabledOption ';
|
|
154
|
+
}
|
|
155
|
+
return isSelected ? classes + ' tw-bg-sq-colored-hover dark:tw-bg-sq-colored-hover-dark' : classes;
|
|
156
|
+
},
|
|
157
|
+
singleValue: () => 'specOpenSelect',
|
|
158
|
+
multiValue: () => multiValueStyles,
|
|
159
|
+
multiValueRemove: () => 'hover:tw-text-sq-danger-color specSelectMultiValueRemove',
|
|
160
|
+
clearIndicator: () => 'tw-text-sq-disabled-gray hover:tw-text-sq-danger-color specClearSelect',
|
|
161
|
+
group: () => 'specSelectGroup',
|
|
162
|
+
groupHeading: () => groupHeadingStyles,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
return creatable ? React.createElement(CreatableSelect, { ...props }) : React.createElement(ReactSelect, { ...props });
|
|
166
|
+
};
|
|
167
|
+
export default Select;
|
|
168
168
|
//# sourceMappingURL=Select.js.map
|