@lab49/react-value-flash
v0.1.7
Published
Flash on value change. Perfect for financial applications.
Downloads
14
Readme
@lab49/react-value-flash
react-value-flash
will display a flashed value on screen based on some value change. This pattern is extremely common in financial applications, and at Lab49, we're focused on the finance industry.
Incorporate this component into your application and pass along a number. As that number changes, this component will briefly flash a color, letting the user know the number has changed. By default, this component will flash green when the value changes up, or red when the value changes down.
Not only are these colors configurable, but the properties of the flash itself and the formatting of the value are configurable as well.
Furthermore, this component doesn't come with any styles, but does provide plenty of hooks to add your own styles. Even though flash color and transition properties are configurable as props, you can still use the generated classnames (which are also configurable) to add your own unique styles.
This component is perfect for:
- Trading platforms
- Analytics dashboards
- Monitoring dashboards
Features
- Written in TypeScript
- Small, simple, configurable, performant
- Maintained by a team of finance industry professionals
Table of contents
Demo
Hosted demo: https://master--5f3fca6e6b5eba0022c71e4e.chromatic.com/
You can also run the demo locally. To get started:
git clone [email protected]:lab49/react-value-flash.git
npm install
npm run storybook
⇡ Top
Installation
npm install @lab49/react-value-flash
⇡ Top
Usage
import { Flash } from '@lab49/react-value-flash';
<Flash value={20_000}>
As discussed above, there are a number of classnames you can use to add your own styles. There is an example of doing exactly that in the include Storybook, but as an example, here's a description of the available classnames:
| Class | Description |
| --- | --- |
| .rvf_Flash
| Root DOM node |
| .rvf_Flash__value
| Rendered value, direct (and only) child of the root node. |
| .rvf_Flash--flashing
| Applied only when the component is in the flashing state. |
| .rvf_Flash--flashing-up
| Applied when flashing 'up'. |
| .rvf_Flash--flashing-down
| Applied when flashing 'down'. |
| .rvf_Flash--positive
| Applied when the value is positive. |
| .rvf_Flash--negative
| Applied when the value is negative. |
⇡ Top
API
Flash
<Flash />
is a (props: Props) => JSX.Element
. See Props
below for a description of the avilable props.
import { Flash } from '@lab49/react-value-flash';
const MyComponent = () => <Flash value={1} />;
Props
interface Props {
/**
* Color value when the component flashes 'down'.
*/
downColor?: string;
/**
* One of the built in formatters.
*/
formatter?: 'currency' | 'percentage' | 'number';
/**
* Pass your own formatter function.
*/
formatterFn?: Formatter;
/**
* Prefix for the CSS selectors in the DOM.
*/
stylePrefix?: string;
/**
* Amount of time the flashed state is visible for, in milliseconds.
*/
timeout?: number;
/**
* Custom CSS transition property.
*/
transition?: string;
/**
* Transition length, in milliseconds.
*/
transitionLength?: number;
/**
* Color value when the component flashes 'up'.
*/
upColor?: string;
/**
* Value to display. The only required prop.
*/
value: number;
}
FlashDirection
enum FlashDirection {
Down = 'down',
Up = 'up',
}
⇡ Top
Extra
This project was created with create-react-library.
⇡ Top
License
MIT @ Lab49