Add labels to input
This commit is contained in:
@@ -2,14 +2,17 @@ import React from 'react'
|
|||||||
import {View, TextInput, TextInputProps, TextStyle} from 'react-native'
|
import {View, TextInput, TextInputProps, TextStyle} from 'react-native'
|
||||||
|
|
||||||
import {useTheme, atoms, web, tokens} from '#/alf'
|
import {useTheme, atoms, web, tokens} from '#/alf'
|
||||||
|
import {Text} from '#/view/com/Typography'
|
||||||
|
|
||||||
type Props = Omit<TextInputProps, 'placeholder'> & {
|
type Props = Omit<TextInputProps, 'placeholder'> & {
|
||||||
|
label?: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
hasError?: boolean
|
hasError?: boolean
|
||||||
icon?: React.FunctionComponent<any>
|
icon?: React.FunctionComponent<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function InputText({hasError, icon: Icon, ...props}: Props) {
|
export function InputText({label, hasError, icon: Icon, ...props}: Props) {
|
||||||
|
const labelId = React.useId()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const [state, setState] = React.useState({
|
const [state, setState] = React.useState({
|
||||||
hovered: false,
|
hovered: false,
|
||||||
@@ -77,7 +80,23 @@ export function InputText({hasError, icon: Icon, ...props}: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[atoms.relative, atoms.w_full]}>
|
<View style={[atoms.relative, atoms.w_full]}>
|
||||||
|
{label && (
|
||||||
|
<Text
|
||||||
|
nativeID={labelId}
|
||||||
|
style={[
|
||||||
|
atoms.text_sm,
|
||||||
|
atoms.font_semibold,
|
||||||
|
t.atoms.text_contrast_700,
|
||||||
|
atoms.mb_sm,
|
||||||
|
]}>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
|
aria-labelledby={labelId}
|
||||||
|
aria-label={label}
|
||||||
|
placeholderTextColor={t.atoms.text_contrast_500.color}
|
||||||
{...props}
|
{...props}
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
@@ -85,13 +104,13 @@ export function InputText({hasError, icon: Icon, ...props}: Props) {
|
|||||||
onMouseEnter: onHoverIn,
|
onMouseEnter: onHoverIn,
|
||||||
onMouseLeave: onHoverOut,
|
onMouseLeave: onHoverOut,
|
||||||
})}
|
})}
|
||||||
placeholderTextColor={t.atoms.text_contrast_500.color}
|
|
||||||
style={[
|
style={[
|
||||||
t.name === 'dark' ? t.atoms.bg_contrast_100 : t.atoms.bg,
|
t.name === 'dark' ? t.atoms.bg_contrast_100 : t.atoms.bg,
|
||||||
atoms.w_full,
|
atoms.w_full,
|
||||||
atoms.px_lg,
|
atoms.px_lg,
|
||||||
atoms.py_md,
|
atoms.py_md,
|
||||||
atoms.rounded_sm,
|
atoms.rounded_sm,
|
||||||
|
atoms.text_md,
|
||||||
t.atoms.border,
|
t.atoms.border,
|
||||||
t.atoms.text,
|
t.atoms.text,
|
||||||
{borderWidth: 2},
|
{borderWidth: 2},
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ export function Buttons() {
|
|||||||
function Forms() {
|
function Forms() {
|
||||||
return (
|
return (
|
||||||
<View style={[a.gap_md, a.align_start]}>
|
<View style={[a.gap_md, a.align_start]}>
|
||||||
<InputText placeholder="Type here" />
|
<InputText label="Name" placeholder="Type here" />
|
||||||
<InputText placeholder="Type here" icon={Logo} />
|
<InputText placeholder="Type here" icon={Logo} />
|
||||||
<InputText hasError placeholder="Type here" icon={Logo} />
|
<InputText hasError placeholder="Type here" icon={Logo} />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user