Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复TabBar组件demo演示页路由跳转失败问题 #451

Merged
merged 28 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
294c18f
feat: 单选按钮组支持options设置子元素
cuiyiworld Oct 26, 2022
cd8f656
Merge branch 'main' of github.com:jdf2e/nutui-react
cuiyiworld Oct 31, 2022
8471e87
fix: 代码review问题处理,完善文档介绍
cuiyiworld Nov 1, 2022
cff5c28
Merge branch 'jdf2e:main' into main
Nov 3, 2022
b686cc7
fix: 修改版本号
cuiyiworld Nov 3, 2022
8f9fef7
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 3, 2022
d4168b6
Merge branch 'jdf2e:main' into main
Nov 7, 2022
4ecaecb
feat: 复选按钮支持options设置子元素
cuiyiworld Nov 7, 2022
1dd547e
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 7, 2022
c3efd7e
Merge branch 'jdf2e:main' into main
Nov 7, 2022
384dbd7
Merge branch 'jdf2e:main' into main
Nov 8, 2022
2a3b669
fix: checkbox组件继承父级参数抽离,与checkbox的interface无关
cuiyiworld Nov 8, 2022
f961b38
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 8, 2022
9516284
fix: tabbarItem组件自定义名称统一为className字段
cuiyiworld Nov 8, 2022
0045ec0
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 8, 2022
dafc38e
fix: menuItem组件className指定到nut-menu__item
cuiyiworld Nov 8, 2022
2bfc0d1
fix: 代码没有同步造成启动报错
cuiyiworld Nov 8, 2022
64701c7
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 8, 2022
0f4d5ff
feat: tag组件添加自定义className和style属性
cuiyiworld Nov 8, 2022
211cfb2
fix: tag组件的className从IComponent中获取
cuiyiworld Nov 8, 2022
03d68fa
feat: rate组件添加className和style属性
cuiyiworld Nov 9, 2022
1205efb
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 9, 2022
84e5ad7
feat: row和col组件支持className和style属性
cuiyiworld Nov 9, 2022
9d75139
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 9, 2022
25c319f
feat: badge组件支持className和style属性
cuiyiworld Nov 10, 2022
fc8e1b8
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 10, 2022
6bf9f19
Merge branch 'main' of https://github.com/cuicuiworld/nutui-react
cuiyiworld Nov 11, 2022
50ca295
fix: 修复TabBar组件路由跳转失败问题
cuiyiworld Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: 单选按钮组支持options设置子元素
  • Loading branch information
cuiyiworld committed Oct 26, 2022
commit 294c18fa7199ece677073ee7ac8248bff9d7502d
27 changes: 27 additions & 0 deletions src/packages/radio/__test__/radio.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,31 @@ describe('radio', () => {
fireEvent.click(screen.getByTestId('r3'))
expect(changeFn).toBeCalledWith('3')
})

test('Render radios by configuring options', () => {
const RadioGroupOptions = () => {
const [radioVal] = useState('1')
const [optionsDemo1, setOptionsDemo1] = useState([
{
label: '选项一',
value: '1',
},
{
label: '选项二',
value: '2',
disabled: true,
},
{
label: '选项三',
value: '3',
},
])
return (
<>
<RadioGroup value={radioVal} options={optionsDemo1}></RadioGroup>
</>
)
}
const { container } = render(<RadioGroupOptions />)
})
})
25 changes: 25 additions & 0 deletions src/packages/radio/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface T {
'70ffa5d8': string
'0f261484': string
'6b1f669d': string
options: string
}

const RadioDemo = () => {
Expand All @@ -24,6 +25,7 @@ const RadioDemo = () => {
'70ffa5d8': '自定义图标',
'0f261484': '触发事件',
'6b1f669d': '当前选中值',
options: '配置 options 渲染单选按钮',
},
'zh-TW': {
'74fc5d8a': '基本用法',
Expand All @@ -33,6 +35,7 @@ const RadioDemo = () => {
'70ffa5d8': '自定義圖示',
'0f261484': '觸發事件',
'6b1f669d': '當前選中值',
options: '配置 options 渲染單選按鈕',
},
'en-US': {
'74fc5d8a': 'Basic Usage',
Expand All @@ -42,11 +45,27 @@ const RadioDemo = () => {
'70ffa5d8': 'Custom Icon',
'0f261484': 'Trigger Event',
'6b1f669d': 'Currently selected',
options: 'Render radios by configuring options',
},
})

const [checked1] = useState(true)
const [radioVal, setRadioVal] = useState(1)
const [optionsDemo1, setOptionsDemo1] = useState([
{
label: '选项一',
value: '1',
},
{
label: '选项二',
value: '2',
disabled: true,
},
{
label: '选项三',
value: '3',
},
])

function handleChange(val: number | string | boolean) {
console.log(val)
Expand Down Expand Up @@ -164,6 +183,12 @@ const RadioDemo = () => {
</Cell>
<Cell title={translated['6b1f669d']} desc={radioVal.toString()} />
</CellGroup>
<h2>{translated.options}</h2>
<CellGroup>
<Cell>
<RadioGroup options={optionsDemo1} value={radioVal}></RadioGroup>
</Cell>
</CellGroup>
</div>
</>
)
Expand Down
25 changes: 25 additions & 0 deletions src/packages/radio/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface T {
'70ffa5d8': string
'0f261484': string
'6b1f669d': string
options: string
}

const RadioDemo = () => {
Expand All @@ -26,6 +27,7 @@ const RadioDemo = () => {
'70ffa5d8': '自定义图标',
'0f261484': '触发事件',
'6b1f669d': '当前选中值',
options: '配置 options 渲染单选按钮',
},
'zh-TW': {
'74fc5d8a': '基本用法',
Expand All @@ -35,6 +37,7 @@ const RadioDemo = () => {
'70ffa5d8': '自定義圖示',
'0f261484': '觸發事件',
'6b1f669d': '當前選中值',
options: '配置 options 渲染單選按鈕',
},
'en-US': {
'74fc5d8a': 'Basic Usage',
Expand All @@ -44,11 +47,27 @@ const RadioDemo = () => {
'70ffa5d8': 'Custom Icon',
'0f261484': 'Trigger Event',
'6b1f669d': 'Currently selected',
options: 'Render radios by configuring options',
},
})

const [checked1] = useState(true)
const [radioVal, setRadioVal] = useState(1)
const [optionsDemo1, setOptionsDemo1] = useState([
{
label: '选项一',
value: '1',
},
{
label: '选项二',
value: '2',
disabled: true,
},
{
label: '选项三',
value: '3',
},
])

function handleChange(val: number | string | boolean) {
console.log(val)
Expand Down Expand Up @@ -166,6 +185,12 @@ const RadioDemo = () => {
</Cell>
<Cell title={translated['6b1f669d']} desc={radioVal.toString()} />
</CellGroup>
<h2>{translated.options}</h2>
<CellGroup>
<Cell>
<RadioGroup options={optionsDemo1} value={radioVal}></RadioGroup>
</Cell>
</CellGroup>
</div>
</>
)
Expand Down
1 change: 1 addition & 0 deletions src/packages/radio/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default RadioGroupLast;
| value | The identifier of the currently selected item, which is selected when the label value is consistent with the | String、Number、Boolean | - |
| textPosition | Where the text is located, optional values: 'left', 'right' | String | `right` |
| direction | Use horizontal and vertical directions The optional values horizontal, vertical, | String | `vertical` |
| options `v1.3.9` | Render radios by configuring options | Array | `Array<{ label: string value: string disabled?: boolean }` |

## RadioGroup Event

Expand Down
2 changes: 2 additions & 0 deletions src/packages/radio/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export default RadioGroupLast;
| value | 当前选中项的标识符,与label值一致时呈选中状态 | String、Number、Boolean | - |
| textPosition | 文本所在的位置,可选值:`left`,`right` | String | `right` |
| direction | 使用横纵方向 可选值 horizontal、vertical | String | `vertical` |
| options `v1.3.9` | 配置 options 渲染单选按钮 | Array | `Array<{ label: string value: string disabled?: boolean }` |


## RadioGroup Event

Expand Down
1 change: 1 addition & 0 deletions src/packages/radio/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default RadioGroupLast;
| value | 當前選取的標識碼,與label值一致時呈選中狀態 | String、Number、Boolean | - |
| textPosition | 文本所在的位置,可選值:'left','right' | String | `right` |
| direction | 使用橫縱方向 可選值 horizontal、vertical | String | `vertical` |
| options `v1.3.9` | 配置 options 渲染單選按鈕 | Array | `Array<{ label: string value: string disabled?: boolean }` |

## RadioGroup Event

Expand Down
41 changes: 36 additions & 5 deletions src/packages/radiogroup/radiogroup.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import React, { useEffect, useState } from 'react'
import React, { MouseEventHandler, useEffect, useState } from 'react'
import RadioContext from '../radio/context'
import Radio from '../radio/index.taro'

import bem from '@/utils/bem'

type Position = 'left' | 'right'
type Direction = 'horizontal' | 'vertical'

export interface RadioGroupOptionType {
label: string
value: string
disabled?: boolean
onChange?: MouseEventHandler<HTMLDivElement>
}

export interface RadioGroupProps {
value: string | number | boolean | null
textPosition: Position
direction: Direction
onChange: (value: string | number | boolean) => void
options: RadioGroupOptionType[]
}

const defaultProps = {
value: null,
textPosition: 'right',
onChange: (value: string | number | boolean) => {},
direction: 'vertical',
options: [],
} as RadioGroupProps
export const RadioGroup = React.forwardRef(
(
Expand All @@ -27,8 +37,15 @@ export const RadioGroup = React.forwardRef(
) => {
const { children } = { ...defaultProps, ...props }
const b = bem('RadioGroup')
const { className, value, onChange, textPosition, direction, ...rest } =
props
const {
className,
value,
onChange,
textPosition,
direction,
options,
...rest
} = props

const [val2State, setVal2State] = useState(value)

Expand Down Expand Up @@ -85,6 +102,18 @@ export const RadioGroup = React.forwardRef(
})
}

function renderOptionsChildren() {
return options?.map(({ label, value, disabled, onChange }) => (
<Radio
key={value?.toString()}
children={label}
value={value}
disabled={disabled}
onChange={onChange}
/>
))
}

return (
<RadioContext.Provider
value={{
Expand All @@ -95,10 +124,12 @@ export const RadioGroup = React.forwardRef(
}}
>
<div
className={`nut-radiogroup nut-radiogroup--${props.direction}`}
className={`nut-radiogroup nut-radiogroup--${props.direction} ${
className || ''
}`}
{...rest}
>
{cloneChildren()}
{options?.length ? renderOptionsChildren() : cloneChildren()}
</div>
</RadioContext.Provider>
)
Expand Down
33 changes: 29 additions & 4 deletions src/packages/radiogroup/radiogroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useEffect, useState } from 'react'
import RadioContext from '../radio/context'
import { RadioGroupOptionType } from './radiogroup.taro'
import { Radio } from '../radio/radio'

import bem from '@/utils/bem'

Expand All @@ -11,13 +13,15 @@ export interface RadioGroupProps {
textPosition: Position
direction: Direction
onChange: (value: string | number | boolean) => void
options: RadioGroupOptionType[]
}

const defaultProps = {
value: null,
textPosition: 'right',
onChange: (value: string | number | boolean) => {},
direction: 'vertical',
options: [],
} as RadioGroupProps
export const RadioGroup = React.forwardRef(
(
Expand All @@ -27,8 +31,15 @@ export const RadioGroup = React.forwardRef(
) => {
const { children } = { ...defaultProps, ...props }
const b = bem('RadioGroup')
const { className, value, onChange, textPosition, direction, ...rest } =
props
const {
className,
value,
onChange,
textPosition,
direction,
options,
...rest
} = props

const [val2State, setVal2State] = useState(value)

Expand Down Expand Up @@ -85,6 +96,18 @@ export const RadioGroup = React.forwardRef(
})
}

function renderOptionsChildren() {
return options?.map(({ label, value, disabled, onChange }) => (
<Radio
key={value?.toString()}
children={label}
value={value}
disabled={disabled}
onChange={onChange}
/>
))
}

return (
<RadioContext.Provider
value={{
Expand All @@ -95,10 +118,12 @@ export const RadioGroup = React.forwardRef(
}}
>
<div
className={`nut-radiogroup nut-radiogroup--${props.direction}`}
className={`nut-radiogroup nut-radiogroup--${props.direction} ${
className || ''
}`}
{...rest}
>
{cloneChildren()}
{options?.length ? renderOptionsChildren() : cloneChildren()}
</div>
</RadioContext.Provider>
)
Expand Down