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