Replace onChange prop with onCheck for Radio and Checkbox

onChange is already defined for HTML inputs and returns event, but we want to return boolean/array of values

[MAILPOET-2773]
This commit is contained in:
Ján Mikláš
2020-05-19 10:50:28 +02:00
committed by Veljko V
parent 6521b4e59f
commit 49b866ad29
6 changed files with 17 additions and 17 deletions

View File

@ -19,14 +19,14 @@ export const Checkboxes = () => (
<Heading level={3}>Inline individual checkboxes</Heading> <Heading level={3}>Inline individual checkboxes</Heading>
<div> <div>
<Checkbox <Checkbox
onChange={action('checkbox-individual-1')} onCheck={action('checkbox-individual-1')}
name="story" name="story"
value="1" value="1"
> >
Option 1 Option 1
</Checkbox> </Checkbox>
<Checkbox <Checkbox
onChange={action('checkbox-individual-2')} onCheck={action('checkbox-individual-2')}
name="story" name="story"
value="2" value="2"
> >
@ -39,7 +39,7 @@ export const Checkboxes = () => (
<div> <div>
<Checkbox <Checkbox
isFullWidth isFullWidth
onChange={action('checkbox-full-individual-1')} onCheck={action('checkbox-full-individual-1')}
name="story-full" name="story-full"
value="1" value="1"
> >
@ -47,7 +47,7 @@ export const Checkboxes = () => (
</Checkbox> </Checkbox>
<Checkbox <Checkbox
isFullWidth isFullWidth
onChange={action('checkbox-full-individual-2')} onCheck={action('checkbox-full-individual-2')}
name="story-full" name="story-full"
value="2" value="2"
> >

View File

@ -2,15 +2,15 @@ import React, { InputHTMLAttributes } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
type Props = InputHTMLAttributes<HTMLInputElement> & { type Props = InputHTMLAttributes<HTMLInputElement> & {
onCheck: (isChecked: boolean) => void,
children?: React.ReactNode, children?: React.ReactNode,
isFullWidth?: boolean, isFullWidth?: boolean,
onChange?: (boolean) => void,
}; };
const Checkbox = ({ const Checkbox = ({
children, children,
isFullWidth, isFullWidth,
onChange, onCheck,
...attributes ...attributes
}: Props) => ( }: Props) => (
<label <label
@ -23,7 +23,7 @@ const Checkbox = ({
> >
<input <input
type="checkbox" type="checkbox"
onChange={(e) => onChange(e.target.checked)} onChange={(e) => onCheck(e.target.checked)}
{...attributes} {...attributes}
/> />
<span className="mailpoet-form-checkbox-control" /> <span className="mailpoet-form-checkbox-control" />

View File

@ -45,7 +45,7 @@ const CheckboxGroup = ({
key={label} key={label}
name={name} name={name}
value={value} value={value}
onChange={(isChecked) => handleChange(value, isChecked)} onCheck={(isChecked) => handleChange(value, isChecked)}
isFullWidth={isFullWidth} isFullWidth={isFullWidth}
{...attributes} // eslint-disable-line react/jsx-props-no-spreading {...attributes} // eslint-disable-line react/jsx-props-no-spreading
> >

View File

@ -19,14 +19,14 @@ export const Radios = () => (
<Heading level={3}>Inline individual radios</Heading> <Heading level={3}>Inline individual radios</Heading>
<div> <div>
<Radio <Radio
onChange={action('radio-individual-1')} onCheck={action('radio-individual-1')}
name="story" name="story"
value="1" value="1"
> >
Option 1 Option 1
</Radio> </Radio>
<Radio <Radio
onChange={action('radio-individual-2')} onCheck={action('radio-individual-2')}
name="story" name="story"
value="2" value="2"
> >
@ -39,7 +39,7 @@ export const Radios = () => (
<div> <div>
<Radio <Radio
isFullWidth isFullWidth
onChange={action('radio-full-individual-1')} onCheck={action('radio-full-individual-1')}
name="story-full" name="story-full"
value="1" value="1"
> >
@ -47,7 +47,7 @@ export const Radios = () => (
</Radio> </Radio>
<Radio <Radio
isFullWidth isFullWidth
onChange={action('radio-full-individual-2')} onCheck={action('radio-full-individual-2')}
name="story-full" name="story-full"
value="2" value="2"
> >

View File

@ -12,7 +12,7 @@ type Props = {
options: RadioProps[], options: RadioProps[],
defaultValue?: RadioValueType, defaultValue?: RadioValueType,
isFullWidth?: boolean, isFullWidth?: boolean,
onChange?: (RadioValueType) => void, onChange?: (value: RadioValueType) => void,
}; };
const RadioGroup = ({ const RadioGroup = ({
@ -37,7 +37,7 @@ const RadioGroup = ({
key={label} key={label}
name={name} name={name}
value={value} value={value}
onChange={() => handleChange(value)} onCheck={() => handleChange(value)}
isFullWidth={isFullWidth} isFullWidth={isFullWidth}
{...attributes} // eslint-disable-line react/jsx-props-no-spreading {...attributes} // eslint-disable-line react/jsx-props-no-spreading
> >

View File

@ -2,15 +2,15 @@ import React, { InputHTMLAttributes } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
type Props = InputHTMLAttributes<HTMLInputElement> & { type Props = InputHTMLAttributes<HTMLInputElement> & {
onCheck: (isChecked: boolean) => void,
children?: React.ReactNode, children?: React.ReactNode,
isFullWidth?: boolean, isFullWidth?: boolean,
onChange?: (boolean) => void,
}; };
const Radio = ({ const Radio = ({
children, children,
isFullWidth, isFullWidth,
onChange, onCheck,
...attributes ...attributes
}: Props) => ( }: Props) => (
<label <label
@ -23,7 +23,7 @@ const Radio = ({
> >
<input <input
type="radio" type="radio"
onChange={(e) => onChange(e.target.checked)} onChange={(e) => onCheck(e.target.checked)}
{...attributes} {...attributes}
/> />
<span className="mailpoet-form-radio-control" /> <span className="mailpoet-form-radio-control" />