Skip to content

Commit 481a1a0

Browse files
committed
feat(TextInputMapper): add component * 3
1 parent 8dae85c commit 481a1a0

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/components/fields/TextInputMapper/TextInputMapper.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export const WithValue = Template.bind({});
5151
WithValue.args = { value: { name: 'value' } };
5252

5353
export const WithValueAndNewMapping = Template.bind({});
54-
WithValueAndNewMapping.args = { value: { name: 'value' } };
54+
WithValueAndNewMapping.args = {
55+
value: { name: 'value' },
56+
keyProps: { placeholder: 'Key placeholder' },
57+
valueProps: { placeholder: 'Value placeholder' },
58+
};
5559

5660
WithValueAndNewMapping.play = async ({ canvasElement }) => {
5761
const canvas = within(canvasElement);

src/components/fields/TextInputMapper/TextInputMapper.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export interface CubeTextInputMapperProps extends FieldBaseProps {
2929
isDisabled?: boolean;
3030
value?: Record<string, string>;
3131
onChange?: (value: Record<string, string> | undefined) => void;
32-
InputComponent?: ComponentType<CubeTextInputMapperInputProps>;
33-
keyPlaceholder?: string;
34-
valuePlaceholder?: string;
32+
ValueComponent?: ComponentType<CubeTextInputMapperInputProps>;
33+
keyProps?: CubeTextInputMapperInputProps;
34+
valueProps?: CubeTextInputMapperInputProps;
3535
}
3636

3737
// remove duplicates in mappings
@@ -61,7 +61,15 @@ function TextInputMapper(props: CubeTextInputMapperProps, ref: any) {
6161

6262
const counterRef = useRef(0);
6363

64-
let { isDisabled, actionLabel, value, onChange, InputComponent } = props;
64+
let {
65+
isDisabled,
66+
actionLabel,
67+
value,
68+
onChange,
69+
keyProps,
70+
valueProps,
71+
ValueComponent,
72+
} = props;
6573

6674
function extractLocalValues(
6775
value: Record<string, string>,
@@ -128,7 +136,7 @@ function TextInputMapper(props: CubeTextInputMapperProps, ref: any) {
128136
);
129137
}, [mappings]);
130138

131-
InputComponent = InputComponent ?? TextInputMapperInput;
139+
ValueComponent = ValueComponent ?? TextInputMapperInput;
132140

133141
const onKeyChange = useEvent((id: number, value: string) => {
134142
mappings.find((mapping) => {
@@ -169,18 +177,20 @@ function TextInputMapper(props: CubeTextInputMapperProps, ref: any) {
169177
isDisabled={isDisabled}
170178
type="name"
171179
value={key}
172-
placeholder={props.keyPlaceholder || 'Key'}
180+
placeholder="Key"
173181
onChange={onKeyChange}
174182
onSubmit={onSubmit}
183+
{...keyProps}
175184
/>
176-
<InputComponent
185+
<ValueComponent
177186
id={id}
178187
type="value"
179188
isDisabled={!key || isDisabled}
180189
value={value}
181-
placeholder={props.valuePlaceholder || 'Value'}
190+
placeholder="Value"
182191
onChange={onValueChange}
183192
onSubmit={onSubmit}
193+
{...valueProps}
184194
/>
185195
<Button
186196
aria-label="Remove mapping"

0 commit comments

Comments
 (0)