diff --git a/src/Meter/README.mdx b/src/Meter/README.mdx new file mode 100644 index 00000000..7c341b08 --- /dev/null +++ b/src/Meter/README.mdx @@ -0,0 +1,26 @@ +--- +name: Meter +menu: Components +--- + +import {Playground, Props} from 'docz'; + +import Meter from './'; + +# Meter + +A stand-in for the native `` HTML element built to ensure consistent visuals across browsers. + +## Examples + + + +
+ +
+ +
+ +## Props + + diff --git a/src/Meter/index.js b/src/Meter/index.js new file mode 100644 index 00000000..07e1b451 --- /dev/null +++ b/src/Meter/index.js @@ -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 ( + + + + + ); +}; + +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; diff --git a/src/ViewMoreText/README.mdx b/src/ViewMoreText/README.mdx index bb4fe15d..51785232 100644 --- a/src/ViewMoreText/README.mdx +++ b/src/ViewMoreText/README.mdx @@ -5,7 +5,6 @@ menu: Components import {Playground, Props} from 'docz'; -import InlineList from '../InlineList'; import ViewMoreText from './'; # ViewMoreText