Skip to content

Commit

Permalink
chore: code style simplify (#6241)
Browse files Browse the repository at this point in the history
chore: 回退if语句简化,保留函数简化
  • Loading branch information
1587315093 authored Jul 12, 2023
1 parent e286ab7 commit ae1f895
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 132 deletions.
4 changes: 1 addition & 3 deletions src/components/capsule-tabs/capsule-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
60 changes: 24 additions & 36 deletions src/components/date-picker/date-picker-date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ export function generateDatePickerColumns(
const upper = maxYear
const years = generateColumn(lower, upper, 'year')
ret.push(
years.map(v => {
return {
label: renderLabel('year', v),
value: v.toString(),
}
})
years.map(v => ({
label: renderLabel('year', v),
value: v.toString(),
}))
)
}

Expand All @@ -118,64 +116,54 @@ export function generateDatePickerColumns(
const upper = isInMaxYear ? maxMonth : 12
const months = generateColumn(lower, upper, 'month')
ret.push(
months.map(v => {
return {
label: renderLabel('month', v),
value: v.toString(),
}
})
months.map(v => ({
label: renderLabel('month', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.day) {
const lower = isInMinMonth ? minDay : 1
const upper = isInMaxMonth ? maxDay : firstDayInSelectedMonth.daysInMonth()
const days = generateColumn(lower, upper, 'day')
ret.push(
days.map(v => {
return {
label: renderLabel('day', v),
value: v.toString(),
}
})
days.map(v => ({
label: renderLabel('day', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.hour) {
const lower = isInMinDay ? minHour : 0
const upper = isInMaxDay ? maxHour : 23
const hours = generateColumn(lower, upper, 'hour')
ret.push(
hours.map(v => {
return {
label: renderLabel('hour', v),
value: v.toString(),
}
})
hours.map(v => ({
label: renderLabel('hour', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.minute) {
const lower = isInMinHour ? minMinute : 0
const upper = isInMaxHour ? maxMinute : 59
const minutes = generateColumn(lower, upper, 'minute')
ret.push(
minutes.map(v => {
return {
label: renderLabel('minute', v),
value: v.toString(),
}
})
minutes.map(v => ({
label: renderLabel('minute', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.second) {
const lower = isInMinMinute ? minSecond : 0
const upper = isInMaxMinute ? maxSecond : 59
const seconds = generateColumn(lower, upper, 'second')
ret.push(
seconds.map(v => {
return {
label: renderLabel('second', v),
value: v.toString(),
}
})
seconds.map(v => ({
label: renderLabel('second', v),
value: v.toString(),
}))
)
}

Expand Down
30 changes: 12 additions & 18 deletions src/components/date-picker/date-picker-week-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ export function generateDatePickerColumns(
const upper = maxYear
const years = generateColumn(lower, upper, 'year')
ret.push(
years.map(v => {
return {
label: renderLabel('year', v),
value: v.toString(),
}
})
years.map(v => ({
label: renderLabel('year', v),
value: v.toString(),
}))
)
}

Expand All @@ -91,25 +89,21 @@ export function generateDatePickerColumns(
const upper = isInMaxYear ? maxWeek : selectedYearWeeks
const weeks = generateColumn(lower, upper, 'week')
ret.push(
weeks.map(v => {
return {
label: renderLabel('week', v),
value: v.toString(),
}
})
weeks.map(v => ({
label: renderLabel('week', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord['week-day']) {
const lower = isInMinWeek ? minWeekday : 1
const upper = isInMaxWeek ? maxWeekday : 7
const weeks = generateColumn(lower, upper, 'week-day')
ret.push(
weeks.map(v => {
return {
label: renderLabel('week-day', v),
value: v.toString(),
}
})
weeks.map(v => ({
label: renderLabel('week-day', v),
value: v.toString(),
}))
)
}

Expand Down
1 change: 0 additions & 1 deletion src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type DropdownProps = {
closeOnMaskClick?: boolean
closeOnClickAway?: boolean
onChange?: (key: string | null) => void
// mask?: boolean;
arrow?: React.ReactNode
getContainer?: PopupProps['getContainer']
} & NativeProps
Expand Down
52 changes: 24 additions & 28 deletions src/components/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,36 @@ export const Footer: FC<FooterProps> = p => {
<Divider>{label}</Divider>
</div>
)}
{links && links.length > 0 && (
{!!links?.length && (
<div className={`${classPrefix}-links`}>
{links.map((link, index) => {
return (
<React.Fragment key={index}>
<a
href={link.href}
rel='noopener noreferrer'
onClick={event => clickLinkItem(link, index, event)}
>
{link.text}
</a>
{index !== links.length - 1 && <Divider direction='vertical' />}
</React.Fragment>
)
})}
{links.map((link, index) => (
<React.Fragment key={index}>
<a
href={link.href}
rel='noopener noreferrer'
onClick={event => clickLinkItem(link, index, event)}
>
{link.text}
</a>
{index !== links.length - 1 && <Divider direction='vertical' />}
</React.Fragment>
))}
</div>
)}
{content && <div className={`${classPrefix}-content`}>{content}</div>}
{chips && chips.length > 0 && (
<div className={`${classPrefix}-chips`}>
{chips.map((chip, index) => {
return (
<div
key={index}
onClick={() => clickChipItem(chip, index)}
className={classNames(`${classPrefix}-chip`, {
[`${classPrefix}-chip-link`]: chip.type === 'link',
})}
>
{chip.text}
</div>
)
})}
{chips.map((chip, index) => (
<div
key={index}
onClick={() => clickChipItem(chip, index)}
className={classNames(`${classPrefix}-chip`, {
[`${classPrefix}-chip-link`]: chip.type === 'link',
})}
>
{chip.text}
</div>
))}
</div>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/form/form-array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface FormArrayOperation {

export interface FormArrayProps {
name: string | number | (string | number)[]
// rules?: ValidatorRule[]
initialValue?: any[]
renderHeader?: (
field: FormArrayField,
Expand Down
4 changes: 1 addition & 3 deletions src/components/image-uploader/image-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ export const ImageUploader: FC<ImageUploaderProps> = p => {
e.target.value = '' // HACK: fix the same file doesn't trigger onChange

if (props.beforeUpload) {
const postFiles = files.map(file => {
return processFile(file, files)
})
const postFiles = files.map(file => processFile(file, files))

await Promise.all(postFiles).then(filesList => {
files = filesList.filter(Boolean) as File[]
Expand Down
32 changes: 15 additions & 17 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,21 @@ export const Modal: FC<ModalProps> = p => {
props.actions.length === 0 && cls('footer-empty')
)}
>
{props.actions.map((action, index) => {
return (
<ModalActionButton
key={action.key}
action={action}
onAction={async () => {
await Promise.all([
action.onClick?.(),
props.onAction?.(action, index),
])
if (props.closeOnAction) {
props.onClose?.()
}
}}
/>
)
})}
{props.actions.map((action, index) => (
<ModalActionButton
key={action.key}
action={action}
onAction={async () => {
await Promise.all([
action.onClick?.(),
props.onAction?.(action, index),
])
if (props.closeOnAction) {
props.onClose?.()
}
}}
/>
))}
</Space>
</>
)
Expand Down
12 changes: 5 additions & 7 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ export const Popover = forwardRef<PopoverRef, PopoverProps>((p, ref) => {

useImperativeHandle(
ref,
() => {
return {
show: () => setVisible(true),
hide: () => setVisible(false),
visible,
}
},
() => ({
show: () => setVisible(true),
hide: () => setVisible(false),
visible,
}),
[visible]
)

Expand Down
8 changes: 4 additions & 4 deletions src/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ const defaultProps = {

export const Popup: FC<PopupProps> = p => {
const props = mergeProps(defaultProps, p)
const { locale } = useConfig()

const bodyCls = classNames(
`${classPrefix}-body`,
props.bodyClassName,
`${classPrefix}-body-position-${props.position}`
)

const { locale } = useConfig()
const [active, setActive] = useState(props.visible)
const ref = useRef<HTMLDivElement>(null)
useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false)

useIsomorphicLayoutEffect(() => {
if (props.visible) {
setActive(true)
}
}, [props.visible])

const ref = useRef<HTMLDivElement>(null)
useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false)

const unmountedRef = useUnmountedRef()
const { percent } = useSpring({
percent: props.visible ? 0 : 100,
Expand Down
4 changes: 2 additions & 2 deletions src/components/result/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const Result: FC<ResultProps> = p => {
<div className={classNames(classPrefix, `${classPrefix}-${status}`)}>
<div className={`${classPrefix}-icon`}>{resultIcon}</div>
<div className={`${classPrefix}-title`}>{title}</div>
{description ? (
{!!description && (
<div className={`${classPrefix}-description`}>{description}</div>
) : null}
)}
</div>
)
}
7 changes: 1 addition & 6 deletions src/components/stepper/stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function InnerStepper<ValueType extends number | string>(
defaultValue = 0 as ValueType,
value,
onChange,

disabled,
step,
max,
Expand Down Expand Up @@ -153,11 +152,7 @@ export function InnerStepper<ValueType extends number | string>(
const formatValue = (value: ValueType | null): string => {
if (value === null) return ''

if (formatter) {
return formatter(value)
} else {
return fixedValue(value)
}
return formatter ? formatter(value) : fixedValue(value)
}

// ======================== Value & InputValue ========================
Expand Down
8 changes: 2 additions & 6 deletions src/components/tree-select/multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,14 @@ export const Multiple: FC<MultipleProps> = p => {
return (
<>
{renderSelectAllLeafItem(columnOptions, index)}
{columnOptions.map(option => {
return renderLeafItem(option)
})}
{columnOptions.map(option => renderLeafItem(option))}
</>
)
}
return (
<>
{renderSelectAllItem(columnOptions, index)}
{columnOptions.map(option => {
return renderItem(option)
})}
{columnOptions.map(option => renderItem(option))}
</>
)
}
Expand Down

0 comments on commit ae1f895

Please sign in to comment.