|
1 | 1 | 'use client' |
2 | 2 |
|
3 | | -import styled from '@emotion/styled' |
4 | 3 | import { Stack } from '@ultraviolet/ui' |
| 4 | +import { assignInlineVars } from '@vanilla-extract/dynamic' |
5 | 5 | import { useEffect, useRef } from 'react' |
6 | | -import { |
7 | | - ANIMATION_DURATION, |
8 | | - NAVIGATION_COLLASPED_WIDTH, |
9 | | - NAVIGATION_MAX_WIDTH, |
10 | | - NAVIGATION_MIN_WIDTH, |
11 | | -} from './constants' |
| 6 | +import { NAVIGATION_COLLASPED_WIDTH, NAVIGATION_MIN_WIDTH } from './constants' |
12 | 7 | import { Footer } from './Footer' |
13 | 8 | import { Header } from './Header' |
14 | 9 | import { useNavigation } from './NavigationProvider' |
| 10 | +import { |
| 11 | + navigation, |
| 12 | + navigationContainer, |
| 13 | + navigationContent, |
| 14 | + navigationContentContainer, |
| 15 | + navigationContentContainerCollapsed, |
| 16 | + navigationSlider, |
| 17 | +} from './styles.css' |
15 | 18 | import type { NavigationProps } from './types' |
16 | | - |
17 | | -const StyledNav = styled.nav` |
18 | | - display: flex; |
19 | | - flex-direction: row; |
20 | | - position: relative; |
21 | | - border-right: 1px solid ${({ theme }) => theme.colors.neutral.borderWeak}; |
22 | | -` |
23 | | - |
24 | | -const Container = styled('div', { |
25 | | - shouldForwardProp: prop => !['width'].includes(prop), |
26 | | -})<{ |
27 | | - width: number |
28 | | -}>` |
29 | | - background: ${({ theme }) => theme.colors.neutral.background}; |
30 | | - display: flex; |
31 | | - flex-direction: column; |
32 | | -
|
33 | | - width: ${({ width }) => width}px; |
34 | | -
|
35 | | - &[data-expanded="true"][data-animation="false"] { |
36 | | - max-width: ${NAVIGATION_MAX_WIDTH}px; |
37 | | - min-width: ${NAVIGATION_MIN_WIDTH}px; |
38 | | - } |
39 | | -
|
40 | | - &[data-expanded="false"] { |
41 | | - width: ${NAVIGATION_COLLASPED_WIDTH}px; |
42 | | - } |
43 | | -
|
44 | | - &[data-animation="expand"] { |
45 | | - transition: width ${ANIMATION_DURATION}ms ease-in-out; |
46 | | - width: ${({ width }) => width}px; |
47 | | - } |
48 | | -
|
49 | | - &[data-animation="collapse"] { |
50 | | - transition: width ${ANIMATION_DURATION}ms ease-in-out; |
51 | | - width: ${NAVIGATION_COLLASPED_WIDTH}px; |
52 | | - } |
53 | | -` |
54 | | - |
55 | | -const ContentContainer = styled.div` |
56 | | - overflow: hidden; |
57 | | - display: flex; |
58 | | - flex-direction: column; |
59 | | - flex-grow: 1; |
60 | | -` |
61 | | - |
62 | | -const Content = styled(Stack)` |
63 | | - overflow-y: auto; |
64 | | - overflow-x: hidden; |
65 | | - flex-grow: 1; |
66 | | -
|
67 | | - &[data-is-expanded="false"] { |
68 | | - align-items: center; |
69 | | - padding: ${({ theme }) => theme.space['2']}; |
70 | | - } |
71 | | -
|
72 | | - &[data-is-expanded="true"], |
73 | | - &[data-animation="expand"] { |
74 | | - padding: ${({ theme }) => theme.space['2']}; |
75 | | - } |
76 | | -` |
77 | | - |
78 | | -const Slider = styled.div` |
79 | | - background: transparent; |
80 | | - position: absolute; |
81 | | - top: 0; |
82 | | - bottom: 0; |
83 | | - right: 0; |
84 | | - width: 6px; |
85 | | - cursor: col-resize; |
86 | | - border-right: 2px solid transparent; |
87 | | - display: flex; |
88 | | -
|
89 | | - &:hover { |
90 | | - border-color: ${({ theme }) => theme.colors.primary.border}; |
91 | | - } |
92 | | -` |
| 19 | +import { widthNavigationContainer } from './variables.css' |
93 | 20 |
|
94 | 21 | export const NavigationContent = ({ |
95 | 22 | children, |
@@ -203,31 +130,40 @@ export const NavigationContent = ({ |
203 | 130 | ]) |
204 | 131 |
|
205 | 132 | return ( |
206 | | - <StyledNav className={className} data-testid={dataTestId} id={id}> |
207 | | - <Container |
208 | | - data-animation={shouldAnimate ? animation : undefined} |
209 | | - data-expanded={expanded} |
| 133 | + <nav |
| 134 | + className={`${className ? `${className} ` : ''}${navigation}`} |
| 135 | + data-testid={dataTestId} |
| 136 | + id={id} |
| 137 | + > |
| 138 | + <div |
| 139 | + className={navigationContainer({ |
| 140 | + animation: shouldAnimate ? animation : undefined, |
| 141 | + expanded, |
| 142 | + })} |
210 | 143 | ref={navigationRef} |
211 | | - width={width} |
| 144 | + style={assignInlineVars({ |
| 145 | + [widthNavigationContainer]: `${width}px`, |
| 146 | + })} |
212 | 147 | > |
213 | 148 | {logo ? <Header logo={logo} /> : null} |
214 | | - <ContentContainer> |
215 | | - <Content |
216 | | - data-animation={shouldAnimate ? animation : undefined} |
217 | | - data-is-expanded={expanded} |
218 | | - gap={0.25} |
219 | | - ref={contentRef} |
220 | | - > |
| 149 | + <div |
| 150 | + className={`${navigationContentContainer}${expanded ? '' : ` ${navigationContentContainerCollapsed}`}`} |
| 151 | + > |
| 152 | + <Stack className={navigationContent} gap={0.25} ref={contentRef}> |
221 | 153 | {children} |
222 | | - </Content> |
| 154 | + </Stack> |
223 | 155 | {allowNavigationResize ? ( |
224 | 156 | <Footer contentRef={contentRef} onToggleExpand={onToggleExpand} /> |
225 | 157 | ) : null} |
226 | | - </ContentContainer> |
227 | | - </Container> |
| 158 | + </div> |
| 159 | + </div> |
228 | 160 | {allowNavigationResize ? ( |
229 | | - <Slider data-testid="slider" ref={sliderRef} /> |
| 161 | + <div |
| 162 | + className={navigationSlider} |
| 163 | + data-testid="slider" |
| 164 | + ref={sliderRef} |
| 165 | + /> |
230 | 166 | ) : null} |
231 | | - </StyledNav> |
| 167 | + </nav> |
232 | 168 | ) |
233 | 169 | } |
0 commit comments