|
1 | | -import React, { forwardRef } from 'react'; |
| 1 | +import React from 'react'; |
2 | 2 | import styled from 'styled-components'; |
3 | 3 | import { CommonStyledProps } from '../types'; |
| 4 | +import { getSize } from '../common/utils'; |
4 | 5 |
|
5 | 6 | type BarProps = { |
6 | 7 | size?: string | number; |
7 | 8 | } & React.HTMLAttributes<HTMLDivElement> & |
8 | 9 | CommonStyledProps; |
9 | 10 |
|
10 | | -const StyledBar = styled.div<BarProps & { size?: string }>` |
| 11 | +// TODO: add horizontal variant |
| 12 | +// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle) |
| 13 | +const Bar = styled.div<BarProps>` |
| 14 | + ${({ theme, size = '100%' }) => ` |
11 | 15 | display: inline-block; |
12 | 16 | box-sizing: border-box; |
13 | | - height: ${({ size }) => size}; |
| 17 | + height: ${getSize(size)}; |
14 | 18 | width: 5px; |
15 | | - border-top: 2px solid ${({ theme }) => theme.borderLightest}; |
16 | | - border-left: 2px solid ${({ theme }) => theme.borderLightest}; |
17 | | - border-bottom: 2px solid ${({ theme }) => theme.borderDark}; |
18 | | - border-right: 2px solid ${({ theme }) => theme.borderDark}; |
19 | | - background: ${({ theme }) => theme.material}; |
| 19 | + border-top: 2px solid ${theme.borderLightest}; |
| 20 | + border-left: 2px solid ${theme.borderLightest}; |
| 21 | + border-bottom: 2px solid ${theme.borderDark}; |
| 22 | + border-right: 2px solid ${theme.borderDark}; |
| 23 | + background: ${theme.material}; |
| 24 | +`} |
20 | 25 | `; |
21 | 26 |
|
22 | | -// TODO: add horizontal variant |
23 | | -// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle) |
24 | | -const Bar = forwardRef<HTMLDivElement, BarProps>(function Bar( |
25 | | - { size: sizeProp = '100%', ...otherProps }, |
26 | | - ref |
27 | | -) { |
28 | | - const size = typeof sizeProp === 'number' ? `${sizeProp}px` : sizeProp; |
29 | | - |
30 | | - return <StyledBar size={size} ref={ref} {...otherProps} />; |
31 | | -}); |
32 | | - |
33 | | -export default Bar; |
| 27 | +export { Bar, BarProps }; |
0 commit comments