@dvrd/dvr-controls 1.0.23 → 1.0.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -24,27 +24,26 @@
24
24
  "@fortawesome/free-solid-svg-icons": "6.3.0",
25
25
  "@fortawesome/react-fontawesome": "0.2.0",
26
26
  "@types/dompurify": "2.4.0",
27
- "@types/js-cookie": "3.0.2",
28
- "@types/lodash": "4.14.189",
29
- "@types/node": "18.11.9",
30
- "@types/react": "18.0.25",
27
+ "@types/js-cookie": "3.0.3",
28
+ "@types/lodash": "4.14.191",
29
+ "@types/node": "18.14.0",
30
+ "@types/react": "18.0.28",
31
31
  "@types/react-color": "3.0.6",
32
- "@types/react-dom": "18.0.9",
32
+ "@types/react-dom": "18.0.11",
33
33
  "@types/react-router-dom": "5.3.3",
34
- "@types/uuid": "8.3.4",
34
+ "@types/uuid": "9.0.0",
35
35
  "classnames": "2.3.2",
36
36
  "cross-env": "7.0.3",
37
- "dompurify": "2.4.1",
37
+ "dompurify": "3.0.0",
38
38
  "js-cookie": "3.0.1",
39
39
  "lodash": "4.17.21",
40
40
  "moment": "2.29.4",
41
41
  "react": "18.2.0",
42
42
  "react-color": "2.19.3",
43
43
  "react-dom": "18.2.0",
44
- "react-rnd": "10.3.7",
45
- "react-router": "^6.8.0",
46
- "react-router-dom": "6.4.3",
47
- "typescript": "4.9.3",
44
+ "react-rnd": "10.4.1",
45
+ "react-router-dom": "6.8.1",
46
+ "typescript": "4.9.5",
48
47
  "uuid": "9.0.0"
49
48
  }
50
49
  }
@@ -50,6 +50,7 @@ interface Props {
50
50
  menuLabelColor?: string;
51
51
  topControl: boolean;
52
52
  topControlProps?: Partial<TopButtonProps>;
53
+ onClickItem?: (item: HeaderItem) => MouseEventHandler;
53
54
  }
54
55
 
55
56
  interface State {
@@ -236,7 +237,7 @@ export default class DVRHeader extends PureComponent<Props, State> {
236
237
  const {onClick, component, customClass, icon, iconOnly, label} = item,
237
238
  renderAble: RenderAble = {
238
239
  toRender: null,
239
- clickHandler: onClick,
240
+ clickHandler: this.props.onClickItem?.(item) ?? onClick,
240
241
  isComp: false,
241
242
  }, className = classNames('dvr-header-item', customClass);
242
243
  if (iconOnly) {
@@ -2,13 +2,22 @@
2
2
  * Copyright (c) 2021. Dave van Rijn Development
3
3
  */
4
4
  import React, {
5
- ChangeEventHandler, CSSProperties, EventHandler, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler,
6
- MouseEventHandler, PureComponent, ReactNode, TextareaHTMLAttributes
5
+ ChangeEventHandler,
6
+ CSSProperties,
7
+ DetailedHTMLProps,
8
+ EventHandler,
9
+ FocusEventHandler,
10
+ InputHTMLAttributes,
11
+ KeyboardEventHandler,
12
+ MouseEventHandler,
13
+ PureComponent,
14
+ ReactNode,
15
+ TextareaHTMLAttributes
7
16
  } from 'react';
8
17
  import {assert, enterPressed} from "../../util/controlUtil";
9
18
  import SimpleInput from "../simple/v2/simpleInputV2";
10
19
  import {ControlVariant, ErrorType, OrnamentShape} from "../../util/interfaces";
11
- import { generateComponentId } from '../../../..';
20
+ import {generateComponentId} from '../../../..';
12
21
 
13
22
  type HTMLProps = Omit<InputHTMLAttributes<any>, 'onChange' | 'step' | 'children'>;
14
23
 
@@ -76,7 +85,7 @@ export interface DVRInputProps extends Omit<DVRInputControllerProps, 'value' | '
76
85
  inputStyle?: CSSProperties;
77
86
  // Other
78
87
  error: ErrorType;
79
- inputProps?: InputHTMLAttributes<any>;
88
+ inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, HTMLInputElement | HTMLTextAreaElement>, 'crossOrigin'>;
80
89
  ornaments?: OrnamentShape | OrnamentShape[];
81
90
  clearAble: boolean;
82
91
  fullWidth: boolean;
@@ -206,7 +215,7 @@ export default class InputControllerV2 extends PureComponent<DVRInputControllerP
206
215
 
207
216
  getViewValue = (): string | number => {
208
217
  const {value, unControlled} = this.props;
209
- if(unControlled || value === undefined) return this.state.value;
218
+ if (unControlled || value === undefined) return this.state.value;
210
219
  return value;
211
220
  };
212
221
 
@@ -3,20 +3,16 @@
3
3
  */
4
4
 
5
5
  import React from 'react';
6
- // import {RouteComponentProps, withRouter} from "react-router";
7
- import { useNavigate } from 'react-router-dom';
8
- import { useLocation } from 'react-router-dom';
6
+ import {useNavigate} from 'react-router-dom';
9
7
  import {debug} from '../util/miscUtil';
10
8
 
11
- // let navigationData: any = null;
12
-
13
9
  export default function AppNavigator() {
14
- const location = useLocation();
15
10
  const navigate = useNavigate();
16
11
 
17
12
  function onNavigate(evt: React.MouseEvent) {
18
13
  const navigator: HTMLButtonElement = evt.target as HTMLButtonElement;
19
- const url = navigator.dataset.url + (navigator.dataset.strip === '0' ? location.search : '');
14
+ const search = window.location.search;
15
+ const url = navigator.dataset.url + (navigator.dataset.strip === '0' ? search : '');
20
16
  navigator.dataset.strip = '0';
21
17
  debug(`Navigating to ${url}`);
22
18
  navigate(url);
@@ -10,7 +10,6 @@ import {
10
10
  directTimeout,
11
11
  dispatchCustomEvent,
12
12
  DvrdButton,
13
- generateComponentId,
14
13
  generateUUID,
15
14
  IndexedObject,
16
15
  PDFElementParams,
@@ -48,10 +47,11 @@ interface Props {
48
47
  maxWidth?: string;
49
48
  supportMultiPage: boolean;
50
49
  options?: PDFOptions;
50
+ singleImage: boolean;
51
51
  }
52
52
 
53
53
  interface State {
54
- elements: IndexedObject<React.ReactElement>;
54
+ elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }>;
55
55
  focusedElement: PdfElement | null;
56
56
  canUndo: boolean;
57
57
  canRedo: boolean;
@@ -62,25 +62,20 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
62
62
  values: {},
63
63
  disableElements: [],
64
64
  supportMultiPage: false,
65
+ singleImage: false,
65
66
  };
66
-
67
- private readonly id: string = generateComponentId(this.props.id, true);
68
67
  private refObjects: IndexedObject<PdfElement>;
69
68
 
70
- state: State = {
71
- elements: {}, focusedElement: null, canRedo: false, canUndo: false,
72
- };
73
-
74
69
  constructor(props: Props) {
75
70
  super(props);
76
71
  this.refObjects = {};
77
- const elements: IndexedObject<React.ReactElement> = this.processItems(props.defaultItems);
72
+ const elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> = this.processItems(props.defaultItems);
78
73
  this.state = {elements, focusedElement: null, canRedo: false, canUndo: false};
79
74
  }
80
75
 
81
76
  processItems = (items?: DefaultPDFElementParams<any, any>[],
82
- convertUnits: boolean = true): IndexedObject<React.ReactElement> => {
83
- const elements: IndexedObject<React.ReactElement> = {};
77
+ convertUnits: boolean = true): IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> => {
78
+ const elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> = {};
84
79
  if (items?.length) {
85
80
  items = JSON.parse(JSON.stringify(items));
86
81
  if (items) {
@@ -154,12 +149,13 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
154
149
 
155
150
  onAddElement = (type: PDFElementType) => (evt: React.MouseEvent) => {
156
151
  evt.stopPropagation();
157
- const id = generateUUID(), scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) + 50,
158
- {elements} = this.state;
152
+ const id = generateUUID();
153
+ const scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) + 50;
154
+ const newElements = Object.assign({}, this.state.elements);
159
155
 
160
- elements[id] = this.getElement(id,
156
+ newElements[id] = this.getElement(id,
161
157
  {dimensions: {width: 150, height: 100, left: 50, top: scrollTop}, type});
162
- this.setState({elements: Object.assign({}, elements)});
158
+ this.setState({elements: newElements});
163
159
  };
164
160
 
165
161
  onSubmit = () => {
@@ -189,7 +185,7 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
189
185
  };
190
186
 
191
187
  getElement = (id: string, config: DefaultPDFElementParams<any, any>,
192
- convertUnits: boolean = true): React.ReactElement => {
188
+ convertUnits: boolean = true): { element: React.ReactElement, config: DefaultPDFElementParams<any, any> } => {
193
189
  const {dimensions, linkedID, persistent} = config;
194
190
  const position: { x: number; y: number } = {
195
191
  x: convertUnits ? ptToPx(dimensions?.left || 0) : (dimensions?.left || 0),
@@ -212,20 +208,38 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
212
208
  defaultSettings: {...config.dimensions, ...config.options},
213
209
  key,
214
210
  }
211
+ let element = <div/>;
215
212
  switch (config.type) {
216
213
  case PDFElementType.TEXT:
217
- return <PdfText {...sharedProps} values={values} persistent={persistent} mainFont={mainFont}
218
- linkedID={linkedID}/>;
214
+ element = <PdfText {...sharedProps} values={values} persistent={persistent} mainFont={mainFont}
215
+ linkedID={linkedID}/>;
216
+ break;
219
217
  case PDFElementType.IMAGE:
220
- return <PdfImage {...sharedProps} values={values} width={width} height={height}
221
- persistent={persistent}/>;
218
+ element = <PdfImage {...sharedProps} values={values} width={width} height={height}
219
+ persistent={persistent}/>;
220
+ break;
222
221
  case PDFElementType.INVOICE_TABLE:
223
- return <PdfInvoiceTable {...sharedProps} width={width} height={height} mainFont={mainFont}
224
- persistent={PDFElementPersist.PERSISTENT}/>;
222
+ element = <PdfInvoiceTable {...sharedProps} width={width} height={height} mainFont={mainFont}
223
+ persistent={PDFElementPersist.PERSISTENT}/>;
224
+ break;
225
225
  }
226
- return <div/>;
226
+ return {element, config};
227
227
  };
228
228
 
229
+ canRenderImageButton = (): boolean => {
230
+ if (this.props.disableElements.includes('image')) return false;
231
+ if (!this.props.singleImage) return true;
232
+ const {elements} = this.state;
233
+ const elementIds = Object.keys(elements);
234
+ if (elementIds.length) {
235
+ for (const id of elementIds) {
236
+ const config = elements[id].config;
237
+ if (config.type === PDFElementType.IMAGE) return false;
238
+ }
239
+ }
240
+ return true;
241
+ }
242
+
229
243
  renderElementButton = (icon: IconName, label: string, type: PDFElementType) => (
230
244
  <div className='element-button' onClick={this.onAddElement(type)}>
231
245
  <AwesomeIcon name={icon} className='element-icon'/>
@@ -257,12 +271,13 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
257
271
  <div>
258
272
  <DvrdButton onClick={this.onSubmit} label='Opslaan'/>
259
273
  {onClickProceed !== undefined &&
260
- <DvrdButton onClick={this.onClickProceed} label='Naar volgende stap' className='proceed-btn'/>}
274
+ <DvrdButton onClick={this.onClickProceed} label='Naar volgende stap'
275
+ className='proceed-btn'/>}
261
276
  </div>
262
277
  </div>
263
278
  <div/>
264
279
  <div className='elements-container'>
265
- {!disableElements.includes('image') &&
280
+ {this.canRenderImageButton() &&
266
281
  this.renderElementButton('image', 'Afbeelding', PDFElementType.IMAGE)}
267
282
  {!disableElements.includes('text') &&
268
283
  this.renderElementButton('font', 'Tekst', PDFElementType.TEXT)}
@@ -287,7 +302,7 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
287
302
  <div className='pdf-paper' onClick={this.onResetElement}>
288
303
  {Object.keys(elements).map((id: string) => (
289
304
  <Fragment key={id}>
290
- {elements[id]}
305
+ {elements[id].element}
291
306
  </Fragment>
292
307
  ))}
293
308
  </div>
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import './style/DVRSlider.scss';
5
5
 
6
- import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
6
+ import React, {CSSProperties, DetailedHTMLProps, InputHTMLAttributes, MouseEventHandler, PureComponent} from 'react';
7
7
  import {ChangeFunction, Colors, convertColor, generateComponentId} from "../../..";
8
8
  import {ElementPosition} from '../util/interfaces';
9
9
  import {ControlContext} from "../util/controlContext";
@@ -22,7 +22,7 @@ interface Props {
22
22
  asNumber?: boolean;
23
23
  label?: string;
24
24
  labelPosition: ElementPosition;
25
- inputProps?: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
25
+ inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'crossOrigin'>;
26
26
  }
27
27
 
28
28
  export default class DVRSlider extends PureComponent<Props> {
@@ -62,7 +62,7 @@ export default class DVRSlider extends PureComponent<Props> {
62
62
  if (onMouseLeave) onMouseLeave(evt);
63
63
  };
64
64
 
65
- getInputProps = (): React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> => {
65
+ getInputProps = (): Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'crossOrigin'> => {
66
66
  const {inputProps} = this.props, defaultProps = {min: 0, max: 100, step: 1};
67
67
  return Object.assign({}, defaultProps, inputProps);
68
68
  }
@@ -4,14 +4,23 @@
4
4
  import './style/dvrdInput.scss';
5
5
 
6
6
  import React, {
7
- ChangeEventHandler, CSSProperties, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler,
8
- PureComponent
7
+ ChangeEventHandler,
8
+ CSSProperties,
9
+ DetailedHTMLProps,
10
+ FocusEventHandler,
11
+ InputHTMLAttributes,
12
+ KeyboardEventHandler,
13
+ MouseEventHandler,
14
+ useEffect,
15
+ useMemo,
16
+ useRef,
17
+ useState
9
18
  } from 'react';
10
19
  import classNames from "classnames";
11
20
  import {ElementPosition, ErrorType, OrnamentShape} from '../util/interfaces';
12
21
  import AwesomeIcon from '../icon/awesomeIcon';
13
22
  import {directTimeout} from '../util/componentUtil';
14
- import {ControlContext} from "../util/controlContext";
23
+ import {stopPropagation} from "../util/controlUtil";
15
24
 
16
25
  interface Props {
17
26
  onChange: ChangeEventHandler;
@@ -25,7 +34,8 @@ interface Props {
25
34
  autoSelect?: boolean;
26
35
  label?: string;
27
36
  ornaments?: OrnamentShape | OrnamentShape[];
28
- inputProps?: InputHTMLAttributes<any>;
37
+ // inputProps?: InputHTMLAttributes<any> & TextareaHTMLAttributes<any>;
38
+ inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, HTMLInputElement | HTMLTextAreaElement>, 'crossOrigin'>;
29
39
  className?: string;
30
40
  inputClassName?: string;
31
41
  labelClassName?: string;
@@ -38,48 +48,47 @@ interface Props {
38
48
  noResize?: boolean;
39
49
  }
40
50
 
41
- interface State {
42
- active: boolean;
43
- }
44
-
45
- export default class DvrdInput extends PureComponent<Props, State> {
46
- static contextType = ControlContext;
47
- private input: HTMLInputElement | HTMLTextAreaElement;
48
-
49
- state: State = {
50
- active: this.props.autoFocus === true,
51
- };
52
-
53
- onClickElement = (evt: React.MouseEvent) => {
54
- evt.stopPropagation();
55
- this.focusInput();
56
- };
51
+ export default function DvrdInput(props: Props) {
52
+ const {
53
+ area, id, label, labelClassName, errorClassName, inputClassName, className, ornamentClassName, inputProps,
54
+ disabled, onBlur, value, onChange, onFocus, autoSelect, autoFocus, onClearInput, noResize, onKeyDown, fullWidth,
55
+ ornaments, error
56
+ } = props;
57
+ const inputRef = useRef<HTMLInputElement & HTMLTextAreaElement>(null);
58
+ const [active, setActive] = useState(props.autoFocus ?? false);
59
+ const hasOrnaments = useMemo(() => !(!ornaments || (Array.isArray(ornaments) && !ornaments.length)),
60
+ [ornaments]);
61
+
62
+ function onClickElement(evt: React.MouseEvent) {
63
+ stopPropagation(evt);
64
+ focusInput();
65
+ }
57
66
 
58
- onFocusInput = (evt: React.FocusEvent) => {
59
- const {disabled, onFocus, autoSelect, value} = this.props;
67
+ function onFocusInput(evt: React.FocusEvent) {
60
68
  if (!disabled) {
61
- this.setState({active: true});
62
- if (autoSelect) {
63
- this.input.selectionStart = 0;
64
- this.input.selectionEnd = value.toString().length;
69
+ setActive(true);
70
+ const input = inputRef.current;
71
+ if (autoSelect && input) {
72
+ input.selectionStart = 0;
73
+ input.selectionEnd = value.toString().length;
65
74
  }
66
75
  }
67
- if (onFocus)
68
- onFocus(evt);
69
- };
76
+ onFocus?.(evt);
77
+ }
70
78
 
71
- onBlurInput = (evt: React.FocusEvent) => {
72
- const {disabled, onBlur} = this.props;
73
- if (!disabled) this.setState({active: false});
74
- if (onBlur)
75
- onBlur(evt);
76
- };
79
+ function onBlurInput(evt: React.FocusEvent) {
80
+ if (!disabled) setActive(false);
81
+ onBlur?.(evt);
82
+ }
77
83
 
78
- hasError = (): boolean => this.props.error !== undefined && this.props.error !== null;
84
+ function focusInput(retry: boolean = false) {
85
+ if (inputRef.current) inputRef.current.focus();
86
+ else if (retry) directTimeout(focusInput);
87
+ }
79
88
 
80
- getContentStyle = (): CSSProperties => {
81
- const style: CSSProperties = {gridTemplateColumns: '1fr'}, {ornaments, onClearInput} = this.props;
82
- if (!ornaments || (Array.isArray(ornaments) && !ornaments.length)) style.gridTemplateColumns = '1fr';
89
+ function getContentStyle(): CSSProperties {
90
+ const style: CSSProperties = {gridTemplateColumns: '1fr'};
91
+ if (!hasOrnaments) style.gridTemplateColumns = '1fr';
83
92
  let hasLeft: boolean = false, hasRight: boolean = onClearInput !== undefined;
84
93
  if (Array.isArray(ornaments))
85
94
  for (const ornament of ornaments) {
@@ -106,114 +115,84 @@ export default class DvrdInput extends PureComponent<Props, State> {
106
115
  style.paddingRight = paddingRight;
107
116
  style.paddingLeft = paddingLeft;
108
117
  return style;
109
- };
110
-
111
- focusInput = (retry: boolean = false) => {
112
- if (this.input) this.input.focus();
113
- else if (retry) directTimeout(this.focusInput);
114
- };
118
+ }
115
119
 
116
- renderLabel = () => {
117
- const {label, labelClassName} = this.props;
120
+ function renderLabel() {
118
121
  if (!label) return null;
119
- return <label className={classNames('dvrd-input-label', labelClassName)}
120
- onClick={this.onClickElement}>{label}</label>
121
- };
122
+ return (
123
+ <label className={classNames('dvrd-input-label', labelClassName)} onClick={onClickElement}>{label}</label>
124
+ );
125
+ }
122
126
 
123
- renderInput = () => {
124
- const {value, onChange, onKeyDown, disabled, inputProps, inputClassName, id, area, noResize} = this.props,
125
- elementProps = {
126
- ...inputProps,
127
- value,
128
- onChange,
129
- onFocus: this.onFocusInput,
130
- onBlur: this.onBlurInput,
131
- onKeyDown,
132
- disabled,
133
- className: classNames('dvrd-input', inputClassName, noResize && 'no-resize'),
134
- id: `${id}-input`,
135
- ref: (ref: HTMLInputElement & HTMLTextAreaElement) => {
136
- this.input = ref
137
- },
138
- };
127
+ function renderInput() {
128
+ const elementProps = {
129
+ ...inputProps, value, onChange, onFocus: onFocusInput, onBlur: onBlurInput, onKeyDown, disabled,
130
+ className: classNames('dvrd-input', inputClassName, noResize && 'no-resize'), id: `${id}-input`,
131
+ ref: inputRef,
132
+ };
139
133
  if (area) return <textarea {...elementProps}/>;
140
134
  return <input {...elementProps}/>
141
- };
135
+ }
142
136
 
143
- renderLeftOrnament = () => {
144
- const {ornaments} = this.props;
145
- if (!ornaments || (Array.isArray(ornaments) && !ornaments.length)) return null;
137
+ function renderLeftOrnament() {
138
+ if (!hasOrnaments) return null;
146
139
  if (Array.isArray(ornaments)) {
147
140
  for (const ornament of ornaments) {
148
141
  if (!ornament.placement || ornament.placement === ElementPosition.LEFT)
149
- return this.renderOrnament(ornament);
142
+ return renderOrnament(ornament);
150
143
  }
151
- } else if (!ornaments.placement || ornaments.placement === ElementPosition.LEFT)
152
- return this.renderOrnament(ornaments);
144
+ } else if (ornaments && (!ornaments.placement || ornaments.placement === ElementPosition.LEFT))
145
+ return renderOrnament(ornaments);
153
146
  return null;
154
- };
147
+ }
155
148
 
156
- renderRightOrnament = () => {
157
- const {ornaments, onClearInput, value} = this.props;
158
- if (onClearInput && value) return this.renderOrnament({
149
+ function renderRightOrnament() {
150
+ if (onClearInput && value) return renderOrnament({
159
151
  element: <AwesomeIcon onClick={onClearInput} name='backspace' className='clear-btn'/>,
160
152
  placement: ElementPosition.RIGHT
161
153
  });
162
- if (!ornaments || (Array.isArray(ornaments) && !ornaments.length)) return null;
154
+ if (!hasOrnaments) return null;
163
155
  if (Array.isArray(ornaments)) {
164
156
  for (const ornament of ornaments) {
165
157
  if (ornament.placement === ElementPosition.RIGHT)
166
- return this.renderOrnament(ornament);
158
+ return renderOrnament(ornament);
167
159
  }
168
- } else if (ornaments.placement === ElementPosition.RIGHT)
169
- return this.renderOrnament(ornaments);
160
+ } else if (ornaments && ornaments.placement === ElementPosition.RIGHT)
161
+ return renderOrnament(ornaments);
170
162
  return null;
171
- };
163
+ }
172
164
 
173
- renderOrnament = (ornament: OrnamentShape) => {
174
- const {ornamentClassName} = this.props;
165
+ function renderOrnament(ornament: OrnamentShape) {
175
166
  if (typeof ornament.element === 'string')
176
167
  return <span className={classNames('dvrd-input-ornament', ornamentClassName)}
177
- onClick={this.onClickElement}>{ornament.element}</span>;
168
+ onClick={onClickElement}>{ornament.element}</span>;
178
169
  else return React.cloneElement(ornament.element, {
179
170
  className: classNames(ornament.element.props.className, ornamentClassName),
180
171
  onClick: (evt: React.MouseEvent) => {
181
- this.onClickElement(evt);
182
- if (React.isValidElement(ornament.element)){
172
+ onClickElement(evt);
173
+ if (React.isValidElement(ornament.element)) {
183
174
  const element: React.ReactElement = ornament.element;
184
175
  element.props.onClick?.(evt);
185
176
  }
186
177
  }
187
178
  });
188
- };
189
-
190
- renderError = () => {
191
- const {error, errorClassName} = this.props;
192
- return <span className={classNames('dvrd-input-error', errorClassName)}>{error}</span>
193
179
  }
194
180
 
195
- componentDidUpdate = (prevProps: Props) => {
196
- if (this.props.autoFocus && !prevProps.autoFocus) this.focusInput(true);
197
- }
198
-
199
- componentDidMount = () => {
200
- if (this.props.autoFocus) this.focusInput(true);
201
- };
202
-
203
- render = () => {
204
- const {disabled, className, id, fullWidth} = this.props, {active} = this.state;
205
- return (
206
- <div onClick={this.onClickElement} id={id}
207
- className={classNames('dvrd-input-container', disabled && 'disabled', this.hasError() && 'error',
208
- active && 'active', fullWidth && 'full', className)}>
209
- {this.renderLabel()}
210
- <div className='content-container' style={this.getContentStyle()}>
211
- {this.renderLeftOrnament()}
212
- {this.renderInput()}
213
- {this.renderRightOrnament()}
214
- </div>
215
- {this.renderError()}
181
+ useEffect(() => {
182
+ if (autoFocus) focusInput(true);
183
+ }, [autoFocus]);
184
+
185
+ return (
186
+ <div onClick={onClickElement} id={id}
187
+ className={classNames('dvrd-input-container', disabled && 'disabled', !!error && 'error',
188
+ active && 'active', fullWidth && 'full', className)}>
189
+ {renderLabel()}
190
+ <div className='content-container' style={getContentStyle()}>
191
+ {renderLeftOrnament()}
192
+ {renderInput()}
193
+ {renderRightOrnament()}
216
194
  </div>
217
- )
218
- }
195
+ <span className={classNames('dvrd-input-error', errorClassName)}>{error}</span>
196
+ </div>
197
+ )
219
198
  }