Skip to content

Commit c4d80c2

Browse files
committed
feat(components): add SideBar dynamic side
1 parent 970104b commit c4d80c2

File tree

5 files changed

+87
-13
lines changed

5 files changed

+87
-13
lines changed

src/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export default class App extends Component<Props> {
1515
<>
1616
<GlobalStyles />
1717
<View style={styles.container}>
18-
<SideBar horizontal={true}>
18+
<SideBar
19+
horizontal={false}
20+
horizontalSide="bottom"
21+
verticalSide="left"
22+
>
1923
<SideBarItem name="home" iconMaterial="home" />
2024
<SideBarItem
2125
name="settings"

src/components/SideBar/Sidebar.tsx

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,85 @@
1-
import { Text } from 'bara-react'
1+
import { BaraReactView, Text, View } from 'bara-react'
22
import React, { ReactNode } from 'react'
3-
import { View } from 'react-native'
3+
import { ViewStyle } from 'react-native'
44

55
import { sidebarSize } from '../variables'
66
import { styles } from './styles'
77

8-
export interface SideBarProps {
8+
export type SideBarDynamicSide = 'top' | 'bottom' | 'left' | 'right'
9+
export interface SideBarProps extends BaraReactView {
910
children?: ReactNode
11+
side?: string
1012
horizontal?: boolean
13+
horizontalSide?: SideBarDynamicSide
14+
verticalSide?: SideBarDynamicSide
1115
}
1216

13-
export const SideBar = ({ children, horizontal = true }: SideBarProps) => {
17+
interface DynamicPreset {
18+
[k: string]: {
19+
wrap: any
20+
inner: any
21+
}
22+
}
23+
24+
const dynamicPreset: DynamicPreset = {
25+
bottom: {
26+
wrap: {
27+
bottom: 0,
28+
left: 0,
29+
right: 0,
30+
},
31+
inner: {
32+
flexDirection: 'row',
33+
height: sidebarSize,
34+
},
35+
},
36+
left: {
37+
wrap: {
38+
top: 0,
39+
bottom: 0,
40+
left: 0,
41+
},
42+
inner: {
43+
flexDirection: 'column',
44+
width: sidebarSize,
45+
},
46+
},
47+
}
48+
49+
dynamicPreset.top = {
50+
...dynamicPreset.bottom,
51+
...{ wrap: { top: 0, left: 0, right: 0 } },
52+
}
53+
54+
dynamicPreset.right = {
55+
...dynamicPreset.left,
56+
...{ wrap: { top: 0, bottom: 0, right: 0 } },
57+
}
58+
59+
export const SideBar = ({
60+
children,
61+
horizontalSide,
62+
verticalSide,
63+
horizontal = true,
64+
...props
65+
}: SideBarProps) => {
66+
const currentSide = horizontal ? horizontalSide! : verticalSide!
1467
return (
15-
<View style={{ zIndex: 1000 }}>
68+
<View
69+
kind="sidebar-container"
70+
style={[
71+
styles.sideBarPosition as ViewStyle,
72+
{
73+
...(dynamicPreset[currentSide].wrap as ViewStyle),
74+
},
75+
]}
76+
{...props}
77+
>
1678
<View
1779
style={[
18-
styles.sideBar,
80+
styles.sideBar as ViewStyle,
1981
{
20-
flexDirection: horizontal ? 'row' : 'column',
21-
width: horizontal ? '100%' : sidebarSize,
22-
height: horizontal ? sidebarSize : '100%',
82+
...(dynamicPreset[currentSide].inner as ViewStyle),
2383
},
2484
]}
2585
>
File renamed without changes.

src/components/SideBar/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './SideBar'
22
export * from './SideBarItem'
3-
export * from './hook'
3+
export * from './api'

src/components/SideBar/styles.shared.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import {
55
} from '../variables'
66

77
export const sharedStyles = {
8+
sideBarPosition: {
9+
zIndex: 1000,
10+
position: 'absolute',
11+
backgroundColor: '#ccc',
12+
},
813
sideBar: {
14+
position: 'relative',
915
flexGrow: 1,
10-
backgroundColor: '#ccc',
16+
justifyContent: 'space-between',
17+
width: '100%',
18+
height: '100%',
1119
},
1220
sideBarItem: {
1321
alignSelf: 'center',
1422
justifyContent: 'center',
1523
alignItems: 'center',
1624
alignContent: 'center',
1725
width: sidebarSize,
18-
height: '100%',
26+
height: sidebarSize,
1927
overflow: 'hidden',
28+
paddingLeft: 8,
29+
paddingRight: 8,
2030
},
2131
sideBarIcon: {
2232
textAlign: 'center',

0 commit comments

Comments
 (0)