@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,91 @@
|
|
|
1
|
+
import { jsx as _jsx } 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 isEqual from 'lodash/isEqual';
|
|
19
|
+
import styled from '@darajs/styled-components';
|
|
20
|
+
const TabWrapper = styled.div `
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
display: flex;
|
|
23
|
+
|
|
24
|
+
/* This is needed as the content of a TabbedCard overflows for the wrapper to not shrink */
|
|
25
|
+
flex-shrink: 0;
|
|
26
|
+
|
|
27
|
+
width: 100%;
|
|
28
|
+
|
|
29
|
+
border-radius: 1rem 1rem 0 0;
|
|
30
|
+
`;
|
|
31
|
+
const TabComponent = styled.span `
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
user-select: none;
|
|
34
|
+
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
display: flex;
|
|
37
|
+
flex: 1 1 0;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
height: 2.5rem;
|
|
43
|
+
|
|
44
|
+
color: ${(props) => (props.selected ? props.theme.colors.primary : props.theme.colors.grey3)};
|
|
45
|
+
|
|
46
|
+
background-color: ${(props) => props.theme.colors.blue1};
|
|
47
|
+
border-bottom: ${(props) => props.selected ? `2px solid ${props.theme.colors.primary}` : `1px solid ${props.theme.colors.grey3}`};
|
|
48
|
+
|
|
49
|
+
:hover {
|
|
50
|
+
color: ${(props) => (props.selected ? props.theme.colors.primary : props.theme.colors.text)};
|
|
51
|
+
background-color: ${(props) => (props.selected ? props.theme.colors.blue1 : props.theme.colors.grey1)};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
h2 {
|
|
55
|
+
font-weight: ${(props) => (props.selected ? '700' : '400')};
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
58
|
+
const Title = styled.h2 `
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
|
|
61
|
+
width: 100%;
|
|
62
|
+
margin: 0;
|
|
63
|
+
padding: 0 1rem;
|
|
64
|
+
|
|
65
|
+
font-size: 1rem;
|
|
66
|
+
font-weight: 300;
|
|
67
|
+
text-align: center;
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
white-space: nowrap;
|
|
70
|
+
`;
|
|
71
|
+
function instanceOfTab(tab) {
|
|
72
|
+
return typeof tab === 'string' ? false : 'title' in tab;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A simple Tabs component that renders a set of tabs and manages which one is currently selected. Accepts an
|
|
76
|
+
* onSelectTab handler to notify the parent component when the selected tab changes
|
|
77
|
+
*
|
|
78
|
+
* @param {TabsProps} props - the component props
|
|
79
|
+
*/
|
|
80
|
+
function Tabs({ className, onSelectTab, selectedTab, tabs }) {
|
|
81
|
+
const objectTabs = tabs.map((tab) => (instanceOfTab(tab) ? tab : { title: tab }));
|
|
82
|
+
const tabSelected = instanceOfTab(selectedTab) ? selectedTab : { title: selectedTab };
|
|
83
|
+
const onClick = (tab) => () => {
|
|
84
|
+
if (onSelectTab) {
|
|
85
|
+
onSelectTab(tab);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return (_jsx(TabWrapper, { className: className, children: objectTabs.map((tab, idx) => (_jsx(TabComponent, { onClick: onClick(instanceOfTab(selectedTab) ? tab : tab.title), selected: isEqual(tab, tabSelected || objectTabs[0]), children: _jsx(Title, { children: tab.title }) }, `tab-${objectTabs[idx].title}`))) }));
|
|
89
|
+
}
|
|
90
|
+
export default Tabs;
|
|
91
|
+
//# sourceMappingURL=tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/tabs/tabs.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,OAAO,MAAM,gBA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AC;AACN,CAAC;AAED,eAAe,IAAI,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
|
+
import * as React from 'react';
|
|
18
|
+
import { InteractiveComponentProps } from '../types';
|
|
19
|
+
export interface TextAreaProps extends InteractiveComponentProps<string> {
|
|
20
|
+
/** An optional prop to focus the textarea upon mounting it */
|
|
21
|
+
autoFocus?: boolean;
|
|
22
|
+
/** An optional keydown event filter, that can filter out invalid chars from an textarea. Should return true to let
|
|
23
|
+
* the char through */
|
|
24
|
+
keydownFilter?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => boolean;
|
|
25
|
+
/** An optional onBlur handler for listening to textarea blur events */
|
|
26
|
+
onBlur?: (e: React.SyntheticEvent<HTMLTextAreaElement>) => void | Promise<void>;
|
|
27
|
+
/** An optional onChange handler for listening to changes in the textarea */
|
|
28
|
+
onChange?: (value: string, e?: React.SyntheticEvent<HTMLTextAreaElement>) => void | Promise<void>;
|
|
29
|
+
/** An optional onClick handler for listening to input click events */
|
|
30
|
+
onClick?: (e: React.SyntheticEvent<HTMLTextAreaElement>) => void | Promise<void>;
|
|
31
|
+
/** An optional event listener for complete events (enter presses) */
|
|
32
|
+
onComplete?: () => void | Promise<void>;
|
|
33
|
+
/** An optional placeholder that will be used when the textarea is empty, defaults to '' */
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
/** An optional property which sets whether the textarea is resizable, and if so, in which directions */
|
|
36
|
+
resize?: 'none' | 'both' | 'horizontal' | 'vertical' | 'block' | 'inline';
|
|
37
|
+
/** The maximum height the textarea will grow to, if not set it will not grow as more text is entered, this expected as an rem value */
|
|
38
|
+
maxHeight?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A simple text area component, accepts an onChange handler to listen for changes.
|
|
42
|
+
*
|
|
43
|
+
* @param props - the component props
|
|
44
|
+
*/
|
|
45
|
+
declare function TextArea({ autoFocus, className, disabled, errorMsg, initialValue, keydownFilter, maxHeight, onBlur, onChange, onClick, onComplete, placeholder, style, value, resize, }: TextAreaProps): JSX.Element;
|
|
46
|
+
export default TextArea;
|
|
47
|
+
//# sourceMappingURL=textarea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/textarea/textarea.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAuDrD,MAAM,WAAW,aAAc,SAAQ,yBAAyB,CAAC,MAAM,CAAC;IACpE,8DAA8D;IAC9D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;0BACsB;IACtB,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,OAAO,CAAC;IACzE,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChF,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClG,sEAAsE;IACtE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjF,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wGAAwG;IACxG,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC1E,uIAAuI;IACvI,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,EACd,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,SAAS,EACT,MAAM,EACN,QAAQ,EACR,OAAO,EACP,UAAU,EACV,WAAW,EACX,KAAK,EACL,KAAK,EACL,MAAM,GACT,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAsE7B;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 * as React from 'react';
|
|
19
|
+
import styled from '@darajs/styled-components';
|
|
20
|
+
import { Key } from '../constants';
|
|
21
|
+
const ErrorMessage = styled.span `
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
|
|
25
|
+
padding-left: 1rem;
|
|
26
|
+
|
|
27
|
+
font-size: 0.75rem;
|
|
28
|
+
color: ${(props) => props.theme.colors.error};
|
|
29
|
+
`;
|
|
30
|
+
const PrimaryTextArea = styled.textarea `
|
|
31
|
+
display: flex;
|
|
32
|
+
flex: 1 1 auto;
|
|
33
|
+
align-items: center;
|
|
34
|
+
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
min-height: 3.4rem;
|
|
38
|
+
padding: 1rem;
|
|
39
|
+
|
|
40
|
+
font-size: 1rem;
|
|
41
|
+
color: ${(props) => (props.disabled ? props.theme.colors.grey2 : props.theme.colors.text)};
|
|
42
|
+
|
|
43
|
+
background-color: ${(props) => props.theme.colors.grey1};
|
|
44
|
+
border: 1px solid ${(props) => (props.isErrored ? props.theme.colors.error : props.theme.colors.grey1)};
|
|
45
|
+
border-radius: 0.25rem;
|
|
46
|
+
outline: 0;
|
|
47
|
+
|
|
48
|
+
:hover:not(:disabled) {
|
|
49
|
+
border: 1px solid ${(props) => (props.isErrored ? props.theme.colors.error : props.theme.colors.grey2)};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
:focus:not(:disabled) {
|
|
53
|
+
border: 1px solid ${(props) => (props.isErrored ? props.theme.colors.error : props.theme.colors.grey3)};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:active:not(:disabled) {
|
|
57
|
+
border: 1px solid ${(props) => (props.isErrored ? props.theme.colors.error : props.theme.colors.grey3)};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:disabled {
|
|
61
|
+
cursor: not-allowed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
::placeholder {
|
|
65
|
+
font-style: italic;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
/**
|
|
69
|
+
* A simple text area component, accepts an onChange handler to listen for changes.
|
|
70
|
+
*
|
|
71
|
+
* @param props - the component props
|
|
72
|
+
*/
|
|
73
|
+
function TextArea({ autoFocus, className, disabled, errorMsg, initialValue, keydownFilter, maxHeight, onBlur, onChange, onClick, onComplete, placeholder, style, value, resize, }) {
|
|
74
|
+
const textareaRef = React.useRef(null);
|
|
75
|
+
React.useLayoutEffect(() => {
|
|
76
|
+
if (maxHeight && textareaRef.current) {
|
|
77
|
+
const computedStyle = window.getComputedStyle(textareaRef.current);
|
|
78
|
+
const minHeight = parseFloat(computedStyle.minHeight);
|
|
79
|
+
const maxHeightInPx = parseFloat(computedStyle.maxHeight);
|
|
80
|
+
// Reset the height to the initial minimum height in px
|
|
81
|
+
textareaRef.current.style.height = `${minHeight}px`;
|
|
82
|
+
// Calculate the new height based on scrollHeight
|
|
83
|
+
const newHeight = textareaRef.current.scrollHeight;
|
|
84
|
+
if (minHeight < newHeight) {
|
|
85
|
+
const adjustedHeight = Math.min(newHeight, maxHeightInPx);
|
|
86
|
+
// Set the textarea height to the new calculated height
|
|
87
|
+
textareaRef.current.style.height = `${adjustedHeight}px`;
|
|
88
|
+
// Toggle overflow-y based on whether maxHeight is reached, this is to guarantee overflow does not show before it is needed
|
|
89
|
+
if (adjustedHeight >= maxHeightInPx) {
|
|
90
|
+
textareaRef.current.style.overflowY = 'auto';
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
textareaRef.current.style.overflowY = 'hidden';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
textareaRef.current.style.overflowY = 'hidden';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [maxHeight, value]);
|
|
101
|
+
const onChangeText = (e) => {
|
|
102
|
+
const target = e.target;
|
|
103
|
+
if (onChange) {
|
|
104
|
+
onChange(target.value, e);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const onKeyDown = (e) => {
|
|
108
|
+
if (keydownFilter && !keydownFilter(e)) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
}
|
|
111
|
+
if (e.key === Key.ENTER && e.shiftKey && onComplete) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (e.key === Key.ENTER && onComplete) {
|
|
115
|
+
onComplete();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return (_jsxs("div", { className: className, style: style, children: [_jsx(PrimaryTextArea, { ref: textareaRef, autoFocus: autoFocus, defaultValue: initialValue, disabled: disabled, isErrored: !!errorMsg, onBlur: onBlur, onChange: onChangeText, onClick: onClick, onKeyDown: onKeyDown, placeholder: placeholder, style: { resize, maxHeight: maxHeight ? `${maxHeight}rem` : 'none' }, value: value }), errorMsg && _jsx(ErrorMessage, { children: errorMsg })] }));
|
|
119
|
+
}
|
|
120
|
+
export default TextArea;
|
|
121
|
+
//# sourceMappingURL=textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../src/textarea/textarea.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAE/C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAA;;;;;;;aAOnB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;CAC/C,CAAC;AAMF,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAsB;;;;;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|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GetReferenceClientRect } from 'tippy.js';
|
|
3
|
+
export interface TooltipProps {
|
|
4
|
+
/** The element to append the tooltip to, by default it gets appended to the body of the document */
|
|
5
|
+
appendTo?: Element | 'parent' | ((ref: Element) => Element);
|
|
6
|
+
/** the children to attached the tooltip too */
|
|
7
|
+
children?: React.ReactElement;
|
|
8
|
+
/** Standard react className property */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** The content to render in the tooltip, can be any react renderable content */
|
|
11
|
+
content: React.ReactNode;
|
|
12
|
+
/** Optional parameter to delay the appearance of the tooltip, defaults to 0 */
|
|
13
|
+
delay?: number | [number | null, number | null];
|
|
14
|
+
/** Optional parameter to determine whether the display of the tooltip is disabled or not */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Whether the tooltip should follow the mouse cursor; or control how it will be followed */
|
|
17
|
+
followCursor?: boolean | 'horizontal' | 'vertical' | 'initial';
|
|
18
|
+
/** Optional prop to use with a virtual element */
|
|
19
|
+
getReferenceClientRect?: GetReferenceClientRect;
|
|
20
|
+
/** Optional parameter to determine whether to hide the tooltip wrapper */
|
|
21
|
+
hidden?: boolean;
|
|
22
|
+
/** Optional parameter to determine if the tooltip should be shown even when the children are clicked, by default
|
|
23
|
+
* it is true and hides the tooltip on clicking the children */
|
|
24
|
+
hideOnClick?: boolean;
|
|
25
|
+
/** Optional parameter to determine if the tooltip is interactive, i.e. it can be hovered over or clicked without
|
|
26
|
+
* hiding */
|
|
27
|
+
interactive?: boolean;
|
|
28
|
+
/** Optional handler to define what happens when clicked outside the tooltip, to be used with controlled mode */
|
|
29
|
+
onClickOutside?: (instance: any, event: Event) => void;
|
|
30
|
+
/** Optional parameter to determine where to place the tooltip in the top or bottom of component */
|
|
31
|
+
placement?: 'top' | 'bottom' | 'auto' | 'left' | 'right';
|
|
32
|
+
/**
|
|
33
|
+
* Standard react styling property
|
|
34
|
+
*/
|
|
35
|
+
style?: React.CSSProperties;
|
|
36
|
+
/** Optional parameter to determine the style preset, options are default and error */
|
|
37
|
+
styling?: 'default' | 'error';
|
|
38
|
+
/** Optional parameter that sets tooltip visibility to be in controlled mode */
|
|
39
|
+
visible?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A tooltip component that can be wrapped around any other react component and attach a tooltip to it
|
|
43
|
+
*
|
|
44
|
+
* @param props the props for the tooltip component
|
|
45
|
+
*/
|
|
46
|
+
declare function Tooltip({ appendTo, getReferenceClientRect, children, className, content, disabled, hideOnClick, interactive, visible, placement, styling, followCursor, hidden, style, delay, onClickOutside, }: TooltipProps): JSX.Element;
|
|
47
|
+
export default Tooltip;
|
|
48
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAiD,MAAM,UAAU,CAAC;AA8GjG,MAAM,WAAW,YAAY;IACzB,qGAAqG;IACrG,QAAQ,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IAC5D,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC9B,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IAChD,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,CAAC;IAC/D,kDAAkD;IAClD,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,0EAA0E;IAC1E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;mEAC+D;IAC/D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;gBACY;IACZ,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gHAAgH;IAChH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACvD,mGAAmG;IACnG,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACzD;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,sFAAsF;IACtF,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH,iBAAS,OAAO,CAAC,EACb,QAAwB,EACxB,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,WAAkB,EAClB,WAAW,EACX,OAAO,EACP,SAAkB,EAClB,OAAmB,EACnB,YAAoB,EACpB,MAAc,EACd,KAAK,EACL,KAAS,EACT,cAA4B,GAC/B,EAAE,YAAY,GAAG,GAAG,CAAC,OAAO,CA+B5B;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 Tippy from '@tippyjs/react/headless';
|
|
19
|
+
import { followCursor as followCursorPlugin } from 'tippy.js';
|
|
20
|
+
import styled from '@darajs/styled-components';
|
|
21
|
+
const TooltipWrapper = styled.div `
|
|
22
|
+
position: relative;
|
|
23
|
+
|
|
24
|
+
display: block;
|
|
25
|
+
|
|
26
|
+
max-width: 15rem;
|
|
27
|
+
padding: 0.75rem 1rem;
|
|
28
|
+
|
|
29
|
+
word-break: break-word;
|
|
30
|
+
|
|
31
|
+
border-radius: 0.25rem;
|
|
32
|
+
|
|
33
|
+
transition: opacity 150ms ease-in-out;
|
|
34
|
+
|
|
35
|
+
${(props) => {
|
|
36
|
+
if (!props.$hidden) {
|
|
37
|
+
return `
|
|
38
|
+
color: ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.blue1};
|
|
39
|
+
font-size: ${props.theme.font.size};
|
|
40
|
+
border: 1px solid ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.errorDown};
|
|
41
|
+
|
|
42
|
+
background-color: ${props.styling === 'default' ? props.theme.colors.grey2 : props.theme.colors.error};
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
}};
|
|
46
|
+
`;
|
|
47
|
+
const Arrow = styled.span `
|
|
48
|
+
position: absolute;
|
|
49
|
+
|
|
50
|
+
${(props) => {
|
|
51
|
+
switch (props.placement) {
|
|
52
|
+
case 'top':
|
|
53
|
+
return 'bottom: 3px; left: -3px !important;';
|
|
54
|
+
case 'bottom':
|
|
55
|
+
return 'top: -5px;';
|
|
56
|
+
case 'left':
|
|
57
|
+
return 'right: 3px;';
|
|
58
|
+
case 'right':
|
|
59
|
+
return 'left: -5px;';
|
|
60
|
+
default:
|
|
61
|
+
// Unsupported placement, hide the arrow
|
|
62
|
+
return 'display: none;';
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
|
|
66
|
+
${(props) => {
|
|
67
|
+
if (props.$hidden) {
|
|
68
|
+
return 'display: none;';
|
|
69
|
+
}
|
|
70
|
+
}}
|
|
71
|
+
|
|
72
|
+
&::before {
|
|
73
|
+
content: '';
|
|
74
|
+
|
|
75
|
+
position: absolute;
|
|
76
|
+
|
|
77
|
+
${(props) => {
|
|
78
|
+
switch (props.placement) {
|
|
79
|
+
case 'top':
|
|
80
|
+
case 'bottom':
|
|
81
|
+
return 'transform: rotate(45deg);';
|
|
82
|
+
case 'left':
|
|
83
|
+
return 'transform: rotate(135deg);';
|
|
84
|
+
case 'right':
|
|
85
|
+
return 'transform: rotate(-45deg);';
|
|
86
|
+
default:
|
|
87
|
+
return 'display: none;';
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
|
|
91
|
+
width: 0.5rem;
|
|
92
|
+
height: 0.5rem;
|
|
93
|
+
|
|
94
|
+
background: ${(props) => {
|
|
95
|
+
return props.styling === 'default' ? props.theme.colors.grey2 : props.theme.colors.error;
|
|
96
|
+
}};
|
|
97
|
+
${(props) => {
|
|
98
|
+
if (props.placement === 'top') {
|
|
99
|
+
return `border-bottom: 1px solid ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.errorDown};
|
|
100
|
+
border-right: 1px solid ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.errorDown};`;
|
|
101
|
+
}
|
|
102
|
+
return `border-top: 1px solid ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.errorDown};
|
|
103
|
+
border-left: 1px solid ${props.styling === 'default' ? props.theme.colors.grey5 : props.theme.colors.errorDown};`;
|
|
104
|
+
}}
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
/**
|
|
108
|
+
* A tooltip component that can be wrapped around any other react component and attach a tooltip to it
|
|
109
|
+
*
|
|
110
|
+
* @param props the props for the tooltip component
|
|
111
|
+
*/
|
|
112
|
+
function Tooltip({ appendTo = document.body, getReferenceClientRect, children, className, content, disabled, hideOnClick = true, interactive, visible, placement = 'auto', styling = 'default', followCursor = false, hidden = false, style, delay = 0, onClickOutside = () => false, }) {
|
|
113
|
+
return (_jsx(Tippy, { appendTo: appendTo, arrow: true, delay: delay, disabled: disabled, followCursor: followCursor, getReferenceClientRect: getReferenceClientRect, hideOnClick: visible !== undefined ? undefined : hideOnClick, interactive: interactive, onClickOutside: onClickOutside, placement: placement, plugins: [followCursorPlugin], render: (attrs) => (_jsxs(TooltipWrapper, Object.assign({ "$hidden": hidden, className: className, style: style, styling: styling }, attrs, { children: [content, _jsx(Arrow, { "$hidden": hidden, "data-popper-arrow": "", placement: attrs['data-placement'], styling: styling })] }))), visible: visible, zIndex: 9998, children: children }));
|
|
114
|
+
}
|
|
115
|
+
export default Tooltip;
|
|
116
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/tooltip/tooltip.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAE5C,OAAO,EAAqC,YAAY,IAAI,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEjG,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAO/C,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAa;;;;;;;;;;;;;;MAcxC,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACjB,OAAO;qBACE,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAA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EACnB,YAAY,GAAG,KAAK,EACpB,MAAM,GAAG,KAAK,EACd,KAAK,EACL,KAAK,GAAG,CAAC,EACT,cAAc,GAAG,GAAG,EAAE,CAAC,KAAK,GACjB;IACX,OAAO,CACH,KAAC,KAAK,IACF,QAAQ,EAAE,QAAQ,EAClB,KAAK,QACL,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,sBAAsB,EAAE,sBAAsB,EAC9C,WAAW,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAC5D,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,CAAC,kBAAkB,CAAC,EAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CACf,MAAC,cAAc,6BAAU,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,IAAM,KAAK,eAC3F,OAAO,EACR,KAAC,KAAK,eACO,MAAM,uBACG,EAAE,EACpB,SAAS,EAAE,KAAK,CAAC,gBAAgB,CAAC,EAClC,OAAO,EAAE,OAAO,GAClB,KACW,CACpB,EACD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,IAAI,YAEX,QAAQ,GACL,CACX,CAAC;AACN,CAAC;AAED,eAAe,OAAO,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from 'react';
|
|
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
|
+
export type JSONData = {
|
|
19
|
+
[k: string]: string | number | boolean | JSONData | Array<JSONData>;
|
|
20
|
+
};
|
|
21
|
+
export interface ItemBadge {
|
|
22
|
+
color?: string;
|
|
23
|
+
label: string;
|
|
24
|
+
}
|
|
25
|
+
/** Standard interface for dropdown items */
|
|
26
|
+
export interface Item {
|
|
27
|
+
badge?: ItemBadge;
|
|
28
|
+
image?: string;
|
|
29
|
+
icon?: JSX.Element;
|
|
30
|
+
label: string;
|
|
31
|
+
onClick?: () => void | Promise<void>;
|
|
32
|
+
value: any;
|
|
33
|
+
}
|
|
34
|
+
export interface CarouselItem {
|
|
35
|
+
component?: React.ReactNode;
|
|
36
|
+
image?: string;
|
|
37
|
+
imageAlt?: string;
|
|
38
|
+
imageHeight?: string;
|
|
39
|
+
imageWidth?: string;
|
|
40
|
+
subtitle?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface AccordionItemType {
|
|
44
|
+
badge?: ItemBadge;
|
|
45
|
+
content: any;
|
|
46
|
+
label: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ComponentSelectItem {
|
|
49
|
+
component: React.ReactNode;
|
|
50
|
+
subtitle?: string;
|
|
51
|
+
title: string;
|
|
52
|
+
}
|
|
53
|
+
export interface InteractiveComponentProps<T> {
|
|
54
|
+
/** Pass through of className property */
|
|
55
|
+
className?: string;
|
|
56
|
+
/** Optional property to disable the button */
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
/** An error message for the component, if it is an empty string then the element is valid. */
|
|
59
|
+
errorMsg?: string;
|
|
60
|
+
/** The initial value of the element */
|
|
61
|
+
initialValue?: T;
|
|
62
|
+
/** Native react style property, can be used to fine tune the element appearance */
|
|
63
|
+
style?: React.CSSProperties;
|
|
64
|
+
/** An optional value field to put the component into controlled mode */
|
|
65
|
+
value?: T;
|
|
66
|
+
}
|
|
67
|
+
/** Type for a Chat message */
|
|
68
|
+
export interface Message {
|
|
69
|
+
/** Unique identifier for the message */
|
|
70
|
+
id: string;
|
|
71
|
+
/** The message content */
|
|
72
|
+
message: string;
|
|
73
|
+
/** The timestamp of the creation of the message */
|
|
74
|
+
created_at: string;
|
|
75
|
+
/** The timestamp of the last time the message was edited */
|
|
76
|
+
updated_at: string;
|
|
77
|
+
/** User data of the person who wrote the message */
|
|
78
|
+
user: UserData;
|
|
79
|
+
/** Optional actions to be displayed with the message */
|
|
80
|
+
actions?: React.ReactNode[];
|
|
81
|
+
}
|
|
82
|
+
export interface UserData {
|
|
83
|
+
/** user unique identifier */
|
|
84
|
+
id?: string;
|
|
85
|
+
/** user name */
|
|
86
|
+
name: string;
|
|
87
|
+
/** user email */
|
|
88
|
+
email?: string;
|
|
89
|
+
/** Optional content of the user bubble to be shown */
|
|
90
|
+
bubbleContent?: React.ReactNode;
|
|
91
|
+
/** Optional color the user bubble should take */
|
|
92
|
+
color?: string;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;CAAE,CAAC;AAE/F,MAAM,WAAW,SAAS;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,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AC9B,MAAM,WAAW,OAAO;IACpB,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,IAAI,EAAE,QAAQ,CAAC;IACf,wDAAwD;IACxD,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,QAAQ;IACrB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
interface ChevronProps {
|
|
19
|
+
/** The initial rotation of the chevron, defaults to 0 */
|
|
20
|
+
angles?: [number, number];
|
|
21
|
+
/** An optional class that can be passed to override the styling */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Whether the chevron is disabled */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Whether the parent component isOpen or not */
|
|
26
|
+
isOpen: boolean;
|
|
27
|
+
/** An optional handler for any click events on the element */
|
|
28
|
+
onClick?: (e: React.SyntheticEvent<SVGSVGElement>) => void | Promise<void>;
|
|
29
|
+
/** The native react style prop */
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
}
|
|
32
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<ChevronProps & React.RefAttributes<any>>>;
|
|
33
|
+
export default _default;
|
|
34
|
+
//# sourceMappingURL=chevron.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chevron.d.ts","sourceRoot":"","sources":["../../src/utils/chevron.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,UAAU,YAAY;IAClB,yDAAyD;IACzD,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,kCAAkC;IAClC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC/B;;AA+BD,wBAAmC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } 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 * as React from 'react';
|
|
19
|
+
import styled from '@darajs/styled-components';
|
|
20
|
+
import { ChevronDown } from '@darajs/ui-icons';
|
|
21
|
+
const shouldForwardProp = (prop) => !['isOpen'].includes(prop);
|
|
22
|
+
const Icon = styled(ChevronDown).withConfig({ shouldForwardProp }) `
|
|
23
|
+
cursor: ${(props) => (props.disabled ? 'not-allowed' : 'pointer')};
|
|
24
|
+
transform: ${(props) => {
|
|
25
|
+
const start = props.angles ? props.angles[0] : 0;
|
|
26
|
+
const end = props.angles ? props.angles[1] : 180;
|
|
27
|
+
return props.isOpen ? `rotate(${end}deg)` : `rotate(${start}deg)`;
|
|
28
|
+
}};
|
|
29
|
+
color: ${(props) => props.theme.colors.grey5};
|
|
30
|
+
transition: transform 0.1s linear;
|
|
31
|
+
`;
|
|
32
|
+
/**
|
|
33
|
+
* A rotating chevron, that flips from pointing down to up with the isOpen prop
|
|
34
|
+
* @param {ChevronProps} props - the component props
|
|
35
|
+
*/
|
|
36
|
+
const Chevron = React.forwardRef((props, ref) => (_jsx(Icon, { angles: props.angles, className: props.className, disabled: props.disabled, isOpen: props.isOpen, onClick: props.onClick, ref: ref, style: props.style })));
|
|
37
|
+
export default React.memo(Chevron);
|
|
38
|
+
//# sourceMappingURL=chevron.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chevron.js","sourceRoot":"","sources":["../../src/utils/chevron.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAiB/C,MAAM,iBAAiB,GAAG,CAAC,IAAS,EAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAE7E,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAc;cAClE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;iBACpD,CAAC,KAAK,EAAE,EAAE;IACnB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,CAAC;AACtE,CAAC;aACQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;;CAE/C,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAoB,CAAC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