@@ -31,6 +31,11 @@ function hasFraction(props: BarProps): props is BarProps & WithFraction {
31
31
return typeof ( props as WithFraction ) . fraction === 'number'
32
32
}
33
33
34
+ /** Format as a "xy%" string */
35
+ function fractionString ( props : BarProps ) : string {
36
+ return hasFraction ( props ) ? 100 * props . fraction + '%' : props . fractionString
37
+ }
38
+
34
39
/**
35
40
* Create a bar, and place it in the given container. If the optional
36
41
* initialFraction is given, then set the bar's width to that value.
@@ -44,11 +49,11 @@ export function Bar(props: BarProps) {
44
49
const liveStyle = {
45
50
backgroundColor : props . color ,
46
51
bodrerRight : '1px solid var(--color-stripe-02)' ,
47
- width : hasFraction ( props ) ? 100 * props . fraction + '%' : props . fractionString
52
+ width : fractionString ( props )
48
53
}
49
54
50
55
return (
51
- < div style = { { display : 'flex' , backgroundColor : 'var(--color-stripe-01)' , height : '45% ' } } >
56
+ < div style = { { display : 'flex' , backgroundColor : 'var(--color-stripe-01)' , height : '1em' , width : '5em ' } } >
52
57
< div style = { liveStyle } />
53
58
</ div >
54
59
)
@@ -66,14 +71,13 @@ export function Bar(props: BarProps) {
66
71
export function BarContainer ( props : {
67
72
children ?: React . ReactNode
68
73
alignment ?: 'space-between' | 'center'
74
+ flexDirection ?: 'column' | 'row'
69
75
onClick ?: string
70
76
} ) {
71
77
const style = {
72
78
display : 'flex' ,
73
- flexDirection : 'column' as const ,
74
- justifyContent : props . alignment || 'space-between' ,
75
- width : '5em' ,
76
- height : '1.375em'
79
+ flexDirection : props . flexDirection || ( 'column' as const ) ,
80
+ justifyContent : props . alignment || 'space-between'
77
81
}
78
82
79
83
return props . onClick ? (
@@ -89,14 +93,16 @@ export function BarContainer(props: {
89
93
* Create a single bar with its own container, and return the container.
90
94
*
91
95
*/
92
- export function SingletonBar ( props : BarProps ) {
96
+ type BP = BarProps & { text ?: boolean }
97
+ export function SingletonBar ( props : BP ) {
93
98
return (
94
- < BarContainer alignment = "center" >
99
+ < BarContainer alignment = "center" flexDirection = "row" >
95
100
< Bar { ...props } />
101
+ { props . text && < span className = "even-smaller-text sub-text small-left-pad" > { fractionString ( props ) } </ span > }
96
102
</ BarContainer >
97
103
)
98
104
}
99
105
100
- export function singletonBar ( props : BarProps ) {
106
+ export function singletonBar ( props : BP ) {
101
107
return < SingletonBar { ...props } />
102
108
}
0 commit comments