Skip to content

Commit 65fd3e2

Browse files
committed
feat(EditableInput): add renderInput props. #166
1 parent 711fb70 commit 65fd3e2

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/color-editable-input/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface EditableInputProps extends Omit<React.InputHTMLAttributes<HTMLI
4949
placement?: 'top' | 'left' | 'bottom' | 'right';
5050
inputStyle?: React.CSSProperties;
5151
onChange?: (evn: React.ChangeEvent<HTMLInputElement>, value: string | number) => void;
52+
renderInput?: (props: React.InputHTMLAttributes<HTMLInputElement>, ref: React.Ref<HTMLInputElement>) => React.ReactNode;
5253
}
5354
declare const EditableInput: React.ForwardRefExoticComponent<EditableInputProps & React.RefAttributes<HTMLInputElement>>;
5455
export default EditableInput;

packages/color-editable-input/src/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface EditableInputProps extends Omit<React.InputHTMLAttributes<HTMLI
1212
placement?: 'top' | 'left' | 'bottom' | 'right';
1313
inputStyle?: React.CSSProperties;
1414
onChange?: (evn: React.ChangeEvent<HTMLInputElement>, value: string | number) => void;
15+
renderInput?: (props: React.InputHTMLAttributes<HTMLInputElement>, ref: React.Ref<HTMLInputElement>) => React.ReactNode;
1516
}
1617

1718
const EditableInput = React.forwardRef<HTMLInputElement, EditableInputProps>((props, ref) => {
@@ -26,6 +27,7 @@ const EditableInput = React.forwardRef<HTMLInputElement, EditableInputProps>((pr
2627
inputStyle,
2728
onChange,
2829
onBlur,
30+
renderInput,
2931
...other
3032
} = props;
3133
const [value, setValue] = useState<string | number | undefined>(initValue);
@@ -90,18 +92,19 @@ const EditableInput = React.forwardRef<HTMLInputElement, EditableInputProps>((pr
9092
boxShadow: 'var(--editable-input-box-shadow)',
9193
...inputStyle,
9294
} as React.CSSProperties;
95+
96+
const inputProps: React.InputHTMLAttributes<HTMLInputElement> = {
97+
value,
98+
onChange: handleChange,
99+
onBlur: handleBlur,
100+
autoComplete: 'off',
101+
onFocus: () => (isFocus.current = true),
102+
...other,
103+
style: editableStyle,
104+
};
93105
return (
94106
<div className={[prefixCls, className || ''].filter(Boolean).join(' ')} style={wrapperStyle}>
95-
<input
96-
ref={ref}
97-
value={value}
98-
onChange={handleChange}
99-
onBlur={handleBlur}
100-
autoComplete="off"
101-
onFocus={() => (isFocus.current = true)}
102-
{...other}
103-
style={editableStyle}
104-
/>
107+
{renderInput ? renderInput(inputProps, ref) : <input ref={ref} {...inputProps} />}
105108
{label && (
106109
<span
107110
style={{

0 commit comments

Comments
 (0)