@darajs/ui-components 0.4.8
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/LICENSE +201 -0
- package/dist/accordion/accordion-item.d.ts +24 -0
- package/dist/accordion/accordion-item.d.ts.map +1 -0
- package/dist/accordion/accordion-item.js +92 -0
- package/dist/accordion/accordion-item.js.map +1 -0
- package/dist/accordion/accordion.d.ts +32 -0
- package/dist/accordion/accordion.d.ts.map +1 -0
- package/dist/accordion/accordion.js +87 -0
- package/dist/accordion/accordion.js.map +1 -0
- package/dist/badge/badge.d.ts +20 -0
- package/dist/badge/badge.d.ts.map +1 -0
- package/dist/badge/badge.js +42 -0
- package/dist/badge/badge.js.map +1 -0
- package/dist/button/button.d.ts +35 -0
- package/dist/button/button.d.ts.map +1 -0
- package/dist/button/button.js +169 -0
- package/dist/button/button.js.map +1 -0
- package/dist/button-bar/button-bar.d.ts +19 -0
- package/dist/button-bar/button-bar.d.ts.map +1 -0
- package/dist/button-bar/button-bar.js +124 -0
- package/dist/button-bar/button-bar.js.map +1 -0
- package/dist/carousel/carousel.d.ts +23 -0
- package/dist/carousel/carousel.d.ts.map +1 -0
- package/dist/carousel/carousel.js +178 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/chat/chat.d.ts +28 -0
- package/dist/chat/chat.d.ts.map +1 -0
- package/dist/chat/chat.js +182 -0
- package/dist/chat/chat.js.map +1 -0
- package/dist/chat/message.d.ts +28 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +220 -0
- package/dist/chat/message.js.map +1 -0
- package/dist/checkbox/checkbox-group.d.ts +35 -0
- package/dist/checkbox/checkbox-group.d.ts.map +1 -0
- package/dist/checkbox/checkbox-group.js +116 -0
- package/dist/checkbox/checkbox-group.js.map +1 -0
- package/dist/checkbox/checkbox.d.ts +27 -0
- package/dist/checkbox/checkbox.d.ts.map +1 -0
- package/dist/checkbox/checkbox.js +164 -0
- package/dist/checkbox/checkbox.js.map +1 -0
- package/dist/checkbox/tri-state-checkbox.d.ts +22 -0
- package/dist/checkbox/tri-state-checkbox.d.ts.map +1 -0
- package/dist/checkbox/tri-state-checkbox.js +87 -0
- package/dist/checkbox/tri-state-checkbox.js.map +1 -0
- package/dist/code-viewer/code-viewer.d.ts +31 -0
- package/dist/code-viewer/code-viewer.d.ts.map +1 -0
- package/dist/code-viewer/code-viewer.js +115 -0
- package/dist/code-viewer/code-viewer.js.map +1 -0
- package/dist/combo-box/combo-box.d.ts +39 -0
- package/dist/combo-box/combo-box.d.ts.map +1 -0
- package/dist/combo-box/combo-box.js +176 -0
- package/dist/combo-box/combo-box.js.map +1 -0
- package/dist/component-select-list/component-select-list.d.ts +27 -0
- package/dist/component-select-list/component-select-list.d.ts.map +1 -0
- package/dist/component-select-list/component-select-list.js +131 -0
- package/dist/component-select-list/component-select-list.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/context-menu/context-menu.d.ts +24 -0
- package/dist/context-menu/context-menu.d.ts.map +1 -0
- package/dist/context-menu/context-menu.js +116 -0
- package/dist/context-menu/context-menu.js.map +1 -0
- package/dist/datepicker/datepicker-select.d.ts +48 -0
- package/dist/datepicker/datepicker-select.d.ts.map +1 -0
- package/dist/datepicker/datepicker-select.js +219 -0
- package/dist/datepicker/datepicker-select.js.map +1 -0
- package/dist/datepicker/datepicker.d.ts +56 -0
- package/dist/datepicker/datepicker.d.ts.map +1 -0
- package/dist/datepicker/datepicker.js +669 -0
- package/dist/datepicker/datepicker.js.map +1 -0
- package/dist/dropzone/dropzone.d.ts +21 -0
- package/dist/dropzone/dropzone.d.ts.map +1 -0
- package/dist/dropzone/dropzone.js +80 -0
- package/dist/dropzone/dropzone.js.map +1 -0
- package/dist/error-boundary/error-boundary.d.ts +33 -0
- package/dist/error-boundary/error-boundary.d.ts.map +1 -0
- package/dist/error-boundary/error-boundary.js +72 -0
- package/dist/error-boundary/error-boundary.js.map +1 -0
- package/dist/filter/categorical-filter.d.ts +26 -0
- package/dist/filter/categorical-filter.d.ts.map +1 -0
- package/dist/filter/categorical-filter.js +153 -0
- package/dist/filter/categorical-filter.js.map +1 -0
- package/dist/filter/datetime-filter.d.ts +28 -0
- package/dist/filter/datetime-filter.d.ts.map +1 -0
- package/dist/filter/datetime-filter.js +174 -0
- package/dist/filter/datetime-filter.js.map +1 -0
- package/dist/filter/numeric-filter.d.ts +24 -0
- package/dist/filter/numeric-filter.d.ts.map +1 -0
- package/dist/filter/numeric-filter.js +148 -0
- package/dist/filter/numeric-filter.js.map +1 -0
- package/dist/hierarchy-selector/hierarchy-selector.d.ts +31 -0
- package/dist/hierarchy-selector/hierarchy-selector.d.ts.map +1 -0
- package/dist/hierarchy-selector/hierarchy-selector.js +65 -0
- package/dist/hierarchy-selector/hierarchy-selector.js.map +1 -0
- package/dist/hierarchy-selector/node/branch.d.ts +47 -0
- package/dist/hierarchy-selector/node/branch.d.ts.map +1 -0
- package/dist/hierarchy-selector/node/branch.js +132 -0
- package/dist/hierarchy-selector/node/branch.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/input/input.d.ts +44 -0
- package/dist/input/input.d.ts.map +1 -0
- package/dist/input/input.js +91 -0
- package/dist/input/input.js.map +1 -0
- package/dist/jest-setup.d.ts +18 -0
- package/dist/jest-setup.d.ts.map +1 -0
- package/dist/jest-setup.js +18 -0
- package/dist/jest-setup.js.map +1 -0
- package/dist/markdown/markdown.d.ts +18 -0
- package/dist/markdown/markdown.d.ts.map +1 -0
- package/dist/markdown/markdown.js +356 -0
- package/dist/markdown/markdown.js.map +1 -0
- package/dist/modal/modal.d.ts +37 -0
- package/dist/modal/modal.d.ts.map +1 -0
- package/dist/modal/modal.js +121 -0
- package/dist/modal/modal.js.map +1 -0
- package/dist/multiselect/multiselect.d.ts +31 -0
- package/dist/multiselect/multiselect.d.ts.map +1 -0
- package/dist/multiselect/multiselect.js +231 -0
- package/dist/multiselect/multiselect.js.map +1 -0
- package/dist/numeric-input/input-stepper.d.ts +33 -0
- package/dist/numeric-input/input-stepper.d.ts.map +1 -0
- package/dist/numeric-input/input-stepper.js +54 -0
- package/dist/numeric-input/input-stepper.js.map +1 -0
- package/dist/numeric-input/numeric-input.d.ts +42 -0
- package/dist/numeric-input/numeric-input.d.ts.map +1 -0
- package/dist/numeric-input/numeric-input.js +234 -0
- package/dist/numeric-input/numeric-input.js.map +1 -0
- package/dist/progress-bar/progress-bar.d.ts +23 -0
- package/dist/progress-bar/progress-bar.d.ts.map +1 -0
- package/dist/progress-bar/progress-bar.js +90 -0
- package/dist/progress-bar/progress-bar.js.map +1 -0
- package/dist/radio/radio-group.d.ts +19 -0
- package/dist/radio/radio-group.d.ts.map +1 -0
- package/dist/radio/radio-group.js +160 -0
- package/dist/radio/radio-group.js.map +1 -0
- package/dist/search-bar/search-bar.d.ts +34 -0
- package/dist/search-bar/search-bar.d.ts.map +1 -0
- package/dist/search-bar/search-bar.js +39 -0
- package/dist/search-bar/search-bar.js.map +1 -0
- package/dist/sectioned-list/sectioned-list.d.ts +29 -0
- package/dist/sectioned-list/sectioned-list.d.ts.map +1 -0
- package/dist/sectioned-list/sectioned-list.js +205 -0
- package/dist/sectioned-list/sectioned-list.js.map +1 -0
- package/dist/select/select.d.ts +54 -0
- package/dist/select/select.d.ts.map +1 -0
- package/dist/select/select.js +143 -0
- package/dist/select/select.js.map +1 -0
- package/dist/shared/chevron-button.d.ts +13 -0
- package/dist/shared/chevron-button.d.ts.map +1 -0
- package/dist/shared/chevron-button.js +35 -0
- package/dist/shared/chevron-button.js.map +1 -0
- package/dist/shared/dropdown-list.d.ts +34 -0
- package/dist/shared/dropdown-list.d.ts.map +1 -0
- package/dist/shared/dropdown-list.js +33 -0
- package/dist/shared/dropdown-list.js.map +1 -0
- package/dist/shared/list-item.d.ts +35 -0
- package/dist/shared/list-item.d.ts.map +1 -0
- package/dist/shared/list-item.js +69 -0
- package/dist/shared/list-item.js.map +1 -0
- package/dist/slider/slider-inputs.d.ts +36 -0
- package/dist/slider/slider-inputs.d.ts.map +1 -0
- package/dist/slider/slider-inputs.js +88 -0
- package/dist/slider/slider-inputs.js.map +1 -0
- package/dist/slider/slider.d.ts +53 -0
- package/dist/slider/slider.d.ts.map +1 -0
- package/dist/slider/slider.js +273 -0
- package/dist/slider/slider.js.map +1 -0
- package/dist/spinner/spinner.d.ts +19 -0
- package/dist/spinner/spinner.d.ts.map +1 -0
- package/dist/spinner/spinner.js +144 -0
- package/dist/spinner/spinner.js.map +1 -0
- package/dist/switch/sun-icon.d.ts +3 -0
- package/dist/switch/sun-icon.d.ts.map +1 -0
- package/dist/switch/sun-icon.js +24 -0
- package/dist/switch/sun-icon.js.map +1 -0
- package/dist/switch/switch.d.ts +16 -0
- package/dist/switch/switch.d.ts.map +1 -0
- package/dist/switch/switch.js +92 -0
- package/dist/switch/switch.js.map +1 -0
- package/dist/table/cells/action-cell.d.ts +34 -0
- package/dist/table/cells/action-cell.d.ts.map +1 -0
- package/dist/table/cells/action-cell.js +68 -0
- package/dist/table/cells/action-cell.js.map +1 -0
- package/dist/table/cells/datetime-cell.d.ts +12 -0
- package/dist/table/cells/datetime-cell.d.ts.map +1 -0
- package/dist/table/cells/datetime-cell.js +36 -0
- package/dist/table/cells/datetime-cell.js.map +1 -0
- package/dist/table/cells/edit-cell-utils.d.ts +32 -0
- package/dist/table/cells/edit-cell-utils.d.ts.map +1 -0
- package/dist/table/cells/edit-cell-utils.js +2 -0
- package/dist/table/cells/edit-cell-utils.js.map +1 -0
- package/dist/table/cells/edit-input-cell.d.ts +10 -0
- package/dist/table/cells/edit-input-cell.d.ts.map +1 -0
- package/dist/table/cells/edit-input-cell.js +61 -0
- package/dist/table/cells/edit-input-cell.js.map +1 -0
- package/dist/table/cells/edit-select-cell.d.ts +12 -0
- package/dist/table/cells/edit-select-cell.d.ts.map +1 -0
- package/dist/table/cells/edit-select-cell.js +55 -0
- package/dist/table/cells/edit-select-cell.js.map +1 -0
- package/dist/table/filters.d.ts +46 -0
- package/dist/table/filters.d.ts.map +1 -0
- package/dist/table/filters.js +226 -0
- package/dist/table/filters.js.map +1 -0
- package/dist/table/headers/select-header.d.ts +14 -0
- package/dist/table/headers/select-header.d.ts.map +1 -0
- package/dist/table/headers/select-header.js +41 -0
- package/dist/table/headers/select-header.js.map +1 -0
- package/dist/table/options-menu.d.ts +25 -0
- package/dist/table/options-menu.d.ts.map +1 -0
- package/dist/table/options-menu.js +123 -0
- package/dist/table/options-menu.js.map +1 -0
- package/dist/table/render-row.d.ts +25 -0
- package/dist/table/render-row.d.ts.map +1 -0
- package/dist/table/render-row.js +163 -0
- package/dist/table/render-row.js.map +1 -0
- package/dist/table/table.d.ts +95 -0
- package/dist/table/table.d.ts.map +1 -0
- package/dist/table/table.js +422 -0
- package/dist/table/table.js.map +1 -0
- package/dist/table/types.d.ts +30 -0
- package/dist/table/types.d.ts.map +1 -0
- package/dist/table/types.js +2 -0
- package/dist/table/types.js.map +1 -0
- package/dist/tabs/tabs.d.ts +22 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +91 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/textarea/textarea.d.ts +47 -0
- package/dist/textarea/textarea.d.ts.map +1 -0
- package/dist/textarea/textarea.js +121 -0
- package/dist/textarea/textarea.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts +48 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -0
- package/dist/tooltip/tooltip.js +116 -0
- package/dist/tooltip/tooltip.js.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chevron.d.ts +34 -0
- package/dist/utils/chevron.d.ts.map +1 -0
- package/dist/utils/chevron.js +38 -0
- package/dist/utils/chevron.js.map +1 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/label.d.ts +3 -0
- package/dist/utils/label.d.ts.map +1 -0
- package/dist/utils/label.js +24 -0
- package/dist/utils/label.js.map +1 -0
- package/dist/utils/list-styles.d.ts +8 -0
- package/dist/utils/list-styles.d.ts.map +1 -0
- package/dist/utils/list-styles.js +43 -0
- package/dist/utils/list-styles.js.map +1 -0
- package/dist/utils/match-width-to-reference.d.ts +24 -0
- package/dist/utils/match-width-to-reference.d.ts.map +1 -0
- package/dist/utils/match-width-to-reference.js +30 -0
- package/dist/utils/match-width-to-reference.js.map +1 -0
- package/dist/utils/syncKbdHighlightIdx.d.ts +23 -0
- package/dist/utils/syncKbdHighlightIdx.d.ts.map +1 -0
- package/dist/utils/syncKbdHighlightIdx.js +41 -0
- package/dist/utils/syncKbdHighlightIdx.js.map +1 -0
- package/dist/utils/use-infinite-loader.d.ts +32 -0
- package/dist/utils/use-infinite-loader.d.ts.map +1 -0
- package/dist/utils/use-infinite-loader.js +119 -0
- package/dist/utils/use-infinite-loader.js.map +1 -0
- package/dist/utils/use-on-click-outside.d.ts +3 -0
- package/dist/utils/use-on-click-outside.d.ts.map +1 -0
- package/dist/utils/use-on-click-outside.js +36 -0
- package/dist/utils/use-on-click-outside.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { autoUpdate, flip, offset, shift, useFloating, useInteractions, useRole } from '@floating-ui/react';
|
|
19
|
+
import { useCombobox } from 'downshift';
|
|
20
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
21
|
+
import ReactDOM from 'react-dom';
|
|
22
|
+
import styled from '@darajs/styled-components';
|
|
23
|
+
import ChevronButton from '../shared/chevron-button';
|
|
24
|
+
import DropdownList from '../shared/dropdown-list';
|
|
25
|
+
import Tooltip from '../tooltip/tooltip';
|
|
26
|
+
import { matchWidthToReference } from '../utils';
|
|
27
|
+
import { syncKbdHighlightIdx } from '../utils/syncKbdHighlightIdx';
|
|
28
|
+
const { stateChangeTypes } = useCombobox;
|
|
29
|
+
export const Wrapper = styled.div `
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
|
|
32
|
+
width: 100%;
|
|
33
|
+
min-width: 4rem;
|
|
34
|
+
height: 2.5rem;
|
|
35
|
+
|
|
36
|
+
border-radius: ${(props) => (props.isOpen ? '0.25rem 0.25rem 0px 0px' : '0.25rem')};
|
|
37
|
+
|
|
38
|
+
${(props) => {
|
|
39
|
+
if (props.isDisabled) {
|
|
40
|
+
return `
|
|
41
|
+
border: 1px solid ${props.theme.colors.grey2};
|
|
42
|
+
|
|
43
|
+
svg {
|
|
44
|
+
color: ${props.theme.colors.grey2};
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
if (props.isErrored) {
|
|
49
|
+
return `border: 1px solid ${props.theme.colors.error};`;
|
|
50
|
+
}
|
|
51
|
+
return `
|
|
52
|
+
border: 1px solid ${props.isOpen ? props.theme.colors.grey3 : props.theme.colors.grey1};
|
|
53
|
+
:hover {
|
|
54
|
+
border: 1px solid ${props.theme.colors.grey3};
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
}}
|
|
59
|
+
`;
|
|
60
|
+
export const InputWrapper = styled.div `
|
|
61
|
+
display: flex;
|
|
62
|
+
flex: 1 1 auto;
|
|
63
|
+
align-items: center;
|
|
64
|
+
justify-content: space-between;
|
|
65
|
+
|
|
66
|
+
width: calc(100% - 1rem);
|
|
67
|
+
height: 100%;
|
|
68
|
+
padding: 0 0.25rem 0 1rem;
|
|
69
|
+
|
|
70
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey2 : props.theme.colors.text)};
|
|
71
|
+
|
|
72
|
+
background-color: ${(props) => props.theme.colors.grey1};
|
|
73
|
+
border: none;
|
|
74
|
+
border-radius: ${(props) => (props.isOpen ? '0.25rem 0.25rem 0px 0px' : '0.25rem')};
|
|
75
|
+
|
|
76
|
+
:hover {
|
|
77
|
+
background-color: ${(props) => (props.disabled ? props.theme.colors.grey1 : props.theme.colors.grey2)};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
svg {
|
|
81
|
+
height: 0.8rem;
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
export const Input = styled.input `
|
|
85
|
+
overflow: hidden;
|
|
86
|
+
flex: 1 1 auto;
|
|
87
|
+
|
|
88
|
+
height: 100%;
|
|
89
|
+
margin-right: 0.5rem;
|
|
90
|
+
padding: 0;
|
|
91
|
+
|
|
92
|
+
font-size: ${(props) => (props.size ? `${props.size}rem` : props.theme.font.size)};
|
|
93
|
+
font-weight: 300;
|
|
94
|
+
color: ${(props) => props.theme.colors.text};
|
|
95
|
+
text-align: left;
|
|
96
|
+
text-overflow: ellipsis;
|
|
97
|
+
white-space: nowrap;
|
|
98
|
+
|
|
99
|
+
background-color: transparent;
|
|
100
|
+
border: none;
|
|
101
|
+
outline: 0;
|
|
102
|
+
|
|
103
|
+
:disabled {
|
|
104
|
+
cursor: not-allowed;
|
|
105
|
+
color: ${(props) => props.theme.colors.grey2};
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
/**
|
|
109
|
+
* A single select combobox component, accepts a list of items to select from and an onSelect handler to listen for
|
|
110
|
+
* changes. Allows to search for item by typing in combo box.
|
|
111
|
+
*
|
|
112
|
+
* @param {ComboBoxProps} props - the component props
|
|
113
|
+
*/
|
|
114
|
+
function ComboBox(props) {
|
|
115
|
+
var _a, _b, _c, _d, _e, _f;
|
|
116
|
+
const [inputValue, setInputValue] = useState((_d = (_b = (_a = props.initialValue) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : (_c = props.selectedItem) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : '');
|
|
117
|
+
const [pendingHighlight, setPendingHighlight] = useState(null);
|
|
118
|
+
const filteredItems = useMemo(() => props.items.filter((item) => { var _a; return inputValue ? (_a = item.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()) : true; }), [inputValue, props.items]);
|
|
119
|
+
const [kbdHighlightIdx, setKbdHighlightIdx] = React.useState();
|
|
120
|
+
const { selectedItem, isOpen, getMenuProps, getInputProps, getToggleButtonProps, getItemProps, setHighlightedIndex, } = useCombobox(Object.assign(Object.assign(Object.assign({ initialIsOpen: props.initialIsOpen, initialSelectedItem: (_e = props.initialValue) !== null && _e !== void 0 ? _e : props.selectedItem, itemToString: (item) => (item ? item.label : ''), items: filteredItems, onInputValueChange: (change) => {
|
|
121
|
+
setInputValue(change.inputValue);
|
|
122
|
+
}, onSelectedItemChange: (changes) => {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
if (props.onSelect) {
|
|
125
|
+
if ((props.selectedItem && ((_a = changes.selectedItem) === null || _a === void 0 ? void 0 : _a.value) !== ((_b = props.selectedItem) === null || _b === void 0 ? void 0 : _b.value)) ||
|
|
126
|
+
!props.selectedItem) {
|
|
127
|
+
props.onSelect(changes.selectedItem);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} }, syncKbdHighlightIdx(setKbdHighlightIdx)), { stateReducer: (state, { changes, type }) => {
|
|
131
|
+
var _a;
|
|
132
|
+
// This resets the input when the dropdown is opened
|
|
133
|
+
if (type === stateChangeTypes.InputFocus ||
|
|
134
|
+
(type === stateChangeTypes.ToggleButtonClick && changes.isOpen) ||
|
|
135
|
+
(type === stateChangeTypes.ControlledPropUpdatedSelectedItem && changes.isOpen)) {
|
|
136
|
+
// This is a hack to change the highlight in the next render cycle so filteredItems had time to update
|
|
137
|
+
setPendingHighlight(changes.selectedItem ? props.items.findIndex((i) => i.value === changes.selectedItem.value) : 0);
|
|
138
|
+
return Object.assign(Object.assign({}, changes), { inputValue: '' });
|
|
139
|
+
}
|
|
140
|
+
// This restores the input value when the dropdown is closed or an item is picked
|
|
141
|
+
if ([
|
|
142
|
+
stateChangeTypes.InputKeyDownEnter,
|
|
143
|
+
stateChangeTypes.ItemClick,
|
|
144
|
+
stateChangeTypes.InputBlur,
|
|
145
|
+
stateChangeTypes.InputKeyDownEscape,
|
|
146
|
+
stateChangeTypes.ToggleButtonClick,
|
|
147
|
+
].includes(type)) {
|
|
148
|
+
return Object.assign(Object.assign({}, changes), { inputValue: ((_a = changes.selectedItem) === null || _a === void 0 ? void 0 : _a.label) || '' });
|
|
149
|
+
}
|
|
150
|
+
return changes;
|
|
151
|
+
} }), ('selectedItem' in props && { selectedItem: props.selectedItem })));
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (isOpen && pendingHighlight !== null) {
|
|
154
|
+
setHighlightedIndex(pendingHighlight);
|
|
155
|
+
setPendingHighlight(null);
|
|
156
|
+
}
|
|
157
|
+
}, [isOpen, pendingHighlight, setHighlightedIndex]);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (props.selectedItem === null) {
|
|
160
|
+
setInputValue('');
|
|
161
|
+
}
|
|
162
|
+
}, [props.selectedItem]);
|
|
163
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
164
|
+
open: isOpen,
|
|
165
|
+
middleware: [flip(), shift(), offset({ crossAxis: 1 }), matchWidthToReference(+2)],
|
|
166
|
+
whileElementsMounted: isOpen ? autoUpdate : undefined,
|
|
167
|
+
});
|
|
168
|
+
const dropdownStyle = useMemo(() => (Object.assign(Object.assign({}, floatingStyles), { marginLeft: -1 })), [floatingStyles]);
|
|
169
|
+
const role = useRole(context, { role: 'combobox' });
|
|
170
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([role]);
|
|
171
|
+
return (_jsx(Tooltip, { content: props.errorMsg, disabled: !props.errorMsg, styling: "error", children: _jsxs(Wrapper, { className: props.className, isDisabled: props.disabled, isErrored: !!props.errorMsg, isOpen: isOpen, style: props.style, children: [_jsxs(InputWrapper, { disabled: props.disabled, isOpen: isOpen, ref: refs.setReference, children: [_jsx(Input, Object.assign({}, getInputProps({
|
|
172
|
+
disabled: props.disabled,
|
|
173
|
+
}), getReferenceProps(), { placeholder: (_f = (selectedItem === null ? props.placeholder : selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.label)) !== null && _f !== void 0 ? _f : props.placeholder, size: props.size })), _jsx(ChevronButton, { disabled: props.disabled, isOpen: isOpen, getToggleButtonProps: getToggleButtonProps })] }), ReactDOM.createPortal(_jsx(DropdownList, { items: filteredItems, getItemProps: getItemProps, getFloatingProps: getFloatingProps, style: dropdownStyle, isOpen: isOpen, getMenuProps: getMenuProps, size: props.size, ref: refs.setFloating, selectedItem: selectedItem, kbdHighlightIdx: kbdHighlightIdx }), document.body)] }) }));
|
|
174
|
+
}
|
|
175
|
+
export default ComboBox;
|
|
176
|
+
//# sourceMappingURL=combo-box.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combo-box.js","sourceRoot":"","sources":["../../src/combo-box/combo-box.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,E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AAG,EAAE,IAAI,CAAC,WAAW,EACrB,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,eAAe,GAClC,EACF,QAAQ,CAAC,IAAI,CAChB,IACK,GACJ,CACb,CAAC;AACN,CAAC;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentSelectItem } from '../types';
|
|
3
|
+
export interface ComponentSelectListProps {
|
|
4
|
+
/** Standard react className property */
|
|
5
|
+
className?: string;
|
|
6
|
+
/** The items to display, each should have a title, subtitle and component */
|
|
7
|
+
items: Array<ComponentSelectItem>;
|
|
8
|
+
/** An optional prop to specify the number of items per row, 3 by default */
|
|
9
|
+
itemsPerRow?: number;
|
|
10
|
+
/** An optional flag for allowing selecting multiple cards, false by default */
|
|
11
|
+
multiSelect?: boolean;
|
|
12
|
+
/** An optional onSelect handler for listening to changes in the selected items */
|
|
13
|
+
onSelect?: (items: Array<string>) => void | Promise<void>;
|
|
14
|
+
/** The optional selected items, can be an array of titles if multiSelect is true otherwise a title */
|
|
15
|
+
selectedItems?: Array<string>;
|
|
16
|
+
/** Pass through of style property to the root element */
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The ComponentSelectList component creates a list of card of selectable cards containing either images or plots.
|
|
21
|
+
* The plot should be passed as a JSX element.
|
|
22
|
+
*
|
|
23
|
+
* @param props the component props
|
|
24
|
+
*/
|
|
25
|
+
declare function ComponentSelectList(props: ComponentSelectListProps): JSX.Element;
|
|
26
|
+
export default ComponentSelectList;
|
|
27
|
+
//# sourceMappingURL=component-select-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-select-list.d.ts","sourceRoot":"","sources":["../../src/component-select-list/component-select-list.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAKhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AA6G/C,MAAM,WAAW,wBAAwB;IACrC,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,KAAK,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kFAAkF;IAClF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,sGAAsG;IACtG,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,yDAAyD;IACzD,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC/B;AAED;;;;;GAKG;AACH,iBAAS,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAuCzE;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import castArray from 'lodash/castArray';
|
|
19
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
20
|
+
import styled from '@darajs/styled-components';
|
|
21
|
+
import { CheckSquare } from '@darajs/ui-icons';
|
|
22
|
+
const Wrapper = styled.div `
|
|
23
|
+
overflow: auto;
|
|
24
|
+
display: grid;
|
|
25
|
+
grid-template-columns: repeat(${(props) => props.itemsPerRow}, 1fr);
|
|
26
|
+
|
|
27
|
+
max-height: 100%;
|
|
28
|
+
margin: 2rem;
|
|
29
|
+
padding: 1rem;
|
|
30
|
+
|
|
31
|
+
color: ${(props) => props.theme.colors.text};
|
|
32
|
+
|
|
33
|
+
background-color: ${(props) => props.theme.colors.grey1};
|
|
34
|
+
border-radius: 0.25rem;
|
|
35
|
+
`;
|
|
36
|
+
const Card = styled.div `
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
|
|
39
|
+
position: relative;
|
|
40
|
+
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
|
|
46
|
+
margin: 1rem;
|
|
47
|
+
padding: 1rem;
|
|
48
|
+
|
|
49
|
+
text-align: center;
|
|
50
|
+
|
|
51
|
+
background-color: ${(props) => props.theme.colors.blue1};
|
|
52
|
+
border: ${(props) => `2px solid ${props.selected ? props.theme.colors.primary : 'transparent'}`};
|
|
53
|
+
border-radius: 0.25rem;
|
|
54
|
+
|
|
55
|
+
:hover {
|
|
56
|
+
border: ${(props) => `2px solid ${props.selected ? props.theme.colors.primary : props.theme.colors.grey3}`};
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
const CardTitle = styled.h2 `
|
|
60
|
+
margin-top: 1rem;
|
|
61
|
+
`;
|
|
62
|
+
const CardSubtitle = styled.h4 `
|
|
63
|
+
margin-top: 1rem;
|
|
64
|
+
color: ${(props) => props.theme.colors.grey6};
|
|
65
|
+
`;
|
|
66
|
+
const StyledCheckSquare = styled(CheckSquare) `
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
|
|
69
|
+
position: absolute;
|
|
70
|
+
z-index: 3;
|
|
71
|
+
top: 10px;
|
|
72
|
+
right: 10px;
|
|
73
|
+
|
|
74
|
+
color: ${(props) => props.theme.colors.primary};
|
|
75
|
+
`;
|
|
76
|
+
const ComponentWrapper = styled.div `
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
display: flex;
|
|
79
|
+
width: 100%;
|
|
80
|
+
`;
|
|
81
|
+
/**
|
|
82
|
+
* Helper function to get the index of the selected item in the items array
|
|
83
|
+
*
|
|
84
|
+
* @param selectedItems the item that is selected
|
|
85
|
+
* @param item the array of items to find the index in
|
|
86
|
+
*/
|
|
87
|
+
function getSelectedIndex(selectedItems, item) {
|
|
88
|
+
return selectedItems.findIndex((selectedItem) => selectedItem === item.title);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Helper function for updating the selected items once a card is clicked
|
|
92
|
+
*
|
|
93
|
+
* @param prevSelections the previously selected card
|
|
94
|
+
* @param item the currently clicked card
|
|
95
|
+
* @param multiSelect flag for allowing multi selection
|
|
96
|
+
*/
|
|
97
|
+
function updateSelectedItems(prevSelections, item, multiSelect) {
|
|
98
|
+
const selectedIndex = getSelectedIndex(prevSelections, item);
|
|
99
|
+
// Remove from selections if item is already selected
|
|
100
|
+
if (selectedIndex > -1) {
|
|
101
|
+
return prevSelections.filter((_, index) => index !== selectedIndex);
|
|
102
|
+
}
|
|
103
|
+
// Add to selection if multi-select is allowed
|
|
104
|
+
if (multiSelect) {
|
|
105
|
+
return [...prevSelections, item.title];
|
|
106
|
+
}
|
|
107
|
+
return [item.title];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The ComponentSelectList component creates a list of card of selectable cards containing either images or plots.
|
|
111
|
+
* The plot should be passed as a JSX element.
|
|
112
|
+
*
|
|
113
|
+
* @param props the component props
|
|
114
|
+
*/
|
|
115
|
+
function ComponentSelectList(props) {
|
|
116
|
+
const [selectedCards, setSelectedCards] = useState(props.selectedItems ? castArray(props.selectedItems) : []);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
setSelectedCards(props.selectedItems ? castArray(props.selectedItems) : []);
|
|
119
|
+
}, [props.selectedItems]);
|
|
120
|
+
const onClick = useCallback((index) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const updatedSelectedCards = updateSelectedItems(selectedCards, props.items[index], props.multiSelect);
|
|
123
|
+
setSelectedCards(updatedSelectedCards);
|
|
124
|
+
(_a = props.onSelect) === null || _a === void 0 ? void 0 : _a.call(props, updatedSelectedCards);
|
|
125
|
+
},
|
|
126
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
|
+
[props.items, props.multiSelect, selectedCards, setSelectedCards]);
|
|
128
|
+
return (_jsx(Wrapper, { className: props.className, itemsPerRow: props.itemsPerRow && props.itemsPerRow > 0 ? props.itemsPerRow : 3, style: props.style, children: props.items.map((item, index) => (_jsxs(Card, { onClick: () => onClick(index), selected: getSelectedIndex(selectedCards, item) > -1, children: [getSelectedIndex(selectedCards, item) > -1 && _jsx(StyledCheckSquare, { size: "2x" }), _jsx(ComponentWrapper, { children: item.component }), _jsx(CardTitle, { children: item.title }), item.subtitle && _jsx(CardSubtitle, { children: item.subtitle })] }, `${item.title}-${index}`))) }));
|
|
129
|
+
}
|
|
130
|
+
export default ComponentSelectList;
|
|
131
|
+
//# sourceMappingURL=component-select-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-select-list.js","sourceRoot":"","sources":["../../src/component-select-list/component-select-list.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,MAAM,OAAO,GAAG,MA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right 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export declare enum Key {
|
|
18
|
+
BACKSPACE = "Backspace",
|
|
19
|
+
CTRL = "Control",
|
|
20
|
+
DOWN = "ArrowDown",
|
|
21
|
+
ENTER = "Enter",
|
|
22
|
+
ESCAPE = "Escape",
|
|
23
|
+
LEFT = "ArrowLeft",
|
|
24
|
+
META = "Meta",
|
|
25
|
+
MINUS = "-",
|
|
26
|
+
PERIOD = ".",
|
|
27
|
+
RIGHT = "ArrowRight",
|
|
28
|
+
SHIFT = "Shift",
|
|
29
|
+
TAB = "Tab",
|
|
30
|
+
UP = "ArrowUp"
|
|
31
|
+
}
|
|
32
|
+
export declare const CONTROL_KEYS: string[];
|
|
33
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,oBAAY,GAAG;IACX,SAAS,cAAc;IACvB,IAAI,YAAY;IAChB,IAAI,cAAc;IAClB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,IAAI,cAAc;IAClB,IAAI,SAAS;IACb,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,KAAK,eAAe;IACpB,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,EAAE,YAAY;CACjB;AAGD,eAAO,MAAM,YAAY,EAAE,MAAM,EAYhC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export var Key;
|
|
18
|
+
(function (Key) {
|
|
19
|
+
Key["BACKSPACE"] = "Backspace";
|
|
20
|
+
Key["CTRL"] = "Control";
|
|
21
|
+
Key["DOWN"] = "ArrowDown";
|
|
22
|
+
Key["ENTER"] = "Enter";
|
|
23
|
+
Key["ESCAPE"] = "Escape";
|
|
24
|
+
Key["LEFT"] = "ArrowLeft";
|
|
25
|
+
Key["META"] = "Meta";
|
|
26
|
+
Key["MINUS"] = "-";
|
|
27
|
+
Key["PERIOD"] = ".";
|
|
28
|
+
Key["RIGHT"] = "ArrowRight";
|
|
29
|
+
Key["SHIFT"] = "Shift";
|
|
30
|
+
Key["TAB"] = "Tab";
|
|
31
|
+
Key["UP"] = "ArrowUp";
|
|
32
|
+
})(Key || (Key = {}));
|
|
33
|
+
// A list of keys for the common controls / modifiers
|
|
34
|
+
export const CONTROL_KEYS = [
|
|
35
|
+
Key.ESCAPE,
|
|
36
|
+
Key.TAB,
|
|
37
|
+
Key.ENTER,
|
|
38
|
+
Key.BACKSPACE,
|
|
39
|
+
Key.CTRL,
|
|
40
|
+
Key.SHIFT,
|
|
41
|
+
Key.UP,
|
|
42
|
+
Key.DOWN,
|
|
43
|
+
Key.LEFT,
|
|
44
|
+
Key.RIGHT,
|
|
45
|
+
Key.META,
|
|
46
|
+
];
|
|
47
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAN,IAAY,GAcX;AAdD,WAAY,GAAG;IACX,8BAAuB,CAAA;IACvB,uBAAgB,CAAA;IAChB,yBAAkB,CAAA;IAClB,sBAAe,CAAA;IACf,wBAAiB,CAAA;IACjB,yBAAkB,CAAA;IAClB,oBAAa,CAAA;IACb,kBAAW,CAAA;IACX,mBAAY,CAAA;IACZ,2BAAoB,CAAA;IACpB,sBAAe,CAAA;IACf,kBAAW,CAAA;IACX,qBAAc,CAAA;AAClB,CAAC,EAdW,GAAG,KAAH,GAAG,QAcd;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,YAAY,GAAa;IAClC,GAAG,CAAC,MAAM;IACV,GAAG,CAAC,GAAG;IACP,GAAG,CAAC,KAAK;IACT,GAAG,CAAC,SAAS;IACb,GAAG,CAAC,IAAI;IACR,GAAG,CAAC,KAAK;IACT,GAAG,CAAC,EAAE;IACN,GAAG,CAAC,IAAI;IACR,GAAG,CAAC,IAAI;IACR,GAAG,CAAC,KAAK;IACT,GAAG,CAAC,IAAI;CACX,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface MenuAction {
|
|
3
|
+
action: () => void;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ContextMenuProps<T> {
|
|
7
|
+
/** An array of actions to show in the context menu */
|
|
8
|
+
actions: Array<MenuAction>;
|
|
9
|
+
/** Pass through children onto the root element */
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
/** Pass through className onto the root element */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Any element props for the root element */
|
|
14
|
+
elementProps?: T;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The ContextMenu is a higher order component that wraps another react component and overrides its context menu to be a
|
|
18
|
+
* custom list of actions, defined by the actions prop.
|
|
19
|
+
*
|
|
20
|
+
* @param Component the component to wrap and draw as the root
|
|
21
|
+
*/
|
|
22
|
+
declare function ContextMenu<T>(Component: React.ComponentType<T> | string): (props: ContextMenuProps<T>) => JSX.Element;
|
|
23
|
+
export default ContextMenu;
|
|
24
|
+
//# sourceMappingURL=context-menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.d.ts","sourceRoot":"","sources":["../../src/context-menu/context-menu.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAOnD,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B,sDAAsD;IACtD,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,YAAY,CAAC,EAAE,CAAC,CAAC;CACpB;AAED;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAgI/G;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { flip, offset, shift, useFloating, useInteractions, useRole } from '@floating-ui/react';
|
|
19
|
+
import React, { useEffect, useState } from 'react';
|
|
20
|
+
import ReactDOM from 'react-dom';
|
|
21
|
+
import { Key } from '../constants';
|
|
22
|
+
import DropdownList from '../shared/dropdown-list';
|
|
23
|
+
/**
|
|
24
|
+
* The ContextMenu is a higher order component that wraps another react component and overrides its context menu to be a
|
|
25
|
+
* custom list of actions, defined by the actions prop.
|
|
26
|
+
*
|
|
27
|
+
* @param Component the component to wrap and draw as the root
|
|
28
|
+
*/
|
|
29
|
+
function ContextMenu(Component) {
|
|
30
|
+
function WrappedContextMenu(props) {
|
|
31
|
+
const [showMenu, setShowMenu] = useState(false);
|
|
32
|
+
// Handle clicking outside the menu or hitting escape and make sure the menu closes.
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const keyHandler = (e) => {
|
|
35
|
+
if (e.key === Key.ESCAPE) {
|
|
36
|
+
setShowMenu(false);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const mouseHandler = () => {
|
|
40
|
+
setShowMenu(false);
|
|
41
|
+
};
|
|
42
|
+
if (showMenu) {
|
|
43
|
+
document.addEventListener('keydown', keyHandler);
|
|
44
|
+
document.addEventListener('click', mouseHandler);
|
|
45
|
+
document.addEventListener('contextmenu', mouseHandler);
|
|
46
|
+
}
|
|
47
|
+
return () => {
|
|
48
|
+
document.removeEventListener('keydown', keyHandler);
|
|
49
|
+
document.removeEventListener('click', mouseHandler);
|
|
50
|
+
document.removeEventListener('contextmenu', mouseHandler);
|
|
51
|
+
};
|
|
52
|
+
}, [showMenu]);
|
|
53
|
+
// Set a timer on opening the dropdown before it can be closed, prevents first menu item being selected
|
|
54
|
+
// immediately, but lets user select action with the mouse up if they want to.
|
|
55
|
+
const [canClose, setCanClose] = useState(true);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (showMenu) {
|
|
58
|
+
setCanClose(false);
|
|
59
|
+
const timeout = setTimeout(() => {
|
|
60
|
+
setCanClose(true);
|
|
61
|
+
}, 300);
|
|
62
|
+
return () => {
|
|
63
|
+
setCanClose(true);
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, [showMenu]);
|
|
68
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
69
|
+
open: showMenu,
|
|
70
|
+
placement: 'bottom-start',
|
|
71
|
+
middleware: [
|
|
72
|
+
offset({
|
|
73
|
+
mainAxis: 4,
|
|
74
|
+
alignmentAxis: 4,
|
|
75
|
+
}),
|
|
76
|
+
shift(),
|
|
77
|
+
flip(),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
const onContextMenu = (e) => {
|
|
81
|
+
// dispatch event of a right click to close other context menu in the page
|
|
82
|
+
document.dispatchEvent(new Event('contextmenu'));
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
refs.setReference({
|
|
86
|
+
getBoundingClientRect: () => ({
|
|
87
|
+
x: e.clientX,
|
|
88
|
+
y: e.clientY,
|
|
89
|
+
width: 0,
|
|
90
|
+
height: 0,
|
|
91
|
+
top: e.clientY,
|
|
92
|
+
right: e.clientX,
|
|
93
|
+
bottom: e.clientY,
|
|
94
|
+
left: e.clientX,
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
setShowMenu(true);
|
|
98
|
+
};
|
|
99
|
+
const onAction = React.useCallback((action) => {
|
|
100
|
+
if (canClose) {
|
|
101
|
+
setShowMenu(false);
|
|
102
|
+
action.action();
|
|
103
|
+
}
|
|
104
|
+
}, [canClose]);
|
|
105
|
+
const role = useRole(context, { role: 'menu' });
|
|
106
|
+
const { getFloatingProps } = useInteractions([role]);
|
|
107
|
+
const dropdownStyle = React.useMemo(() => (Object.assign(Object.assign({}, floatingStyles), { 'overflow-y': 'auto', minWidth: 150, borderRadius: '0.25rem' })), [floatingStyles]);
|
|
108
|
+
const getItemProps = React.useCallback(({ item }) => ({
|
|
109
|
+
onMouseUp: () => onAction(item),
|
|
110
|
+
}), [onAction]);
|
|
111
|
+
return (_jsxs(_Fragment, { children: [_jsx(Component, Object.assign({}, props.elementProps, { className: props.className, onContextMenu: onContextMenu, children: props.children })), ReactDOM.createPortal(_jsx(DropdownList, { items: props.actions, getItemProps: getItemProps, getFloatingProps: getFloatingProps, style: dropdownStyle, isOpen: showMenu, ref: refs.setFloating }), document.body)] }));
|
|
112
|
+
}
|
|
113
|
+
return WrappedContextMenu;
|
|
114
|
+
}
|
|
115
|
+
export default ContextMenu;
|
|
116
|
+
//# sourceMappingURL=context-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.js","sourceRoot":"","sources":["../../src/context-menu/context-menu.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,QAAQ,MAAM,WAAW,CAAC;AA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AAC,WAAW,GACvB,EACF,QAAQ,CAAC,IAAI,CAChB,IACF,CACN,CAAC;IACN,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC9B,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { Placement } from '@floating-ui/react';
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { InteractiveComponentProps, Item } from '../types';
|
|
20
|
+
export interface SelectProps extends InteractiveComponentProps<Item> {
|
|
21
|
+
/** The left displacement from dropdown the items should show */
|
|
22
|
+
displacement?: number;
|
|
23
|
+
/** A function taking an element for the ref of the dropdown */
|
|
24
|
+
dropdownRef?: (element: any) => void;
|
|
25
|
+
/** className property to put on the select's items and the item wrapper */
|
|
26
|
+
itemClass?: string;
|
|
27
|
+
/** The items to pick from the list. Each should have a label and a value */
|
|
28
|
+
items: Array<Item>;
|
|
29
|
+
/** onClick event. */
|
|
30
|
+
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void | Promise<void>;
|
|
31
|
+
/** An optional onSelect handler for listening to changes in the selected item */
|
|
32
|
+
onSelect?: (item: Item) => void | Promise<void>;
|
|
33
|
+
/** Specify a specific placement for the list */
|
|
34
|
+
placement?: Placement;
|
|
35
|
+
/** Set the selected value to a specific value, will put the component in controlled mode */
|
|
36
|
+
selectedItem?: Item;
|
|
37
|
+
/** Font size in rem to show in the Select */
|
|
38
|
+
size?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A single select dropdown component that has no search capability, accepts a list of items to select from and an
|
|
42
|
+
* onSelect handler to listen for changes in the selection
|
|
43
|
+
*
|
|
44
|
+
* @param {SelectProps} props - the props of the component
|
|
45
|
+
*/
|
|
46
|
+
declare function DatepickerSelect(props: SelectProps): JSX.Element;
|
|
47
|
+
export default DatepickerSelect;
|
|
48
|
+
//# sourceMappingURL=datepicker-select.d.ts.map
|