From 57ba1514c70c39972e3624792c3a1ee8beca7120 Mon Sep 17 00:00:00 2001 From: kshih-lab49 Date: Fri, 20 May 2022 15:55:51 -0400 Subject: [PATCH 1/3] Set up the render props support --- src/Flash.tsx | 30 +++++++++++++++++ stories/Flash.stories.tsx | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/src/Flash.tsx b/src/Flash.tsx index 3d8aefc..1997633 100644 --- a/src/Flash.tsx +++ b/src/Flash.tsx @@ -8,6 +8,29 @@ export enum FlashDirection { Up = 'up', } +export interface RenderProps { + /** + * The className to be applied to the wrapper if needed. + */ + wrapperClassName?: string; + /** + * The computed inline styles for the wrapper element. + */ + style?: React.CSSProperties; + /** + * The className to be applied to the label if needed. + */ + labelClassName?: string; + /** + * The value exposed to the renderProps. + */ + value?: number; + /** + * The formatter function to format the value. + */ + valueFormatter?: Formatter; +} + export interface Props { /** * Color value when the component flashes 'down'. @@ -45,6 +68,8 @@ export interface Props { * Value to display. The only required prop. */ value: number; + + render?: (renderProps: RenderProps) => JSX.Element; } /** @@ -70,6 +95,7 @@ export interface Props { * add your own unique styles. */ export const Flash = ({ + render, downColor = '#d43215', formatter, formatterFn, @@ -120,6 +146,10 @@ export const Flash = ({ }; }, [value, timeout]); + if (render) { + return render({ cls, style, valueFormatter, value, labelClassName: `${stylePrefix}__value` }); + } + return (
{valueFormatter(value)} diff --git a/stories/Flash.stories.tsx b/stories/Flash.stories.tsx index 289b550..09b0b3a 100644 --- a/stories/Flash.stories.tsx +++ b/stories/Flash.stories.tsx @@ -225,3 +225,72 @@ export const MakeItNice = () => {
); }; + +export const RenderProps = () => { + return ( +
+