Consistent imports

This commit is contained in:
Eric Bailey
2024-01-18 14:10:48 -06:00
parent 175466ade6
commit 1514ffd6e9
10 changed files with 49 additions and 89 deletions
+1 -2
View File
@@ -12,11 +12,10 @@ import {Button} from '#/components/Button'
import {DialogOuterProps, DialogInnerProps} from '#/components/Dialog/types' import {DialogOuterProps, DialogInnerProps} from '#/components/Dialog/types'
import {Context, useDialogContext} from '#/components/Dialog/context' import {Context, useDialogContext} from '#/components/Dialog/context'
import TextField from '#/components/forms/TextField'
export {useDialogControl, useDialogContext} from '#/components/Dialog/context' export {useDialogControl, useDialogContext} from '#/components/Dialog/context'
export * from '#/components/Dialog/types' export * from '#/components/Dialog/types'
export const Input = TextField.Input export {Input} from '#/components/forms/TextField'
const stopPropagation = (e: any) => e.stopPropagation() const stopPropagation = (e: any) => e.stopPropagation()
@@ -7,7 +7,7 @@ import DateTimePicker, {
import {useTheme, atoms} from '#/alf' import {useTheme, atoms} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {useInteractionState} from '#/components/hooks/useInteractionState' import {useInteractionState} from '#/components/hooks/useInteractionState'
import TextField, {useSharedInputStyles} from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
import {CalendarDays_Stroke2_Corner0_Rounded as CalendarDays} from '#/components/icons/CalendarDays' import {CalendarDays_Stroke2_Corner0_Rounded as CalendarDays} from '#/components/icons/CalendarDays'
import {DateFieldProps} from '#/components/forms/DateField/types' import {DateFieldProps} from '#/components/forms/DateField/types'
@@ -35,7 +35,8 @@ export function DateField({
} = useInteractionState() } = useInteractionState()
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState() const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
const {chromeFocus, chromeError, chromeErrorHover} = useSharedInputStyles() const {chromeFocus, chromeError, chromeErrorHover} =
TextField.useSharedInputStyles()
const onChangeInternal = React.useCallback< const onChangeInternal = React.useCallback<
Required<DateTimePickerProps>['onChange'] Required<DateTimePickerProps>['onChange']
+1 -1
View File
@@ -5,7 +5,7 @@ import DateTimePicker, {
} from '@react-native-community/datetimepicker' } from '@react-native-community/datetimepicker'
import {useTheme, atoms} from '#/alf' import {useTheme, atoms} from '#/alf'
import TextField from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
import {toSimpleDateString} from '#/components/forms/DateField/utils' import {toSimpleDateString} from '#/components/forms/DateField/utils'
import {DateFieldProps} from '#/components/forms/DateField/types' import {DateFieldProps} from '#/components/forms/DateField/types'
+2 -2
View File
@@ -3,7 +3,7 @@ import {TextInput, TextInputProps, StyleSheet} from 'react-native'
// @ts-ignore // @ts-ignore
import {unstable_createElement} from 'react-native-web' import {unstable_createElement} from 'react-native-web'
import TextField, {createInput} from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
import {toSimpleDateString} from '#/components/forms/DateField/utils' import {toSimpleDateString} from '#/components/forms/DateField/utils'
import {DateFieldProps} from '#/components/forms/DateField/types' import {DateFieldProps} from '#/components/forms/DateField/types'
@@ -29,7 +29,7 @@ const InputBase = React.forwardRef<HTMLInputElement, TextInputProps>(
InputBase.displayName = 'InputBase' InputBase.displayName = 'InputBase'
const Input = createInput(InputBase as unknown as typeof TextInput) const Input = TextField.createInput(InputBase as unknown as typeof TextInput)
export function DateField({ export function DateField({
value, value,
+5 -13
View File
@@ -38,7 +38,7 @@ const Context = React.createContext<{
export type RootProps = React.PropsWithChildren<{isInvalid?: boolean}> export type RootProps = React.PropsWithChildren<{isInvalid?: boolean}>
function Root({children, isInvalid = false}: RootProps) { export function Root({children, isInvalid = false}: RootProps) {
const inputRef = React.useRef<TextInput>(null) const inputRef = React.useRef<TextInput>(null)
const rootRef = React.useRef<View>(null) const rootRef = React.useRef<View>(null)
const { const {
@@ -226,9 +226,9 @@ export function createInput(Component: typeof TextInput) {
} }
} }
const Input = createInput(TextInput) export const Input = createInput(TextInput)
function Label({children}: React.PropsWithChildren<{}>) { export function Label({children}: React.PropsWithChildren<{}>) {
const t = useTheme() const t = useTheme()
return ( return (
<Text style={[a.text_sm, a.font_bold, t.atoms.text_contrast_600, a.mb_sm]}> <Text style={[a.text_sm, a.font_bold, t.atoms.text_contrast_600, a.mb_sm]}>
@@ -237,7 +237,7 @@ function Label({children}: React.PropsWithChildren<{}>) {
) )
} }
function Icon({icon: Comp}: {icon: React.ComponentType<SVGIconProps>}) { export function Icon({icon: Comp}: {icon: React.ComponentType<SVGIconProps>}) {
const t = useTheme() const t = useTheme()
const ctx = React.useContext(Context) const ctx = React.useContext(Context)
const {hover, focus, errorHover, errorFocus} = React.useMemo(() => { const {hover, focus, errorHover, errorFocus} = React.useMemo(() => {
@@ -286,7 +286,7 @@ function Icon({icon: Comp}: {icon: React.ComponentType<SVGIconProps>}) {
) )
} }
function Suffix({ export function Suffix({
children, children,
label, label,
accessibilityHint, accessibilityHint,
@@ -322,11 +322,3 @@ function Suffix({
</Text> </Text>
) )
} }
export default {
Root,
Input,
Label,
Icon,
Suffix,
}
+24 -33
View File
@@ -5,11 +5,11 @@ import {useTheme, atoms as a, web} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {useInteractionState} from '#/components/hooks/useInteractionState' import {useInteractionState} from '#/components/hooks/useInteractionState'
type ItemState = { export type ItemState = {
name: string name: string
selected: boolean selected: boolean
disabled: boolean disabled: boolean
hasError: boolean isInvalid: boolean
hovered: boolean hovered: boolean
pressed: boolean pressed: boolean
focused: boolean focused: boolean
@@ -19,7 +19,7 @@ const ItemContext = React.createContext<ItemState>({
name: '', name: '',
selected: false, selected: false,
disabled: false, disabled: false,
hasError: false, isInvalid: false,
hovered: false, hovered: false,
pressed: false, pressed: false,
focused: false, focused: false,
@@ -55,7 +55,7 @@ export type ItemProps = {
value?: boolean value?: boolean
disabled?: boolean disabled?: boolean
onChange?: (selected: boolean) => void onChange?: (selected: boolean) => void
hasError?: boolean isInvalid?: boolean
style?: (state: ItemState) => ViewStyle style?: (state: ItemState) => ViewStyle
children: ((props: ItemState) => React.ReactNode) | React.ReactNode children: ((props: ItemState) => React.ReactNode) | React.ReactNode
} }
@@ -64,7 +64,7 @@ export function useItemContext() {
return React.useContext(ItemContext) return React.useContext(ItemContext)
} }
function Group({ export function Group({
children, children,
values: providedValues, values: providedValues,
onChange, onChange,
@@ -138,13 +138,13 @@ function Group({
) )
} }
function Item({ export function Item({
children, children,
name, name,
value = false, value = false,
disabled: itemDisabled = false, disabled: itemDisabled = false,
onChange, onChange,
hasError, isInvalid,
style, style,
type = 'checkbox', type = 'checkbox',
label, label,
@@ -185,12 +185,12 @@ function Item({
name, name,
selected, selected,
disabled: disabled ?? false, disabled: disabled ?? false,
hasError: hasError ?? false, isInvalid: isInvalid ?? false,
hovered, hovered,
pressed, pressed,
focused, focused,
}), }),
[name, selected, disabled, hovered, pressed, focused, hasError], [name, selected, disabled, hovered, pressed, focused, isInvalid],
) )
return ( return (
@@ -201,7 +201,7 @@ function Item({
disabled={disabled} disabled={disabled}
aria-disabled={disabled ?? false} aria-disabled={disabled ?? false}
aria-checked={selected} aria-checked={selected}
aria-invalid={hasError} aria-invalid={isInvalid}
aria-label={label} aria-label={label}
role={role} role={role}
accessibilityRole={role} accessibilityRole={role}
@@ -230,7 +230,7 @@ function Item({
) )
} }
function Label({children}: React.PropsWithChildren<{}>) { export function Label({children}: React.PropsWithChildren<{}>) {
const t = useTheme() const t = useTheme()
const {disabled} = useItemContext() const {disabled} = useItemContext()
return ( return (
@@ -247,20 +247,20 @@ function Label({children}: React.PropsWithChildren<{}>) {
) )
} }
function createSharedToggleStyles({ export function createSharedToggleStyles({
theme: t, theme: t,
hovered, hovered,
focused, focused,
selected, selected,
disabled, disabled,
hasError, isInvalid,
}: { }: {
theme: ReturnType<typeof useTheme> theme: ReturnType<typeof useTheme>
selected: boolean selected: boolean
hovered: boolean hovered: boolean
focused: boolean focused: boolean
disabled: boolean disabled: boolean
hasError: boolean isInvalid: boolean
}) { }) {
const base: ViewStyle[] = [] const base: ViewStyle[] = []
const baseHover: ViewStyle[] = [] const baseHover: ViewStyle[] = []
@@ -290,7 +290,7 @@ function createSharedToggleStyles({
} }
} }
if (hasError) { if (isInvalid) {
base.push({ base.push({
backgroundColor: backgroundColor:
t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900, t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900,
@@ -321,9 +321,9 @@ function createSharedToggleStyles({
} }
} }
function Checkbox() { export function Checkbox() {
const t = useTheme() const t = useTheme()
const {selected, hovered, focused, disabled, hasError} = useItemContext() const {selected, hovered, focused, disabled, isInvalid} = useItemContext()
const {baseStyles, baseHoverStyles, indicatorStyles} = const {baseStyles, baseHoverStyles, indicatorStyles} =
createSharedToggleStyles({ createSharedToggleStyles({
theme: t, theme: t,
@@ -331,7 +331,7 @@ function Checkbox() {
focused, focused,
selected, selected,
disabled, disabled,
hasError, isInvalid,
}) })
return ( return (
<View <View
@@ -369,9 +369,9 @@ function Checkbox() {
) )
} }
function Switch() { export function Switch() {
const t = useTheme() const t = useTheme()
const {selected, hovered, focused, disabled, hasError} = useItemContext() const {selected, hovered, focused, disabled, isInvalid} = useItemContext()
const {baseStyles, baseHoverStyles, indicatorStyles} = const {baseStyles, baseHoverStyles, indicatorStyles} =
createSharedToggleStyles({ createSharedToggleStyles({
theme: t, theme: t,
@@ -379,7 +379,7 @@ function Switch() {
focused, focused,
selected, selected,
disabled, disabled,
hasError, isInvalid,
}) })
return ( return (
<View <View
@@ -420,9 +420,9 @@ function Switch() {
) )
} }
function Radio() { export function Radio() {
const t = useTheme() const t = useTheme()
const {selected, hovered, focused, disabled, hasError} = const {selected, hovered, focused, disabled, isInvalid} =
React.useContext(ItemContext) React.useContext(ItemContext)
const {baseStyles, baseHoverStyles, indicatorStyles} = const {baseStyles, baseHoverStyles, indicatorStyles} =
createSharedToggleStyles({ createSharedToggleStyles({
@@ -431,7 +431,7 @@ function Radio() {
focused, focused,
selected, selected,
disabled, disabled,
hasError, isInvalid,
}) })
return ( return (
<View <View
@@ -468,12 +468,3 @@ function Radio() {
</View> </View>
) )
} }
export default {
Item,
Checkbox,
Label,
Switch,
Radio,
Group,
}
+4 -13
View File
@@ -4,17 +4,13 @@ import {View, AccessibilityProps, TextStyle, ViewStyle} from 'react-native'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import Toggle, { import * as Toggle from '#/components/forms/Toggle'
GroupProps as BaseGroupProps,
ItemProps as BaseItemProps,
useItemContext,
} from '#/components/forms/Toggle'
export type ItemProps = Omit<BaseItemProps, 'style' | 'role' | 'children'> & export type ItemProps = Omit<Toggle.ItemProps, 'style' | 'role' | 'children'> &
AccessibilityProps & AccessibilityProps &
React.PropsWithChildren<{}> React.PropsWithChildren<{}>
export type GroupProps = Omit<BaseGroupProps, 'style' | 'type'> & { export type GroupProps = Omit<Toggle.GroupProps, 'style' | 'type'> & {
multiple?: boolean multiple?: boolean
} }
@@ -46,7 +42,7 @@ export function Button({children, ...props}: ItemProps) {
function ButtonInner({children}: React.PropsWithChildren<{}>) { function ButtonInner({children}: React.PropsWithChildren<{}>) {
const t = useTheme() const t = useTheme()
const state = useItemContext() const state = Toggle.useItemContext()
const {baseStyles, hoverStyles, activeStyles, textStyles} = const {baseStyles, hoverStyles, activeStyles, textStyles} =
React.useMemo(() => { React.useMemo(() => {
@@ -123,8 +119,3 @@ function ButtonInner({children}: React.PropsWithChildren<{}>) {
</View> </View>
) )
} }
export default {
Group,
Button,
}
-11
View File
@@ -1,11 +0,0 @@
import {AccessibilityProps} from 'react-native'
export type RequiredAccessibilityProps = Required<AccessibilityProps>
export type BaseProps<T = string> = AccessibilityProps & {
value: T
onChange: (value: T) => void
testID?: string
label: string
hasError?: boolean
}
+6 -6
View File
@@ -3,10 +3,10 @@ import {View} from 'react-native'
import {atoms as a} from '#/alf' import {atoms as a} from '#/alf'
import {H1, H3} from '#/components/Typography' import {H1, H3} from '#/components/Typography'
import TextField from '#/components/forms/TextField' import * as TextField from '#/components/forms/TextField'
import {DateField, Label} from '#/components/forms/DateField' import {DateField, Label} from '#/components/forms/DateField'
import Toggle from '#/components/forms/Toggle' import * as Toggle from '#/components/forms/Toggle'
import ToggleButton from '#/components/forms/ToggleButton' import * as ToggleButton from '#/components/forms/ToggleButton'
import {Button} from '#/components/Button' import {Button} from '#/components/Button'
import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe' import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe'
@@ -113,7 +113,7 @@ export function Forms() {
<Toggle.Switch /> <Toggle.Switch />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
<Toggle.Item name="e" hasError label="Click me"> <Toggle.Item name="e" isInvalid label="Click me">
<Toggle.Switch /> <Toggle.Switch />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
@@ -143,7 +143,7 @@ export function Forms() {
<Toggle.Checkbox /> <Toggle.Checkbox />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
<Toggle.Item name="e" hasError label="Click me"> <Toggle.Item name="e" isInvalid label="Click me">
<Toggle.Checkbox /> <Toggle.Checkbox />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
@@ -172,7 +172,7 @@ export function Forms() {
<Toggle.Radio /> <Toggle.Radio />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
<Toggle.Item name="e" hasError label="Click me"> <Toggle.Item name="e" isInvalid label="Click me">
<Toggle.Radio /> <Toggle.Radio />
<Toggle.Label>Click me</Toggle.Label> <Toggle.Label>Click me</Toggle.Label>
</Toggle.Item> </Toggle.Item>
+3 -6
View File
@@ -30,8 +30,7 @@ export function Storybook() {
variant="outline" variant="outline"
color="primary" color="primary"
size="small" size="small"
accessibilityLabel='Set theme to "system"' label='Set theme to "system"'
accessibilityHint="Set theme to system default"
onPress={() => setColorMode('system')}> onPress={() => setColorMode('system')}>
System System
</Button> </Button>
@@ -39,8 +38,7 @@ export function Storybook() {
variant="solid" variant="solid"
color="secondary" color="secondary"
size="small" size="small"
accessibilityLabel='Set theme to "system"' label='Set theme to "system"'
accessibilityHint="Set theme to system default"
onPress={() => setColorMode('light')}> onPress={() => setColorMode('light')}>
Light Light
</Button> </Button>
@@ -48,8 +46,7 @@ export function Storybook() {
variant="solid" variant="solid"
color="secondary" color="secondary"
size="small" size="small"
accessibilityLabel='Set theme to "system"' label='Set theme to "system"'
accessibilityHint="Set theme to system default"
onPress={() => setColorMode('dark')}> onPress={() => setColorMode('dark')}>
Dark Dark
</Button> </Button>