This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v14.12.1
- v14.12.0
- v14.11.0
- v14.10.0
- v14.9.1
- v14.9.0
- v14.8.0
- v14.7.0
- v14.6.0
- v14.5.0
- v14.4.3
- v14.4.2
- v14.4.1
- v14.4.0
- v14.3.5
- v14.3.4
- v14.3.3
- v14.3.2
- v14.3.1
- v14.3.0
- v14.2.0
- v14.1.0
- v14.0.1
- v14.0.0
- v13.5.3
- v13.5.2
- v13.5.1
- v13.5.0
- v13.4.9
- v13.4.8
- v13.4.7
- v13.4.6
- v13.4.5
- v13.4.4
- v13.4.3
- v13.4.2
- v13.4.1
- v13.4.0
- v13.3.1
- v13.3.0
- v13.2.2
- v13.2.1
- v13.2.0
- v13.1.5
- v13.1.4
- v13.1.3
- v13.1.2
- v13.1.1
- v13.1.0
- v13.0.1
- v13.0.0
- v12.1.6
- v12.1.5
- v12.1.4
- v12.1.3
- v12.1.2
- v12.1.1
- v12.1.0
- v12.0.2
- v12.0.1
- v12.0.0
- v11.26.1
- v11.26.0
- v11.25.0
- v11.24.0
- v11.23.0
- v11.22.0
- v11.21.0
- v11.20.2
- v11.20.1
- v11.20.0
- v11.19.2
- v11.19.1
- v11.19.0
- v11.18.0
- v11.17.0
- v11.16.1
- v11.16.0
- v11.15.4
- v11.15.3
- v11.15.2
- v11.15.1
- v11.15.0
- v11.14.5
- v11.14.4
- v11.14.3
- v11.14.2
- v11.14.1
- v11.14.0
- v11.13.0
- v11.12.3
- v11.12.2
- v11.12.1
- v11.12.0
- v11.11.3
- v11.11.2
- v11.11.1
- v11.11.0
- v11.10.7
- v11.10.6
- v11.10.5
- v11.10.4
- v11.10.3
- v11.10.2
- v11.10.1
- v11.10.0
- v11.9.2
- v11.9.1
- v11.9.0
- v11.8.1
- v11.8.0
- v11.7.1
- v11.7.0
- v11.6.0
- v11.5.0
- v11.4.3
- v11.4.2
- v11.4.1
- v11.4.0
- v11.3.3
- v11.3.2
- v11.3.1
- v11.3.0
- v11.2.0
- v11.1.0
- v11.0.2
- v11.0.1
- v11.0.0
- v10.8.0
- v10.7.0
- v10.6.0
- v10.5.0
- v10.4.0
- v10.3.2
- v10.3.1
- v10.3.0
- v10.2.0
- v10.1.2
- v10.1.1
- v10.1.0
- v10.0.0
- v9.5.0
- v9.4.1
- v9.4.0
- v9.3.2
- v9.3.1
- v9.3.0
- v9.2.2
- v9.2.1
- v9.2.0
- v9.1.2
- v9.1.1
- v9.1.0
- v9.0.2
- v9.0.1
- v9.0.0
- v8.3.0
- v8.2.3
- v8.2.2
- v8.2.1
- v8.2.0
- v8.1.2
- v8.1.1
- v8.1.0
- v8.0.0
- v7.3.1
- v7.3.0
- v7.2.2
- v7.2.1
- v7.2.0
- v7.1.0
- v7.0.0
- v6.17.5
- v6.17.4
- v6.17.3
- v6.17.2
- v6.17.1
- v6.17.0
- v6.16.0
- v6.15.1
- v6.15.0
- v6.14.0
- v6.13.1
- v6.13.0
- v6.12.2
- v6.12.1
- v6.12.0
- v6.11.1
- v6.11.0
- v6.10.7
- v6.10.6
- v6.10.5
- v6.10.4
- v6.10.3
- v6.10.2
- v6.10.1
- v6.10.0
- v6.9.0
- v6.8.0
- v6.7.3
- v6.7.2
- v6.7.1
- v6.7.0
- v6.6.0
- v6.5.1
- v6.5.0
- v6.4.0
- v6.3.0
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.0
- v5.4.1
- v5.4.0
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.0
- v4.0.1
- v4.0.0
- v3.11.0
- v3.10.0
1 parent
0f78209
commit 59f51d6
Showing
3 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
name: Meter | ||
menu: Components | ||
--- | ||
|
||
import {Playground, Props} from 'docz'; | ||
|
||
import Meter from './'; | ||
|
||
# Meter | ||
|
||
A stand-in for the native `<meter>` HTML element built to ensure consistent visuals across browsers. | ||
|
||
## Examples | ||
|
||
<Playground> | ||
<Meter value={0.3} max={1} /> | ||
<br /> | ||
<Meter value={39} min={-100} max={100} high={33} /> | ||
<br /> | ||
<Meter value={80} min={0} max={100} color="links" /> | ||
</Playground> | ||
|
||
## Props | ||
|
||
<Props of={Meter} /> |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import {getColorBlock} from '../utils/colors'; | ||
|
||
import VisuallyHidden from '../VisuallyHidden'; | ||
|
||
function getMeterColor({value, low, high, min, max, theme}) { | ||
if (value === null) { | ||
return null; | ||
} | ||
if (value <= low || value === min) { | ||
return getColorBlock('negative', theme); | ||
} else if (value >= high || value === max) { | ||
return getColorBlock('positive', theme); | ||
} else { | ||
return getColorBlock('neutral', theme); | ||
} | ||
} | ||
|
||
function getMeterWidth({value, min = 0, max = 1, visualMin = 0}) { | ||
if (value === null || value === undefined) return '0%'; | ||
|
||
const difference = max - min; | ||
const clampedValue = Math.max(value, visualMin); | ||
const fraction = (clampedValue - min) / difference; | ||
|
||
return `${fraction * 100}%`; | ||
} | ||
|
||
const Wrapper = styled.div.attrs({ | ||
role: 'presentation', | ||
})` | ||
width: 100%; | ||
height: 0.3rem; | ||
background-color: rgba(0, 0, 0, 0.1); | ||
`; | ||
|
||
const MockMeter = styled.div.attrs({ | ||
role: 'presentation', | ||
'aria-hidden': 'true', | ||
})` | ||
width: ${getMeterWidth}; | ||
height: 0.3rem; | ||
background: ${p => | ||
p.color ? getColorBlock(p.color, p.theme) : getMeterColor(p)}; | ||
transition: width 300ms ease-out; | ||
`; | ||
|
||
const Meter = ({...props}) => { | ||
return ( | ||
<Wrapper> | ||
<MockMeter {...props} /> | ||
<VisuallyHidden as="meter" {...props} /> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
Meter.propTypes = { | ||
value: PropTypes.number, | ||
max: PropTypes.number, | ||
high: PropTypes.number, | ||
low: PropTypes.number, | ||
min: PropTypes.number, | ||
optimum: PropTypes.number, | ||
visualMin: PropTypes.number, | ||
}; | ||
|
||
export default Meter; |
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