@dvrd/dvr-controls 1.0.4 → 1.0.7

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.
Files changed (177) hide show
  1. package/package.json +1 -1
  2. package/src/js/button/button.tsx +0 -102
  3. package/src/js/button/buttonController.tsx +0 -179
  4. package/src/js/button/closeButton.tsx +0 -29
  5. package/src/js/button/dvrdButton.tsx +0 -128
  6. package/src/js/button/outlinedButton.tsx +0 -105
  7. package/src/js/button/simpleButton.tsx +0 -163
  8. package/src/js/button/style/button.scss +0 -95
  9. package/src/js/button/style/closeButton.scss +0 -15
  10. package/src/js/button/style/dvrdButton.scss +0 -30
  11. package/src/js/button/style/outlinedButton.scss +0 -84
  12. package/src/js/button/style/simpleButton.scss +0 -80
  13. package/src/js/carousel/DVRCarousel.tsx +0 -163
  14. package/src/js/carousel/DVRCarouselController.tsx +0 -95
  15. package/src/js/carousel/style/DVRCarousel.scss +0 -38
  16. package/src/js/checkbox/checkbox.tsx +0 -147
  17. package/src/js/checkbox/checkboxController.tsx +0 -131
  18. package/src/js/checkbox/style/checkbox.scss +0 -109
  19. package/src/js/colorPicker/colorPicker.tsx +0 -118
  20. package/src/js/colorPicker/style/colorPicker.scss +0 -20
  21. package/src/js/date/dvrdDatePicker.tsx +0 -357
  22. package/src/js/date/style/dvrdDatePicker.scss +0 -307
  23. package/src/js/dialog/dialog.tsx +0 -207
  24. package/src/js/dialog/dialogController.tsx +0 -70
  25. package/src/js/dialog/inlineDialog.tsx +0 -127
  26. package/src/js/dialog/style/dialog.scss +0 -61
  27. package/src/js/events/withEvents.tsx +0 -40
  28. package/src/js/head/DVRHead.tsx +0 -49
  29. package/src/js/header/DVRHeader.tsx +0 -413
  30. package/src/js/header/style/header.scss +0 -206
  31. package/src/js/icon/awesomeIcon.tsx +0 -46
  32. package/src/js/image/imageUpload.tsx +0 -69
  33. package/src/js/image/style/imageUpload.scss +0 -11
  34. package/src/js/info/info.tsx +0 -136
  35. package/src/js/info/style/info.scss +0 -39
  36. package/src/js/input/animated/animatedTextField.tsx +0 -159
  37. package/src/js/input/date/dateField.tsx +0 -360
  38. package/src/js/input/date/dateFieldController.tsx +0 -245
  39. package/src/js/input/date/datePicker/datePicker.tsx +0 -186
  40. package/src/js/input/date/datePicker/style/datePicker.scss +0 -102
  41. package/src/js/input/date/input/dateInput.tsx +0 -213
  42. package/src/js/input/date/style/dateField.scss +0 -40
  43. package/src/js/input/date/timePicker/style/timePicker.scss +0 -95
  44. package/src/js/input/date/timePicker/timePicker.tsx +0 -143
  45. package/src/js/input/editor/DVREditor.tsx +0 -21
  46. package/src/js/input/number/numberInput.tsx +0 -157
  47. package/src/js/input/password/passwordInput.tsx +0 -140
  48. package/src/js/input/password/passwordRules.tsx +0 -48
  49. package/src/js/input/password/style/passwordInput.scss +0 -39
  50. package/src/js/input/password/style/passwordRules.scss +0 -41
  51. package/src/js/input/simple/style/simpleInput.scss +0 -98
  52. package/src/js/input/simple/v2/simpleInputV2.tsx +0 -178
  53. package/src/js/input/style/input.scss +0 -138
  54. package/src/js/input/v2/inputController_v2.tsx +0 -250
  55. package/src/js/input/v2/input_v2.tsx +0 -7
  56. package/src/js/label/label.tsx +0 -196
  57. package/src/js/label/style/label.scss +0 -4
  58. package/src/js/link/link.tsx +0 -37
  59. package/src/js/link/style/link.scss +0 -30
  60. package/src/js/loader/loader.tsx +0 -79
  61. package/src/js/loader/loaderController.tsx +0 -61
  62. package/src/js/loader/style/loader.scss +0 -53
  63. package/src/js/media/media.tsx +0 -72
  64. package/src/js/navigator/navigator.tsx +0 -51
  65. package/src/js/optionsList/dvrdOptionsList.tsx +0 -112
  66. package/src/js/optionsList/style/dvrdOptionsList.scss +0 -84
  67. package/src/js/optionsMenu/optionsMenu.tsx +0 -187
  68. package/src/js/optionsMenu/style/optionsMenu.scss +0 -70
  69. package/src/js/pdf/element/pdfElement.tsx +0 -315
  70. package/src/js/pdf/element/style/pdfElement.scss +0 -111
  71. package/src/js/pdf/history/pdfHistory.ts +0 -57
  72. package/src/js/pdf/image/pdfImage.tsx +0 -175
  73. package/src/js/pdf/image/style/pdfImage.scss +0 -34
  74. package/src/js/pdf/invoiceTable/pdfInvoiceTable.tsx +0 -176
  75. package/src/js/pdf/invoiceTable/style/pdfInvoiceTable.scss +0 -32
  76. package/src/js/pdf/pdfTemplateCreator.tsx +0 -278
  77. package/src/js/pdf/settings/buttons/iconButton.tsx +0 -49
  78. package/src/js/pdf/settings/buttons/style/iconButton.scss +0 -50
  79. package/src/js/pdf/settings/image/pdfImageSettings.tsx +0 -82
  80. package/src/js/pdf/settings/image/style/pdfImageSettings.scss +0 -9
  81. package/src/js/pdf/settings/invoiceTable/pdfInvoiceTableSettings.tsx +0 -141
  82. package/src/js/pdf/settings/invoiceTable/style/pdfInvoiceTableSettings.scss +0 -38
  83. package/src/js/pdf/settings/pdfElementSettings.tsx +0 -86
  84. package/src/js/pdf/settings/style/pdfElementSettings.scss +0 -56
  85. package/src/js/pdf/settings/text/pdfTextSettings.tsx +0 -202
  86. package/src/js/pdf/settings/text/style/pdfTextSettings.scss +0 -94
  87. package/src/js/pdf/style/pdfTemplateCreator.scss +0 -118
  88. package/src/js/pdf/text/pdfText.tsx +0 -267
  89. package/src/js/pdf/text/style/pdfText.scss +0 -22
  90. package/src/js/popup/style/withBackground.scss +0 -29
  91. package/src/js/popup/withBackground.tsx +0 -102
  92. package/src/js/select/async/asyncSelect.tsx +0 -46
  93. package/src/js/select/async/style/asyncSelect.scss +0 -23
  94. package/src/js/select/dvrdSelect.tsx +0 -185
  95. package/src/js/select/dvrdSelectController.tsx +0 -81
  96. package/src/js/select/select.tsx +0 -310
  97. package/src/js/select/selectController.tsx +0 -341
  98. package/src/js/select/style/dvrdSelect.scss +0 -140
  99. package/src/js/select/style/select.scss +0 -199
  100. package/src/js/sidebarMenu/sidebarMenu.tsx +0 -165
  101. package/src/js/sidebarMenu/style/sidebarMenu.scss +0 -161
  102. package/src/js/slider/DVRSlider.tsx +0 -107
  103. package/src/js/slider/style/DVRSlider.scss +0 -88
  104. package/src/js/snackbar/snackbar.tsx +0 -72
  105. package/src/js/snackbar/snackbarController.tsx +0 -104
  106. package/src/js/snackbar/style/snackbar.scss +0 -46
  107. package/src/js/switch/dvrdSwitch.tsx +0 -53
  108. package/src/js/switch/style/dvrdSwitch.scss +0 -47
  109. package/src/js/switch/style/switch.scss +0 -84
  110. package/src/js/switch/switch.tsx +0 -115
  111. package/src/js/switch/switchController.tsx +0 -97
  112. package/src/js/textField/dvrdInput.tsx +0 -217
  113. package/src/js/textField/dvrdInputController.tsx +0 -97
  114. package/src/js/textField/dvrdNumberInput.tsx +0 -141
  115. package/src/js/textField/dvrdPasswordInput.tsx +0 -40
  116. package/src/js/textField/style/dvrdInput.scss +0 -114
  117. package/src/js/textField/style/dvrdPassword.scss +0 -15
  118. package/src/js/topButton/style/topButton.scss +0 -54
  119. package/src/js/topButton/topButton.tsx +0 -135
  120. package/src/js/util/analyticsUtil.ts +0 -41
  121. package/src/js/util/colorUtil.ts +0 -230
  122. package/src/js/util/componentUtil.tsx +0 -59
  123. package/src/js/util/constants.ts +0 -12
  124. package/src/js/util/controlContext.tsx +0 -46
  125. package/src/js/util/controlUtil.ts +0 -107
  126. package/src/js/util/cookieUtil.ts +0 -17
  127. package/src/js/util/eventUtil.ts +0 -65
  128. package/src/js/util/googleUtil.ts +0 -88
  129. package/src/js/util/interfaces.ts +0 -179
  130. package/src/js/util/jwtUtil.ts +0 -72
  131. package/src/js/util/miscUtil.ts +0 -170
  132. package/src/js/util/momentUtil.ts +0 -45
  133. package/src/js/util/pdfUtil.ts +0 -124
  134. package/src/js/util/requestUtil.ts +0 -146
  135. package/src/js/util/responsiveUtil.ts +0 -37
  136. package/src/js/util/validationUtil.ts +0 -13
  137. package/src/res/img/lock-handle.png +0 -0
  138. package/src/res/img/lock-handle.webp +0 -0
  139. package/src/res/img/lock.png +0 -0
  140. package/src/res/img/lock.webp +0 -0
  141. package/src/style/common-icons-variables.scss +0 -140
  142. package/src/style/common-icons.scss +0 -714
  143. package/src/style/common-variables.scss +0 -243
  144. package/src/style/display-breakpoints.scss +0 -141
  145. package/src/style/fonts/common-icons.eot +0 -0
  146. package/src/style/fonts/common-icons.svg +0 -150
  147. package/src/style/fonts/common-icons.ttf +0 -0
  148. package/src/style/fonts/common-icons.woff +0 -0
  149. package/src/style/fonts/common-icons.woff2 +0 -0
  150. package/src/style/fonts/fontAwesome/css/all.css +0 -7003
  151. package/src/style/fonts/fontAwesome/css/all.min.css +0 -6
  152. package/src/style/fonts/fontAwesome/css/brands.css +0 -1423
  153. package/src/style/fonts/fontAwesome/css/brands.min.css +0 -6
  154. package/src/style/fonts/fontAwesome/css/fontawesome.css +0 -5519
  155. package/src/style/fonts/fontAwesome/css/fontawesome.min.css +0 -6
  156. package/src/style/fonts/fontAwesome/css/regular.css +0 -19
  157. package/src/style/fonts/fontAwesome/css/regular.min.css +0 -6
  158. package/src/style/fonts/fontAwesome/css/solid.css +0 -19
  159. package/src/style/fonts/fontAwesome/css/solid.min.css +0 -6
  160. package/src/style/fonts/fontAwesome/css/svg-with-js.css +0 -634
  161. package/src/style/fonts/fontAwesome/css/svg-with-js.min.css +0 -6
  162. package/src/style/fonts/fontAwesome/css/v4-font-face.css +0 -26
  163. package/src/style/fonts/fontAwesome/css/v4-font-face.min.css +0 -6
  164. package/src/style/fonts/fontAwesome/css/v4-shims.css +0 -2146
  165. package/src/style/fonts/fontAwesome/css/v4-shims.min.css +0 -6
  166. package/src/style/fonts/fontAwesome/css/v5-font-face.css +0 -22
  167. package/src/style/fonts/fontAwesome/css/v5-font-face.min.css +0 -6
  168. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.ttf +0 -0
  169. package/src/style/fonts/fontAwesome/webfonts/fa-brands-400.woff2 +0 -0
  170. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.ttf +0 -0
  171. package/src/style/fonts/fontAwesome/webfonts/fa-regular-400.woff2 +0 -0
  172. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.ttf +0 -0
  173. package/src/style/fonts/fontAwesome/webfonts/fa-solid-900.woff2 +0 -0
  174. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.ttf +0 -0
  175. package/src/style/fonts/fontAwesome/webfonts/fa-v4compatibility.woff2 +0 -0
  176. package/src/style/variables.scss +0 -11
  177. package/tsconfig.json +0 -15
@@ -1,185 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
- import './style/dvrdSelect.scss';
5
-
6
- import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
7
- import classNames from 'classnames';
8
- import {ChangeFunction, ErrorType, SelectItemShape} from '../util/interfaces';
9
- import {hasHover, stopPropagation } from '../util/controlUtil';
10
- import AwesomeIcon from '../icon/awesomeIcon';
11
-
12
- interface Props {
13
- onChange: (value: string | number) => MouseEventHandler;
14
- onChangeSearch: ChangeFunction;
15
- value: string | number;
16
- items: SelectItemShape[];
17
- disabled?: boolean;
18
- error?: ErrorType;
19
- label?: string;
20
- className?: string;
21
- labelClassName?: string;
22
- valueClassName?: string;
23
- arrowClassName?: string;
24
- errorClassName?: string;
25
- itemContainerClassName?: string;
26
- itemClassName?: string;
27
- itemsPosition: 'top' | 'bottom';
28
- selectOnly: boolean;
29
- searchValue: string;
30
- optionsContainerHeight: number | string;
31
- }
32
-
33
- interface State {
34
- open: boolean;
35
- searchFocused: boolean;
36
- }
37
-
38
- export default class DvrdSelect extends PureComponent<Props, State> {
39
- private container: HTMLDivElement;
40
- state: State = {
41
- open: false,
42
- searchFocused: false,
43
- };
44
-
45
- hasError = (): boolean => this.props.error !== undefined && this.props.error !== null;
46
-
47
- onClickElement = (evt: React.MouseEvent) => {
48
- evt.stopPropagation();
49
- if (!this.props.disabled)
50
- this.setState({open: !this.state.open});
51
- };
52
-
53
- onClickItem = (value: string | number) => (evt: React.MouseEvent) => {
54
- evt.stopPropagation();
55
- this.props.onChange(value)(evt);
56
- this.setState({open: false});
57
- };
58
-
59
- onFocusInput = () => {
60
- this.setState({searchFocused: true, open: true});
61
- };
62
-
63
- onBlurInput = () => {
64
- window.setTimeout(() => {
65
- this.setState({searchFocused: false});
66
- this.props.onChangeSearch({target: {value: ''}});
67
- }, 200);
68
- };
69
-
70
- getLongestValue = (): string => {
71
- const {items} = this.props;
72
- let longest: string = '';
73
- for (const item of items) {
74
- if (item.label.toString().length > longest.length) {
75
- longest = item.label.toString();
76
- }
77
- }
78
- return longest;
79
- };
80
-
81
- getValueLabel = (): string | number => {
82
- const {value, items} = this.props;
83
- for (const item of items)
84
- if (item.value === value) return item.inputLabel ?? item.label;
85
- return '';
86
- }
87
-
88
- getItemsContainerStyle = (): CSSProperties => {
89
- let {optionsContainerHeight} = this.props;
90
- if(typeof optionsContainerHeight === 'number') optionsContainerHeight = `${optionsContainerHeight}px`;
91
- return {maxHeight: optionsContainerHeight};
92
- }
93
-
94
- renderLabel = () => {
95
- const {labelClassName, label} = this.props;
96
- if (!label) return null;
97
- return <label className={classNames('dvrd-select-label', labelClassName)}
98
- onClick={this.onClickElement}>{label}</label>
99
- };
100
-
101
- renderValue = () => {
102
- const {valueClassName, selectOnly, searchValue, onChangeSearch, disabled} = this.props,
103
- {searchFocused} = this.state, valueLabel = this.getValueLabel();
104
- if (selectOnly)
105
- return (
106
- <div style={{display: 'flex', flexDirection: 'column'}}>
107
- <label className={classNames('dvrd-select-value', valueClassName)}
108
- onClick={this.onClickElement}>{valueLabel}</label>
109
- <label style={{height: 0, visibility: 'hidden'}}>{this.getLongestValue()}</label>
110
- </div>
111
- );
112
- const value = searchFocused ? searchValue : valueLabel;
113
- return <input className='dvrd-select-search' value={value} onChange={onChangeSearch} disabled={disabled}
114
- onFocus={this.onFocusInput} onBlur={this.onBlurInput} onClick={stopPropagation}/>
115
- };
116
-
117
- renderArrow = () => {
118
- const {arrowClassName} = this.props, {open} = this.state;
119
- return <AwesomeIcon name='chevron-down' onClick={this.onClickElement}
120
- className={classNames('dvrd-select-arrow', open && 'open', arrowClassName)}/>;
121
- };
122
-
123
- renderItems = () => {
124
- const {items, disabled, itemContainerClassName, itemClassName, itemsPosition} = this.props, {open} = this.state;
125
- return (
126
- <div
127
- className={classNames('dvrd-select-items', (open && !disabled) && 'open', itemsPosition,
128
- itemContainerClassName)} style={this.getItemsContainerStyle()}>
129
- {items.filter((item) => item.label.toString().length > 0 && item.selectable !== false)
130
- .map((item: SelectItemShape, index: number) => (
131
- <label key={index} className={classNames('dvrd-select-item', itemClassName)}
132
- onClick={this.onClickItem(item.value)}>{item.label}</label>
133
- ))}
134
- </div>
135
- )
136
- };
137
-
138
- renderError = () => {
139
- if (!this.hasError()) return null;
140
- const {error, errorClassName} = this.props;
141
- return <label className={classNames('dvrd-select-error', errorClassName)}>{error}</label>
142
- };
143
-
144
- addClickListener = () => {
145
- document.addEventListener('click', this.clickListener);
146
- };
147
-
148
- removeClickListener = () => {
149
- document.removeEventListener('click', this.clickListener);
150
- }
151
-
152
- clickListener = () => {
153
- if (!hasHover(this.container)) this.setState({open: false});
154
- };
155
-
156
- componentDidUpdate = (props: Props, prevState: State) => {
157
- const {open} = this.state, prevOpen = prevState.open;
158
- if (open && !prevOpen) this.addClickListener();
159
- else if (!open && prevOpen) this.removeClickListener();
160
- };
161
-
162
- componentWillUnmount = () => {
163
- this.removeClickListener();
164
- };
165
-
166
- render = () => {
167
- const {className, disabled, selectOnly} = this.props, {open} = this.state;
168
- return (
169
- <div
170
- className={classNames('dvrd-select-container', disabled && 'disabled', open && 'open',
171
- this.hasError() && 'error', className)}
172
- ref={(ref: HTMLDivElement) => {
173
- this.container = ref
174
- }} onClick={this.onClickElement}>
175
- {this.renderLabel()}
176
- <div className={classNames('content-container', !selectOnly && 'search')}>
177
- {this.renderValue()}
178
- {this.renderArrow()}
179
- </div>
180
- {this.renderItems()}
181
- {this.renderError()}
182
- </div>
183
- )
184
- };
185
- };
@@ -1,81 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React, {PureComponent} from 'react';
6
- import DvrdSelect from "./dvrdSelect";
7
- import {ChangeFunction, ErrorType, SelectItemShape} from "../util/interfaces";
8
- import {stringContains} from '../util/controlUtil';
9
-
10
- interface Props {
11
- onChange: ChangeFunction;
12
- value: string | number;
13
- items: SelectItemShape[];
14
- disabled?: boolean;
15
- label?: string;
16
- error?: ErrorType;
17
- className?: string;
18
- labelClassName?: string;
19
- valueClassName?: string;
20
- arrowClassName?: string;
21
- errorClassName?: string;
22
- itemContainerClassName?: string;
23
- itemClassName?: string;
24
- itemsPosition: 'top' | 'bottom';
25
- selectOnly: boolean;
26
- optionsContainerHeight: number | string;
27
- }
28
-
29
- interface State {
30
- searchValue: string;
31
- }
32
-
33
- export default class DvrdSelectController extends PureComponent<Props, State> {
34
- private select: DvrdSelect;
35
-
36
- static defaultProps = {
37
- itemsPosition: 'bottom',
38
- selectOnly: true,
39
- optionsContainerHeight: '15rem',
40
- };
41
-
42
- state: State = {
43
- searchValue: '',
44
- };
45
-
46
- onChange = (value: string) => () => {
47
- this.props.onChange(value);
48
- };
49
-
50
- onChangeSearch = (evt: React.ChangeEvent<HTMLInputElement>) => {
51
- const {value} = evt.target;
52
- this.setState({searchValue: value});
53
- };
54
-
55
- onOpen = (evt: React.MouseEvent) => {
56
- if (this.select) this.select.onClickElement(evt);
57
- };
58
-
59
- getItems = () => {
60
- const items = this.props.items.slice(), {searchValue} = this.state;
61
- if (!searchValue) return items;
62
- return items.filter((item) => stringContains(item.label.toString(), searchValue))
63
- }
64
-
65
- render = () => {
66
- const {
67
- arrowClassName, label, error, className, labelClassName, valueClassName, itemContainerClassName,
68
- itemClassName, errorClassName, disabled, value, itemsPosition, selectOnly, optionsContainerHeight
69
- } = this.props, {searchValue} = this.state;
70
- return (
71
- <DvrdSelect onChange={this.onChange} value={value} items={this.getItems()} disabled={disabled}
72
- errorClassName={errorClassName} itemClassName={itemClassName}
73
- itemContainerClassName={itemContainerClassName} valueClassName={valueClassName}
74
- labelClassName={labelClassName} className={className} error={error} label={label}
75
- arrowClassName={arrowClassName} itemsPosition={itemsPosition} ref={(ref: DvrdSelect) => {
76
- this.select = ref
77
- }} searchValue={searchValue} onChangeSearch={this.onChangeSearch} selectOnly={selectOnly}
78
- optionsContainerHeight={optionsContainerHeight}/>
79
- );
80
- }
81
- };
@@ -1,310 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import './style/select.scss';
6
-
7
- import React, {CSSProperties, FocusEventHandler, KeyboardEventHandler, MouseEventHandler} from 'react';
8
- import classNames from 'classnames';
9
- import {Breakpoint, ChangeFunction, ElementPosition, OrnamentShape, SelectItemShape} from "../util/interfaces";
10
- import AwesomeIcon from '../icon/awesomeIcon';
11
- import TextField from '../input/v2/inputController_v2';
12
- import {isNotNull, isNull, pxToRem, voidFunction} from "../util/controlUtil";
13
- import {colorIsWhite, convertColor, hexToRgb} from "../util/colorUtil";
14
- import {ControlContext} from "../util/controlContext";
15
- import {getBreakPoint, getScreenHeight } from '../util/responsiveUtil';
16
-
17
- interface Props {
18
- onSelect: any;
19
- onSelectNative: React.ChangeEventHandler;
20
- onClickLabel: any;
21
- onMouseEnter: MouseEventHandler;
22
- onMouseLeave: MouseEventHandler;
23
- onMouseEnterItem: any;
24
- onMouseLeaveItem: MouseEventHandler;
25
- onSearch: ChangeFunction;
26
- onClear: any;
27
- onEnter?: KeyboardEventHandler;
28
- renderItems?: Function;
29
- onFocus: FocusEventHandler;
30
- onClick: any;
31
- error: string | null;
32
- placeholder: string | null;
33
- value: string | string[] | number | number[] | null;
34
- hoverItem: string | number | null;
35
- containerClass: string;
36
- inputContainerClass: string;
37
- labelClass: string;
38
- itemContainerClass: string;
39
- itemClass: string;
40
- baseColor: string;
41
- searchValue: string;
42
- id: string;
43
- itemsHeight?: string;
44
- itemsPosition: 'absolute' | 'fixed' | 'relative' | 'sticky';
45
- label: string;
46
- disabled: boolean;
47
- selectOnly: boolean;
48
- readOnly: boolean;
49
- isHovered: boolean;
50
- isFocused: boolean;
51
- itemsOpen: boolean;
52
- fullWidth: boolean;
53
- items: SelectItemShape[];
54
- multiple: boolean;
55
- unControlled: boolean;
56
- mobileNative: boolean;
57
- itemsCoords: {
58
- top: number;
59
- scrollTop: number;
60
- left: number;
61
- };
62
- }
63
-
64
- export class Select extends React.Component<Props> {
65
- declare context: React.ContextType<typeof ControlContext>;
66
- static contextType = ControlContext;
67
-
68
- getBaseColor = (allowWhite: boolean = true): string => {
69
- const {baseColor} = this.props, {contrastColor} = this.context;
70
- let color = convertColor(baseColor);
71
- if (colorIsWhite(color)) {
72
- if (allowWhite) return color;
73
- return convertColor(contrastColor);
74
- }
75
- return color;
76
- }
77
-
78
- getItemLabel = (value: string | string[] | number | number[] | null): string => {
79
- if (value === null) return '';
80
- if (this.props.multiple) return this.getMultipleItemLabel((value as (string | number)[]));
81
-
82
- const {items} = this.props;
83
- for (const item of items)
84
- if (item.value === value) {
85
- if (item.inputLabel !== null && item.inputLabel !== undefined) return item.inputLabel;
86
- return item.label.toString();
87
- }
88
- return '';
89
- };
90
-
91
- getMultipleItemLabel = (value: (string | number)[]): string => {
92
- if (value.length === 1) {
93
- const selected: string | number = value[0];
94
- const {items} = this.props;
95
- for (const item of items)
96
- if (item.value === selected) {
97
- if (item.inputLabel !== null && item.inputLabel !== undefined) return item.inputLabel;
98
- return item.label.toString();
99
- }
100
- } else if (value.length > 1) return `${value.length} geselecteerd`;
101
- return '';
102
- };
103
-
104
- getContainerClass = (): string => {
105
- const {containerClass, error, disabled, fullWidth, readOnly} = this.props,
106
- classes = ['selectContainer'];
107
- if (isNotNull(error)) classes.push('error');
108
-
109
- if (disabled) classes.push('disabled');
110
- else if (readOnly) classes.push('readOnly');
111
-
112
- if (fullWidth) classes.push('fullWidth');
113
- classes.push(containerClass);
114
- return classNames(classes);
115
- };
116
-
117
- getContainerStyle = (): object => {
118
- const {baseColor, disabled, readOnly, error, isFocused, isHovered} = this.props;
119
- let color = 'color-gray-4';
120
- if (isNotNull(error)) color = 'red';
121
- else if (!(disabled || readOnly) && isFocused && isHovered) color = baseColor;
122
-
123
- return {borderColor: convertColor(color)};
124
- };
125
-
126
- getInputClass = (): string => {
127
- const {inputContainerClass} = this.props, classes = ['selectInput'];
128
- classes.push(inputContainerClass);
129
- return classNames(classes);
130
- };
131
-
132
- getItemStyle = (itemValue: string | number) => {
133
- const {hoverItem, multiple, value} = this.props, baseColor = this.getBaseColor(false);
134
- let color = 'white';
135
- if (hoverItem === itemValue) {
136
- const rgb = hexToRgb(convertColor(baseColor));
137
- if (rgb !== null) {
138
- const {r, g, b} = rgb;
139
- color = `rgba(${r},${g},${b},.4`;
140
- }
141
- } else if ((multiple && (value as (string | number)[]).includes(itemValue)) || value === itemValue) {
142
- const rgb = hexToRgb(convertColor(multiple ? 'color-green-whatsapp' : baseColor));
143
- if (rgb !== null) {
144
- const {r, g, b} = rgb;
145
- color = `rgba(${r},${g},${b},.3`;
146
- }
147
- }
148
- return {backgroundColor: color};
149
- };
150
-
151
- getNativeLabelStyle = (): { color: string, fontWeight: number } => {
152
- const {contrastColor} = this.context, color = convertColor(contrastColor), fontWeight = 500;
153
- return {color, fontWeight};
154
- };
155
-
156
- getItemContainerStyle = (): CSSProperties => {
157
- const styles: CSSProperties = {}, {items, itemsHeight, itemsPosition, itemsCoords} = this.props,
158
- renderAbleItems = items.filter((item) => item.label.toString().length > 0);
159
- styles.maxHeight = isNull(itemsHeight) ? pxToRem(Math.min(renderAbleItems.length, 4) * 35) + 'rem' : itemsHeight;
160
- styles.position = itemsPosition;
161
- if (itemsPosition === 'absolute') {
162
- styles.top = '100%';
163
- styles.left = 0;
164
- styles.width = '100%';
165
- } else if (itemsPosition === 'fixed') {
166
- const top = itemsCoords.top - itemsCoords.scrollTop;
167
- styles.top = top + 'px';
168
- styles.maxHeight = getScreenHeight() - top + 'px';
169
- styles.left = itemsCoords.left + 'px';
170
- styles.width = this.getContainerWidth() + 'px';
171
- }
172
- return styles;
173
- };
174
-
175
- itemIsSelected = (itemValue: string | number) => {
176
- const {value, multiple} = this.props;
177
- if (value === null) return false;
178
- if (multiple && Array.isArray(value)) return (value as (string | number)[]).includes(itemValue);
179
- return value === itemValue;
180
- };
181
-
182
- setMinItemsWidth = () => {
183
- if (this.props.itemsPosition === 'fixed') {
184
- const container = document.getElementById(this.props.id);
185
- if (container) {
186
- const itemsContainer = container.querySelector('div.itemsContainer') as HTMLDivElement | null;
187
- if (itemsContainer) itemsContainer.style.width = this.getContainerWidth() + 'px;';
188
- }
189
- }
190
- };
191
-
192
- getContainerWidth = (): number => {
193
- const container = document.getElementById(this.props.id + '-input');
194
- if (container)
195
- return container.getBoundingClientRect().width;
196
- return 0;
197
- };
198
-
199
- renderInput = (): React.ReactNode => {
200
- const {
201
- searchValue, onSearch, onFocus, disabled, readOnly, selectOnly, value, id, label, itemsOpen, error,
202
- onClickLabel, multiple, onClear, onEnter,
203
- } = this.props;
204
- if (selectOnly)
205
- return (
206
- <div className={classNames('valueLabelContainer', isNotNull(error) && 'hasError')}
207
- onClick={onClickLabel} style={this.getContainerStyle()} id={id}>
208
- <label className={classNames('selectLabel', isNotNull(value) && 'up')}>{label}</label>
209
- <div className='labelContainer'>
210
- <label className={classNames('valueLabel', disabled && 'disabled', readOnly && 'readOnly')}>
211
- {this.getItemLabel(value)}</label>
212
- {(multiple && isNotNull(value)) &&
213
- <span className='common-icon-cross clearSelectButton' onClick={onClear}/>}
214
- </div>
215
- <label className='error'>{error}</label>
216
- </div>
217
- );
218
-
219
- const inputValue = itemsOpen ? searchValue : this.getItemLabel(value);
220
- return <TextField value={inputValue} onChange={onSearch} onFocus={onFocus} id={id}
221
- ornaments={this.renderInputOrnament()} label={label} error={error}
222
- className={this.getInputClass()} disabled={disabled} readOnly={readOnly}
223
- inputProps={{autoComplete: 'off'}} onEnter={onEnter}/>;
224
- // return <InputController value={inputValue} onChange={onSearch} onFocus={onFocus} id={id + '-input'}
225
- // ornaments={this.renderInputOrnament()} label={label} error={error}
226
- // containerClass={this.getInputClass()} disabled={disabled} readOnly={readOnly}
227
- // inputProps={{autoComplete: 'off'}} onEnter={onEnter}/>;
228
- };
229
-
230
- renderInputOrnament = (): OrnamentShape | OrnamentShape[] => {
231
- const {searchValue, multiple, value, onClear} = this.props;
232
- if (multiple && isNotNull(value))
233
- return {
234
- placement: ElementPosition.RIGHT,
235
- element: <span className='common-icon-cross clearSelectButton' onClick={onClear}/>
236
- };
237
- if (isNull(searchValue))
238
- return {placement: ElementPosition.RIGHT, element: <AwesomeIcon name='search' className='searchIcon'/>};
239
- return [];
240
- };
241
-
242
- renderOrnament = (): React.ReactNode => {
243
- const {itemsOpen, selectOnly, onClickLabel} = this.props;
244
- return <AwesomeIcon name='chevron-up' className={classNames('caretIcon', !itemsOpen && 'down')}
245
- onClick={selectOnly ? onClickLabel : voidFunction}/>;
246
- };
247
-
248
- renderItemContainer = (): React.ReactNode => {
249
- const {
250
- itemContainerClass, items, itemsOpen, itemClass, onMouseEnterItem, onMouseLeaveItem, onSelect, renderItems,
251
- multiple
252
- } = this.props;
253
- return (
254
- <div className={classNames('itemsContainer', itemsOpen && 'open', itemContainerClass)}
255
- style={this.getItemContainerStyle()}>
256
- {items.map((item, key) => {
257
- if(!item.label) return null;
258
- if (renderItems !== null && renderItems !== undefined) return renderItems(item, key);
259
- return (
260
- <div key={key}
261
- className={classNames('itemContainer', multiple && 'multiple',
262
- item.selectable === false && 'readOnly', itemClass)}
263
- onClick={onSelect(item)} onMouseEnter={onMouseEnterItem(item)}
264
- onMouseLeave={onMouseLeaveItem} style={this.getItemStyle(item.value)}>
265
- <label className={classNames('itemLabel', item.labelClass)}
266
- style={item.labelStyle}>{item.label}</label>
267
- {(multiple && this.itemIsSelected(item.value)) &&
268
- <AwesomeIcon name='check' className='selectedCheck'/>}
269
- </div>
270
- )
271
- })}
272
- </div>
273
- );
274
- };
275
-
276
- renderNative = (): React.ReactNode => {
277
- const {items, onSelectNative, value, id, label} = this.props;
278
- let selectValue: string = '';
279
- if (Array.isArray(value) && value.length) selectValue = value[0].toString();
280
- else if (value instanceof Number) selectValue = value.toString();
281
- else if (typeof value === 'string') selectValue = value;
282
- return (
283
- <div className={classNames('native-select-container', this.props.containerClass)}>
284
- <label htmlFor={id} style={this.getNativeLabelStyle()} className='native-select-label'>{label}</label>
285
- <select id={id} onChange={onSelectNative} value={selectValue}>
286
- {items.map((item, index) => <option key={index} value={item.value}>{item.label}</option>)}
287
- </select>
288
- </div>
289
- )
290
- };
291
-
292
- componentDidMount = () => {
293
- this.setMinItemsWidth();
294
- };
295
-
296
- render = () => {
297
- const {onClick, id, mobileNative} = this.props;
298
- const breakPoint = getBreakPoint();
299
- if ([Breakpoint.XS, Breakpoint.SM].includes(breakPoint) && mobileNative) return this.renderNative();
300
- return (
301
- <div className={this.getContainerClass()} style={this.getContainerStyle()} onClick={onClick} id={id}>
302
- <div className='selectInputContainer'>
303
- {this.renderInput()}
304
- {this.renderOrnament()}
305
- </div>
306
- {this.renderItemContainer()}
307
- </div>
308
- )
309
- }
310
- }