1
- import React from 'react' ;
2
- import propTypes from 'prop-types' ;
1
+ import React , { forwardRef } from 'react' ;
3
2
import styled from 'styled-components' ;
3
+ import { CommonStyledProps } from '../types' ;
4
4
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 } > `
6
11
display: inline-block;
7
12
box-sizing: border-box;
8
13
height: ${ ( { size } ) => size } ;
@@ -13,20 +18,16 @@ const StyledBar = styled.div`
13
18
border-right: 2px solid ${ ( { theme } ) => theme . borderDark } ;
14
19
background: ${ ( { theme } ) => theme . material } ;
15
20
` ;
21
+
16
22
// TODO: add horizontal variant
17
23
// 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
+ ) {
20
28
const size = typeof sizeProp === 'number' ? `${ sizeProp } px` : sizeProp ;
21
29
22
30
return < StyledBar size = { size } ref = { ref } { ...otherProps } /> ;
23
31
} ) ;
24
32
25
- Bar . defaultProps = {
26
- size : '100%'
27
- } ;
28
- Bar . propTypes = {
29
- size : propTypes . oneOfType ( [ propTypes . string , propTypes . number ] )
30
- } ;
31
-
32
33
export default Bar ;
0 commit comments