-
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.
test: extract and add stories for in chat download-buttons
- Loading branch information
1 parent
11f5c77
commit b37d0aa
Showing
4 changed files
with
109 additions
and
94 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
40 changes: 40 additions & 0 deletions
40
apps/nextjs/src/components/AppComponents/Chat/chat-list/in-chat-download-buttons.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,40 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { DemoContext } from "@/components/ContextProviders/Demo"; | ||
|
||
import { InChatDownloadButtons } from "./in-chat-download-buttons"; | ||
|
||
const DemoDecorator: Story["decorators"] = (Story, { parameters }) => ( | ||
<DemoContext.Provider | ||
value={{ | ||
isDemoUser: false, | ||
isSharingEnabled: true, | ||
...parameters.demoContext, | ||
}} | ||
> | ||
<Story /> | ||
</DemoContext.Provider> | ||
); | ||
|
||
const meta: Meta<typeof InChatDownloadButtons> = { | ||
title: "Components/Chat/InChatDownloadButtons", | ||
component: InChatDownloadButtons, | ||
tags: ["autodocs"], | ||
args: { | ||
id: "test-chat-id", | ||
}, | ||
decorators: [DemoDecorator], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof InChatDownloadButtons>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const SharingDisabled: Story = { | ||
parameters: { | ||
demoContext: { | ||
isSharingEnabled: false, | ||
}, | ||
}, | ||
}; |
64 changes: 64 additions & 0 deletions
64
apps/nextjs/src/components/AppComponents/Chat/chat-list/in-chat-download-buttons.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,64 @@ | ||
import { OakBox, OakFlex, OakIcon, OakSpan } from "@oaknational/oak-components"; | ||
import Link from "next/link"; | ||
|
||
import { useDemoUser } from "@/components/ContextProviders/Demo"; | ||
|
||
import { useDialog } from "../../DialogContext"; | ||
|
||
export const InChatDownloadButtons = ({ id }: { id: string }) => { | ||
const demo = useDemoUser(); | ||
const { setDialogWindow } = useDialog(); | ||
|
||
return ( | ||
<OakFlex $flexDirection="column" $gap="all-spacing-7" $mv="space-between-l"> | ||
{demo.isSharingEnabled && ( | ||
<Link | ||
href={demo.isSharingEnabled ? `/aila/download/${id}` : "#"} | ||
onClick={() => { | ||
if (!demo.isSharingEnabled) { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="download">Download</InnerInChatButton> | ||
</Link> | ||
)} | ||
<button | ||
onClick={() => { | ||
if (demo.isSharingEnabled) { | ||
setDialogWindow("share-chat"); | ||
} else { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="share">Share</InnerInChatButton> | ||
</button> | ||
</OakFlex> | ||
); | ||
}; | ||
|
||
const InnerInChatButton = ({ | ||
iconName, | ||
children, | ||
}: { | ||
iconName: "download" | "share"; | ||
|
||
children: string; | ||
}) => { | ||
return ( | ||
<OakFlex | ||
$pa="inner-padding-m" | ||
$gap="all-spacing-3" | ||
$background="white" | ||
$borderRadius="border-radius-m" | ||
$alignItems="center" | ||
$dropShadow="drop-shadow-standard" | ||
> | ||
<OakBox $transform="scale"> | ||
<OakIcon iconName={iconName} $width="all-spacing-7" /> | ||
</OakBox> | ||
<OakSpan $font="body-2">{children}</OakSpan> | ||
</OakFlex> | ||
); | ||
}; |
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