Skip to content

Commit

Permalink
feat: radio adaptation (#2721)
Browse files Browse the repository at this point in the history
* feat: radio adaptation

* feat: update the usage of the 'color' property in the Icon component
  • Loading branch information
oasis-cloud authored Nov 11, 2024
1 parent 5efd427 commit 1222cb6
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
"author": "dsj"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "Radio",
"type": "component",
"cName": "单选按钮",
Expand All @@ -599,7 +599,7 @@
"author": "oasis"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "RadioGroup",
"type": "component",
"cName": "单选按钮组",
Expand Down
5 changes: 1 addition & 4 deletions src/packages/radio/demos/taro/demo8.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Checklist } from '@nutui/icons-react-taro'

const Demo8 = () => {
return (
<Radio
icon={<Checklist />}
activeIcon={<Checklist style={{ color: 'red' }} />}
>
<Radio icon={<Checklist />} activeIcon={<Checklist color="red" />}>
自定义图标
</Radio>
)
Expand Down
4 changes: 2 additions & 2 deletions src/packages/radio/demos/taro/demo9.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const Demo9 = () => {
>
<Radio
icon={<Checklist />}
activeIcon={<Checklist style={{ color: 'red' }} />}
activeIcon={<Checklist color="red" />}
value="1"
>
自定义图标
</Radio>
<Radio
icon={<Checklist />}
activeIcon={<Checklist style={{ color: 'red' }} />}
activeIcon={<Checklist color="red" />}
value="2"
>
自定义图标
Expand Down
14 changes: 12 additions & 2 deletions src/packages/radio/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Radio } from './radio.taro'
import React from 'react'
import { Radio, RadioProps } from './radio.taro'
import { RadioGroup } from '../radiogroup/radiogroup.taro'

export type { RadioProps } from './radio.taro'
export type { RadioShape, RadioPosition } from './types'

export default Radio
type CompoundedComponent = React.FC<
Partial<RadioProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
> & {
Group: typeof RadioGroup
}
const InnerRadio = Radio as CompoundedComponent
InnerRadio.Group = RadioGroup

export default InnerRadio
14 changes: 12 additions & 2 deletions src/packages/radio/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Radio } from './radio'
import React from 'react'
import { Radio, RadioProps } from './radio'
import { RadioGroup } from '../radiogroup/radiogroup'

export type { RadioProps } from './radio'
export type { RadioShape, RadioPosition } from './types'
export default Radio
type CompoundedComponent = React.FC<
Partial<RadioProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
> & {
Group: typeof RadioGroup
}
const InnerRadio = Radio as CompoundedComponent
InnerRadio.Group = RadioGroup

export default InnerRadio
1 change: 1 addition & 0 deletions src/packages/radio/radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
border: 1px solid $color-text-disabled;
}
}

[dir='rtl'] .nut-radio,
.nut-rtl .nut-radio {
&:last-child {
Expand Down
25 changes: 10 additions & 15 deletions src/packages/radio/radio.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FunctionComponent, useContext } from 'react'
import React, { FC, useContext } from 'react'
import {
CheckChecked,
CheckNormal,
CheckDisabled,
CheckNormal,
} from '@nutui/icons-react-taro'
import classNames from 'classnames'
import { View, ITouchEvent } from '@tarojs/components'
import classNames, { Mapping } from 'classnames'
import { ITouchEvent, View } from '@tarojs/components'
import RadioContext from '../radiogroup/context'
import RadioGroup from '@/packages/radiogroup/index.taro'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
Expand Down Expand Up @@ -34,9 +34,9 @@ const defaultProps = {
activeIcon: null,
onChange: (checked: boolean) => {},
} as RadioProps
export const Radio: FunctionComponent<
export const Radio: FC<
Partial<RadioProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
> & { Group: typeof RadioGroup } = (props) => {
> = (props) => {
const classPrefix = 'nut-radio'
const {
children,
Expand Down Expand Up @@ -80,7 +80,7 @@ export const Radio: FunctionComponent<
}
}
}
const color = () => {
const color = (): Mapping => {
return {
[`${classPrefix}-icon-disabled`]: disabled,
[`${classPrefix}-icon`]: !checkedStatement,
Expand Down Expand Up @@ -118,7 +118,7 @@ export const Radio: FunctionComponent<
return (
<>
{renderIcon()}
<div className={labelcls}>{children}</div>
<View className={labelcls}>{children}</View>
</>
)
}
Expand All @@ -127,7 +127,7 @@ export const Radio: FunctionComponent<
[`${classPrefix}-button-active`]: checkedStatement,
[`${classPrefix}-button-disabled`]: disabled,
})
return <div className={buttoncls}>{children}</div>
return <View className={buttoncls}>{children}</View>
}
const renderByShape = (shape: RadioShape) => {
return shape === 'button' ? renderButton() : renderLabel()
Expand All @@ -149,12 +149,7 @@ export const Radio: FunctionComponent<
className
)
return (
<View
className={cls}
style={style}
onClick={handleClick}
// {...rest}
>
<View className={cls} style={style} onClick={handleClick}>
{renderRadioItem()}
</View>
)
Expand Down
2 changes: 1 addition & 1 deletion src/packages/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultProps = {
} as RadioProps
export const Radio: FunctionComponent<
Partial<RadioProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
> & { Group: typeof RadioGroup } = (props) => {
> = (props) => {
const classPrefix = 'nut-radio'
const {
children,
Expand Down
7 changes: 4 additions & 3 deletions src/packages/radiogroup/radiogroup.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
import {
RadioGroupDirection,
RadioGroupOption,
Expand Down Expand Up @@ -53,7 +54,7 @@ export const RadioGroup = React.forwardRef(
const cls = classNames(
classPrefix,
{
[`${classPrefix}-${props.direction}`]: props.direction,
[`${classPrefix}-${direction}`]: direction,
},
className
)
Expand Down Expand Up @@ -97,9 +98,9 @@ export const RadioGroup = React.forwardRef(
},
}}
>
<div className={cls} {...rest}>
<View className={cls} {...rest}>

Check failure on line 101 in src/packages/radiogroup/radiogroup.taro.tsx

View workflow job for this annotation

GitHub Actions / build

Type '{ children: string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | Element[] | null | undefined; ... 260 more ...; className: string; }' is not assignable to type 'ViewProps'.
{options?.length ? renderOptionsChildren() : children}
</div>
</View>
</RadioContext.Provider>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/packages/radiogroup/radiogroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const RadioGroup = React.forwardRef(
const cls = classNames(
classPrefix,
{
[`${classPrefix}-${props.direction}`]: props.direction,
[`${classPrefix}-${direction}`]: direction,
},
className
)
Expand Down

0 comments on commit 1222cb6

Please sign in to comment.