♻️(react) improve props propagation

Before we had to edit input components using Field when adding new props
to the latter.
This commit is contained in:
Nathan Vasse
2023-08-30 11:40:35 +02:00
committed by NathanVss
parent b530e966ae
commit 051c79fd6f
5 changed files with 16 additions and 84 deletions

View File

@@ -17,17 +17,7 @@ export type CheckboxProps = InputHTMLAttributes<HTMLInputElement> &
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
(
{
indeterminate,
className = "",
checked,
label,
text,
textItems,
rightText,
state,
...props
}: CheckboxProps,
{ indeterminate, className = "", checked, label, ...props }: CheckboxProps,
ref,
) => {
const inputRef = useRef<HTMLInputElement>();
@@ -49,13 +39,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
"c__checkbox--disabled": props.disabled,
})}
>
<Field
text={text}
rightText={rightText}
compact={true}
state={state}
textItems={textItems}
>
<Field compact={true} {...props}>
<div className="c__checkbox__container">
<div className="c__checkbox__wrapper">
<input
@@ -87,19 +71,10 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
export const CheckboxGroup = ({
children,
state,
text,
textItems,
rightText,
...props
}: PropsWithChildren & FieldProps) => {
return (
<Field
className="c__checkbox__group"
state={state}
text={text}
textItems={textItems}
rightText={rightText}
>
<Field className="c__checkbox__group" {...props}>
<div className="c__checkbox__group__list">{children}</div>
</Field>
);

View File

@@ -29,11 +29,6 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
id,
icon,
rightIcon,
state = "default",
text,
textItems,
rightText,
fullWidth,
charCounter,
charCounterMax,
...props
@@ -51,7 +46,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
const idToUse = useRef(id || randomString());
const rightTextToUse = charCounter
? `${value.toString().length}/${charCounterMax}`
: rightText;
: props.rightText;
const updateLabel = () => {
if (inputFocus) {
@@ -74,20 +69,14 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
}, [props.value]);
return (
<Field
state={state}
text={text}
textItems={textItems}
rightText={rightTextToUse}
fullWidth={fullWidth}
>
<Field {...props} rightText={rightTextToUse}>
{/* We disabled linting for this specific line because we consider that the onClick props is only used for */}
{/* mouse users, so this do not engender any issue for accessibility. */}
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
className={classNames(
"c__input__wrapper",
"c__input__wrapper--" + state,
"c__input__wrapper--" + props.state,
{
"c__input__wrapper--disabled": props.disabled,
},

View File

@@ -12,14 +12,14 @@ export type RadioProps = InputHTMLAttributes<HTMLInputElement> &
};
export const Radio = forwardRef<HTMLInputElement, RadioProps>(
({ label, text, textItems, state, ...props }: RadioProps, ref) => {
({ label, ...props }: RadioProps, ref) => {
return (
<label
className={classNames("c__checkbox", "c__radio", {
"c__checkbox--disabled": props.disabled,
})}
>
<Field text={text} compact={true} state={state} textItems={textItems}>
<Field compact={true} {...props}>
<div className="c__checkbox__container">
<input type="radio" {...props} ref={ref} />
{label && <div className="c__checkbox__label">{label}</div>}
@@ -32,20 +32,14 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>(
export const RadioGroup = ({
children,
state,
text,
textItems,
rightText,
style,
...props
}: PropsWithChildren & FieldProps & { style?: React.CSSProperties }) => {
return (
<Field
className="c__radio__group c__checkbox__group"
state={state}
text={text}
textItems={textItems}
rightText={rightText}
compact={true}
{...props}
>
<div className="c__checkbox__group__list" style={style}>
{children}

View File

@@ -57,10 +57,6 @@ export interface SelectAuxProps extends SubProps {
export const SelectMonoAux = ({
children,
state = "default",
text,
textItems,
rightText,
fullWidth,
options,
name,
label,
@@ -72,6 +68,7 @@ export const SelectMonoAux = ({
disabled,
clearable = true,
onBlur,
...props
}: SelectAuxProps) => {
const { t } = useCunningham();
const labelProps = downshiftReturn.getLabelProps();
@@ -88,13 +85,7 @@ export const SelectMonoAux = ({
}, [value]);
return (
<Field
state={state}
text={text}
textItems={textItems}
rightText={rightText}
fullWidth={fullWidth}
>
<Field state={state} {...props}>
<div
className={classNames(
"c__select",

View File

@@ -9,18 +9,7 @@ export type SwitchProps = InputHTMLAttributes<HTMLInputElement> &
};
export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
(
{
label,
text,
textItems,
state,
fullWidth,
labelSide = "left",
...props
}: SwitchProps,
ref,
) => {
({ label, labelSide = "left", ...props }: SwitchProps, ref) => {
return (
<label
className={classNames(
@@ -29,17 +18,11 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
"c__switch--" + labelSide,
{
"c__checkbox--disabled": props.disabled,
"c__switch--full-width": fullWidth,
"c__switch--full-width": props.fullWidth,
},
)}
>
<Field
text={text}
textItems={textItems}
compact={true}
state={state}
fullWidth={fullWidth}
>
<Field compact={true} {...props}>
<div className="c__checkbox__container">
{label && <div className="c__checkbox__label">{label}</div>}
<div className="c__switch__rail__wrapper">