|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { useState } from "react"; |
| 5 | + |
| 6 | +import Box from "@cloudscape-design/components/box"; |
| 7 | +import Button from "@cloudscape-design/components/button"; |
| 8 | +import Container from "@cloudscape-design/components/container"; |
| 9 | +import Header from "@cloudscape-design/components/header"; |
| 10 | +import SpaceBetween from "@cloudscape-design/components/space-between"; |
| 11 | + |
| 12 | +import { ChatBubble } from "../../lib/components"; |
| 13 | +import { Page } from "../app/templates"; |
| 14 | +import { ChatBubbleAvatarGenAI, ChatBubbleAvatarUser } from "./util-components"; |
| 15 | + |
| 16 | +export default function ChatBubbleSelectablePage() { |
| 17 | + const [selectedCardId, setSelectedCardId] = useState<null | string>(null); |
| 18 | + return ( |
| 19 | + <Page title="Chat bubble: selectable"> |
| 20 | + <SpaceBetween direction="horizontal" size="l"> |
| 21 | + <Container header={<Header variant="h3">Chat container</Header>}> |
| 22 | + <SpaceBetween size="m"> |
| 23 | + <ChatBubble avatar={<ChatBubbleAvatarUser />} type="outgoing" ariaLabel="User at 4:24:12pm"> |
| 24 | + <Box color="text-body-secondary">User request example</Box> |
| 25 | + </ChatBubble> |
| 26 | + |
| 27 | + <ChatBubble avatar={<ChatBubbleAvatarGenAI />} type="incoming" ariaLabel="Gen AI at 4:24:24pm"> |
| 28 | + <Box color="text-body-secondary">Normal response example</Box> |
| 29 | + </ChatBubble> |
| 30 | + |
| 31 | + <ChatBubble |
| 32 | + avatar={<ChatBubbleAvatarGenAI />} |
| 33 | + hideAvatar={true} |
| 34 | + type="incoming" |
| 35 | + ariaLabel="Gen AI at 4:24:25pm" |
| 36 | + selectionType="card-click" |
| 37 | + onSelect={() => setSelectedCardId((prev) => (prev !== "1" ? "1" : null))} |
| 38 | + selected={selectedCardId === "1"} |
| 39 | + > |
| 40 | + <Box variant="h4">Selectable response example</Box> |
| 41 | + <Box variant="p">This entire card is clickable</Box> |
| 42 | + </ChatBubble> |
| 43 | + |
| 44 | + <ChatBubble |
| 45 | + avatar={<ChatBubbleAvatarGenAI />} |
| 46 | + hideAvatar={true} |
| 47 | + type="incoming" |
| 48 | + ariaLabel="Gen AI at 4:24:25pm" |
| 49 | + selectionType="custom" |
| 50 | + selected={selectedCardId === "2"} |
| 51 | + > |
| 52 | + <div style={{ display: "flex", gap: 8, justifyContent: "space-between" }}> |
| 53 | + <Box variant="h4">Selectable response example</Box> |
| 54 | + {selectedCardId !== "2" ? ( |
| 55 | + <Button variant="inline-link" onClick={() => setSelectedCardId("2")}> |
| 56 | + Show |
| 57 | + </Button> |
| 58 | + ) : ( |
| 59 | + <Button variant="inline-link" onClick={() => setSelectedCardId(null)}> |
| 60 | + Hide |
| 61 | + </Button> |
| 62 | + )} |
| 63 | + </div> |
| 64 | + <Box variant="p"> |
| 65 | + This entire card is not clickable. Instead, there is a custom action in the top-right. |
| 66 | + </Box> |
| 67 | + </ChatBubble> |
| 68 | + </SpaceBetween> |
| 69 | + </Container> |
| 70 | + |
| 71 | + <Container header={<Header variant="h3">Presentation container</Header>}> |
| 72 | + {selectedCardId ? ( |
| 73 | + <SpaceBetween size="m"> |
| 74 | + <Box>{selectedCardId === "1" ? "First" : "Second"} card is selected</Box> |
| 75 | + <Button onClick={() => setSelectedCardId(null)}>Clear selection</Button> |
| 76 | + </SpaceBetween> |
| 77 | + ) : null} |
| 78 | + </Container> |
| 79 | + </SpaceBetween> |
| 80 | + </Page> |
| 81 | + ); |
| 82 | +} |
0 commit comments