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

chore: master merge feature #6244

Merged
merged 7 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/guide/i18n.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following languages are currently supported:
| Danish | da-DK |
| Norwegian (Bokmål) | nb-NO |
| Dutch (Netherlands) | nl-NL |
| Russian (Russia) | ru-RU |

See more usage at [ConfigProvider](../components/config-provider).

Expand Down
1 change: 1 addition & 0 deletions docs/guide/i18n.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ return (
| 丹麦语 | da-DK |
| 挪威 | nb-NO |
| 荷兰语 | nl-NL |
| 俄罗斯语 | ru-RU |

具体的使用方法请参考 [ConfigProvider](../components/config-provider) 文档。

Expand Down
8 changes: 2 additions & 6 deletions src/components/calendar/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ export function convertValueToRange(
selectionMode: 'single' | 'range' | undefined,
value: Date | [Date, Date] | null
): DateRange {
if (selectionMode === undefined) {
return null
}
if (value === null) {
return null
}
if (selectionMode === undefined || value === null) return null

if (Array.isArray(value)) {
return value
}
Expand Down
10 changes: 4 additions & 6 deletions src/components/capsule-tabs/capsule-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {
FC,
ReactNode,
ReactElement,
ComponentProps,
isValidElement,
useRef,
} from 'react'
import classNames from 'classnames'
Expand All @@ -25,9 +25,7 @@ export type CapsuleTabProps = {
children?: ReactNode
} & NativeProps

export const CapsuleTab: FC<CapsuleTabProps> = () => {
return null
}
export const CapsuleTab: FC<CapsuleTabProps> = () => null

export type CapsuleTabsProps = {
activeKey?: string | null
Expand All @@ -42,10 +40,10 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
const keyToIndexRecord: Record<string, number> = {}
let firstActiveKey: string | null = null

const panes: ReactElement<ComponentProps<typeof CapsuleTab>>[] = []
const panes: ReactElement<CapsuleTabProps>[] = []

traverseReactNode(props.children, (child, index) => {
if (!React.isValidElement(child)) return
if (!isValidElement<CapsuleTabProps>(child)) return
const key = child.key
if (typeof key !== 'string') return
if (index === 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type CheckboxProps = {
id?: string
icon?: (checked: boolean, indeterminate: boolean) => React.ReactNode
children?: React.ReactNode
onClick?: (event: React.MouseEvent<HTMLLabelElement, MouseEvent>) => void
} & NativeProps<'--icon-size' | '--font-size' | '--gap'>

const defaultProps = {
Expand Down Expand Up @@ -110,6 +111,7 @@ export const Checkbox = forwardRef<CheckboxRef, CheckboxProps>((p, ref) => {
return withNativeProps(
props,
<label
onClick={props.onClick}
className={classNames(classPrefix, {
[`${classPrefix}-checked`]: checked && !props.indeterminate,
[`${classPrefix}-indeterminate`]: props.indeterminate,
Expand Down
1 change: 1 addition & 0 deletions src/components/checkbox/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type CheckboxValue = string | number
| id | The id of the input element, often used in conjunction with the label | `string` | - |
| indeterminate | To set the `indeterminate` state, only responsible for style control | `boolean` | `false` |
| onChange | Callback function when changing | `(val: boolean) => void` | - |
| onClick | Checkbox's click event | `(event: React.MouseEvent<HTMLLabelElement, MouseEvent>) => void` | - |
| value | The value carrying identification, used in `Group` mode | `CheckboxValue` | - |

### Ref
Expand Down
1 change: 1 addition & 0 deletions src/components/checkbox/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type CheckboxValue = string | number
| id | `input` 元素的 `id`,常用来配合 `label` 使用 | `string` | - |
| indeterminate | 设置 `indeterminate` 状态,只负责样式控制 | `boolean` | `false` |
| onChange | 变化时回调函数 | `(val: boolean) => void` | - |
| onClick | Checkbox 的点击事件 | `(event: React.MouseEvent<HTMLLabelElement, MouseEvent>) => void` | - |
| value | 携带的标识值,用于 `Group` 模式 | `CheckboxValue` | - |

### Ref
Expand Down
9 changes: 9 additions & 0 deletions src/components/checkbox/tests/checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ describe('Checkbox', () => {
expect(input).not.toBeChecked()
expect(checkbox).not.toHaveClass(`${classPrefix}-checked`)
})
test('Checkbox click', () => {
const handleClick = jest.fn()
const { container } = render(
<Checkbox onClick={handleClick}>click</Checkbox>
)
const checkbox = container.getElementsByTagName('label')[0]

fireEvent.click(checkbox)
expect(handleClick).toHaveBeenCalledTimes(1)
})
test('renders with disabled', async () => {
const { container } = render(<Checkbox disabled>Checkbox</Checkbox>)
const input = container.querySelectorAll('input')[0]
Expand Down
7 changes: 4 additions & 3 deletions src/components/collapse/collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, ReactElement, ComponentProps, useRef } from 'react'
import React, { FC, ReactElement, isValidElement, useRef } from 'react'
import { NativeProps, withNativeProps } from '../../utils/native-props'
import List from '../list'
import { DownOutline } from 'antd-mobile-icons'
Expand Down Expand Up @@ -120,11 +120,12 @@ export type CollapseProps = (
} & NativeProps

export const Collapse: FC<CollapseProps> = props => {
const panels: ReactElement<ComponentProps<typeof CollapsePanel>>[] = []
const panels: ReactElement<CollapsePanelProps>[] = []
traverseReactNode(props.children, child => {
if (!React.isValidElement(child)) return
if (!isValidElement<CollapsePanelProps>(child)) return
const key = child.key
if (typeof key !== 'string') return

panels.push(child)
})

Expand Down
Loading