From 7671c24b72527b424cb8a1b82d25748662f415be Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:39:06 +0100 Subject: [PATCH] add ChatMessage component --- .../src/chat-message/chat-message.stories.tsx | 50 +++++++++++ .../src/chat-message/chat-message.tsx | 87 +++++++++++++++++++ .../src/chat-message/components/actions.tsx | 15 ++++ .../src/chat-message/components/reactions.tsx | 31 +++++++ .../components/src/chat-message/index.tsx | 26 ++++++ 5 files changed, 209 insertions(+) create mode 100644 packages/components/src/chat-message/chat-message.stories.tsx create mode 100644 packages/components/src/chat-message/chat-message.tsx create mode 100644 packages/components/src/chat-message/components/actions.tsx create mode 100644 packages/components/src/chat-message/components/reactions.tsx create mode 100644 packages/components/src/chat-message/index.tsx diff --git a/packages/components/src/chat-message/chat-message.stories.tsx b/packages/components/src/chat-message/chat-message.stories.tsx new file mode 100644 index 00000000..d815f0ca --- /dev/null +++ b/packages/components/src/chat-message/chat-message.stories.tsx @@ -0,0 +1,50 @@ +import { ChatMessage } from './chat-message' + +import type { Meta, StoryObj } from '@storybook/react' + +// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction +const meta: Meta = { + component: ChatMessage, + argTypes: {}, + parameters: { + design: { + type: 'figma', + url: 'https://www.figma.com/file/IBmFKgGL1B4GzqD8LQTw6n/Design-System-for-Web?node-id=611%3A36006&t=Gyy71OAckl3b2TWj-4', + }, + }, +} + +type Story = StoryObj + +// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args +export const Simple: Story = { + args: { + text: 'This is a simple message.', + }, +} + +export const SimpleLongText: Story = { + args: { + text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', + }, +} + +export const SimpleWithReactions: Story = { + name: 'Simple with reactions', + args: { + text: 'This is a simple message.', + reactions: ['thumb'], + }, +} + +export const Image: Story = { + args: { + images: [ + { + url: 'https://images.unsplash.com/photo-1673831792265-68b44126c999?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=866&q=80', + }, + ], + }, +} + +export default meta diff --git a/packages/components/src/chat-message/chat-message.tsx b/packages/components/src/chat-message/chat-message.tsx new file mode 100644 index 00000000..2d18a763 --- /dev/null +++ b/packages/components/src/chat-message/chat-message.tsx @@ -0,0 +1,87 @@ +import React from 'react' + +import { Stack, Unspaced, XStack, YStack } from 'tamagui' + +import { Avatar } from '../avatar' +import { Image } from '../image' +import { Paragraph } from '../typography' +import { Actions } from './components/actions' +import { Reactions } from './components/reactions' + +interface Props { + text?: React.ReactNode + images?: Array<{ url: string }> + reactions?: [] +} + +const ChatMessage = (props: Props) => { + const { text, images, reactions } = props + + const [hovered, setHovered] = React.useState(false) + + return ( + setHovered(true)} + onHoverOut={() => setHovered(false)} + > + {hovered && ( + + + + )} + + + + + + + Alisher Yakupov + + + zQ3...9d4Gs0 + + + 09:30 + + + + {text && ( + + {text} + + )} + + {images?.map(image => ( + + + + ))} + + {reactions && } + + + ) +} + +export { ChatMessage } diff --git a/packages/components/src/chat-message/components/actions.tsx b/packages/components/src/chat-message/components/actions.tsx new file mode 100644 index 00000000..eeb12bc2 --- /dev/null +++ b/packages/components/src/chat-message/components/actions.tsx @@ -0,0 +1,15 @@ +import { Stack } from 'tamagui' + +import { Text } from '../../typography' + +interface Props {} + +export const Actions = (props: Props) => { + const {} = props + + return ( + + actions + + ) +} diff --git a/packages/components/src/chat-message/components/reactions.tsx b/packages/components/src/chat-message/components/reactions.tsx new file mode 100644 index 00000000..66af3659 --- /dev/null +++ b/packages/components/src/chat-message/components/reactions.tsx @@ -0,0 +1,31 @@ +import { Pressable } from 'react-native' +import { Stack, XStack, YStack } from 'tamagui' + +interface Props {} + +const ReactionButton = ({ type }) => { + return ( + + {type} + + ) +} + +export const Reactions = (props: Props) => { + const {} = props + + return ( + + + + + + + + ) +} diff --git a/packages/components/src/chat-message/index.tsx b/packages/components/src/chat-message/index.tsx new file mode 100644 index 00000000..1eff084f --- /dev/null +++ b/packages/components/src/chat-message/index.tsx @@ -0,0 +1,26 @@ +import { ChatMessage } from './chat-message' + +export * from './chat-message' + +export const Messages = () => { + return ( + <> + + + + + + + + + + + + ) +}