Skip to content

Commit

Permalink
style: code style shortening
Browse files Browse the repository at this point in the history
  • Loading branch information
1587315093 committed Jul 10, 2023
1 parent e286ab7 commit cce2221
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 67 deletions.
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
14 changes: 5 additions & 9 deletions src/components/pull-to-refresh/pull-to-refresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ export const PullToRefresh: FC<PullToRefreshProps> = p => {
while (true) {
if (!scrollParent) return
const scrollTop = getScrollTop(scrollParent)
if (scrollTop > 0) {
return
}
if (scrollParent instanceof Window) {
break
}
if (scrollTop > 0) return

if (scrollParent instanceof Window) break

scrollParent = getScrollParent(scrollParent.parentNode as Element)
}
pullingRef.current = true
Expand Down Expand Up @@ -168,9 +166,7 @@ export const PullToRefresh: FC<PullToRefreshProps> = p => {
)

const renderStatusText = () => {
if (props.renderText) {
return props.renderText?.(status)
}
if (props.renderText) return props.renderText?.(status)

if (status === 'pulling') return props.pullingText
if (status === 'canRelease') return props.canReleaseText
Expand Down
5 changes: 2 additions & 3 deletions src/components/selector/selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ export const Selector = <V extends SelectorValue>(p: SelectorProps<V>) => {
key={option.value}
className={itemCls}
onClick={() => {
if (disabled) {
return
}
if (disabled) return

if (props.multiple) {
const val = active
? value.filter(v => v !== option.value)
Expand Down
1 change: 1 addition & 0 deletions src/components/side-bar/side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const SideBar: FC<SideBarProps> = props => {
const { key } = item
if (key === undefined || key === null || item.props.disabled)
return

setActiveKey(key.toString())
}}
className={classNames(`${classPrefix}-item`, {
Expand Down
4 changes: 1 addition & 3 deletions src/components/slider/marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const Marks: FC<MarksProps> = ({ marks, upperBound, lowerBound, max, min }) => {
.filter(point => point >= min && point <= max)
.map(point => {
const markPoint = marks[point]
if (!markPoint && markPoint !== 0) {
return null
}
if (!markPoint && markPoint !== 0) return null

const isActive = point <= upperBound && point >= lowerBound
const markClassName = classNames({
Expand Down
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
6 changes: 2 additions & 4 deletions src/components/swipe-action/swipe-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>(
right: leftWidth,
}
},
// rubberband: true,
axis: 'x',
preventScroll: true,
pointer: { touch: true },
Expand Down Expand Up @@ -175,9 +174,8 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>(
useEffect(() => {
if (!props.closeOnTouchOutside) return
function handle(e: Event) {
if (x.get() === 0) {
return
}
if (x.get() === 0) return

const root = rootRef.current
if (root && !root.contains(e.target as Node)) {
close()
Expand Down
5 changes: 2 additions & 3 deletions src/components/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export const Switch: FC<SwitchProps> = p => {
})

async function onClick() {
if (disabled || props.loading || changing) {
return
}
if (disabled || props.loading || changing) return

const nextChecked = !checked
if (props.beforeChange) {
setChanging(true)
Expand Down
9 changes: 4 additions & 5 deletions src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ export const Tabs: FC<TabsProps> = p => {
if (!container) return
const activeIndex = keyToIndexRecord[activeKey as string]
if (activeIndex === undefined) {
api.start({
return api.start({
x: 0,
width: 0,
immediate: true,
})
return
}

const activeLine = activeLineRef.current
if (!activeLine) return

Expand Down Expand Up @@ -296,9 +296,8 @@ export const Tabs: FC<TabsProps> = p => {
</animated.div>
</div>
{panes.map(pane => {
if (pane.props.children === undefined) {
return null
}
if (pane.props.children === undefined) return null

const active = pane.key === activeKey
return (
<ShouldRender
Expand Down
40 changes: 13 additions & 27 deletions src/components/tree-select/multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ export const Multiple: FC<MultipleProps> = p => {
const getLeafKeys = (option?: TreeSelectOption) => {
const keys: string[] = []
const walker = (op?: TreeSelectOption) => {
if (!op) {
return
}
if (!op) return

if (op[childrenName]?.length) {
op[childrenName].forEach((i: TreeSelectOption) => walker(i))
} else {
Expand Down Expand Up @@ -111,9 +110,8 @@ export const Multiple: FC<MultipleProps> = p => {
// 遍历 allChildrenValues, 向上递归
const walker = (key: string) => {
const parentOption = optionsParentMap.get(key)
if (!parentOption) {
return
}
if (!parentOption) return

map.set(parentOption[valueName], true)
walker(parentOption[valueName])
}
Expand All @@ -130,13 +128,10 @@ export const Multiple: FC<MultipleProps> = p => {

const walker = (keys: string[]) => {
keys.forEach(key => {
if (unusedKeys.includes(key)) {
return
}
if (unusedKeys.includes(key)) return
const parent = optionsParentMap.get(key)
if (!parent) {
return
}
if (!parent) return

const childrenKeys: string[] =
parent[childrenName]?.map((i: TreeSelectOption) => i[valueName]) || []
if (childrenKeys.every(i => groupKeys.includes(i))) {
Expand Down Expand Up @@ -180,9 +175,7 @@ export const Multiple: FC<MultipleProps> = p => {
index: number
) => {
const text = props.selectAllText?.[index]
if (!text) {
return
}
if (!text) return

let currentLeafKeys: string[] = []
columnOptions.forEach(option => {
Expand Down Expand Up @@ -215,9 +208,8 @@ export const Multiple: FC<MultipleProps> = p => {
index: number
) => {
const text = props.selectAllText?.[index]
if (!text) {
return
}
if (!text) return

const currentLeafKeys: string[] = columnOptions.map(i => i[valueName])

const allSelected = currentLeafKeys.every(i =>
Expand Down Expand Up @@ -311,27 +303,21 @@ export const Multiple: FC<MultipleProps> = p => {
columnOptions: TreeSelectOption[] = [],
index: number
) => {
if (columnOptions.length === 0) {
return
}
if (columnOptions.length === 0) return

const isLeaf = deep === index + 1
if (isLeaf) {
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
5 changes: 2 additions & 3 deletions src/components/virtual-input/virtual-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export const VirtualInput = forwardRef<VirtualInputRef, VirtualInputProps>(
function scrollToEnd() {
const root = rootRef.current
if (!root) return
if (document.activeElement !== root) {
return
}
if (document.activeElement !== root) return

const content = contentRef.current
if (!content) return
content.scrollLeft = content.clientWidth
Expand Down

0 comments on commit cce2221

Please sign in to comment.