@oliasoft-open-source/react-ui-library 2.4.8 → 3.0.1
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 +0 -1
- package/dist/global.css +21840 -0
- package/dist/index.js +43567 -0
- package/package.json +37 -55
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -125
- package/.gitlab-ci.yml +0 -76
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -3
- package/.prettierrc +0 -4
- package/.storybook/main.js +0 -36
- package/.storybook/preview.js +0 -40
- package/.storybook/storybook.less +0 -8
- package/babel.config.js +0 -31
- package/index.js +0 -76
- package/jest.config.js +0 -9
- package/scripts/send-mattermost-message.sh +0 -21
- package/src/components/accordion/accordion.jsx +0 -132
- package/src/components/accordion/accordion.module.less +0 -66
- package/src/components/accordion/accordion.stories.jsx +0 -171
- package/src/components/accordion/chevron/chevron.jsx +0 -12
- package/src/components/accordion/chevron/chevron.module.less +0 -12
- package/src/components/accordion/helpers/accordion-with-default-toggle.jsx +0 -106
- package/src/components/accordion/helpers/accordion-with-default-toggle.module.less +0 -24
- package/src/components/actions/actions.jsx +0 -129
- package/src/components/actions/actions.module.less +0 -44
- package/src/components/actions/actions.shape.js +0 -32
- package/src/components/actions/actions.stories.jsx +0 -79
- package/src/components/badge/badge.jsx +0 -58
- package/src/components/badge/badge.module.less +0 -55
- package/src/components/badge/badge.stories.jsx +0 -31
- package/src/components/breadcrumb/breadcrumb.jsx +0 -49
- package/src/components/breadcrumb/breadcrumb.module.less +0 -39
- package/src/components/breadcrumb/breadcrumb.stories.jsx +0 -45
- package/src/components/breadcrumb/link.jsx +0 -31
- package/src/components/button/button.jsx +0 -156
- package/src/components/button/button.module.less +0 -300
- package/src/components/button/button.stories.jsx +0 -74
- package/src/components/button-group/button-group.jsx +0 -140
- package/src/components/button-group/button-group.module.less +0 -24
- package/src/components/button-group/button-group.stories-data.jsx +0 -67
- package/src/components/button-group/button-group.stories.jsx +0 -63
- package/src/components/buttons-and-links.stories.mdx +0 -55
- package/src/components/card/card.jsx +0 -51
- package/src/components/card/card.module.less +0 -48
- package/src/components/card/card.stories.jsx +0 -39
- package/src/components/check-box/check-box.jsx +0 -92
- package/src/components/check-box/check-box.module.less +0 -101
- package/src/components/check-box/check-box.stories.jsx +0 -27
- package/src/components/color/color.stories-data.jsx +0 -71
- package/src/components/color/color.stories.mdx +0 -37
- package/src/components/dialog/dialog.jsx +0 -77
- package/src/components/dialog/dialog.module.less +0 -76
- package/src/components/divider/divider.jsx +0 -40
- package/src/components/divider/divider.module.less +0 -28
- package/src/components/divider/divider.stories.jsx +0 -50
- package/src/components/drawer/drawer-resize-wrapper.jsx +0 -76
- package/src/components/drawer/drawer-tabs.jsx +0 -44
- package/src/components/drawer/drawer.jsx +0 -161
- package/src/components/drawer/drawer.module.less +0 -217
- package/src/components/drawer/drawer.stories.jsx +0 -296
- package/src/components/empty/empty.jsx +0 -52
- package/src/components/empty/empty.module.less +0 -17
- package/src/components/empty/empty.stories.jsx +0 -26
- package/src/components/file-input/file-input.jsx +0 -101
- package/src/components/file-input/file-input.module.less +0 -3
- package/src/components/file-input/file-input.stories.jsx +0 -109
- package/src/components/form/field.jsx +0 -96
- package/src/components/form/field.stories.jsx +0 -101
- package/src/components/form/form.module.less +0 -30
- package/src/components/form/form.stories.jsx +0 -191
- package/src/components/heading/heading.jsx +0 -105
- package/src/components/heading/heading.module.less +0 -59
- package/src/components/heading/heading.stories.jsx +0 -60
- package/src/components/icon/deprecated-icon.jsx +0 -97
- package/src/components/icon/icon.jsx +0 -71
- package/src/components/icon/icon.module.less +0 -33
- package/src/components/icon/icon.stories.jsx +0 -37
- package/src/components/icon/icons.example.module.less +0 -4
- package/src/components/input/input.jsx +0 -167
- package/src/components/input/input.module.less +0 -94
- package/src/components/input/input.stories.jsx +0 -28
- package/src/components/input-group/input-group-addon/input-group-addon.jsx +0 -36
- package/src/components/input-group/input-group-addon/input-group-addon.module.less +0 -31
- package/src/components/input-group/input-group.jsx +0 -51
- package/src/components/input-group/input-group.module.less +0 -10
- package/src/components/input-group/input-group.stories.jsx +0 -77
- package/src/components/input-validation.stories.mdx +0 -61
- package/src/components/inputs.stories.mdx +0 -201
- package/src/components/label/label.jsx +0 -115
- package/src/components/label/label.module.less +0 -43
- package/src/components/label/label.stories.jsx +0 -60
- package/src/components/layout/column/column.jsx +0 -85
- package/src/components/layout/column/styles.js +0 -45
- package/src/components/layout/column.stories.jsx +0 -60
- package/src/components/layout/examples/afe.stories.jsx +0 -180
- package/src/components/layout/examples/blowout.stories.jsx +0 -68
- package/src/components/layout/examples/casing-loads.stories.jsx +0 -297
- package/src/components/layout/examples/formation.stories.jsx +0 -110
- package/src/components/layout/examples/projects.stories.jsx +0 -108
- package/src/components/layout/examples/reservoirs.stories.jsx +0 -211
- package/src/components/layout/examples/site.stories.jsx +0 -263
- package/src/components/layout/flex/flex.jsx +0 -48
- package/src/components/layout/flex/flex.stories.jsx +0 -59
- package/src/components/layout/form-row/form-row.jsx +0 -15
- package/src/components/layout/form-row/form-row.module.less +0 -11
- package/src/components/layout/grid/grid.jsx +0 -62
- package/src/components/layout/grid/grid.stories.jsx +0 -67
- package/src/components/layout/page/page.jsx +0 -42
- package/src/components/layout/page/page.module.less +0 -27
- package/src/components/layout/page.stories.jsx +0 -93
- package/src/components/layout/placeholder.jsx +0 -2
- package/src/components/layout/print-header/print-header.jsx +0 -22
- package/src/components/layout/print-header/print-header.module.less +0 -9
- package/src/components/layout/row/row.jsx +0 -75
- package/src/components/layout/row/row.module.less +0 -7
- package/src/components/layout/spacer/spacer.jsx +0 -26
- package/src/components/layout/spacer/spacer.stories.jsx +0 -50
- package/src/components/layout-forms.stories.mdx +0 -104
- package/src/components/layout-general.stories.mdx +0 -215
- package/src/components/list/list-row/item-content.jsx +0 -15
- package/src/components/list/list-row/label.jsx +0 -11
- package/src/components/list/list-row/list-heading.jsx +0 -52
- package/src/components/list/list-row/list-row.jsx +0 -128
- package/src/components/list/list-row/list-subheading.jsx +0 -72
- package/src/components/list/list-row/meta-content.jsx +0 -24
- package/src/components/list/list-row/meta-count.jsx +0 -10
- package/src/components/list/list-row/name.jsx +0 -45
- package/src/components/list/list.jsx +0 -276
- package/src/components/list/list.module.less +0 -256
- package/src/components/list/list.stories-data.jsx +0 -287
- package/src/components/list/list.stories.jsx +0 -458
- package/src/components/list/toggle-narrow.jsx +0 -13
- package/src/components/loader/loader.jsx +0 -63
- package/src/components/loader/loader.module.less +0 -63
- package/src/components/loader/loader.stories.jsx +0 -155
- package/src/components/menu/index.js +0 -7
- package/src/components/menu/layer/divider.jsx +0 -4
- package/src/components/menu/layer/heading.jsx +0 -15
- package/src/components/menu/layer/layer.jsx +0 -82
- package/src/components/menu/layer/option.jsx +0 -77
- package/src/components/menu/layer/path.js +0 -44
- package/src/components/menu/layer/placementOptions.js +0 -6
- package/src/components/menu/layer/section.jsx +0 -66
- package/src/components/menu/menu.jsx +0 -359
- package/src/components/menu/menu.module.less +0 -241
- package/src/components/menu/menu.stories-data.jsx +0 -168
- package/src/components/menu/menu.stories.jsx +0 -126
- package/src/components/menu/menu.test.js +0 -58
- package/src/components/menu/trigger/button.jsx +0 -50
- package/src/components/menu/trigger/component.jsx +0 -14
- package/src/components/menu/trigger/text.jsx +0 -25
- package/src/components/menu/trigger/trigger.jsx +0 -86
- package/src/components/message/dismiss.jsx +0 -26
- package/src/components/message/message.jsx +0 -137
- package/src/components/message/message.module.less +0 -114
- package/src/components/message/message.stories.jsx +0 -84
- package/src/components/modal/modal.jsx +0 -50
- package/src/components/modal/modal.module.less +0 -39
- package/src/components/modal/modal.stories.jsx +0 -162
- package/src/components/option-dropdown/heading.jsx +0 -6
- package/src/components/option-dropdown/layer.jsx +0 -81
- package/src/components/option-dropdown/option-dropdown.jsx +0 -53
- package/src/components/option-dropdown/option-dropdown.module.less +0 -50
- package/src/components/option-dropdown/option-dropdown.stories.jsx +0 -35
- package/src/components/option-dropdown/option.jsx +0 -13
- package/src/components/pagination/pagination.jsx +0 -139
- package/src/components/pagination/pagination.module.less +0 -11
- package/src/components/pagination/pagination.stories.jsx +0 -78
- package/src/components/pagination/pagination.test.js +0 -92
- package/src/components/pagination/pagination.viewdata.js +0 -66
- package/src/components/pop-confirm/content.jsx +0 -25
- package/src/components/pop-confirm/pop-confirm.jsx +0 -61
- package/src/components/pop-confirm/pop-confirm.module.less +0 -18
- package/src/components/pop-confirm/pop-confirm.stories.jsx +0 -53
- package/src/components/popover/popover.jsx +0 -112
- package/src/components/popover/popover.module.less +0 -22
- package/src/components/popover/popover.stories.jsx +0 -59
- package/src/components/portal/portal.jsx +0 -16
- package/src/components/portal/portal.stories.jsx +0 -69
- package/src/components/progress-bar/progress-bar.jsx +0 -64
- package/src/components/progress-bar/progress-bar.module.less +0 -64
- package/src/components/progress-bar/progress-bar.stories.jsx +0 -23
- package/src/components/radio-button/radio-button.jsx +0 -139
- package/src/components/radio-button/radio-button.module.less +0 -135
- package/src/components/radio-button/radio-button.stories.jsx +0 -37
- package/src/components/radio-button/radio-input.jsx +0 -52
- package/src/components/select/custom-select/custom-select.jsx +0 -440
- package/src/components/select/custom-select/custom-select.module.less +0 -123
- package/src/components/select/custom-select/custom-select.reducer.js +0 -157
- package/src/components/select/custom-select/layer/heading.jsx +0 -13
- package/src/components/select/custom-select/layer/layer.jsx +0 -73
- package/src/components/select/custom-select/layer/option.jsx +0 -54
- package/src/components/select/custom-select/layer/placementOptions.js +0 -7
- package/src/components/select/custom-select/layer/section.jsx +0 -35
- package/src/components/select/custom-select/trigger/input.jsx +0 -100
- package/src/components/select/custom-select/trigger/trigger.jsx +0 -155
- package/src/components/select/custom-select/trigger/trigger.module.less +0 -289
- package/src/components/select/native-select/native-select.jsx +0 -198
- package/src/components/select/native-select/native-select.module.less +0 -107
- package/src/components/select/select.input.js +0 -146
- package/src/components/select/select.jsx +0 -207
- package/src/components/select/select.stories-data.jsx +0 -92
- package/src/components/select/select.stories.jsx +0 -135
- package/src/components/select/select.test.js +0 -519
- package/src/components/side-bar/container.module.less +0 -29
- package/src/components/side-bar/link.jsx +0 -83
- package/src/components/side-bar/sections.jsx +0 -23
- package/src/components/side-bar/side-bar.jsx +0 -102
- package/src/components/side-bar/side-bar.module.less +0 -137
- package/src/components/side-bar/side-bar.stories.jsx +0 -101
- package/src/components/slider/rc-slider.less +0 -47
- package/src/components/slider/slider-tooltip.jsx +0 -20
- package/src/components/slider/slider.jsx +0 -233
- package/src/components/slider/slider.module.less +0 -40
- package/src/components/slider/slider.stories.jsx +0 -110
- package/src/components/spinner/spinner.jsx +0 -37
- package/src/components/spinner/spinner.module.less +0 -115
- package/src/components/spinner/spinner.stories.jsx +0 -24
- package/src/components/table/cell/cell.jsx +0 -621
- package/src/components/table/cell/cell.module.less +0 -164
- package/src/components/table/footer/footer.jsx +0 -66
- package/src/components/table/footer/footer.module.less +0 -14
- package/src/components/table/helper.js +0 -64
- package/src/components/table/helper.test.js +0 -166
- package/src/components/table/icon/icon.module.less +0 -31
- package/src/components/table/row/expanded-content-row.jsx +0 -16
- package/src/components/table/row/row.jsx +0 -253
- package/src/components/table/row/row.module.less +0 -62
- package/src/components/table/table-scroll-wrapper.jsx +0 -49
- package/src/components/table/table.jsx +0 -234
- package/src/components/table/table.module.less +0 -146
- package/src/components/table/table.stories-data.jsx +0 -875
- package/src/components/table/table.stories.jsx +0 -759
- package/src/components/table/table.test.js +0 -30
- package/src/components/table/table.variables.less +0 -11
- package/src/components/table/table.viewdata.js +0 -26
- package/src/components/table/title/title.jsx +0 -30
- package/src/components/table/title/title.module.less +0 -11
- package/src/components/tabs/content.jsx +0 -14
- package/src/components/tabs/label.jsx +0 -50
- package/src/components/tabs/tabs.jsx +0 -191
- package/src/components/tabs/tabs.module.less +0 -73
- package/src/components/tabs/tabs.stories.jsx +0 -110
- package/src/components/text/text.jsx +0 -64
- package/src/components/text/text.module.less +0 -45
- package/src/components/text/text.stories.jsx +0 -31
- package/src/components/text-link/text-link.jsx +0 -23
- package/src/components/text-link/text-link.stories.jsx +0 -20
- package/src/components/textarea/textarea.jsx +0 -126
- package/src/components/textarea/textarea.module.less +0 -55
- package/src/components/textarea/textarea.stories.jsx +0 -26
- package/src/components/toaster/toaster.jsx +0 -39
- package/src/components/toaster/toaster.less +0 -17
- package/src/components/toaster/toaster.stories.jsx +0 -116
- package/src/components/toggle/toggle.jsx +0 -65
- package/src/components/toggle/toggle.module.less +0 -139
- package/src/components/toggle/toggle.stories.jsx +0 -26
- package/src/components/tooltip/tooltip-layer.jsx +0 -72
- package/src/components/tooltip/tooltip.jsx +0 -108
- package/src/components/tooltip/tooltip.module.less +0 -28
- package/src/components/tooltip/tooltip.stories.jsx +0 -71
- package/src/components/top-bar/element/element.jsx +0 -72
- package/src/components/top-bar/element/link.jsx +0 -29
- package/src/components/top-bar/title.jsx +0 -24
- package/src/components/top-bar/top-bar.jsx +0 -79
- package/src/components/top-bar/top-bar.module.less +0 -190
- package/src/components/top-bar/top-bar.stories.jsx +0 -137
- package/src/components/top-bar/warning.jsx +0 -6
- package/src/components/tree/tree-item.jsx +0 -79
- package/src/components/tree/tree-placeholder.jsx +0 -6
- package/src/components/tree/tree.jsx +0 -129
- package/src/components/tree/tree.module.less +0 -33
- package/src/components/tree/tree.stories-data.jsx +0 -89
- package/src/components/tree/tree.stories.jsx +0 -106
- package/src/docs/components/page/page.jsx +0 -16
- package/src/docs/config/config.js +0 -1
- package/src/docs/html/favicon.png +0 -0
- package/src/docs/html/index.html +0 -11
- package/src/docs/navigation/footer/footer.jsx +0 -48
- package/src/docs/navigation/header/header.jsx +0 -39
- package/src/docs/navigation/header/header.module.less +0 -32
- package/src/docs/navigation/routes/routes.jsx +0 -16
- package/src/docs/start.jsx +0 -12
- package/src/docs/views/main/main.jsx +0 -209
- package/src/docs/views/main/main.module.less +0 -14
- package/src/docs/views/not-found/not-found.jsx +0 -5
- package/src/helpers/disabled-context.js +0 -8
- package/src/helpers/styles.js +0 -68
- package/src/helpers/text.js +0 -6
- package/src/helpers/types.js +0 -5
- package/src/hooks/index.js +0 -3
- package/src/hooks/use-focus.js +0 -11
- package/src/hooks/use-keyboard-event.js +0 -16
- package/src/hooks/use-window-width.js +0 -20
- package/src/images/icons/icon-drop.png +0 -0
- package/src/images/icons/icon-share.png +0 -0
- package/src/images/icons/icons8-junction.svg +0 -4
- package/src/images/logo.png +0 -0
- package/src/images/logo.svg +0 -13
- package/src/images/oliasoft-logo.svg +0 -1
- package/src/style/colors.less +0 -26
- package/src/style/external.less +0 -10
- package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
- package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
- package/src/style/fonts.less +0 -27
- package/src/style/global.less +0 -51
- package/src/style/mixins.less +0 -68
- package/src/style/reset/reset.less +0 -34
- package/src/style/shared.less +0 -25
- package/src/style/theme.dark.less +0 -37
- package/src/style/theme.default.less +0 -74
- package/src/style/variables.less +0 -49
- package/webpack/webpack.common.js +0 -39
- package/webpack/webpack.common.rules.js +0 -102
- package/webpack/webpack.dev.js +0 -22
- package/webpack/webpack.prod.js +0 -23
- package/webpack/webpack.resolve.js +0 -22
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
export const isMulti = (selectedOptions) => selectedOptions instanceof Array;
|
|
2
|
-
|
|
3
|
-
const isEmptyNullOrUndefined = (value) =>
|
|
4
|
-
value === null || value === undefined || value === '';
|
|
5
|
-
|
|
6
|
-
export const standardizeOptions = (options, simple) => {
|
|
7
|
-
return simple && options instanceof Array
|
|
8
|
-
? options.map((o) =>
|
|
9
|
-
typeof o === 'string' || typeof o === 'number'
|
|
10
|
-
? { label: o, value: o }
|
|
11
|
-
: o,
|
|
12
|
-
)
|
|
13
|
-
: options;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const standardizeSelectedOption = (
|
|
17
|
-
standardizedOptions,
|
|
18
|
-
selectedOption,
|
|
19
|
-
) => {
|
|
20
|
-
if (
|
|
21
|
-
selectedOption !== null &&
|
|
22
|
-
typeof selectedOption === 'object' &&
|
|
23
|
-
selectedOption.hasOwnProperty('label') &&
|
|
24
|
-
selectedOption.hasOwnProperty('value')
|
|
25
|
-
) {
|
|
26
|
-
return selectedOption;
|
|
27
|
-
} else {
|
|
28
|
-
const value =
|
|
29
|
-
selectedOption !== null &&
|
|
30
|
-
typeof selectedOption === 'object' &&
|
|
31
|
-
selectedOption.hasOwnProperty('value')
|
|
32
|
-
? selectedOption.value
|
|
33
|
-
: selectedOption;
|
|
34
|
-
const foundFullValue =
|
|
35
|
-
standardizedOptions instanceof Array
|
|
36
|
-
? standardizedOptions
|
|
37
|
-
.filter((o) => o.type !== 'Heading')
|
|
38
|
-
.find((o) => o.value == value /* allow coercion */)
|
|
39
|
-
: undefined;
|
|
40
|
-
return (
|
|
41
|
-
foundFullValue ||
|
|
42
|
-
(isEmptyNullOrUndefined(value) ? undefined : { value, label: value })
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const standardizeSelectedOptions = (
|
|
48
|
-
standardizedOptions,
|
|
49
|
-
selectedOptions,
|
|
50
|
-
) => {
|
|
51
|
-
const isMulti = selectedOptions instanceof Array;
|
|
52
|
-
if (isMulti) {
|
|
53
|
-
return selectedOptions
|
|
54
|
-
.map((selectedOption) =>
|
|
55
|
-
standardizeSelectedOption(standardizedOptions, selectedOption),
|
|
56
|
-
)
|
|
57
|
-
.filter((selectedOption) => selectedOption !== undefined);
|
|
58
|
-
} else {
|
|
59
|
-
return selectedOptions === null
|
|
60
|
-
? undefined
|
|
61
|
-
: standardizeSelectedOption(standardizedOptions, selectedOptions);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const isSimpleOptions = (options) =>
|
|
66
|
-
options instanceof Array &&
|
|
67
|
-
options.some((o) => typeof o === 'string' || typeof o === 'number');
|
|
68
|
-
|
|
69
|
-
export const isSimpleSelectedOptions = (selectedOptions) => {
|
|
70
|
-
return (
|
|
71
|
-
typeof selectedOptions === 'string' ||
|
|
72
|
-
typeof selectedOptions === 'number' ||
|
|
73
|
-
(selectedOptions instanceof Array && isSimpleOptions(selectedOptions))
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const getFirstSelectedOptionIndex = (options, selectedOptions) => {
|
|
78
|
-
const firstSelected =
|
|
79
|
-
selectedOptions instanceof Array
|
|
80
|
-
? selectedOptions.length
|
|
81
|
-
? selectedOptions[0]
|
|
82
|
-
: null
|
|
83
|
-
: selectedOptions;
|
|
84
|
-
const firstSelectedValue =
|
|
85
|
-
firstSelected === null || firstSelected === undefined
|
|
86
|
-
? null
|
|
87
|
-
: typeof firstSelected === 'string' || typeof firstSelected === 'number'
|
|
88
|
-
? firstSelected
|
|
89
|
-
: firstSelected.value;
|
|
90
|
-
const index = options
|
|
91
|
-
.filter((o) => o.type !== 'Heading')
|
|
92
|
-
.findIndex((o) => {
|
|
93
|
-
if (typeof o === 'string' || typeof o === 'number') {
|
|
94
|
-
return o == firstSelectedValue; //allow coercion
|
|
95
|
-
} else {
|
|
96
|
-
return o.value == firstSelectedValue; //allow coercion
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return index === -1 ? null : index;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export const nonExistentValue = (options, selectedOptions) => {
|
|
103
|
-
const isMulti = selectedOptions instanceof Array;
|
|
104
|
-
const selected = isMulti
|
|
105
|
-
? selectedOptions
|
|
106
|
-
: isEmptyNullOrUndefined(selectedOptions)
|
|
107
|
-
? []
|
|
108
|
-
: [selectedOptions];
|
|
109
|
-
return !selected.every((selectedValue) => {
|
|
110
|
-
const found = options.find((o) => o.value === selectedValue.value);
|
|
111
|
-
return found !== undefined;
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const standardizeInputs = (
|
|
116
|
-
options,
|
|
117
|
-
selectedOptions,
|
|
118
|
-
enableAutoScroll,
|
|
119
|
-
checkNonExistentValues,
|
|
120
|
-
) => {
|
|
121
|
-
const cleanedOptions = options instanceof Array ? options : []; // don't crash when options is null or wrong type
|
|
122
|
-
const multi = isMulti(selectedOptions);
|
|
123
|
-
const simpleOptions = isSimpleOptions(cleanedOptions);
|
|
124
|
-
const simpleSelectedOptions = isSimpleSelectedOptions(selectedOptions);
|
|
125
|
-
const standardizedOptions = standardizeOptions(cleanedOptions, simpleOptions);
|
|
126
|
-
const firstSelectedOptionIndex = enableAutoScroll
|
|
127
|
-
? getFirstSelectedOptionIndex(cleanedOptions, selectedOptions)
|
|
128
|
-
: null;
|
|
129
|
-
const standardizedSelectedOptions = standardizeSelectedOptions(
|
|
130
|
-
standardizedOptions,
|
|
131
|
-
selectedOptions,
|
|
132
|
-
simpleSelectedOptions,
|
|
133
|
-
multi,
|
|
134
|
-
);
|
|
135
|
-
const hasNonExistentValue = checkNonExistentValues
|
|
136
|
-
? nonExistentValue(standardizedOptions, standardizedSelectedOptions)
|
|
137
|
-
: false;
|
|
138
|
-
return {
|
|
139
|
-
options: standardizedOptions,
|
|
140
|
-
selectedOptions: standardizedSelectedOptions,
|
|
141
|
-
multi,
|
|
142
|
-
simpleInputs: simpleOptions,
|
|
143
|
-
firstSelectedOptionIndex,
|
|
144
|
-
hasNonExistentValue,
|
|
145
|
-
};
|
|
146
|
-
};
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
|
-
import { NativeSelect } from './native-select/native-select';
|
|
4
|
-
import {
|
|
5
|
-
CustomSelect,
|
|
6
|
-
selectOptionShape,
|
|
7
|
-
selectedOptionsShape,
|
|
8
|
-
} from './custom-select/custom-select';
|
|
9
|
-
import { standardizeInputs } from './select.input';
|
|
10
|
-
|
|
11
|
-
export const Select = (props) => {
|
|
12
|
-
const {
|
|
13
|
-
name,
|
|
14
|
-
options: rawOptions = [],
|
|
15
|
-
value: rawSelectedOptions,
|
|
16
|
-
native,
|
|
17
|
-
onChange,
|
|
18
|
-
deprecatedEventHandler,
|
|
19
|
-
autoScroll = true,
|
|
20
|
-
warning,
|
|
21
|
-
error,
|
|
22
|
-
checkNonExistentValues,
|
|
23
|
-
closeOnOptionActionClick,
|
|
24
|
-
testId,
|
|
25
|
-
} = props;
|
|
26
|
-
const enableAutoScroll = !native && autoScroll === true;
|
|
27
|
-
const {
|
|
28
|
-
multi,
|
|
29
|
-
simpleInputs,
|
|
30
|
-
options,
|
|
31
|
-
selectedOptions,
|
|
32
|
-
firstSelectedOptionIndex,
|
|
33
|
-
hasNonExistentValue,
|
|
34
|
-
} = standardizeInputs(
|
|
35
|
-
rawOptions,
|
|
36
|
-
rawSelectedOptions,
|
|
37
|
-
enableAutoScroll,
|
|
38
|
-
checkNonExistentValues,
|
|
39
|
-
);
|
|
40
|
-
const canUseNative = !multi; //ignore searchable since it's on by default
|
|
41
|
-
const useNative = native && canUseNative;
|
|
42
|
-
if (native && !canUseNative) {
|
|
43
|
-
console.warn('Native select does not support provided props (see stories)');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const nonExistentWarning = 'Value no longer available for re-selection';
|
|
47
|
-
const fullWarning = hasNonExistentValue ? (
|
|
48
|
-
warning ? (
|
|
49
|
-
<div>
|
|
50
|
-
<div>{nonExistentWarning}</div>
|
|
51
|
-
<div>{warning}</div>
|
|
52
|
-
</div>
|
|
53
|
-
) : (
|
|
54
|
-
nonExistentWarning
|
|
55
|
-
)
|
|
56
|
-
) : (
|
|
57
|
-
warning
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const fullError =
|
|
61
|
-
hasNonExistentValue && error ? (
|
|
62
|
-
<div>
|
|
63
|
-
<div>{nonExistentWarning}</div>
|
|
64
|
-
<div>{error}</div>
|
|
65
|
-
</div>
|
|
66
|
-
) : (
|
|
67
|
-
error
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const onChangeSelectedValue = (evt, selectedOptions) => {
|
|
71
|
-
if (deprecatedEventHandler) {
|
|
72
|
-
const newSelectedOptions = multi
|
|
73
|
-
? selectedOptions.map((o) => (simpleInputs ? o.value : o))
|
|
74
|
-
: simpleInputs
|
|
75
|
-
? selectedOptions.value
|
|
76
|
-
: selectedOptions;
|
|
77
|
-
onChange(newSelectedOptions);
|
|
78
|
-
} else {
|
|
79
|
-
/*
|
|
80
|
-
- For React synthetic events, mutate the values and forward the event
|
|
81
|
-
- For native (keyboard) events, clone the enumerable properties and forward
|
|
82
|
-
- Explanation:
|
|
83
|
-
https://gitlab.com/oliasoft-open-source/react-ui-library/-/issues/77
|
|
84
|
-
*/
|
|
85
|
-
const isSyntheticEvent = !(evt instanceof Event);
|
|
86
|
-
const value = multi ? selectedOptions : selectedOptions.value;
|
|
87
|
-
if (isSyntheticEvent) {
|
|
88
|
-
evt.target.name = name;
|
|
89
|
-
evt.target.value = value;
|
|
90
|
-
if (!multi) {
|
|
91
|
-
evt.target.label = selectedOptions.label;
|
|
92
|
-
}
|
|
93
|
-
onChange(evt);
|
|
94
|
-
} else {
|
|
95
|
-
onChange({
|
|
96
|
-
...evt,
|
|
97
|
-
target: {
|
|
98
|
-
...evt.target,
|
|
99
|
-
name,
|
|
100
|
-
value,
|
|
101
|
-
...(!multi && { label: selectedOptions.label }),
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
return useNative ? (
|
|
109
|
-
<NativeSelect
|
|
110
|
-
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
|
111
|
-
options={options}
|
|
112
|
-
selectedOption={selectedOptions}
|
|
113
|
-
onChange={onChangeSelectedValue}
|
|
114
|
-
hasNonExistentValue={hasNonExistentValue}
|
|
115
|
-
warning={fullWarning}
|
|
116
|
-
error={fullError}
|
|
117
|
-
testId={testId}
|
|
118
|
-
/>
|
|
119
|
-
) : (
|
|
120
|
-
<CustomSelect
|
|
121
|
-
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
|
122
|
-
options={options}
|
|
123
|
-
selectedOptions={selectedOptions}
|
|
124
|
-
onChange={onChangeSelectedValue}
|
|
125
|
-
multi={multi}
|
|
126
|
-
firstSelectedOptionIndex={firstSelectedOptionIndex}
|
|
127
|
-
warning={fullWarning}
|
|
128
|
-
error={fullError}
|
|
129
|
-
testId={testId}
|
|
130
|
-
closeOnOptionActionClick={closeOnOptionActionClick}
|
|
131
|
-
/>
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
Select.defaultProps = {
|
|
136
|
-
autoLayerWidth: false,
|
|
137
|
-
borderRadius: null,
|
|
138
|
-
clearable: false,
|
|
139
|
-
disabled: false,
|
|
140
|
-
error: null,
|
|
141
|
-
firstSelectedOptionIndex: null,
|
|
142
|
-
groupOrder: null,
|
|
143
|
-
isInTable: false,
|
|
144
|
-
multi: false,
|
|
145
|
-
onBlur: () => {},
|
|
146
|
-
onChange: () => {},
|
|
147
|
-
onCreate: null,
|
|
148
|
-
onFocus: () => {},
|
|
149
|
-
right: false,
|
|
150
|
-
searchable: true,
|
|
151
|
-
selectedOption: null,
|
|
152
|
-
selectedOptions: null,
|
|
153
|
-
small: false,
|
|
154
|
-
tabIndex: 0,
|
|
155
|
-
tooltip: null,
|
|
156
|
-
warning: null,
|
|
157
|
-
width: null,
|
|
158
|
-
checkNonExistentValues: true,
|
|
159
|
-
closeOnOptionActionClick: true,
|
|
160
|
-
testId: undefined,
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const SelectShape = {
|
|
164
|
-
name: PropTypes.string,
|
|
165
|
-
disabled: PropTypes.bool,
|
|
166
|
-
error: PropTypes.oneOfType([
|
|
167
|
-
PropTypes.string,
|
|
168
|
-
PropTypes.number,
|
|
169
|
-
PropTypes.node,
|
|
170
|
-
]),
|
|
171
|
-
warning: PropTypes.oneOfType([
|
|
172
|
-
PropTypes.string,
|
|
173
|
-
PropTypes.number,
|
|
174
|
-
PropTypes.node,
|
|
175
|
-
]),
|
|
176
|
-
tooltip: PropTypes.oneOfType([
|
|
177
|
-
PropTypes.string,
|
|
178
|
-
PropTypes.number,
|
|
179
|
-
PropTypes.node,
|
|
180
|
-
]),
|
|
181
|
-
options: PropTypes.arrayOf(selectOptionShape).isRequired,
|
|
182
|
-
value: selectedOptionsShape,
|
|
183
|
-
onChange: PropTypes.func,
|
|
184
|
-
onCreate: PropTypes.func,
|
|
185
|
-
small: PropTypes.bool,
|
|
186
|
-
tabIndex: PropTypes.number,
|
|
187
|
-
width: PropTypes.string,
|
|
188
|
-
autoLayerWidth: PropTypes.bool,
|
|
189
|
-
onFocus: PropTypes.func,
|
|
190
|
-
onBlur: PropTypes.func,
|
|
191
|
-
searchable: PropTypes.bool,
|
|
192
|
-
clearable: PropTypes.bool,
|
|
193
|
-
maxTooltipWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
194
|
-
autoScroll: PropTypes.bool,
|
|
195
|
-
checkNonExistentValues: PropTypes.bool,
|
|
196
|
-
testId: PropTypes.string,
|
|
197
|
-
closeOnOptionActionClick: PropTypes.bool,
|
|
198
|
-
//native select only:
|
|
199
|
-
borderRadius: PropTypes.number,
|
|
200
|
-
//deprecated props:
|
|
201
|
-
deprecatedEventHandler: PropTypes.bool,
|
|
202
|
-
//private props (don't use)
|
|
203
|
-
isInTable: PropTypes.bool,
|
|
204
|
-
right: PropTypes.bool,
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
Select.propTypes = PropTypes.shape(SelectShape).isRequired;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
FaExclamationTriangle,
|
|
4
|
-
FaPencilAlt,
|
|
5
|
-
FaSkull,
|
|
6
|
-
FaTrash,
|
|
7
|
-
} from 'react-icons/fa';
|
|
8
|
-
|
|
9
|
-
export const options = [
|
|
10
|
-
{ label: 'Aardvarks', value: 'termites' },
|
|
11
|
-
{ label: 'Kangaroos', value: 'grass' },
|
|
12
|
-
{ label: 'Monkeys', value: 'bananas', disabled: true },
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export const optionsWithDetails = [
|
|
16
|
-
{ label: 'Kangaroos', value: 'grass', details: '(grass)' },
|
|
17
|
-
{ label: 'Monkeys', value: 'bananas', details: '(bananas)' },
|
|
18
|
-
{ label: 'Possums', value: 'slugs', details: '(slugs)' },
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
export const optionsWithHeadings = [
|
|
22
|
-
{ type: 'Heading', label: 'Large' },
|
|
23
|
-
{ label: 'Aardvarks', value: 'termites' },
|
|
24
|
-
{ label: 'Kangaroos', value: 'grass' },
|
|
25
|
-
{ label: 'Monkeys', value: 'bananas' },
|
|
26
|
-
{ type: 'Heading', label: 'Small' },
|
|
27
|
-
{ label: 'Possums', value: 'slugs' },
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
export const optionsNumeric = [
|
|
31
|
-
{ label: 1, value: 1 },
|
|
32
|
-
{ label: 2, value: 2 },
|
|
33
|
-
{ label: 3, value: 3 },
|
|
34
|
-
{ label: 4, value: 4 },
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export const optionsWithIcons = [
|
|
38
|
-
{
|
|
39
|
-
label: 'Aardvarks',
|
|
40
|
-
value: 'termites',
|
|
41
|
-
},
|
|
42
|
-
{ label: 'Monkeys', value: 'bananas' },
|
|
43
|
-
{
|
|
44
|
-
label: 'Vampires',
|
|
45
|
-
value: 'blood',
|
|
46
|
-
icon: <FaExclamationTriangle color="var(--color-text-warning)" />,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: 'Zombies',
|
|
50
|
-
value: 'brains',
|
|
51
|
-
icon: <FaSkull color="var(--color-text-error)" />,
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
export const actions = [
|
|
56
|
-
{
|
|
57
|
-
label: 'Delete',
|
|
58
|
-
icon: <FaTrash />,
|
|
59
|
-
onClick: () => {},
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
label: 'Rename',
|
|
63
|
-
icon: <FaPencilAlt />,
|
|
64
|
-
onClick: () => {},
|
|
65
|
-
},
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
export const optionsWithActions = [
|
|
69
|
-
{
|
|
70
|
-
label: 'Kangaroos',
|
|
71
|
-
value: 'grass',
|
|
72
|
-
actions,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
label: 'Monkeys',
|
|
76
|
-
value: 'bananas',
|
|
77
|
-
actions,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
label: 'Possums',
|
|
81
|
-
value: 'slugs',
|
|
82
|
-
actions,
|
|
83
|
-
details: '(some details)',
|
|
84
|
-
},
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
export const optionsLong = [...Array(10000).keys()].map((o, i) => ({
|
|
88
|
-
label: Math.random().toString(36).substring(7),
|
|
89
|
-
value: i,
|
|
90
|
-
}));
|
|
91
|
-
|
|
92
|
-
export const optionsSimple = ['Aardvarks', 'Kangaroos', 'Monkeys', 'Possums'];
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Select } from './select';
|
|
3
|
-
import * as storyData from './select.stories-data';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Forms/Select',
|
|
7
|
-
component: Select,
|
|
8
|
-
args: {
|
|
9
|
-
options: storyData.options,
|
|
10
|
-
native: false,
|
|
11
|
-
multi: false,
|
|
12
|
-
disabled: false,
|
|
13
|
-
small: false,
|
|
14
|
-
autoLayerWidth: false,
|
|
15
|
-
clearable: false,
|
|
16
|
-
searchable: true,
|
|
17
|
-
right: false,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const Template = (args) => {
|
|
22
|
-
const { multi, value } = args;
|
|
23
|
-
const [selectedValue, setSelectedValue] = useState(
|
|
24
|
-
value || (multi ? [] : undefined),
|
|
25
|
-
);
|
|
26
|
-
const handleChange = (evt) => {
|
|
27
|
-
const { value } = evt.target;
|
|
28
|
-
setSelectedValue(multi ? value : { value });
|
|
29
|
-
};
|
|
30
|
-
return (
|
|
31
|
-
<Select
|
|
32
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
33
|
-
{...args}
|
|
34
|
-
value={selectedValue}
|
|
35
|
-
onChange={handleChange}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Default = Template.bind({});
|
|
41
|
-
|
|
42
|
-
export const Native = Template.bind({});
|
|
43
|
-
Native.args = { native: true };
|
|
44
|
-
|
|
45
|
-
export const Multiselect = Template.bind({});
|
|
46
|
-
Multiselect.args = { multi: true };
|
|
47
|
-
|
|
48
|
-
export const Empty = Template.bind({});
|
|
49
|
-
Empty.args = { options: [] };
|
|
50
|
-
|
|
51
|
-
export const Clearable = Template.bind({});
|
|
52
|
-
Clearable.args = { clearable: true };
|
|
53
|
-
|
|
54
|
-
export const OptionsWithDetails = Template.bind({});
|
|
55
|
-
OptionsWithDetails.args = { options: storyData.optionsWithDetails };
|
|
56
|
-
|
|
57
|
-
export const NonExistentValue = Template.bind({});
|
|
58
|
-
NonExistentValue.args = { value: { label: 'Vampires', value: 'blood' } };
|
|
59
|
-
|
|
60
|
-
export const CustomPlaceholder = Template.bind({});
|
|
61
|
-
CustomPlaceholder.args = { placeholder: 'Select the best animal...' };
|
|
62
|
-
|
|
63
|
-
export const OptionsWithHeadings = Template.bind({});
|
|
64
|
-
OptionsWithHeadings.args = { options: storyData.optionsWithHeadings };
|
|
65
|
-
|
|
66
|
-
export const OptionsWithIcons = Template.bind({});
|
|
67
|
-
OptionsWithIcons.args = { options: storyData.optionsWithIcons };
|
|
68
|
-
|
|
69
|
-
export const OptionsWithActions = Template.bind({});
|
|
70
|
-
OptionsWithActions.args = { options: storyData.optionsWithActions };
|
|
71
|
-
|
|
72
|
-
export const NotSearchable = Template.bind({});
|
|
73
|
-
NotSearchable.args = { searchable: false };
|
|
74
|
-
|
|
75
|
-
export const Small = Template.bind({});
|
|
76
|
-
Small.args = { small: true };
|
|
77
|
-
|
|
78
|
-
export const RightAligned = Template.bind({});
|
|
79
|
-
RightAligned.args = { right: true };
|
|
80
|
-
|
|
81
|
-
export const AutoWidth = Template.bind({});
|
|
82
|
-
AutoWidth.parameters = {
|
|
83
|
-
docs: {
|
|
84
|
-
description: {
|
|
85
|
-
story: 'Avoid `width: auto` for very long lists in custom selects (slow)',
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
AutoWidth.args = { width: 'auto' };
|
|
90
|
-
|
|
91
|
-
export const AutoLayerWidth = Template.bind({});
|
|
92
|
-
AutoLayerWidth.parameters = {
|
|
93
|
-
docs: {
|
|
94
|
-
description: {
|
|
95
|
-
story:
|
|
96
|
-
'Avoid autoLayerWidth for very long lists in custom selects (slow)',
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
AutoLayerWidth.args = { width: '70px', autoLayerWidth: true };
|
|
101
|
-
|
|
102
|
-
export const FixedWidth = Template.bind({});
|
|
103
|
-
FixedWidth.args = { width: '200px' };
|
|
104
|
-
|
|
105
|
-
export const Tooltip = Template.bind({});
|
|
106
|
-
Tooltip.args = { tooltip: 'Some info' };
|
|
107
|
-
|
|
108
|
-
export const Error = Template.bind({});
|
|
109
|
-
Error.args = { error: 'Some info' };
|
|
110
|
-
|
|
111
|
-
export const Warning = Template.bind({});
|
|
112
|
-
Warning.args = { warning: 'Some info' };
|
|
113
|
-
|
|
114
|
-
export const Disabled = Template.bind({});
|
|
115
|
-
Disabled.args = { disabled: true };
|
|
116
|
-
|
|
117
|
-
export const NumericOptions = Template.bind({});
|
|
118
|
-
NumericOptions.args = { options: storyData.optionsNumeric };
|
|
119
|
-
|
|
120
|
-
export const SimpleOptions = Template.bind({});
|
|
121
|
-
SimpleOptions.args = { options: storyData.optionsSimple };
|
|
122
|
-
|
|
123
|
-
export const VeryLongList = Template.bind({});
|
|
124
|
-
VeryLongList.parameters = {
|
|
125
|
-
docs: {
|
|
126
|
-
description: {
|
|
127
|
-
story:
|
|
128
|
-
'Avoid `width: auto` and autoLayerWidth for very long lists in custom selects (slow). Consider checkNonExistentValues={false}.',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
VeryLongList.args = { options: storyData.optionsLong };
|
|
133
|
-
|
|
134
|
-
export const DeprecatedEventHandler = Template.bind({});
|
|
135
|
-
DeprecatedEventHandler.args = { deprecatedEventHandler: true };
|