Skip to content

Commit f49db0d

Browse files
committed
Remove redundant assertions
1 parent e10fbf7 commit f49db0d

File tree

2 files changed

+55
-64
lines changed

2 files changed

+55
-64
lines changed

packages/sidenav/src/index.tsx

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,23 @@ import merge from 'deepmerge'
1717
const createNestedLinks = (
1818
children: ReactNode,
1919
depth: number = 0
20-
): ReactNode[] => {
21-
const links = React.Children.toArray(children).reduce(
22-
(acc: ReactNode[], child) => {
23-
if (!React.isValidElement(child)) {
24-
return acc
25-
}
26-
const type: string = child.props && child.props.mdxType
27-
if (!child.props || !child.props.children) return acc
28-
if (type === 'a') return [...acc, child]
29-
if (depth > 0 && type === 'ul') {
30-
const last = acc[acc.length - 1]
31-
acc[acc.length - 1] = React.cloneElement(last as ReactElement, {
32-
links: createNestedLinks(child.props.children),
33-
})
34-
return acc
35-
}
36-
return [...acc, ...createNestedLinks(child.props.children, depth + 1)]
37-
},
38-
[]
39-
) as ReactNode[]
40-
return links
41-
}
20+
): ReactNode[] =>
21+
React.Children.toArray(children).reduce((acc: ReactNode[], child) => {
22+
if (!React.isValidElement(child)) {
23+
return acc
24+
}
25+
const type: string = child.props && child.props.mdxType
26+
if (!child.props || !child.props.children) return acc
27+
if (type === 'a') return [...acc, child]
28+
if (depth > 0 && type === 'ul') {
29+
const last = acc[acc.length - 1]
30+
acc[acc.length - 1] = React.cloneElement(last as ReactElement, {
31+
links: createNestedLinks(child.props.children),
32+
})
33+
return acc
34+
}
35+
return [...acc, ...createNestedLinks(child.props.children, depth + 1)]
36+
}, [])
4237

4338
const flattenLinks = (children: ReactNode): ReactNode[] =>
4439
React.Children.toArray(children).reduce((acc: ReactNode[], child) => {
@@ -53,7 +48,7 @@ const flattenLinks = (children: ReactNode): ReactNode[] =>
5348
])
5449
}
5550
return acc
56-
}, []) as ReactNode[]
51+
}, [])
5752

5853
const Overlay: FunctionComponent<{
5954
onClick?: EventHandler<MouseEvent<HTMLDivElement>>
@@ -121,24 +116,22 @@ export const Sidenav = forwardRef<
121116
<div
122117
{...props}
123118
ref={ref}
124-
sx={
125-
{
126-
position: ['fixed', 'sticky'],
127-
top: 0,
128-
left: 0,
129-
bottom: [0, 'auto'],
130-
zIndex: 1,
131-
minWidth: 0,
132-
width: 256,
133-
maxHeight: ['100vh', 'none'],
134-
overflowX: 'visible',
135-
overflowY: 'auto',
136-
WebkitOverflowScrolling: 'touch',
137-
transition: 'transform .2s ease-out',
138-
transform: [open ? 'translateX(0)' : 'translate(-100%)', 'none'],
139-
bg: ['background', 'transparent'],
140-
} as SxStyleProp
141-
}
119+
sx={{
120+
position: ['fixed', 'sticky'],
121+
top: 0,
122+
left: 0,
123+
bottom: [0, 'auto'],
124+
zIndex: 1,
125+
minWidth: 0,
126+
width: 256,
127+
maxHeight: ['100vh', 'none'],
128+
overflowX: 'visible',
129+
overflowY: 'auto',
130+
transition: 'transform .2s ease-out',
131+
transform: [open ? 'translateX(0)' : 'translate(-100%)', 'none'],
132+
bg: ['background', 'transparent'],
133+
...{ WebkitOverflowScrolling: 'touch' },
134+
}}
142135
/>
143136
</MDXProvider>
144137
</ThemeProvider>
@@ -259,24 +252,22 @@ export const AccordionNav = forwardRef<
259252
<div
260253
ref={ref}
261254
className={className}
262-
sx={
263-
{
264-
position: ['fixed', 'sticky'],
265-
top: 0,
266-
left: 0,
267-
bottom: [0, 'auto'],
268-
zIndex: 1,
269-
minWidth: 0,
270-
width: 256,
271-
maxHeight: ['100vh', 'none'],
272-
overflowX: 'visible',
273-
overflowY: 'auto',
274-
WebkitOverflowScrolling: 'touch',
275-
transition: 'transform .2s ease-out',
276-
transform: [open ? 'translateX(0)' : 'translate(-100%)', 'none'],
277-
bg: ['background', 'transparent'],
278-
} as SxStyleProp
279-
}>
255+
sx={{
256+
position: ['fixed', 'sticky'],
257+
top: 0,
258+
left: 0,
259+
bottom: [0, 'auto'],
260+
zIndex: 1,
261+
minWidth: 0,
262+
width: 256,
263+
maxHeight: ['100vh', 'none'],
264+
overflowX: 'visible',
265+
overflowY: 'auto',
266+
transition: 'transform .2s ease-out',
267+
transform: [open ? 'translateX(0)' : 'translate(-100%)', 'none'],
268+
bg: ['background', 'transparent'],
269+
...{ WebkitOverflowScrolling: 'touch' },
270+
}}>
280271
<ul
281272
sx={{
282273
listStyle: 'none',

packages/sidenav/test/__snapshots__/index.tsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ exports[`AccordionNav renders 1`] = `
1212
max-height: 100vh;
1313
overflow-x: visible;
1414
overflow-y: auto;
15-
-webkit-overflow-scrolling: touch;
1615
-webkit-transition: -webkit-transform .2s ease-out;
1716
-webkit-transition: transform .2s ease-out;
1817
transition: transform .2s ease-out;
1918
-webkit-transform: translate(-100%);
2019
-ms-transform: translate(-100%);
2120
transform: translate(-100%);
2221
background-color: background;
22+
-webkit-overflow-scrolling: touch;
2323
}
2424
2525
@media screen and (min-width:40em) {
@@ -117,14 +117,14 @@ exports[`AccordionNav renders open 1`] = `
117117
max-height: 100vh;
118118
overflow-x: visible;
119119
overflow-y: auto;
120-
-webkit-overflow-scrolling: touch;
121120
-webkit-transition: -webkit-transform .2s ease-out;
122121
-webkit-transition: transform .2s ease-out;
123122
transition: transform .2s ease-out;
124123
-webkit-transform: translateX(0);
125124
-ms-transform: translateX(0);
126125
transform: translateX(0);
127126
background-color: background;
127+
-webkit-overflow-scrolling: touch;
128128
}
129129
130130
@media screen and (min-width:40em) {
@@ -282,14 +282,14 @@ exports[`AccordionNav renders with nested links 1`] = `
282282
max-height: 100vh;
283283
overflow-x: visible;
284284
overflow-y: auto;
285-
-webkit-overflow-scrolling: touch;
286285
-webkit-transition: -webkit-transform .2s ease-out;
287286
-webkit-transition: transform .2s ease-out;
288287
transition: transform .2s ease-out;
289288
-webkit-transform: translate(-100%);
290289
-ms-transform: translate(-100%);
291290
transform: translate(-100%);
292291
background-color: background;
292+
-webkit-overflow-scrolling: touch;
293293
}
294294
295295
@media screen and (min-width:40em) {
@@ -491,14 +491,14 @@ exports[`Sidenav renders 1`] = `
491491
max-height: 100vh;
492492
overflow-x: visible;
493493
overflow-y: auto;
494-
-webkit-overflow-scrolling: touch;
495494
-webkit-transition: -webkit-transform .2s ease-out;
496495
-webkit-transition: transform .2s ease-out;
497496
transition: transform .2s ease-out;
498497
-webkit-transform: translate(-100%);
499498
-ms-transform: translate(-100%);
500499
transform: translate(-100%);
501500
background-color: background;
501+
-webkit-overflow-scrolling: touch;
502502
}
503503
504504
@media screen and (min-width:40em) {
@@ -570,14 +570,14 @@ Array [
570570
max-height: 100vh;
571571
overflow-x: visible;
572572
overflow-y: auto;
573-
-webkit-overflow-scrolling: touch;
574573
-webkit-transition: -webkit-transform .2s ease-out;
575574
-webkit-transition: transform .2s ease-out;
576575
transition: transform .2s ease-out;
577576
-webkit-transform: translateX(0);
578577
-ms-transform: translateX(0);
579578
transform: translateX(0);
580579
background-color: background;
580+
-webkit-overflow-scrolling: touch;
581581
}
582582
583583
@media screen and (min-width:40em) {

0 commit comments

Comments
 (0)