github formatjs/formatjs v3.2.0

latest releases: vue-intl@6.5.2, react-intl@6.6.8, intl-messageformat@10.5.14...
4 years ago

Bug Fixes

  • fix tests & add corresponding formatToParts fns (855e272)

Features

<FormattedNumber
  value={1000}
  style="unit"
  unit="kilobyte"
  unitDisplay="narrow"
/>
<span>1,000kB</span>
<FormattedNumber
  value={1000}
  unit="fahrenheit"
  unitDisplay="long"
  style="unit"
/>
<span>1,000 degrees Fahrenheit</span>
  • add support for formatToParts (e8167f3)
  • introduce Parts component (a1b5ff1), closes #1048
    This component provides more customization to FormattedNumber/Date/Time by allowing children function to have access to underlying parts of the formatted date. The available parts are listed here

Props:

props: NumberFormatOptions &
  {
    value: number,
    format: string,
    children: (parts: Intl.NumberFormatPart[]) => ReactElement,
  };

Example:

<FormattedNumberParts value={1000}>
  {parts => (
    <>
      <b>{parts[0].value}</b>
      {parts[1].value}
      <small>{parts[2].value}</small>
    </>
  )}
</FormattedNumberParts>
<b>1</b>,<small>000</small>

Don't miss a new formatjs release

NewReleases is sending notifications on new releases.