-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(getsize): create 'getSize' util
- Loading branch information
Showing
6 changed files
with
28 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
import React, { forwardRef } from 'react'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { CommonStyledProps } from '../types'; | ||
import { getSize } from '../common/utils'; | ||
|
||
type BarProps = { | ||
size?: string | number; | ||
} & React.HTMLAttributes<HTMLDivElement> & | ||
CommonStyledProps; | ||
|
||
const StyledBar = styled.div<BarProps & { size?: string }>` | ||
// TODO: add horizontal variant | ||
// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle) | ||
const Bar = styled.div<BarProps>` | ||
${({ theme, size = '100%' }) => ` | ||
display: inline-block; | ||
box-sizing: border-box; | ||
height: ${({ size }) => size}; | ||
height: ${getSize(size)}; | ||
width: 5px; | ||
border-top: 2px solid ${({ theme }) => theme.borderLightest}; | ||
border-left: 2px solid ${({ theme }) => theme.borderLightest}; | ||
border-bottom: 2px solid ${({ theme }) => theme.borderDark}; | ||
border-right: 2px solid ${({ theme }) => theme.borderDark}; | ||
background: ${({ theme }) => theme.material}; | ||
border-top: 2px solid ${theme.borderLightest}; | ||
border-left: 2px solid ${theme.borderLightest}; | ||
border-bottom: 2px solid ${theme.borderDark}; | ||
border-right: 2px solid ${theme.borderDark}; | ||
background: ${theme.material}; | ||
`} | ||
`; | ||
|
||
// TODO: add horizontal variant | ||
// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle) | ||
const Bar = forwardRef<HTMLDivElement, BarProps>(function Bar( | ||
{ size: sizeProp = '100%', ...otherProps }, | ||
ref | ||
) { | ||
const size = typeof sizeProp === 'number' ? `${sizeProp}px` : sizeProp; | ||
|
||
return <StyledBar size={size} ref={ref} {...otherProps} />; | ||
}); | ||
|
||
export default Bar; | ||
export { Bar, BarProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters