1- import React from 'react' ;
2- import propTypes from 'prop-types' ;
1+ import React , { forwardRef } from 'react' ;
32import styled from 'styled-components' ;
3+ import { CommonStyledProps } from '../types' ;
44
5- const StyledBar = styled . div `
5+ type BarProps = {
6+ size ?: string | number ;
7+ } & React . HTMLAttributes < HTMLDivElement > &
8+ CommonStyledProps ;
9+
10+ const StyledBar = styled . div < BarProps & { size ?: string } > `
611 display: inline-block;
712 box-sizing: border-box;
813 height: ${ ( { size } ) => size } ;
@@ -13,20 +18,16 @@ const StyledBar = styled.div`
1318 border-right: 2px solid ${ ( { theme } ) => theme . borderDark } ;
1419 background: ${ ( { theme } ) => theme . material } ;
1520` ;
21+
1622// TODO: add horizontal variant
1723// TODO: allow user to specify number of bars (like 3 horizontal bars for drag handle)
18- const Bar = React . forwardRef ( function Bar ( props , ref ) {
19- const { size : sizeProp , ...otherProps } = props ;
24+ const Bar = forwardRef < HTMLDivElement , BarProps > ( function Bar (
25+ { size : sizeProp = '100%' , ...otherProps } ,
26+ ref
27+ ) {
2028 const size = typeof sizeProp === 'number' ? `${ sizeProp } px` : sizeProp ;
2129
2230 return < StyledBar size = { size } ref = { ref } { ...otherProps } /> ;
2331} ) ;
2432
25- Bar . defaultProps = {
26- size : '100%'
27- } ;
28- Bar . propTypes = {
29- size : propTypes . oneOfType ( [ propTypes . string , propTypes . number ] )
30- } ;
31-
3233export default Bar ;
0 commit comments