Skip to content

Commit

Permalink
Merge pull request #810 from thundersdata-frontend/form-issue
Browse files Browse the repository at this point in the history
fix: 继续优化Input组件的样式问题
  • Loading branch information
chj-damon authored Jan 2, 2024
2 parents 5125dd8 + b541087 commit bb6f66d
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changeset/shiny-islands-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@td-design/react-native-picker': patch
'@td-design/react-native': patch
---

fix: 继续优化Input组件的样式问题
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const DatePeriodInput: FC<DatePeriodInputProps> = ({
borderWidth={ONE_PIXEL}
borderColor="border"
borderRadius="x1"
height={itemHeight}
style={itemHeight ? { height: itemHeight } : {}}
>
<Pressable disabled={disabled} onPress={handleStartPress} activeOpacity={activeOpacity} style={styles.content}>
<Flex>
Expand Down
8 changes: 6 additions & 2 deletions packages/react-native-picker/src/date-picker-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const DatePickerInput = forwardRef<PickerRef, DatePickerInputProps>(
borderWidth: ONE_PIXEL,
borderColor: theme.colors.border,
borderRadius: theme.borderRadii.x1,
height: itemHeight,
},
top: {},
left: { flex: 1 },
Expand All @@ -84,7 +83,12 @@ const DatePickerInput = forwardRef<PickerRef, DatePickerInputProps>(
<Pressable
onPress={handlePress}
activeOpacity={activeOpacity}
style={[styles.content, style, labelPosition === 'top' ? styles.top : styles.left]}
style={[
itemHeight ? { height: itemHeight } : {},
styles.content,
style,
labelPosition === 'top' ? styles.top : styles.left,
]}
>
<Flex flex={1}>
<SvgIcon name="date" color={theme.colors.icon} />
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-picker/src/date-picker-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface PickerItemProps extends DatePickerPropsBase, Omit<ModalPickerProps, 'v
/** 是否禁用 */
disabled?: boolean;
style?: StyleProp<ViewStyle>;
inForm?: boolean;
}

const DatePickerItem = forwardRef<PickerRef, PickerItemProps>(
Expand All @@ -29,6 +30,7 @@ const DatePickerItem = forwardRef<PickerRef, PickerItemProps>(
allowClear = true,
disabled = false,
activeOpacity = 0.6,
inForm,
...restProps
},
ref
Expand All @@ -47,6 +49,8 @@ const DatePickerItem = forwardRef<PickerRef, PickerItemProps>(
justifyContent: 'flex-end',
alignItems: 'center',
flexDirection: 'row',
flexGrow: 1,
paddingHorizontal: theme.spacing[inForm ? 'x0' : 'x1'],
},
icon: { alignItems: 'flex-end' },
});
Expand Down
19 changes: 16 additions & 3 deletions packages/react-native-picker/src/picker-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const PickerInput = forwardRef<PickerRef, PickerInputProps>(
borderWidth: ONE_PIXEL,
borderColor: theme.colors.border,
borderRadius: theme.borderRadii.x1,
height: itemHeight,
},
top: {},
left: { flex: 1 },
Expand Down Expand Up @@ -106,12 +105,26 @@ const PickerInput = forwardRef<PickerRef, PickerInputProps>(
<Pressable
onPress={handlePress}
activeOpacity={activeOpacity}
style={[styles.content, style, labelPosition === 'top' ? styles.top : styles.left]}
style={[
itemHeight ? { height: itemHeight } : {},
styles.content,
style,
labelPosition === 'top' ? styles.top : styles.left,
]}
>
{BaseContent}
</Pressable>
) : (
<Box style={[styles.content, style, labelPosition === 'top' ? styles.top : styles.left]}>{BaseContent}</Box>
<Box
style={[
itemHeight ? { height: itemHeight } : {},
styles.content,
style,
labelPosition === 'top' ? styles.top : styles.left,
]}
>
{BaseContent}
</Box>
);

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-picker/src/picker-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface PickerItemProps extends PickerProps, Omit<ModalPickerProps, 'visible'
disabled?: boolean;
/** 自定义样式 */
style?: StyleProp<ViewStyle>;
inForm?: boolean;
}

const PickerItem = forwardRef<PickerRef, PickerItemProps>(
Expand All @@ -31,6 +32,7 @@ const PickerItem = forwardRef<PickerRef, PickerItemProps>(
style,
allowClear = true,
activeOpacity = 0.6,
inForm,
...restProps
},
ref
Expand All @@ -51,6 +53,7 @@ const PickerItem = forwardRef<PickerRef, PickerItemProps>(
justifyContent: 'flex-end',
alignItems: 'center',
flexDirection: 'row',
paddingHorizontal: theme.spacing[inForm ? 'x0' : 'x1'],
},
icon: { alignItems: 'flex-end' },
});
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/src/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const FormItem: FC<FormItemProps> = ({ children, noStyle = false, name, ...field
}
) => {
setErrors(meta.errors);
const fieldErrors = fieldContext.getFieldsError().filter(item => item.errors.length > 0);
const errors = fieldContext.getFieldsError() || [];
const fieldErrors = errors.filter(item => item.errors.length > 0);
if (fieldErrors.length > 0 && name === fieldErrors[0]?.name?.[0]) {
ref.current?.focus();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/src/form/FormListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const FormListItem: FC<FormListItemProps> = ({
}
) => {
setErrors(meta.errors);
const fieldErrors = fieldContext.getFieldsError().filter(item => item.errors.length > 0);
const errors = fieldContext.getFieldsError() || [];
const fieldErrors = errors.filter(item => item.errors.length > 0);
if (fieldErrors.length > 0 && name === fieldErrors[0]?.name?.[0]) {
ref.current?.focus();
}
Expand Down Expand Up @@ -70,6 +71,7 @@ const FormListItem: FC<FormListItemProps> = ({
<Field {...fieldProps} name={name} onMetaChange={onMetaChange}>
{React.cloneElement(children, {
ref,
inForm: true,
})}
</Field>
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/src/input/InputItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface InputItemProps
onClear?: () => void;
/** 容器自定义样式 */
style?: StyleProp<ViewStyle>;
inForm?: boolean;
}
const InputItem = forwardRef<TextInput, InputItemProps>(
(
Expand All @@ -45,6 +46,7 @@ const InputItem = forwardRef<TextInput, InputItemProps>(
onClear,
style,
defaultValue,
inForm,
...restProps
},
ref
Expand All @@ -68,7 +70,7 @@ const InputItem = forwardRef<TextInput, InputItemProps>(
});

return (
<Flex flex={1} justifyContent="flex-end" style={style}>
<Flex flexGrow={1} paddingHorizontal={inForm ? 'x0' : 'x1'} style={style}>
<Box flexGrow={1}>
<TextInput
ref={ref}
Expand Down
5 changes: 2 additions & 3 deletions packages/react-native/src/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const Input = forwardRef<TextInput, InputProps>(
paddingHorizontal: theme.spacing.x1,
paddingVertical: theme.spacing.x2,
fontSize: px(14),
height: itemHeight,
color: theme.colors.text,
includeFontPadding: false,
textAlignVertical: 'center',
Expand All @@ -112,7 +111,7 @@ const Input = forwardRef<TextInput, InputProps>(
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
style={[styles.input, inputStyle]}
style={[itemHeight ? { height: itemHeight } : {}, styles.input, inputStyle]}
editable={!disabled}
placeholderTextColor={theme.colors.gray300}
selectionColor={theme.colors.primary200}
Expand All @@ -134,7 +133,7 @@ const Input = forwardRef<TextInput, InputProps>(
<SvgIcon name={eyeOpen ? 'eyeclose' : 'eyeopen'} color={theme.colors.icon} />
</Pressable>
)}
{!!rightIcon && <Box>{rightIcon}</Box>}
{!!rightIcon && <Box marginLeft={allowClear ? 'x1' : 'x0'}>{rightIcon}</Box>}
</Flex>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ const NumberKeyboardInput = forwardRef<NumberKeyboardRef, NumberKeyboardInputPro
setTrue();
}}
style={[
itemHeight ? { height: itemHeight } : {},
{
flex: 1,
paddingVertical: theme.spacing.x2,
height: itemHeight,
},
style,
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
allowClear = true,
digit = 0,
activeOpacity = 0.6,
inForm,
...restProps
},
ref
Expand All @@ -53,8 +54,8 @@ const NumberKeyboardItem = forwardRef<NumberKeyboardRef, NumberKeyboardItemProps
});

return (
<Box width="100%">
<Flex style={style}>
<Box flexGrow={1} paddingHorizontal={inForm ? 'x0' : 'x1'} justifyContent={'center'} style={style}>
<Flex>
<Pressable
activeOpacity={activeOpacity}
onPress={() => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/number-keyboard/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface NumberKeyboardItemProps extends Pick<NumberKeyboardViewProps, '
disabled?: boolean;
/** 保留小数位 */
digit?: number;
inForm?: boolean;
}

export interface NumberKeyboardInputProps extends NumberKeyboardItemProps {
Expand Down
16 changes: 11 additions & 5 deletions packages/react-native/src/search-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,36 @@ const SearchBar: FC<SearchBarProps> = props => {
const CancelBtn = useMemo(() => {
if (!showCancelButton || !focused) return null;
return (
<Pressable onPress={onCancel} activeOpacity={activeOpacity} style={{ marginHorizontal: theme.spacing.x2 }}>
<Pressable
onPress={onCancel}
activeOpacity={activeOpacity}
style={{
marginLeft: allowClear ? 0 : theme.spacing.x1,
marginRight: theme.spacing.x1,
}}
>
<Text variant="p0" color="primary200">
{cancelText}
</Text>
</Pressable>
);
}, [showCancelButton, focused, activeOpacity, theme.spacing.x2, cancelText, onCancel]);
}, [showCancelButton, focused, activeOpacity, theme.spacing.x1, cancelText, onCancel, allowClear]);

return (
<Flex style={[styles.container, style]}>
{!!children && (
<Box
justifyContent="center"
alignItems="center"
paddingLeft={'x1'}
paddingRight={'x2'}
marginHorizontal={'x1'}
borderRightWidth={ONE_PIXEL}
borderRightColor={'gray500'}
>
{children}
</Box>
)}
{/* 搜索小图标 */}
<SvgIcon name="search" color={theme.colors.icon} style={{ marginHorizontal: theme.spacing.x2 }} />
<SvgIcon name="search" color={theme.colors.icon} style={{ marginHorizontal: theme.spacing.x1 }} />
<InputItem
ref={inputRef}
style={styles.textInput}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const VehicleKeyboardInput = forwardRef<VehicleKeyboardRef, VehicleKeyboardInput
setTrue();
}}
style={[
itemHeight ? { height: itemHeight } : {},
{
flex: 1,
paddingVertical: theme.spacing.x2,
height: itemHeight,
},
style,
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const VehicleKeyboardItem = forwardRef<VehicleKeyboardRef, VehicleKeyboardItemPr
extra,
allowClear = true,
activeOpacity = 0.6,
inForm,
...restProps
},
ref
Expand All @@ -41,8 +42,8 @@ const VehicleKeyboardItem = forwardRef<VehicleKeyboardRef, VehicleKeyboardItemPr
});

return (
<Box width="100%">
<Flex style={style}>
<Box flexGrow={1} paddingHorizontal={inForm ? 'x0' : 'x1'} justifyContent={'center'} style={style}>
<Flex>
<Pressable
activeOpacity={activeOpacity}
onPress={() => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/vehicle-keyboard/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface VehicleKeyboardItemProps extends Pick<VehicleKeyboardViewProps,
extra?: ReactNode;
allowClear?: boolean;
disabled?: boolean;
inForm?: boolean;
}

export interface VehicleKeyboardInputProps extends VehicleKeyboardItemProps {
Expand Down

0 comments on commit bb6f66d

Please sign in to comment.