|
1 | | -import { Text } from 'bara-react' |
| 1 | +import { BaraReactView, Text, View } from 'bara-react' |
2 | 2 | import React, { ReactNode } from 'react' |
3 | | -import { View } from 'react-native' |
| 3 | +import { ViewStyle } from 'react-native' |
4 | 4 |
|
5 | 5 | import { sidebarSize } from '../variables' |
6 | 6 | import { styles } from './styles' |
7 | 7 |
|
8 | | -export interface SideBarProps { |
| 8 | +export type SideBarDynamicSide = 'top' | 'bottom' | 'left' | 'right' |
| 9 | +export interface SideBarProps extends BaraReactView { |
9 | 10 | children?: ReactNode |
| 11 | + side?: string |
10 | 12 | horizontal?: boolean |
| 13 | + horizontalSide?: SideBarDynamicSide |
| 14 | + verticalSide?: SideBarDynamicSide |
11 | 15 | } |
12 | 16 |
|
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! |
14 | 67 | 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 | + > |
16 | 78 | <View |
17 | 79 | style={[ |
18 | | - styles.sideBar, |
| 80 | + styles.sideBar as ViewStyle, |
19 | 81 | { |
20 | | - flexDirection: horizontal ? 'row' : 'column', |
21 | | - width: horizontal ? '100%' : sidebarSize, |
22 | | - height: horizontal ? sidebarSize : '100%', |
| 82 | + ...(dynamicPreset[currentSide].inner as ViewStyle), |
23 | 83 | }, |
24 | 84 | ]} |
25 | 85 | > |
|
0 commit comments