mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-22 19:48:49 +08:00
chore: upgrade deps
style(prettier): format code style
This commit is contained in:
@@ -3,6 +3,7 @@ module.exports = {
|
||||
tabWidth: 2,
|
||||
printWidth: 100,
|
||||
trailingComma: 'all',
|
||||
arrowParens: 'avoid',
|
||||
singleQuote: true,
|
||||
jsxBracketSameLine: true,
|
||||
endOfLine: 'lf',
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('AutoComplete Search', () => {
|
||||
|
||||
it('should update value when dropdown clicked', () => {
|
||||
let value = ''
|
||||
const wrapper = mount(<AutoComplete options={mockOptions} onChange={(val) => (value = val)} />)
|
||||
const wrapper = mount(<AutoComplete options={mockOptions} onChange={val => (value = val)} />)
|
||||
wrapper.find('input').at(0).simulate('focus')
|
||||
wrapper.find('.item').at(0).simulate('click', nativeEvent)
|
||||
expect(value).toEqual('london')
|
||||
@@ -26,7 +26,7 @@ describe('AutoComplete Search', () => {
|
||||
it('should ignore events when disabled', () => {
|
||||
let value = ''
|
||||
const wrapper = mount(
|
||||
<AutoComplete disabled options={mockOptions} onChange={(val) => (value = val)} />,
|
||||
<AutoComplete disabled options={mockOptions} onChange={val => (value = val)} />,
|
||||
)
|
||||
wrapper.find('input').at(0).simulate('focus')
|
||||
wrapper.find('.item').at(0).simulate('click', nativeEvent)
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('Checkbox Group', () => {
|
||||
it('should change value after click', () => {
|
||||
let value = ['sydney']
|
||||
const wrapper = mount(
|
||||
<Checkbox.Group value={['sydney']} onChange={(val) => (value = val)}>
|
||||
<Checkbox.Group value={['sydney']} onChange={val => (value = val)}>
|
||||
<Checkbox value="sydney">Sydney</Checkbox>
|
||||
<Checkbox value="beijing">BeiJing</Checkbox>
|
||||
</Checkbox.Group>,
|
||||
@@ -51,7 +51,7 @@ describe('Checkbox Group', () => {
|
||||
it('should ignore events when disabled', () => {
|
||||
let value = ['sydney']
|
||||
const wrapper = mount(
|
||||
<Checkbox.Group disabled value={['sydney']} onChange={(val) => (value = val)}>
|
||||
<Checkbox.Group disabled value={['sydney']} onChange={val => (value = val)}>
|
||||
<Checkbox value="sydney">Sydney</Checkbox>
|
||||
<Checkbox value="beijing">BeiJing</Checkbox>
|
||||
</Checkbox.Group>,
|
||||
@@ -68,7 +68,7 @@ describe('Checkbox Group', () => {
|
||||
it('should throw error when value missing', () => {
|
||||
let errorMessage = ''
|
||||
const Group = Checkbox.Group as any
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
mount(
|
||||
<Group>
|
||||
<Checkbox value="sydney">Sydney</Checkbox>
|
||||
@@ -82,7 +82,7 @@ describe('Checkbox Group', () => {
|
||||
|
||||
it('should throw error when set check prop in group', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
mount(
|
||||
<Checkbox.Group value={[]}>
|
||||
<Checkbox value="sydney" checked>
|
||||
|
||||
@@ -33,7 +33,7 @@ const CheckboxGroup: React.FC<React.PropsWithChildren<CheckboxGroupProps>> = ({
|
||||
}
|
||||
|
||||
const updateState = (val: string, checked: boolean) => {
|
||||
const removed = selfVal.filter((v) => v !== val)
|
||||
const removed = selfVal.filter(v => v !== val)
|
||||
const next = checked ? [...removed, val] : removed
|
||||
setSelfVal(next)
|
||||
onChange && onChange(next)
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('Code', () => {
|
||||
|
||||
it('should alert warning when use bash', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
|
||||
mount(<Code bash>code</Code>)
|
||||
expect(errorMessage.toLowerCase()).toContain('deprecated')
|
||||
@@ -40,7 +40,7 @@ describe('Code', () => {
|
||||
|
||||
it('should alert warning when use darkBash', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
|
||||
mount(<Code darkBash>code</Code>)
|
||||
expect(errorMessage.toLowerCase()).toContain('deprecated')
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('Collapse', () => {
|
||||
it('should throw error when title missing', () => {
|
||||
const Component = Collapse as any
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
|
||||
mount(<Component subtitle="subtitle">content</Component>)
|
||||
expect(errorMessage.toLowerCase()).not.toEqual('')
|
||||
|
||||
@@ -28,7 +28,7 @@ const CollapseGroup: React.FC<React.PropsWithChildren<CollapseGroupProps>> = ({
|
||||
const theme = useTheme()
|
||||
const [state, setState, stateRef] = useCurrentState<Array<number>>([])
|
||||
const updateValues = (currentIndex: number, nextState: boolean) => {
|
||||
const hasChild = stateRef.current.find((val) => val === currentIndex)
|
||||
const hasChild = stateRef.current.find(val => val === currentIndex)
|
||||
if (accordion) {
|
||||
if (nextState) return setState([currentIndex])
|
||||
return setState([])
|
||||
@@ -41,7 +41,7 @@ const CollapseGroup: React.FC<React.PropsWithChildren<CollapseGroupProps>> = ({
|
||||
if (hasChild) return
|
||||
return setState([...stateRef.current, currentIndex])
|
||||
}
|
||||
setState(stateRef.current.filter((item) => item !== currentIndex))
|
||||
setState(stateRef.current.filter(item => item !== currentIndex))
|
||||
}
|
||||
|
||||
const initialValue = useMemo<CollapseConfig>(
|
||||
|
||||
@@ -45,7 +45,7 @@ const Collapse: React.FC<React.PropsWithChildren<CollapseProps>> = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (!values.length) return
|
||||
const isActive = !!values.find((item) => item === index)
|
||||
const isActive = !!values.find(item => item === index)
|
||||
setVisible(isActive)
|
||||
}, [values.join(',')])
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('Fieldset Group', () => {
|
||||
|
||||
it('should throw error when value duplicated', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
|
||||
mount(
|
||||
<Fieldset.Group value="two">
|
||||
@@ -50,7 +50,7 @@ describe('Fieldset Group', () => {
|
||||
|
||||
it('should throw error when label missing', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
|
||||
mount(
|
||||
<Fieldset.Group value="one">
|
||||
|
||||
@@ -30,7 +30,7 @@ const FieldsetGroup: React.FC<React.PropsWithChildren<FieldsetGroupProps>> = ({
|
||||
const [items, setItems, ref] = useCurrentState<FieldItem[]>([])
|
||||
|
||||
const register = (newItem: FieldItem) => {
|
||||
const hasItem = ref.current.find((item) => item.value === newItem.value)
|
||||
const hasItem = ref.current.find(item => item.value === newItem.value)
|
||||
if (hasItem) {
|
||||
useWarning('The "value" of each "Fieldset" must be unique.', 'Fieldset')
|
||||
}
|
||||
@@ -58,7 +58,7 @@ const FieldsetGroup: React.FC<React.PropsWithChildren<FieldsetGroupProps>> = ({
|
||||
<FieldsetContext.Provider value={providerValue}>
|
||||
<div className={` ${className}`} {...props}>
|
||||
<div className="group">
|
||||
{items.map((item) => (
|
||||
{items.map(item => (
|
||||
<button
|
||||
onClick={() => clickHandle(item.value)}
|
||||
key={item.value}
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('Tree', () => {
|
||||
})
|
||||
|
||||
it('should show extra messages', () => {
|
||||
const files = mockFiles.map((item) => ({ ...item, extra: 'extra' }))
|
||||
const files = mockFiles.map(item => ({ ...item, extra: 'extra' }))
|
||||
const wrapper = mount(<Tree value={files} />)
|
||||
const firstName = wrapper.find('.name').at(0)
|
||||
expect(firstName.text()).toContain('extra')
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Input, useInput } from 'components'
|
||||
describe('UseInput', () => {
|
||||
it('should follow change with use-input', () => {
|
||||
let log = ''
|
||||
const logSpy = jest.spyOn(console, 'log').mockImplementation((msg) => (log = msg))
|
||||
const logSpy = jest.spyOn(console, 'log').mockImplementation(msg => (log = msg))
|
||||
const MockInput: React.FC<{ value?: string }> = ({ value }) => {
|
||||
const { state, setState, bindings } = useInput('')
|
||||
useEffect(() => {
|
||||
|
||||
@@ -25,7 +25,7 @@ const InputPassword = React.forwardRef<
|
||||
useImperativeHandle(ref, () => inputRef.current)
|
||||
|
||||
const iconClickHandler = () => {
|
||||
setVisible((v) => !v)
|
||||
setVisible(v => !v)
|
||||
/* istanbul ignore next */
|
||||
if (inputRef && inputRef.current) {
|
||||
inputRef.current.focus()
|
||||
|
||||
@@ -95,7 +95,7 @@ describe('Modal', () => {
|
||||
const wrapper = mount(
|
||||
<Modal open={true} onClose={closeHandler}>
|
||||
<Modal.Title>Modal</Modal.Title>
|
||||
<Modal.Action passive onClick={(e) => e.close()}>
|
||||
<Modal.Action passive onClick={e => e.close()}>
|
||||
Close
|
||||
</Modal.Action>
|
||||
</Modal>,
|
||||
|
||||
@@ -47,7 +47,7 @@ const getCurrentColor = (
|
||||
const colorKeys = Object.keys(colors)
|
||||
if (colorKeys.length === 0) return defaultColors[type]
|
||||
|
||||
const customColorKey = colorKeys.find((key) => ratio <= +key)
|
||||
const customColorKey = colorKeys.find(key => ratio <= +key)
|
||||
if (!customColorKey || Number.isNaN(+customColorKey)) return defaultColors[type]
|
||||
return colors[+customColorKey]
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('Radio Group', () => {
|
||||
|
||||
it('should trigger events in group', () => {
|
||||
let value = ''
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(
|
||||
<Radio.Group onChange={changeHandler}>
|
||||
<Radio value="1">Option 1</Radio>
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('Select', () => {
|
||||
|
||||
it('should trigger events when option changed', async () => {
|
||||
let value = ''
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(
|
||||
<Select onChange={changeHandler}>
|
||||
<Select.Option value="1">1</Select.Option>
|
||||
@@ -68,7 +68,7 @@ describe('Select', () => {
|
||||
|
||||
it('should ignore option when option disabled', async () => {
|
||||
let value = ''
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(
|
||||
<Select onChange={changeHandler}>
|
||||
<Select.Option value="1">1</Select.Option>
|
||||
@@ -104,7 +104,7 @@ describe('Select', () => {
|
||||
|
||||
it('should be wraning when ident value missing', () => {
|
||||
let errorMessage = ''
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg) => (errorMessage = msg))
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(msg => (errorMessage = msg))
|
||||
const SelectOption = Select.Option as any
|
||||
const wrapper = mount(
|
||||
<Select>
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('Slider', () => {
|
||||
|
||||
it('should trigger events when click', async () => {
|
||||
let value = 0
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(<Slider initialValue={20} onChange={changeHandler} />)
|
||||
wrapper.find('.slider').simulate('click', {
|
||||
...nativeEvent,
|
||||
@@ -59,7 +59,7 @@ describe('Slider', () => {
|
||||
|
||||
it('should trigger events when drag', async () => {
|
||||
let value = 0
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(<Slider initialValue={0} onChange={changeHandler} />)
|
||||
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('Slider', () => {
|
||||
|
||||
it('should ignore events when disabled', async () => {
|
||||
let value = 0
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(<Slider initialValue={0} disabled onChange={changeHandler} />)
|
||||
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
|
||||
|
||||
@@ -91,7 +91,7 @@ describe('Slider', () => {
|
||||
|
||||
it('should move unit length is step', async () => {
|
||||
let value = 0
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(<Slider step={10} onChange={changeHandler} />)
|
||||
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('Slider', () => {
|
||||
|
||||
it('should return the specified when the limit is exceeded', () => {
|
||||
let value = 0
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(<Slider min={10} max={20} onChange={changeHandler} />)
|
||||
const dot = wrapper.find('.dot').getDOMNode() as HTMLDivElement
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ const Slider: React.FC<React.PropsWithChildren<SliderProps>> = ({
|
||||
}
|
||||
|
||||
const updateValue = useCallback(
|
||||
(offset) => {
|
||||
offset => {
|
||||
const currentValue = getValue(max, min, step, offset, sideWidthRef.current)
|
||||
setValue(currentValue)
|
||||
onChange && onChange(currentValue)
|
||||
|
||||
@@ -17,7 +17,7 @@ type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
|
||||
export type TableHeadProps = Props & typeof defaultProps & NativeAttrs
|
||||
|
||||
const makeColgroup = (width: number, columns: Array<TableColumnItem>) => {
|
||||
const unsetWidthCount = columns.filter((c) => !c.width).length
|
||||
const unsetWidthCount = columns.filter(c => !c.width).length
|
||||
const customWidthTotal = columns.reduce((pre, current) => {
|
||||
return current.width ? pre + current.width : pre
|
||||
}, 0)
|
||||
@@ -34,7 +34,7 @@ const makeColgroup = (width: number, columns: Array<TableColumnItem>) => {
|
||||
|
||||
const TableHead: React.FC<TableHeadProps> = ({ columns, width }) => {
|
||||
const theme = useTheme()
|
||||
const isScalableWidth = useMemo(() => columns.find((item) => !!item.width), [columns])
|
||||
const isScalableWidth = useMemo(() => columns.find(item => !!item.width), [columns])
|
||||
const colgroup = useMemo(() => {
|
||||
if (!isScalableWidth) return <colgroup />
|
||||
return makeColgroup(width, columns)
|
||||
|
||||
@@ -49,7 +49,7 @@ const Table: React.FC<React.PropsWithChildren<TableProps>> = ({
|
||||
const [columns, setColumns, columnsRef] = useCurrentState<Array<TableColumnItem>>([])
|
||||
const [selfData, setSelfData, dataRef] = useCurrentState<Array<TableColumnItem>>([])
|
||||
const appendColumn = (column: TableColumnItem) => {
|
||||
const pureCurrent = columnsRef.current.filter((item) => item.value !== column.value)
|
||||
const pureCurrent = columnsRef.current.filter(item => item.value !== column.value)
|
||||
setColumns([...pureCurrent, column])
|
||||
}
|
||||
const removeRow = (rowIndex: number) => {
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('Tabs', () => {
|
||||
|
||||
it('should trigger events when tab changed', () => {
|
||||
let value = ''
|
||||
const changeHandler = jest.fn().mockImplementation((val) => (value = val))
|
||||
const changeHandler = jest.fn().mockImplementation(val => (value = val))
|
||||
const wrapper = mount(
|
||||
<Tabs initialValue="1" onChange={changeHandler}>
|
||||
<Tabs.Item label="label1" value="1">
|
||||
|
||||
@@ -32,14 +32,14 @@ const Tabs: React.FC<React.PropsWithChildren<TabsProps>> = ({
|
||||
const [tabs, setTabs, tabsRef] = useCurrentState<Array<TabsLabelItem>>([])
|
||||
|
||||
const register = (next: TabsLabelItem) => {
|
||||
const hasItem = tabsRef.current.find((item) => item.value === next.value)
|
||||
const hasItem = tabsRef.current.find(item => item.value === next.value)
|
||||
if (hasItem) {
|
||||
useWarning('The "value" of each "Tabs.Item" must be unique.', 'Tabs')
|
||||
}
|
||||
setTabs([...tabsRef.current, next])
|
||||
}
|
||||
const unregister = (next: TabsLabelItem) => {
|
||||
const nextTabs = tabsRef.current.filter((item) => item.value !== next.value)
|
||||
const nextTabs = tabsRef.current.filter(item => item.value !== next.value)
|
||||
setTabs([...nextTabs])
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('Textarea', () => {
|
||||
|
||||
it('should trigger events when textarea changed', () => {
|
||||
let value = ''
|
||||
const handler = jest.fn().mockImplementation((e) => (value = e.target.value))
|
||||
const handler = jest.fn().mockImplementation(e => (value = e.target.value))
|
||||
const wrapper = mount(<Textarea onChange={handler} />)
|
||||
wrapper.find('textarea').simulate('change', { target: { value: 'test-value' } })
|
||||
expect(handler).toHaveBeenCalled()
|
||||
|
||||
@@ -59,7 +59,7 @@ const useToasts = (): [Array<Toast>, (t: Toast) => void] => {
|
||||
|
||||
const cancel = (id: string, delay: number) => {
|
||||
updateToasts((currentToasts: Array<ToastWithID>) => {
|
||||
return currentToasts.map((item) => {
|
||||
return currentToasts.map(item => {
|
||||
if (item.id !== id) return item
|
||||
return { ...item, willBeDestroy: true }
|
||||
})
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Toggle', () => {
|
||||
|
||||
it('should trigger events when toggle changed', async () => {
|
||||
let checked = false
|
||||
const changeHandler = jest.fn().mockImplementation((e) => (checked = e.target.checked))
|
||||
const changeHandler = jest.fn().mockImplementation(e => (checked = e.target.checked))
|
||||
const wrapper = mount(<Toggle onChange={changeHandler} />)
|
||||
|
||||
wrapper.find('input').simulate('change', {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('UseCurrentState', () => {
|
||||
const { result } = renderHook(() => useCurrentState(0))
|
||||
expect(result.current[0]).toEqual(0)
|
||||
|
||||
act(() => result.current[1]((pre) => pre + 10))
|
||||
act(() => result.current[1](pre => pre + 10))
|
||||
expect(result.current[0]).toEqual(10)
|
||||
expect(result.current[2].current).toEqual(10)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ export const getId = () => {
|
||||
}
|
||||
|
||||
export const hasChild = (children: ReactNode | undefined, child: React.ElementType): boolean => {
|
||||
const types = React.Children.map(children, (item) => {
|
||||
const types = React.Children.map(children, item => {
|
||||
if (!React.isValidElement(item)) return null
|
||||
return item.type
|
||||
})
|
||||
@@ -18,7 +18,7 @@ export const pickChild = (
|
||||
targetChild: React.ElementType,
|
||||
): [ReactNode | undefined, ReactNode | undefined] => {
|
||||
let target: ReactNode[] = []
|
||||
const withoutTargetChildren = React.Children.map(children, (item) => {
|
||||
const withoutTargetChildren = React.Children.map(children, item => {
|
||||
if (!React.isValidElement(item)) return item
|
||||
if (item.type === targetChild) {
|
||||
target.push(item)
|
||||
@@ -38,7 +38,7 @@ export const pickChildByProps = (
|
||||
value: any,
|
||||
): [ReactNode | undefined, ReactNode | undefined] => {
|
||||
let target: ReactNode[] = []
|
||||
const withoutPropChildren = React.Children.map(children, (item) => {
|
||||
const withoutPropChildren = React.Children.map(children, item => {
|
||||
if (!React.isValidElement(item)) return null
|
||||
if (!item.props) return item
|
||||
if (item.props[key] === value) {
|
||||
@@ -66,11 +66,11 @@ export const setChildrenProps = (
|
||||
const allowAll = targetComponents.length === 0
|
||||
const clone = (child: React.ReactElement, props = {}) => React.cloneElement(child, props)
|
||||
|
||||
return React.Children.map(children, (item) => {
|
||||
return React.Children.map(children, item => {
|
||||
if (!React.isValidElement(item)) return item
|
||||
if (allowAll) return clone(item, props)
|
||||
|
||||
const isAllowed = targetComponents.find((child) => child === item.type)
|
||||
const isAllowed = targetComponents.find(child => child === item.type)
|
||||
if (isAllowed) return clone(item, props)
|
||||
return item
|
||||
})
|
||||
@@ -85,12 +85,12 @@ export const setChildrenIndex = (
|
||||
const clone = (child: React.ReactElement, props = {}) => React.cloneElement(child, props)
|
||||
let index = 0
|
||||
|
||||
return React.Children.map(children, (item) => {
|
||||
return React.Children.map(children, item => {
|
||||
if (!React.isValidElement(item)) return item
|
||||
index = index + 1
|
||||
if (allowAll) return clone(item, { index })
|
||||
|
||||
const isAllowed = targetComponents.find((child) => child === item.type)
|
||||
const isAllowed = targetComponents.find(child => child === item.type)
|
||||
if (isAllowed) return clone(item, { index })
|
||||
index = index - 1
|
||||
return item
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface ZeitUiContextParams {
|
||||
const defaultParams: ZeitUiContextParams = {
|
||||
toasts: [],
|
||||
toastHovering: false,
|
||||
updateToasts: (t) => t,
|
||||
updateToasts: t => t,
|
||||
updateToastHoverStatus: () => {},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import React from 'react'
|
||||
import { Text, useTheme } from 'components'
|
||||
|
||||
export const getFileName = (name: string): string => {
|
||||
return name.replace(/^(.)/, (g) => g.toLowerCase())
|
||||
return name.replace(/^(.)/, g => g.toLowerCase())
|
||||
}
|
||||
|
||||
export const getImportString = (name: string) => {
|
||||
|
||||
@@ -15,14 +15,14 @@ const Menu: React.FC<{}> = () => {
|
||||
? ['/zh-cn/guide/introduction', '/zh-cn/components/text', '/zh-cn/customization']
|
||||
: ['/en-us/guide/introduction', '/en-us/components/text', '/en-us/customization']
|
||||
await Promise.all(
|
||||
urls.map(async (url) => {
|
||||
urls.map(async url => {
|
||||
await router.prefetch(url)
|
||||
}),
|
||||
)
|
||||
}
|
||||
prefetch()
|
||||
.then()
|
||||
.catch((err) => console.log(err))
|
||||
.catch(err => console.log(err))
|
||||
}, [isChinese])
|
||||
|
||||
if (!showAfterRender) return null
|
||||
|
||||
@@ -40,7 +40,7 @@ const MenuSticker = () => {
|
||||
<nav className={fixed ? 'fixed' : ''}>
|
||||
<div className="sticker">
|
||||
<div className="inner">
|
||||
<Tabs value={tabValue} onChange={(val) => setTabValue(val)}>
|
||||
<Tabs value={tabValue} onChange={val => setTabValue(val)}>
|
||||
{tabbarData
|
||||
? tabbarData.map((tab, index) => (
|
||||
<Tabs.Item
|
||||
|
||||
@@ -28,7 +28,7 @@ export const Sidebar: React.FC<Props> = React.memo(() => {
|
||||
|
||||
const tabbarData = useMemo(() => {
|
||||
const allSides = Metadatas[locale]
|
||||
const currentSide = allSides.filter((side) => side.name === tabbar)[0]
|
||||
const currentSide = allSides.filter(side => side.name === tabbar)[0]
|
||||
return (currentSide.children || []) as Array<Sides>
|
||||
}, [locale, tabbar])
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ const useLocale = (): LocaleTypes => {
|
||||
const [tabbar, setTab, tabRef] = useCurrentState<string>(DEFAULT_TAB)
|
||||
|
||||
useEffect(() => {
|
||||
const names = pathname.split('/').filter((r) => !!r)
|
||||
const names = pathname.split('/').filter(r => !!r)
|
||||
const currentLocale = names[0] || DEFAULT_LOCALE
|
||||
const currentTabbar = names[1] || DEFAULT_TAB
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"@types/styled-jsx": "^2.2.8",
|
||||
"@typescript-eslint/eslint-plugin": "^2.24.0",
|
||||
"@typescript-eslint/parser": "^2.24.0",
|
||||
"@zeit-ui/react-icons": "^1.2.1",
|
||||
"@zeit-ui/react-icons": "^1.2.2",
|
||||
"babel-jest": "^25.3.0",
|
||||
"babel-loader": "^8.0.6",
|
||||
"enzyme": "^3.11.0",
|
||||
|
||||
@@ -51,6 +51,6 @@ export default {
|
||||
// name: 'ZeitUI',
|
||||
// },
|
||||
],
|
||||
external: (id) => /^react|react-dom|styled-jsx/.test(id),
|
||||
external: id => /^react|react-dom|styled-jsx/.test(id),
|
||||
plugins: plugins,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const path = require('path')
|
||||
const extractMetadata = require('extract-mdx-metadata')
|
||||
const metaLocales = require('./locales')
|
||||
const pagePrefix = path.join(__dirname, '../pages')
|
||||
const getTargetPath = (locale) => {
|
||||
const getTargetPath = locale => {
|
||||
return path.join(__dirname, '../lib/data/', `metadata-${locale}.json`)
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ const groupWeights = {
|
||||
const getMetadata = async (files, parentPath) => {
|
||||
return Promise.all(
|
||||
files
|
||||
.filter((name) => name.endsWith('.mdx') || !name.includes('.'))
|
||||
.map(async (file) => {
|
||||
.filter(name => name.endsWith('.mdx') || !name.includes('.'))
|
||||
.map(async file => {
|
||||
const filePath = path.join(parentPath, file)
|
||||
const isDirectory = fs.statSync(filePath).isDirectory()
|
||||
if (isDirectory) {
|
||||
@@ -51,13 +51,13 @@ const getMetadata = async (files, parentPath) => {
|
||||
const sorted = childrenMetadata.sort((a, b) => a.index - b.index)
|
||||
|
||||
// grouping
|
||||
const childrenHasGroup = sorted.find((item) => item.group)
|
||||
const childrenHasGroup = sorted.find(item => item.group)
|
||||
if (childrenHasGroup) {
|
||||
const groups = [...new Set(sorted.map((item) => item.group || 'others'))]
|
||||
const groups = [...new Set(sorted.map(item => item.group || 'others'))]
|
||||
const groupChildren = groups
|
||||
.map((groupName) => ({
|
||||
.map(groupName => ({
|
||||
name: groupName,
|
||||
children: sorted.filter((item) => (item.group || 'others') === groupName),
|
||||
children: sorted.filter(item => (item.group || 'others') === groupName),
|
||||
}))
|
||||
.sort((a, b) => {
|
||||
const pre = a.name.toLowerCase()
|
||||
@@ -87,7 +87,7 @@ const getMetadata = async (files, parentPath) => {
|
||||
|
||||
const deepTranslate = (metadata, locales) => {
|
||||
if (!metadata || !Array.isArray(metadata)) return metadata
|
||||
return metadata.map((data) => {
|
||||
return metadata.map(data => {
|
||||
if (typeof data !== 'object') return data
|
||||
if (data.children) {
|
||||
data.children = deepTranslate(data.children, locales)
|
||||
@@ -103,14 +103,14 @@ const deepTranslate = (metadata, locales) => {
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
const locales = (await fs.readdir(pagePrefix)).filter((name) => {
|
||||
const locales = (await fs.readdir(pagePrefix)).filter(name => {
|
||||
const fullPath = path.join(pagePrefix, name)
|
||||
if (name === 'docs') return false
|
||||
return fs.statSync(fullPath).isDirectory()
|
||||
})
|
||||
|
||||
const sortdMetaData = await Promise.all(
|
||||
locales.map(async (name) => {
|
||||
locales.map(async name => {
|
||||
const currentLocale = metaLocales[name] || {}
|
||||
const dir = path.join(pagePrefix, name)
|
||||
const childDirs = await fs.readdir(dir)
|
||||
@@ -126,7 +126,7 @@ const deepTranslate = (metadata, locales) => {
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
sortdMetaData.map(async (data) => {
|
||||
sortdMetaData.map(async data => {
|
||||
const targetPath = getTargetPath(data.name)
|
||||
await fs.ensureFile(targetPath)
|
||||
await fs.writeJson(targetPath, data.content)
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = async () => {
|
||||
const files = await fs.readdir(componentsPath)
|
||||
|
||||
const components = await Promise.all(
|
||||
files.map(async (name) => {
|
||||
files.map(async name => {
|
||||
const comPath = path.join(componentsPath, name)
|
||||
const entry = path.join(comPath, 'index.ts')
|
||||
|
||||
@@ -21,7 +21,7 @@ module.exports = async () => {
|
||||
)
|
||||
|
||||
const componentsEntries = components
|
||||
.filter((r) => r)
|
||||
.filter(r => r)
|
||||
.reduce((pre, current) => {
|
||||
return Object.assign({}, pre, { [current.name]: current.url })
|
||||
}, {})
|
||||
|
||||
@@ -2,7 +2,7 @@ import { act } from 'react-dom/test-utils'
|
||||
import { ReactWrapper } from 'enzyme'
|
||||
|
||||
export const sleep = (time: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, time))
|
||||
return new Promise(resolve => setTimeout(resolve, time))
|
||||
}
|
||||
|
||||
export const updateWrapper = async (wrapper: ReactWrapper, time: number = 0) => {
|
||||
|
||||
@@ -1769,10 +1769,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
|
||||
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
|
||||
|
||||
"@zeit-ui/react-icons@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@zeit-ui/react-icons/-/react-icons-1.2.1.tgz#6e200adf6870aca0cd4a6e0d2ba5fb5196d53234"
|
||||
integrity sha512-K0r7ZmqCB6Tl/tCmrjKXYuoWL9iMxUQem1lzUP/QCEJI+o0v5B0MnrEMzxrlXDFZDN/0wPjna0jcecQTL80GAA==
|
||||
"@zeit-ui/react-icons@^1.2.2":
|
||||
version "1.2.2"
|
||||
resolved "https://registry.yarnpkg.com/@zeit-ui/react-icons/-/react-icons-1.2.2.tgz#92f8474c986b0a0f9f8afc30e354ac3d54631813"
|
||||
integrity sha512-O0BVU6c9yLyW64DNN7+ovn3s+BtysQcxqKIWVofSnjbToTXaAob5BZXoV+QpEWrUod3olTzJzdw9/D3ha1YMiw==
|
||||
|
||||
abab@^2.0.0:
|
||||
version "2.0.3"
|
||||
|
||||
Reference in New Issue
Block a user