Some styles

This commit is contained in:
Eric Bailey
2024-01-13 13:21:51 -06:00
parent ceef55041a
commit 1e9c44fc75
4 changed files with 146 additions and 37 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ import {View, PressableProps, LayoutChangeEvent} from 'react-native'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {useTheme, atoms as a} from '#/alf' import {useTheme, atoms as a} from '#/alf'
import {H2, P} from '#/components/Typography' import {H4, P} from '#/components/Typography'
import {Button} from '#/components/Button' import {Button} from '#/components/Button'
import * as Dialog from '#/components/Dialog' import * as Dialog from '#/components/Dialog'
@@ -70,11 +70,11 @@ export function Title({children}: React.PropsWithChildren<{}>) {
const t = useTheme() const t = useTheme()
const {titleId} = React.useContext(Context) const {titleId} = React.useContext(Context)
return ( return (
<H2 <H4
nativeID={titleId} nativeID={titleId}
style={[a.font_bold, t.atoms.text_contrast_600, a.pb_sm]}> style={[a.font_bold, t.atoms.text_contrast_600, a.pb_sm]}>
{children} {children}
</H2> </H4>
) )
} }
+7 -1
View File
@@ -1,12 +1,13 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {atoms} from '#/alf' import {atoms, useTheme} from '#/alf'
/** /**
* NOT FINISHED, just here as a reference * NOT FINISHED, just here as a reference
*/ */
export function InputGroup(props: React.PropsWithChildren<{}>) { export function InputGroup(props: React.PropsWithChildren<{}>) {
const t = useTheme()
const children = React.Children.toArray(props.children) const children = React.Children.toArray(props.children)
const total = children.length const total = children.length
return ( return (
@@ -14,6 +15,11 @@ export function InputGroup(props: React.PropsWithChildren<{}>) {
{children.map((child, i) => { {children.map((child, i) => {
return React.isValidElement(child) ? ( return React.isValidElement(child) ? (
<React.Fragment key={i}> <React.Fragment key={i}>
{i > 0 ? (
<View
style={[atoms.border_b, {borderColor: t.palette.contrast_500}]}
/>
) : null}
{React.cloneElement(child, { {React.cloneElement(child, {
// @ts-ignore // @ts-ignore
style: [ style: [
+82 -27
View File
@@ -42,6 +42,7 @@ export function InputText({
onOut: onHoverOut, onOut: onHoverOut,
} = useInteractionState() } = useInteractionState()
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState() const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
const hasIcon = !!Icon
const handleSuffixLayout = React.useCallback( const handleSuffixLayout = React.useCallback(
(e: LayoutChangeEvent) => { (e: LayoutChangeEvent) => {
@@ -50,39 +51,85 @@ export function InputText({
[setSuffixPadding], [setSuffixPadding],
) )
const {inputStyles, iconStyles} = React.useMemo(() => { const {inputBaseStyles, inputHoverStyles, inputFocusStyles} =
const input: TextStyle[] = [] React.useMemo(() => {
const icon: TextStyle[] = [] const base: TextStyle[] = []
const hover: TextStyle[] = [
{
borderColor: t.palette.contrast_300,
},
]
const focus: TextStyle[] = [
{
backgroundColor: t.palette.contrast_50,
borderColor: t.palette.primary_500,
},
]
if (Icon) { if (hasIcon) {
input.push({ base.push({
paddingLeft: 40, paddingLeft: 40,
}) })
} }
if (hasError) { if (hasError) {
input.push({ base.push({
borderColor: tokens.color.red_200, backgroundColor:
t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900,
borderColor:
t.name === 'light'
? t.palette.negative_300
: t.palette.negative_800,
}) })
icon.push({ hover.push({
color: tokens.color.red_400, borderColor: tokens.color.red_500,
}) })
} focus.push({
backgroundColor:
if (hovered || focused) { t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900,
input.push({
borderColor: t.atoms.border_contrast.borderColor,
})
if (hasError) {
input.push({
borderColor: tokens.color.red_500, borderColor: tokens.color.red_500,
}) })
} }
return {
inputBaseStyles: base,
inputHoverStyles: hover,
inputFocusStyles: focus,
}
}, [t, hasError, hasIcon])
const {iconBaseStyles, iconHoverStyles, iconFocusStyles} =
React.useMemo(() => {
const base: TextStyle[] = []
const hover: TextStyle[] = [
{
color: t.palette.contrast_500,
},
]
const focus: TextStyle[] = [
{
color: t.palette.primary_500,
},
]
if (hasError) {
base.push({
color: t.palette.negative_400,
})
hover.push({
color: t.palette.negative_500,
})
focus.push({
color: t.palette.negative_500,
})
} }
return {inputStyles: input, iconStyles: icon} return {
}, [t, hovered, focused, hasError, Icon]) iconBaseStyles: base,
iconHoverStyles: hover,
iconFocusStyles: focus,
}
}, [t, hasError])
const handleOnChange = React.useCallback( const handleOnChange = React.useCallback(
(e: any) => { (e: any) => {
@@ -116,7 +163,7 @@ export function InputText({
aria-label={label} aria-label={label}
accessibilityLabel={accessibilityLabel} accessibilityLabel={accessibilityLabel}
accessibilityHint={accessibilityHint} accessibilityHint={accessibilityHint}
placeholderTextColor={t.atoms.text_contrast_500.color} placeholderTextColor={t.atoms.text_contrast_400.color}
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}
onChange={handleOnChange} onChange={handleOnChange}
@@ -125,20 +172,21 @@ export function InputText({
onMouseLeave: onHoverOut, onMouseLeave: onHoverOut,
})} })}
style={[ style={[
t.name === 'dark' ? t.atoms.bg_contrast_100 : t.atoms.bg, t.atoms.bg_contrast_50,
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, atoms.text_md,
t.atoms.border,
t.atoms.text, t.atoms.text,
web({ web({
paddingTop: atoms.pt_md.paddingTop - 1, paddingTop: atoms.pt_md.paddingTop - 1,
}), }),
{paddingRight: suffixPadding}, {borderColor: 'transparent', paddingRight: suffixPadding},
{borderWidth: 2, lineHeight: atoms.text_md.lineHeight * 1.1875}, {borderWidth: 2, lineHeight: atoms.text_md.lineHeight * 1.1875},
...inputStyles, ...inputBaseStyles,
...(hovered ? inputHoverStyles : []),
...(focused ? inputFocusStyles : []),
...(Array.isArray(props.style) ? props.style : [props.style]), ...(Array.isArray(props.style) ? props.style : [props.style]),
]} ]}
/> />
@@ -155,12 +203,19 @@ export function InputText({
]}> ]}>
<Icon <Icon
style={[ style={[
{color: t.atoms.border_contrast.borderColor}, {
color:
t.name === 'light'
? t.palette.contrast_400
: t.palette.contrast_700,
},
{ {
width: 20, width: 20,
pointerEvents: 'none', pointerEvents: 'none',
}, },
...iconStyles, ...iconBaseStyles,
...(hovered ? iconHoverStyles : []),
...(focused ? iconFocusStyles : []),
]} ]}
/> />
</View> </View>
+48
View File
@@ -5,6 +5,7 @@ import {atoms as a} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {InputText} from '#/components/forms/InputText' import {InputText} from '#/components/forms/InputText'
import {InputDate, utils} from '#/components/forms/InputDate' import {InputDate, utils} from '#/components/forms/InputDate'
import {InputGroup} from '#/components/forms/InputGroup'
import {Logo} from '#/view/icons/Logo' import {Logo} from '#/view/icons/Logo'
export function Forms() { export function Forms() {
@@ -27,6 +28,16 @@ export function Forms() {
value="Test initial value" value="Test initial value"
onChange={text => console.log(text)} onChange={text => console.log(text)}
/> />
<InputText
hasError
testID="input"
accessibilityLabel="Input"
accessibilityHint="Enter some text"
placeholder="Type here"
value="Test initial value"
onChange={text => console.log(text)}
icon={Logo}
/>
<InputText <InputText
testID="input" testID="input"
accessibilityLabel="Input" accessibilityLabel="Input"
@@ -46,6 +57,43 @@ export function Forms() {
icon={Logo} icon={Logo}
suffix={() => <Text>.bksy.social</Text>} suffix={() => <Text>.bksy.social</Text>}
/> />
<InputText
multiline
numberOfLines={3}
testID="input"
accessibilityLabel="Input"
accessibilityHint="Enter some text"
placeholder="Type here"
value=""
onChange={text => console.log(text)}
/>
<InputGroup>
<InputText
testID="input"
accessibilityLabel="Input"
accessibilityHint="Enter some text"
placeholder="Type here"
value=""
onChange={text => console.log(text)}
/>
<InputText
testID="input"
accessibilityLabel="Input"
accessibilityHint="Enter some text"
placeholder="Type here"
value=""
onChange={text => console.log(text)}
/>
<InputText
testID="input"
accessibilityLabel="Input"
accessibilityHint="Enter some text"
placeholder="Type here"
value=""
onChange={text => console.log(text)}
/>
</InputGroup>
<InputDate <InputDate
testID="date" testID="date"