feat(system): add label to Input component

This commit is contained in:
Pavel Prichodko 2022-04-06 14:04:42 +02:00
parent d428554d94
commit db47a0aeb0
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import React, { forwardRef } from 'react'
import { Box } from '../box'
import { Text } from '../text'
import { Base } from './styles'
import type { Ref } from 'react'
@ -10,11 +11,13 @@ type InputProps = React.InputHTMLAttributes<HTMLInputElement>
interface Props {
id?: string
name?: string
label?: string
type?: InputProps['type']
value?: string
defaultValue?: string
onChange?: InputProps['onChange']
onBlur?: InputProps['onBlur']
onClick?: InputProps['onClick']
disabled?: boolean
readOnly?: boolean
required?: boolean
@ -28,9 +31,16 @@ interface Props {
}
const TextInput = (props: Props, ref: Ref<HTMLInputElement>) => {
const { label, ...inputProps } = props
return (
<Box>
<Base ref={ref} {...props} />
{label && (
<Text size={13} weight={500} css={{ marginBottom: 6 }}>
{label}
</Text>
)}
<Base ref={ref} {...inputProps} />
</Box>
)
}