-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e25c56
commit 9da305d
Showing
4 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
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 { Skeleton } from "@/components/ui/Skeleton"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from "@/components/ui/Tooltip"; | ||
import { Warning } from "@phosphor-icons/react/dist/ssr"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
type Props = { | ||
isLoading?: boolean; | ||
error?: string; | ||
}; | ||
|
||
const DataBlock = ({ | ||
isLoading, | ||
error, | ||
children, | ||
}: PropsWithChildren<Props>): JSX.Element => { | ||
if (isLoading) return <Skeleton className="inline w-24" />; | ||
|
||
return ( | ||
<Tooltip open={error ? undefined : false}> | ||
<TooltipTrigger asChild> | ||
<span className="break-words rounded-md bg-blackAlpha px-1.5 py-0.5 text-sm dark:bg-blackAlpha-hard"> | ||
{error && ( | ||
<Warning | ||
weight="bold" | ||
className="-top-px relative mr-1.5 inline-flex text-icon-warning" | ||
/> | ||
)} | ||
<span className="font-mono">{children}</span> | ||
</span> | ||
</TooltipTrigger> | ||
<TooltipContent side="top"> | ||
<p>{error}</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export { DataBlock }; |
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,37 @@ | ||
import { DataBlock } from "@/components/requirements/DataBlock"; | ||
import { Card } from "@/components/ui/Card"; | ||
import { TooltipProvider } from "@/components/ui/Tooltip"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof DataBlock> = { | ||
title: "Requirement building blocks/DataBlock", | ||
component: DataBlock, | ||
decorators: (Story) => ( | ||
<TooltipProvider> | ||
<Card className="p-4"> | ||
<span>{"This is a "}</span> | ||
<Story /> | ||
<span>{" example"}</span> | ||
</Card> | ||
</TooltipProvider> | ||
), | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DataBlock>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: "DataBlock", | ||
error: "", | ||
}, | ||
}; | ||
|
||
export const ErrorState: Story = { | ||
name: "Error state", | ||
args: { | ||
...Default.args, | ||
error: "An error occurred", | ||
}, | ||
}; |
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