add ChatMessage component

This commit is contained in:
Pavel Prichodko 2023-01-18 16:39:06 +01:00
parent dc9951c52b
commit 7671c24b72
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
5 changed files with 209 additions and 0 deletions

View File

@ -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<typeof ChatMessage> = {
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<typeof ChatMessage>
// 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

View File

@ -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 (
<XStack
space={10}
position="relative"
alignItems="flex-start"
paddingHorizontal={8}
paddingVertical={12}
borderRadius={16}
hoverStyle={{
backgroundColor: '$neutral-5',
}}
onHoverIn={() => setHovered(true)}
onHoverOut={() => setHovered(false)}
>
{hovered && (
<Unspaced>
<Actions />
</Unspaced>
)}
<Avatar
size={32}
src="https://images.unsplash.com/photo-1524638431109-93d95c968f03?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=500&ixid=MnwxfDB8MXxyYW5kb218MHx8Z2lybHx8fHx8fDE2NzM4ODQ0NzU&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=500"
indicator="online"
/>
<YStack flex={1}>
<XStack space={8} alignItems="center">
<Paragraph weight="semibold" color="$neutral-100">
Alisher Yakupov
</Paragraph>
<Paragraph fontFamily="$mono" color="$neutral-50" fontSize={11}>
zQ3...9d4Gs0
</Paragraph>
<Paragraph color="$neutral-50" variant={11}>
09:30
</Paragraph>
</XStack>
{text && (
<Paragraph flexGrow={0} weight="regular" color="$neutral-100">
{text}
</Paragraph>
)}
{images?.map(image => (
<Stack
key={image.url}
borderRadius={12}
overflow="hidden"
marginTop={6}
$gtMd={{
maxWidth: 320,
}}
>
<Image src={image.url} width="full" height={320} />
</Stack>
))}
{reactions && <Reactions />}
</YStack>
</XStack>
)
}
export { ChatMessage }

View File

@ -0,0 +1,15 @@
import { Stack } from 'tamagui'
import { Text } from '../../typography'
interface Props {}
export const Actions = (props: Props) => {
const {} = props
return (
<Stack position="absolute" top={0} right={0}>
<Text>actions</Text>
</Stack>
)
}

View File

@ -0,0 +1,31 @@
import { Pressable } from 'react-native'
import { Stack, XStack, YStack } from 'tamagui'
interface Props {}
const ReactionButton = ({ type }) => {
return (
<Stack
padding={3}
borderWidth={1}
borderColor="$neutral-100"
borderRadius={2}
>
{type}
</Stack>
)
}
export const Reactions = (props: Props) => {
const {} = props
return (
<XStack>
<ReactionButton type="like" />
<ReactionButton type="+1" />
<ReactionButton type="-1" />
<ReactionButton type="sad" />
<ReactionButton type="angry" />
</XStack>
)
}

View File

@ -0,0 +1,26 @@
import { ChatMessage } from './chat-message'
export * from './chat-message'
export const Messages = () => {
return (
<>
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage
images={[
{
url: 'https://images.unsplash.com/photo-1673433107234-14d1a4424658?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80',
},
]}
/>
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
<ChatMessage text="fsdjkf kasldjf ksdlfjksdlfj asdklfj sdkljf" />
</>
)
}