From 90c5ec23aec523d434e2d53bb3866cd6c8bb4994 Mon Sep 17 00:00:00 2001 From: hanyuxinting Date: Fri, 11 Oct 2024 11:22:03 +0800 Subject: [PATCH] fix(radio): lint fixed --- src/packages/radio/radio.taro.tsx | 68 ++++++++------------- src/packages/radio/radio.tsx | 68 ++++++++------------- src/packages/radiogroup/radiogroup.taro.tsx | 21 +++---- src/packages/radiogroup/radiogroup.tsx | 21 +++---- 4 files changed, 68 insertions(+), 110 deletions(-) diff --git a/src/packages/radio/radio.taro.tsx b/src/packages/radio/radio.taro.tsx index 86656aea4d..663d5b10f7 100644 --- a/src/packages/radio/radio.taro.tsx +++ b/src/packages/radio/radio.taro.tsx @@ -37,7 +37,6 @@ export const Radio: FunctionComponent< Partial & Omit, 'onChange'> > & { Group: typeof RadioGroup } = (props) => { const classPrefix = 'nut-radio' - const { children, className, @@ -80,30 +79,6 @@ export const Radio: FunctionComponent< } } } - - const renderLabel = () => { - return ( -
- {children} -
- ) - } - const renderButton = () => { - return ( -
- {children} -
- ) - } const color = () => { return { [`${classPrefix}-icon-disabled`]: disabled, @@ -116,7 +91,6 @@ export const Radio: FunctionComponent< if (disabled && !checkedStatement) { return } - if (checkedStatement) { return React.isValidElement(activeIcon) ? ( React.cloneElement(activeIcon, { @@ -136,16 +110,27 @@ export const Radio: FunctionComponent< ) } - const renderByShape = (shape: RadioShape) => { - return shape === 'button' ? ( - renderButton() - ) : ( + const renderLabel = () => { + const labelcls = classNames(`${classPrefix}-label`, { + [`${classPrefix}-label-disabled`]: disabled, + }) + return ( <> {renderIcon()} - {renderLabel()} +
{children}
) } + const renderButton = () => { + const buttoncls = classNames(`${classPrefix}-button`, { + [`${classPrefix}-button-active`]: checkedStatement, + [`${classPrefix}-button-disabled`]: disabled, + }) + return
{children}
+ } + const renderByShape = (shape: RadioShape) => { + return shape === 'button' ? renderButton() : renderLabel() + } const renderRadioItem = () => { return renderByShape(context && context.shape ? context.shape : shape) } @@ -153,20 +138,15 @@ export const Radio: FunctionComponent< if (disabled || checkedStatement) return setCheckedStatement(!checkedStatement) } - + const cls = classNames( + classPrefix, + { + [`${classPrefix}-reverse`]: labelPosition === 'left', + }, + className + ) return ( -
+
{renderRadioItem()}
) diff --git a/src/packages/radio/radio.tsx b/src/packages/radio/radio.tsx index 42daba2b96..1ec85467c6 100644 --- a/src/packages/radio/radio.tsx +++ b/src/packages/radio/radio.tsx @@ -33,7 +33,6 @@ export const Radio: FunctionComponent< Partial & Omit, 'onChange'> > & { Group: typeof RadioGroup } = (props) => { const classPrefix = 'nut-radio' - const { children, className, @@ -76,30 +75,6 @@ export const Radio: FunctionComponent< } } } - - const renderLabel = () => { - return ( -
- {children} -
- ) - } - const renderButton = () => { - return ( -
- {children} -
- ) - } const color = () => { return { [`${classPrefix}-icon-disabled`]: disabled, @@ -112,7 +87,6 @@ export const Radio: FunctionComponent< if (disabled && !checkedStatement) { return } - if (checkedStatement) { return React.isValidElement(activeIcon) ? ( React.cloneElement(activeIcon, { @@ -132,16 +106,27 @@ export const Radio: FunctionComponent< ) } - const renderByShape = (shape: RadioShape) => { - return shape === 'button' ? ( - renderButton() - ) : ( + const renderLabel = () => { + const labelcls = classNames(`${classPrefix}-label`, { + [`${classPrefix}-label-disabled`]: disabled, + }) + return ( <> {renderIcon()} - {renderLabel()} +
{children}
) } + const renderButton = () => { + const buttoncls = classNames(`${classPrefix}-button`, { + [`${classPrefix}-button-active`]: checkedStatement, + [`${classPrefix}-button-disabled`]: disabled, + }) + return
{children}
+ } + const renderByShape = (shape: RadioShape) => { + return shape === 'button' ? renderButton() : renderLabel() + } const renderRadioItem = () => { return renderByShape(context && context.shape ? context.shape : shape) } @@ -149,20 +134,15 @@ export const Radio: FunctionComponent< if (disabled || checkedStatement) return setCheckedStatement(!checkedStatement) } - + const cls = classNames( + classPrefix, + { + [`${classPrefix}-reverse`]: labelPosition === 'left', + }, + className + ) return ( -
+
{renderRadioItem()}
) diff --git a/src/packages/radiogroup/radiogroup.taro.tsx b/src/packages/radiogroup/radiogroup.taro.tsx index 8548414972..bce96a7f12 100644 --- a/src/packages/radiogroup/radiogroup.taro.tsx +++ b/src/packages/radiogroup/radiogroup.taro.tsx @@ -50,6 +50,14 @@ export const RadioGroup = React.forwardRef( ...rest } = { ...defaultProps, ...props } + const cls = classNames( + classPrefix, + { + [`${classPrefix}-${props.direction}`]: props.direction, + }, + className + ) + const [val2State, setVal2State] = usePropsValue({ defaultValue: props.defaultValue, value: props.value, @@ -72,7 +80,7 @@ export const RadioGroup = React.forwardRef( /> ) }) - }, [options]) + }, [options, labelPosition, val2State]) return ( -
+
{options?.length ? renderOptionsChildren() : children}
diff --git a/src/packages/radiogroup/radiogroup.tsx b/src/packages/radiogroup/radiogroup.tsx index 0df2c66f60..1bc6fa82a6 100644 --- a/src/packages/radiogroup/radiogroup.tsx +++ b/src/packages/radiogroup/radiogroup.tsx @@ -50,6 +50,14 @@ export const RadioGroup = React.forwardRef( ...rest } = { ...defaultProps, ...props } + const cls = classNames( + classPrefix, + { + [`${classPrefix}-${props.direction}`]: props.direction, + }, + className + ) + const [val2State, setVal2State] = usePropsValue({ defaultValue: props.defaultValue, value: props.value, @@ -72,7 +80,7 @@ export const RadioGroup = React.forwardRef( /> ) }) - }, [options]) + }, [options, labelPosition, val2State]) return ( -
+
{options?.length ? renderOptionsChildren() : children}