-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseInput.tsx
More file actions
51 lines (45 loc) · 1.36 KB
/
BaseInput.tsx
File metadata and controls
51 lines (45 loc) · 1.36 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
import React from 'react';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';
import { useGenerateSimpleNumberId } from '@ids-internal/hooks/generators';
import { BaseInputProps } from './BaseInput.types';
const INPUT_ID_PREFIX = 'ids-input-';
const BaseInput = ({
name,
disabled = false,
error = false,
className = '',
extraInputAttrs = {},
id = undefined,
required = false,
size = 'medium',
title = '',
type = 'text',
value = '',
}: BaseInputProps) => {
const componentGeneratedNumberId = useGenerateSimpleNumberId();
const componentId = id ?? `${INPUT_ID_PREFIX}${componentGeneratedNumberId.toString()}`;
const componentClassName = createCssClassNames({
'ids-input': true,
[`ids-input--${type}`]: true,
[`ids-input--${size}`]: true,
'ids-input--disabled': disabled,
'ids-input--error': error,
'ids-input--required': required,
[className]: !!className,
});
return (
<input
aria-invalid={error}
aria-required={required}
className={componentClassName}
disabled={disabled}
id={componentId}
name={name}
title={title}
type={type}
value={value}
{...extraInputAttrs}
/>
);
};
export default BaseInput;