-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22392: Added additional PropertyLabels, MINOR (#76)
- Loading branch information
1 parent
43a5e86
commit 0195c0c
Showing
7 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/components/DataDisplay/LocaleNumber/LocaleNumber.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { LocaleNumber } from "."; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export | ||
const meta: Meta<typeof LocaleNumber> = { | ||
component: LocaleNumber, | ||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page | ||
tags: ["autodocs"], | ||
parameters: { | ||
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout | ||
layout: "centered", | ||
}, | ||
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes | ||
argTypes: {}, | ||
args: { | ||
loading: false, | ||
value: 300_452, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof LocaleNumber>; | ||
|
||
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
export const Default: Story = { | ||
// More on args: https://storybook.js.org/docs/react/writing-stories/args | ||
args: { | ||
value: 300_452, | ||
}, | ||
}; | ||
|
||
export const Loading: Story = { | ||
args: { | ||
loading: true, | ||
}, | ||
}; | ||
|
||
export const NullOrUndefined: Story = { | ||
args: { | ||
value: undefined, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FC, ReactNode } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { Skeleton, SkeletonProps } from "../../Feedback"; | ||
|
||
export type LocaleNumberProps = { | ||
/** A value to be displayed if no value is present when not loading */ | ||
defaultValue?: ReactNode; | ||
/** Defaults to { maximumFractionDigits: 3 } */ | ||
formatter?: Intl.NumberFormat; | ||
loading?: boolean; | ||
skeleton?: SkeletonProps; | ||
value: number | null | undefined; | ||
}; | ||
export const LocaleNumber: FC<LocaleNumberProps> = ({ | ||
defaultValue = "-", | ||
formatter = defaultIntlNumberFormatter, | ||
loading = false, | ||
skeleton, | ||
value, | ||
}) => { | ||
if (loading) { | ||
return ( | ||
<Skeleton | ||
variant="text" | ||
className={twMerge("w-28", skeleton?.className)} | ||
/> | ||
); | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return defaultValue; | ||
} | ||
|
||
return formatter.format(value); | ||
}; | ||
|
||
export const defaultIntlNumberFormatter = new Intl.NumberFormat(undefined, { | ||
maximumFractionDigits: 3, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./LocaleNumber"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { FC } from "react"; | ||
import { PropertyLabel, type PropertyLabelProps } from "./PropertyLabel"; | ||
|
||
export const FeaturesLabel: FC<Omit<PropertyLabelProps, "property">> = ( | ||
props, | ||
) => <PropertyLabel {...props} property={"features"} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters