@darajs/ui-components 1.0.0-a.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/LICENSE +201 -0
- package/dist/accordion/accordion-item.d.ts +25 -0
- package/dist/accordion/accordion-item.d.ts.map +1 -0
- package/dist/accordion/accordion-item.js +90 -0
- package/dist/accordion/accordion-item.js.map +1 -0
- package/dist/accordion/accordion.d.ts +33 -0
- package/dist/accordion/accordion.d.ts.map +1 -0
- package/dist/accordion/accordion.js +86 -0
- package/dist/accordion/accordion.js.map +1 -0
- package/dist/badge/badge.d.ts +21 -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 +123 -0
- package/dist/button-bar/button-bar.js.map +1 -0
- package/dist/carousel/carousel.d.ts +24 -0
- package/dist/carousel/carousel.d.ts.map +1 -0
- package/dist/carousel/carousel.js +175 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/checkbox/checkbox-group.d.ts +36 -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 +28 -0
- package/dist/checkbox/checkbox.d.ts.map +1 -0
- package/dist/checkbox/checkbox.js +162 -0
- package/dist/checkbox/checkbox.js.map +1 -0
- package/dist/checkbox/tri-state-checkbox.d.ts +23 -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/combo-box/combo-box.d.ts +328 -0
- package/dist/combo-box/combo-box.d.ts.map +1 -0
- package/dist/combo-box/combo-box.js +213 -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 +129 -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 +112 -0
- package/dist/context-menu/context-menu.js.map +1 -0
- package/dist/datepicker/datepicker-select.d.ts +50 -0
- package/dist/datepicker/datepicker-select.d.ts.map +1 -0
- package/dist/datepicker/datepicker-select.js +211 -0
- package/dist/datepicker/datepicker-select.js.map +1 -0
- package/dist/datepicker/datepicker.d.ts +57 -0
- package/dist/datepicker/datepicker.d.ts.map +1 -0
- package/dist/datepicker/datepicker.js +608 -0
- package/dist/datepicker/datepicker.js.map +1 -0
- package/dist/dropzone/dropzone.d.ts +20 -0
- package/dist/dropzone/dropzone.d.ts.map +1 -0
- package/dist/dropzone/dropzone.js +77 -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 +27 -0
- package/dist/filter/categorical-filter.d.ts.map +1 -0
- package/dist/filter/categorical-filter.js +150 -0
- package/dist/filter/categorical-filter.js.map +1 -0
- package/dist/filter/datetime-filter.d.ts +29 -0
- package/dist/filter/datetime-filter.d.ts.map +1 -0
- package/dist/filter/datetime-filter.js +196 -0
- package/dist/filter/datetime-filter.js.map +1 -0
- package/dist/filter/numeric-filter.d.ts +25 -0
- package/dist/filter/numeric-filter.d.ts.map +1 -0
- package/dist/filter/numeric-filter.js +146 -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 +133 -0
- package/dist/hierarchy-selector/node/branch.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/input/input.d.ts +58 -0
- package/dist/input/input.d.ts.map +1 -0
- package/dist/input/input.js +102 -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/modal/modal.d.ts +37 -0
- package/dist/modal/modal.d.ts.map +1 -0
- package/dist/modal/modal.js +120 -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 +282 -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 +48 -0
- package/dist/numeric-input/numeric-input.d.ts.map +1 -0
- package/dist/numeric-input/numeric-input.js +199 -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 +88 -0
- package/dist/progress-bar/progress-bar.js.map +1 -0
- package/dist/radio/radio-group.d.ts +20 -0
- package/dist/radio/radio-group.d.ts.map +1 -0
- package/dist/radio/radio-group.js +158 -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 +208 -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 +159 -0
- package/dist/select/select.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 +85 -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 +267 -0
- package/dist/slider/slider.js.map +1 -0
- package/dist/spinner/spinner.d.ts +20 -0
- package/dist/spinner/spinner.d.ts.map +1 -0
- package/dist/spinner/spinner.js +132 -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 +17 -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 +223 -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 +120 -0
- package/dist/table/options-menu.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 +524 -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 +88 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/textarea/textarea.d.ts +45 -0
- package/dist/textarea/textarea.d.ts.map +1 -0
- package/dist/textarea/textarea.js +77 -0
- package/dist/textarea/textarea.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts +46 -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 +66 -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 +40 -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 +12 -0
- package/dist/utils/list-styles.d.ts.map +1 -0
- package/dist/utils/list-styles.js +58 -0
- package/dist/utils/list-styles.js.map +1 -0
- package/dist/utils/same-width-modifier.d.ts +23 -0
- package/dist/utils/same-width-modifier.d.ts.map +1 -0
- package/dist/utils/same-width-modifier.js +17 -0
- package/dist/utils/same-width-modifier.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 +114 -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 +105 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { InteractiveComponentProps, Item } from '../types';
|
|
2
|
+
export interface MultiSelectProps extends InteractiveComponentProps<Array<Item>> {
|
|
3
|
+
/** Whether to open the select dropdown on load or not, defaults to false */
|
|
4
|
+
initialIsOpen?: boolean;
|
|
5
|
+
/** The items to pick from the list. Each should have a label and a value */
|
|
6
|
+
items: Array<Item>;
|
|
7
|
+
/** An optional property for the maximum number of rows of items to show. Defaults to 3 */
|
|
8
|
+
maxRows?: number;
|
|
9
|
+
/** An optional max-width property in pixels or a percentage of parent. Defaults to 100% */
|
|
10
|
+
maxWidth?: string;
|
|
11
|
+
/** An optional onSelect handler for listening to changes in the selected item */
|
|
12
|
+
onSelect?: (item: Array<Item>) => void | Promise<void>;
|
|
13
|
+
/** An optional handler when the search term is changed */
|
|
14
|
+
onTermChange?: (term: string) => void | Promise<void>;
|
|
15
|
+
/** An optional placeholder for the input field to display when nothing is selected, defaults to '' */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Set the selected items to a specific value, will put the component in controlled mode */
|
|
18
|
+
selectedItems?: Item[];
|
|
19
|
+
/** Font size in rem to show in the Select */
|
|
20
|
+
size?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A multiselect select combobox component, accepts a list of items to select from and an onSelect handler to listen for
|
|
24
|
+
* changes. Renders currently selected items as list of tags which have a cross for removing them. Component will expand
|
|
25
|
+
* vertically to fit all selected items.
|
|
26
|
+
*
|
|
27
|
+
* @param {MultiSelectProps} props - the component props
|
|
28
|
+
*/
|
|
29
|
+
declare function MultiSelect({ maxWidth, maxRows, ...props }: MultiSelectProps): JSX.Element;
|
|
30
|
+
export default MultiSelect;
|
|
31
|
+
//# sourceMappingURL=multiselect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiselect.d.ts","sourceRoot":"","sources":["../../src/multiselect/multiselect.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAuM3D,MAAM,WAAW,gBAAiB,SAAQ,yBAAyB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5E,4EAA4E;IAC5E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,4EAA4E;IAC5E,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,0DAA0D;IAC1D,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC;IACvB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,iBAAS,WAAW,CAAC,EAAE,QAAiB,EAAE,OAAW,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAgKhG;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { createElement as _createElement } from "react";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
/**
|
|
15
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
16
|
+
*
|
|
17
|
+
*
|
|
18
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License.
|
|
20
|
+
* You may obtain a copy of the License at
|
|
21
|
+
*
|
|
22
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
+
*
|
|
24
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
25
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
26
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
27
|
+
* See the License for the specific language governing permissions and
|
|
28
|
+
* limitations under the License.
|
|
29
|
+
*/
|
|
30
|
+
import { useCombobox, useMultipleSelection } from 'downshift';
|
|
31
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
32
|
+
import ReactDOM from 'react-dom';
|
|
33
|
+
import { usePopper } from 'react-popper';
|
|
34
|
+
import styled from '@darajs/styled-components';
|
|
35
|
+
import { Cross } from '@darajs/ui-icons';
|
|
36
|
+
import Button from '../button/button';
|
|
37
|
+
import Tooltip from '../tooltip/tooltip';
|
|
38
|
+
import { Chevron, List, ListItem, sameWidthModifier } from '../utils';
|
|
39
|
+
const { stateChangeTypes } = useCombobox;
|
|
40
|
+
const tagHeight = 2;
|
|
41
|
+
const tagTopMargin = 0.5;
|
|
42
|
+
const Wrapper = styled.div `
|
|
43
|
+
display: inline-flex;
|
|
44
|
+
${(props) => {
|
|
45
|
+
if (props.isDisabled) {
|
|
46
|
+
return `
|
|
47
|
+
cursor: not-allowed;
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
}}
|
|
51
|
+
|
|
52
|
+
width: 100%;
|
|
53
|
+
max-width: ${(props) => props.maxWidth};
|
|
54
|
+
max-height: ${(props) => props.maxRows * (tagHeight + tagTopMargin)}rem;
|
|
55
|
+
|
|
56
|
+
border-radius: ${(props) => (props.isOpen ? '0.25rem 0.25rem 0rem 0rem' : '0.25rem')};
|
|
57
|
+
`;
|
|
58
|
+
const InputWrapper = styled.div `
|
|
59
|
+
display: flex;
|
|
60
|
+
flex: 1 1 auto;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: space-between;
|
|
63
|
+
|
|
64
|
+
width: 100%;
|
|
65
|
+
min-width: 10rem;
|
|
66
|
+
min-height: 2.5rem;
|
|
67
|
+
margin-right: 0.25rem;
|
|
68
|
+
padding: 0.25rem 0.5rem 0.25rem 1rem;
|
|
69
|
+
|
|
70
|
+
color: ${(props) => (props.isDisabled ? 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 0rem 0rem' : '0.25rem')};
|
|
75
|
+
|
|
76
|
+
:hover {
|
|
77
|
+
background-color: ${(props) => (props.isDisabled ? props.theme.colors.grey1 : props.theme.colors.grey2)};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
svg {
|
|
81
|
+
height: 0.8rem;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
${(props) => {
|
|
85
|
+
if (props.isDisabled) {
|
|
86
|
+
return `
|
|
87
|
+
border: 1px solid ${props.theme.colors.grey1};
|
|
88
|
+
|
|
89
|
+
svg {
|
|
90
|
+
color: ${props.theme.colors.grey2};
|
|
91
|
+
cursor: not-allowed;
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
if (props.isErrored) {
|
|
96
|
+
return `border: 1px solid ${props.theme.colors.error};`;
|
|
97
|
+
}
|
|
98
|
+
return `
|
|
99
|
+
border: 1px solid ${props.isOpen ? props.theme.colors.grey3 : props.theme.colors.grey1};
|
|
100
|
+
:hover {
|
|
101
|
+
border: 1px solid ${props.theme.colors.grey3};
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
}}
|
|
106
|
+
`;
|
|
107
|
+
const Input = styled.input `
|
|
108
|
+
overflow: hidden;
|
|
109
|
+
flex: 1 1 auto;
|
|
110
|
+
|
|
111
|
+
height: 100%;
|
|
112
|
+
margin-right: 0.5rem;
|
|
113
|
+
padding: 0rem;
|
|
114
|
+
|
|
115
|
+
font-size: ${(props) => (props.size ? `${props.size}rem` : props.theme.font.size)};
|
|
116
|
+
font-weight: 300;
|
|
117
|
+
color: ${(props) => props.theme.colors.grey6};
|
|
118
|
+
text-align: left;
|
|
119
|
+
text-overflow: ellipsis;
|
|
120
|
+
white-space: nowrap;
|
|
121
|
+
|
|
122
|
+
background-color: transparent;
|
|
123
|
+
border: none;
|
|
124
|
+
outline: 0;
|
|
125
|
+
|
|
126
|
+
:disabled {
|
|
127
|
+
cursor: not-allowed;
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
const TagWrapper = styled.div `
|
|
131
|
+
overflow: auto;
|
|
132
|
+
display: flex;
|
|
133
|
+
flex-wrap: wrap;
|
|
134
|
+
gap: 0.5rem;
|
|
135
|
+
align-items: center;
|
|
136
|
+
|
|
137
|
+
width: 100%;
|
|
138
|
+
max-height: ${(props) => props.maxRows * (tagHeight + tagTopMargin) - 0.25}rem;
|
|
139
|
+
`;
|
|
140
|
+
const Tag = styled.span `
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
display: flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
|
|
145
|
+
height: ${tagHeight}rem;
|
|
146
|
+
padding: 0 0.75rem;
|
|
147
|
+
|
|
148
|
+
font-size: 0.875rem;
|
|
149
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey3 : props.theme.colors.text)};
|
|
150
|
+
|
|
151
|
+
background-color: ${(props) => (props.disabled ? props.theme.colors.grey3 : props.theme.colors.blue3)};
|
|
152
|
+
border: 1px solid ${(props) => props.theme.colors.primary};
|
|
153
|
+
border-radius: 1rem;
|
|
154
|
+
|
|
155
|
+
svg {
|
|
156
|
+
width: 0.85rem;
|
|
157
|
+
height: 0.85rem;
|
|
158
|
+
margin-left: 0.25rem;
|
|
159
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey3 : props.theme.colors.text)};
|
|
160
|
+
|
|
161
|
+
:hover {
|
|
162
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey3 : props.theme.colors.primary)};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
const TagText = styled.span `
|
|
167
|
+
overflow: hidden;
|
|
168
|
+
text-overflow: ellipsis;
|
|
169
|
+
white-space: nowrap;
|
|
170
|
+
`;
|
|
171
|
+
const NoItemsLabel = styled.span `
|
|
172
|
+
display: flex;
|
|
173
|
+
flex: 1 1 auto;
|
|
174
|
+
align-items: center;
|
|
175
|
+
justify-content: center;
|
|
176
|
+
|
|
177
|
+
height: 2rem;
|
|
178
|
+
|
|
179
|
+
font-size: 1rem;
|
|
180
|
+
color: ${(props) => props.theme.colors.grey4};
|
|
181
|
+
|
|
182
|
+
background-color: ${(props) => props.theme.colors.blue1};
|
|
183
|
+
`;
|
|
184
|
+
const DropdownList = styled(List) `
|
|
185
|
+
border-radius: 0px 0px 0.25rem 0.25rem;
|
|
186
|
+
outline: 0;
|
|
187
|
+
box-shadow: ${(props) => props.theme.shadow.light};
|
|
188
|
+
`;
|
|
189
|
+
const ChevronButton = styled(Button).attrs((attrs) => (Object.assign(Object.assign({}, attrs), { styling: 'ghost' }))) `
|
|
190
|
+
min-width: 0;
|
|
191
|
+
height: auto;
|
|
192
|
+
margin: 0;
|
|
193
|
+
padding: 0 0.25rem;
|
|
194
|
+
|
|
195
|
+
background-color: transparent !important;
|
|
196
|
+
`;
|
|
197
|
+
/**
|
|
198
|
+
* A multiselect select combobox component, accepts a list of items to select from and an onSelect handler to listen for
|
|
199
|
+
* changes. Renders currently selected items as list of tags which have a cross for removing them. Component will expand
|
|
200
|
+
* vertically to fit all selected items.
|
|
201
|
+
*
|
|
202
|
+
* @param {MultiSelectProps} props - the component props
|
|
203
|
+
*/
|
|
204
|
+
function MultiSelect(_a) {
|
|
205
|
+
var _b, _c;
|
|
206
|
+
var { maxWidth = '100%', maxRows = 3 } = _a, props = __rest(_a, ["maxWidth", "maxRows"]);
|
|
207
|
+
const referenceElement = useRef(null);
|
|
208
|
+
const popperElement = useRef(null);
|
|
209
|
+
const { styles, attributes, update } = usePopper(referenceElement.current, popperElement.current, {
|
|
210
|
+
modifiers: [sameWidthModifier],
|
|
211
|
+
placement: 'bottom-start',
|
|
212
|
+
});
|
|
213
|
+
const [inputValue, setInputValue] = useState('');
|
|
214
|
+
const { getSelectedItemProps, getDropdownProps, addSelectedItem, removeSelectedItem, selectedItems } = useMultipleSelection(Object.assign({ initialSelectedItems: (_b = props.initialValue) !== null && _b !== void 0 ? _b : [], onSelectedItemsChange: (changes) => {
|
|
215
|
+
if (props.onSelect) {
|
|
216
|
+
props.onSelect(changes.selectedItems);
|
|
217
|
+
}
|
|
218
|
+
update();
|
|
219
|
+
} }, ('selectedItems' in props && { selectedItems: props.selectedItems })));
|
|
220
|
+
const onTermChange = useCallback((term) => {
|
|
221
|
+
setInputValue(term);
|
|
222
|
+
if (props.onTermChange) {
|
|
223
|
+
props.onTermChange(term);
|
|
224
|
+
}
|
|
225
|
+
}, []);
|
|
226
|
+
// If there is a term change function passed in then don't filter locally
|
|
227
|
+
const filteredItems = props.onTermChange
|
|
228
|
+
? props.items
|
|
229
|
+
: props.items.filter((item) => { var _a; return !selectedItems.includes(item) && ((_a = item.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(inputValue.toLowerCase())); });
|
|
230
|
+
const { isOpen, getMenuProps, getInputProps, highlightedIndex, getItemProps, openMenu, getToggleButtonProps } = useCombobox({
|
|
231
|
+
defaultHighlightedIndex: -1,
|
|
232
|
+
initialIsOpen: props.initialIsOpen,
|
|
233
|
+
inputValue,
|
|
234
|
+
itemToString: (item) => (item === null || item === void 0 ? void 0 : item.label) || '',
|
|
235
|
+
items: filteredItems,
|
|
236
|
+
onStateChange: ({ inputValue: internalInputVal, selectedItem, type }) => {
|
|
237
|
+
if (type === stateChangeTypes.InputChange) {
|
|
238
|
+
onTermChange(internalInputVal);
|
|
239
|
+
}
|
|
240
|
+
if ([
|
|
241
|
+
stateChangeTypes.InputKeyDownEnter,
|
|
242
|
+
stateChangeTypes.ItemClick,
|
|
243
|
+
stateChangeTypes.InputBlur,
|
|
244
|
+
].includes(type)) {
|
|
245
|
+
if (selectedItem) {
|
|
246
|
+
onTermChange('');
|
|
247
|
+
addSelectedItem(selectedItem);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
selectedItem: null,
|
|
252
|
+
stateReducer: (state, { changes, type }) => {
|
|
253
|
+
if (type === stateChangeTypes.ItemClick || type === stateChangeTypes.InputKeyDownEnter) {
|
|
254
|
+
return Object.assign(Object.assign({}, changes), { isOpen: true });
|
|
255
|
+
}
|
|
256
|
+
return changes;
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
// After the dropdown is opened, trigger an update of it's position, so it positions correctly.
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
if (isOpen && update) {
|
|
262
|
+
update();
|
|
263
|
+
}
|
|
264
|
+
}, [isOpen, update]);
|
|
265
|
+
// Both downshift and popper want a ref to the reference element and popper element, the following blocks combine
|
|
266
|
+
// these refs into a single function that can be applied to the elements
|
|
267
|
+
const menuProps = getMenuProps();
|
|
268
|
+
const setMenuRef = menuProps.ref;
|
|
269
|
+
delete menuProps.ref;
|
|
270
|
+
const setMenuReference = (value) => {
|
|
271
|
+
setMenuRef(value);
|
|
272
|
+
popperElement.current = value;
|
|
273
|
+
};
|
|
274
|
+
return (_jsxs(Wrapper, { className: props.className, isDisabled: props.disabled, isOpen: isOpen, maxRows: maxRows, maxWidth: maxWidth, style: props.style, children: [_jsx(Tooltip, { content: props.errorMsg, disabled: !props.errorMsg, styling: "error", children: _jsxs(InputWrapper, { isDisabled: props.disabled, isOpen: isOpen, ref: referenceElement, children: [_jsxs(TagWrapper, { maxRows: maxRows, children: [selectedItems.map((selectedItem, index) => (_jsxs(Tag, Object.assign({ disabled: props.disabled }, getSelectedItemProps({ index, selectedItem }), { children: [_jsx(TagText, { children: selectedItem.label }), _jsx(Cross, { asButton: true, onClick: (e) => {
|
|
275
|
+
// See https://github.com/downshift-js/downshift/issues/1188
|
|
276
|
+
e.stopPropagation();
|
|
277
|
+
return removeSelectedItem(selectedItem);
|
|
278
|
+
} })] }), selectedItem.value))), _jsx(Input, Object.assign({}, getInputProps(getDropdownProps({ preventKeyAction: isOpen })), { disabled: props.disabled, onFocus: openMenu, placeholder: props.placeholder, size: props.size }))] }), _jsx(ChevronButton, Object.assign({}, getToggleButtonProps(), { children: _jsx(Chevron, { disabled: props.disabled, isOpen: isOpen }) }))] }) }), ReactDOM.createPortal(_jsxs(DropdownList, Object.assign({}, menuProps, attributes.popper, { isOpen: isOpen, ref: setMenuReference, style: Object.assign(Object.assign({}, styles.popper), { width: parseFloat((_c = styles.popper) === null || _c === void 0 ? void 0 : _c.width), zIndex: 9999 }), children: [filteredItems.length > 0 &&
|
|
279
|
+
filteredItems.map((item, index) => (_createElement(ListItem, Object.assign({}, getItemProps({ index, item }), { hovered: index === highlightedIndex, key: `item-${index}`, size: props.size, title: item.label }), item.label))), filteredItems.length === 0 && _jsx(NoItemsLabel, { children: "No Items" })] })), document.body)] }));
|
|
280
|
+
}
|
|
281
|
+
export default MultiSelect;
|
|
282
|
+
//# sourceMappingURL=multiselect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiselect.js","sourceRoot":"","sources":["../../src/multiselect/multiselect.tsx"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAmC,WAAW,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MA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E,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAI,IACzC,IACL,GACT,EACT,QAAQ,CAAC,YAAY,CAClB,MAAC,YAAY,oBACL,SAAS,EACT,UAAU,CAAC,MAAM,IACrB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,gBAAgB,EACrB,KAAK,kCACE,MAAM,CAAC,MAAM,KAEhB,KAAK,EAAE,UAAU,CAAC,MAAC,MAAM,CAAC,MAAc,0CAAE,KAAK,CAAC,EAChD,MAAM,EAAE,IAAI,gBAGf,aAAa,CAAC,MAAM,GAAG,CAAC;wBACrB,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAC/B,eAAC,QAAQ,oBACD,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IACjC,OAAO,EAAE,KAAK,KAAK,gBAAgB,EACnC,GAAG,EAAE,QAAQ,KAAK,EAAE,EACpB,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,KAAK,EAAE,IAAI,CAAC,KAAK,KAEhB,IAAI,CAAC,KAAK,CACJ,CACd,CAAC,EACL,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,KAAC,YAAY,2BAAwB,KACzD,EACf,QAAQ,CAAC,IAAI,CAChB,IACK,CACb,CAAC;AACN,CAAC;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { FunctionComponent } from 'react';
|
|
18
|
+
interface InputStepperProps {
|
|
19
|
+
/** property that disables the stepper */
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
/** callback that determines the logic for increasing or decreasing input value */
|
|
22
|
+
step: (value: number) => void;
|
|
23
|
+
/** Optional property to set how many steps the stepper should take */
|
|
24
|
+
stepSkip?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A simple stepper component that can be added to an input component to increase or decrease its value
|
|
28
|
+
*
|
|
29
|
+
* @param props the component props
|
|
30
|
+
*/
|
|
31
|
+
declare const InputStepper: FunctionComponent<InputStepperProps>;
|
|
32
|
+
export default InputStepper;
|
|
33
|
+
//# sourceMappingURL=input-stepper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-stepper.d.ts","sourceRoot":"","sources":["../../src/numeric-input/input-stepper.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAkD1C,UAAU,iBAAiB;IACvB,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,kFAAkF;IAClF,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AAEH,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAgBtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styled from '@darajs/styled-components';
|
|
3
|
+
import { ChevronDown, ChevronUp } from '@darajs/ui-icons';
|
|
4
|
+
import Button from '../button/button';
|
|
5
|
+
const StepperWrapper = styled.div `
|
|
6
|
+
cursor: ${(props) => (props.disabled ? 'not-allowed' : 'pointer')};
|
|
7
|
+
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
justify-content: space-around;
|
|
11
|
+
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
padding: 0.25rem 0rem;
|
|
14
|
+
|
|
15
|
+
border-radius: 0rem 0.25rem 0.25rem 0rem;
|
|
16
|
+
`;
|
|
17
|
+
const StepperButton = styled(Button) `
|
|
18
|
+
min-width: 0.75rem;
|
|
19
|
+
height: max-content;
|
|
20
|
+
padding: 0;
|
|
21
|
+
background-color: transparent !important;
|
|
22
|
+
|
|
23
|
+
svg {
|
|
24
|
+
cursor: ${(props) => (props.disabled ? 'not-allowed' : 'pointer')};
|
|
25
|
+
width: 0.75rem;
|
|
26
|
+
height: 0.75rem;
|
|
27
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey3 : props.theme.colors.grey4)};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:hover:not(:disabled) {
|
|
31
|
+
svg {
|
|
32
|
+
color: ${(props) => props.theme.colors.grey5};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
:active:not(:disabled) {
|
|
37
|
+
svg {
|
|
38
|
+
transform: scale(0.75);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
/**
|
|
43
|
+
* A simple stepper component that can be added to an input component to increase or decrease its value
|
|
44
|
+
*
|
|
45
|
+
* @param props the component props
|
|
46
|
+
*/
|
|
47
|
+
const InputStepper = ({ disabled, step, stepSkip }) => {
|
|
48
|
+
const amountToStep = Math.abs(stepSkip !== null && stepSkip !== void 0 ? stepSkip : 1);
|
|
49
|
+
const stepUp = () => step(amountToStep);
|
|
50
|
+
const stepDown = () => step(amountToStep * -1);
|
|
51
|
+
return (_jsxs(StepperWrapper, { disabled: disabled, children: [_jsx(StepperButton, { disabled: disabled, onClick: stepUp, styling: "ghost", tabIndex: -1, children: _jsx(ChevronUp, {}) }), _jsx(StepperButton, { disabled: disabled, onClick: stepDown, styling: "ghost", tabIndex: -1, children: _jsx(ChevronDown, {}) })] }));
|
|
52
|
+
};
|
|
53
|
+
export default InputStepper;
|
|
54
|
+
//# sourceMappingURL=input-stepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-stepper.js","sourceRoot":"","sources":["../../src/numeric-input/input-stepper.tsx"],"names":[],"mappings":";AAkBA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAMtC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAqB;cACxC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;;;;;;;;;;CAUpE,CAAC;AAEF,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;;;;kBAOlB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;;;iBAGxD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;;;;;qBAK7E,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;;;;;;;;;CASvD,CAAC;AAWF;;;;GAIG;AAEH,MAAM,YAAY,GAAyC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;IACxF,MAAM,YAAY,GAAW,IAAI,CAAC,GAAG,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,CAAC,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;IAErD,OAAO,CACH,MAAC,cAAc,IAAC,QAAQ,EAAE,QAAQ,aAC9B,KAAC,aAAa,IAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAE,CAAC,CAAC,YAC5E,KAAC,SAAS,KAAG,GACD,EAEhB,KAAC,aAAa,IAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAE,CAAC,CAAC,YAC9E,KAAC,WAAW,KAAG,GACH,IACH,CACpB,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,YAAY,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 * as React from 'react';
|
|
18
|
+
import { InteractiveComponentProps } from '../types';
|
|
19
|
+
export interface NumericInputProps extends InteractiveComponentProps<number> {
|
|
20
|
+
/** An optional prop to focus the input upon mounting it */
|
|
21
|
+
autoFocus?: boolean;
|
|
22
|
+
/** An optional parameter to restrict the field to just integers */
|
|
23
|
+
integerOnly?: boolean;
|
|
24
|
+
/** An optional property to set the maximum accepted value */
|
|
25
|
+
maxValue?: number;
|
|
26
|
+
/** An optional property to set the minimum accepted value */
|
|
27
|
+
minValue?: number;
|
|
28
|
+
/** An optional onBlur handler for listening to input blur events */
|
|
29
|
+
onBlur?: (e: React.SyntheticEvent<HTMLInputElement>) => void | Promise<void>;
|
|
30
|
+
/** An optional onChange handler for listening to changes in the input */
|
|
31
|
+
onChange?: (value: number, e?: React.SyntheticEvent<HTMLInputElement>) => void | Promise<void>;
|
|
32
|
+
/** An optional event listener for complete events (enter presses) */
|
|
33
|
+
onComplete?: () => void | Promise<void>;
|
|
34
|
+
/** An optional placeholder that will be used when the input is empty, defaults to '' */
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** An optional property to set how many steps the stepper should take */
|
|
37
|
+
stepSkip?: number;
|
|
38
|
+
/** An optional property to show input stepper control */
|
|
39
|
+
stepper?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* NumericInput is a wrapper around the input component that restricts the value to be numeric, either float or integer.
|
|
43
|
+
*
|
|
44
|
+
* @param props the component props
|
|
45
|
+
*/
|
|
46
|
+
declare const NumericInput: React.ForwardRefExoticComponent<NumericInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
47
|
+
export default NumericInput;
|
|
48
|
+
//# sourceMappingURL=numeric-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-input.d.ts","sourceRoot":"","sources":["../../src/numeric-input/numeric-input.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAgHrD,MAAM,WAAW,iBAAkB,SAAQ,yBAAyB,CAAC,MAAM,CAAC;IACxE,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mEAAmE;IACnE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/F,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,QAAA,MAAM,YAAY,4FA2FjB,CAAC;AAGF,eAAe,YAAY,CAAC"}
|