@hixme-ui/percentage

hixme-ui Percentage component

Usage no npm install needed!

<script type="module">
  import hixmeUiPercentage from 'https://cdn.skypack.dev/@hixme-ui/percentage';
</script>

README

Percentage

npm i --save @hixme-ui/percentage

View it live

Props

Name Type Default
hideDecimals bool false
value number null

Basic Usage

Percentage can use a child value or a value prop for the number, and handles decimal placement and rounding.

import Input from '@hixme-ui/percentage'

<Percentage value='0.314' />
<Percentage>0.314</Percentage>
// both output 31.40%

hideDecimals

<Percentage hideDecimals value='0.891342' />
// outputs 89%

Format

Percentage has a static format function if needed outside of a JSX context.

Percentage.format({
  value: 0.1234
})
// outputs 12.34%

Percentage.format({
  value: 0.1234,
  hideDecimals: true,
})
// outputs 12%