-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseChoiceInput.tsx
More file actions
70 lines (65 loc) · 1.97 KB
/
BaseChoiceInput.tsx
File metadata and controls
70 lines (65 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import BaseInput from '@ids-internal/partials/BaseInput';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';
import { BaseChoiceInputProps } from './BaseChoiceInput.types';
const BaseChoiceInput = ({
name,
type,
onBlur = () => undefined,
onChange = () => undefined,
onFocus = () => undefined,
onInput = () => undefined,
checked = false,
className = '',
disabled = false,
error = false,
extraAria = {},
id = undefined,
inputClassName = '',
ref,
required = false,
title = '',
value = '',
}: BaseChoiceInputProps) => {
const componentClassName = createCssClassNames({
'ids-choice-input': true,
[className]: !!className,
});
const componentOnBlur = (event: React.FocusEvent<HTMLInputElement>) => {
onBlur(event);
};
const componentOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
onChange(event.target.checked, event);
};
const componentOnFocus = (event: React.FocusEvent<HTMLInputElement>) => {
onFocus(event);
};
const componentOnInput = (event: React.ChangeEvent<HTMLInputElement>) => {
onInput(event.target.checked, event);
};
return (
<div className={componentClassName}>
<BaseInput
className={inputClassName}
disabled={disabled}
error={error}
extraInputAttrs={{
checked,
onBlur: componentOnBlur,
onChange: componentOnChange,
onFocus: componentOnFocus,
onInput: componentOnInput,
...extraAria,
}}
id={id}
name={name}
ref={ref}
required={required}
title={title}
type={type}
value={value}
/>
</div>
);
};
export default BaseChoiceInput;