-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Message): add message component (#1004)
- Loading branch information
Showing
14 changed files
with
384 additions
and
4 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
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
56 changes: 56 additions & 0 deletions
56
packages/components/src/components/Message/Message.module.scss
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,56 @@ | ||
.message { | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: var(--message--spacing-y); | ||
width: max-content; | ||
max-width: 100%; | ||
|
||
.content { | ||
grid-area: content; | ||
border-radius: var(--message--corner-radius); | ||
padding-inline: var(--message--padding-x); | ||
padding-block: var(--message--padding-y); | ||
background-color: var(--message--background-color-sender); | ||
} | ||
|
||
&.responder .content { | ||
background-color: var(--message--background-color-responder); | ||
} | ||
|
||
.header { | ||
display: flex; | ||
column-gap: var(--message--spacing-x); | ||
row-gap: var(--message--spacing-y); | ||
align-items: center; | ||
flex-wrap: wrap; | ||
font-size: var(--font-size-text--s); | ||
|
||
.user { | ||
order: 1; | ||
flex-grow: 1; | ||
} | ||
|
||
.date { | ||
font-size: var(--font-size-text--s); | ||
order: 2; | ||
} | ||
|
||
.action { | ||
order: 3; | ||
} | ||
} | ||
|
||
&.right { | ||
.header { | ||
flex-direction: row-reverse; | ||
|
||
.user { | ||
flex-direction: row-reverse; | ||
|
||
:global(.flow--text) { | ||
text-align: end; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,59 @@ | ||
import type { FC, PropsWithChildren } from "react"; | ||
import React from "react"; | ||
import clsx from "clsx"; | ||
import styles from "./Message.module.scss"; | ||
import type { PropsWithClassName } from "@/lib/types/props"; | ||
import type { PropsContext } from "@/lib/propsContext"; | ||
import { IconContextMenu } from "@/components/Icon/components/icons"; | ||
import PropsContextProvider from "@/lib/propsContext/PropsContextProvider"; | ||
|
||
export interface MessageProps extends PropsWithChildren, PropsWithClassName { | ||
/** @default "sender" */ | ||
type?: "responder" | "sender"; | ||
orientation?: "left" | "right"; | ||
} | ||
|
||
export const Message: FC<MessageProps> = (props) => { | ||
const { type = "sender", children, className, orientation = "left" } = props; | ||
|
||
const rootClassName = clsx( | ||
styles.message, | ||
styles[type], | ||
styles[orientation], | ||
className, | ||
); | ||
|
||
const propsContext: PropsContext = { | ||
Content: { className: styles.content }, | ||
Header: { | ||
className: styles.header, | ||
Button: { | ||
className: styles.action, | ||
size: "s", | ||
variant: "plain", | ||
color: "secondary", | ||
}, | ||
ContextMenuTrigger: { | ||
Button: { | ||
className: styles.action, | ||
size: "s", | ||
variant: "plain", | ||
color: "secondary", | ||
children: <IconContextMenu />, | ||
}, | ||
}, | ||
Text: { className: styles.date }, | ||
Align: { | ||
className: styles.user, | ||
}, | ||
}, | ||
}; | ||
|
||
return ( | ||
<PropsContextProvider props={propsContext}> | ||
<article className={rootClassName}>{children}</article> | ||
</PropsContextProvider> | ||
); | ||
}; | ||
|
||
export default Message; |
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,4 @@ | ||
import { Message } from "./Message"; | ||
|
||
export { type MessageProps, Message } from "./Message"; | ||
export default Message; |
66 changes: 66 additions & 0 deletions
66
packages/components/src/components/Message/stories/Default.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,66 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
import { Message } from "@/components/Message"; | ||
import { Header } from "@/components/Header"; | ||
import { ContextMenu, ContextMenuTrigger } from "@/components/ContextMenu"; | ||
import { Button } from "@/components/Button"; | ||
import MenuItem from "@/components/MenuItem"; | ||
import { Align } from "@/components/Align"; | ||
import { Avatar } from "@/components/Avatar"; | ||
import { Initials } from "@/components/Initials"; | ||
import { Content } from "@/components/Content"; | ||
import { Text } from "@/components/Text"; | ||
|
||
const meta: Meta<typeof Message> = { | ||
title: "Content/Message", | ||
component: Message, | ||
parameters: { | ||
controls: { exclude: ["className"] }, | ||
}, | ||
render: (props) => ( | ||
<Message {...props}> | ||
<Header> | ||
<ContextMenuTrigger> | ||
<Button /> | ||
<ContextMenu> | ||
<MenuItem>Bearbeiten</MenuItem> | ||
<MenuItem>Löschen</MenuItem> | ||
</ContextMenu> | ||
</ContextMenuTrigger> | ||
<Align> | ||
<Avatar> | ||
<Initials>Max Mustermann</Initials> | ||
</Avatar> | ||
<Text> | ||
<b>Max Mustermann</b> | ||
Organisationsinhaber | ||
</Text> | ||
</Align> | ||
<Text>01.09.2024, 12:45</Text> | ||
</Header> | ||
|
||
<Content> | ||
<Text>Das ist eine Nachricht</Text> | ||
</Content> | ||
</Message> | ||
), | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Message>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Responder: Story = { args: { type: "responder" } }; | ||
|
||
export const MessageOnly: Story = { | ||
render: (props) => ( | ||
<Message {...props}> | ||
<Content> | ||
<Text>Das ist eine Nachricht</Text> | ||
</Content> | ||
</Message> | ||
), | ||
}; | ||
|
||
export const OrientationRight: Story = { args: { orientation: "right" } }; |
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
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,15 @@ | ||
message: | ||
corner-radius: | ||
value: "{corner-radius.default}" | ||
padding-y: | ||
value: "{size-px.s}" | ||
padding-x: | ||
value: "{size-px.m}" | ||
spacing-y: | ||
value: "{size-rem.s}" | ||
spacing-x: | ||
value: "{size-rem.m}" | ||
background-color-responder: | ||
value: "{color.gray.400}" | ||
background-color-sender: | ||
value: "{color.hosting-blue.200}" |
46 changes: 46 additions & 0 deletions
46
packages/docs/src/content/03-components/content/message/examples/default.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,46 @@ | ||
import { Message } from "@mittwald/flow-react-components/Message"; | ||
import { Header } from "@mittwald/flow-react-components/Header"; | ||
import { | ||
ContextMenu, | ||
ContextMenuTrigger, | ||
} from "@mittwald/flow-react-components/ContextMenu"; | ||
import { Button } from "@mittwald/flow-react-components/Button"; | ||
import MenuItem from "@mittwald/flow-react-components/MenuItem"; | ||
import { Align } from "@mittwald/flow-react-components/Align"; | ||
import { Avatar } from "@mittwald/flow-react-components/Avatar"; | ||
import { Initials } from "@mittwald/flow-react-components/Initials"; | ||
import { Text } from "@mittwald/flow-react-components/Text"; | ||
import { Content } from "@mittwald/flow-react-components/Content"; | ||
|
||
<Message> | ||
<Header> | ||
<ContextMenuTrigger> | ||
<Button /> | ||
<ContextMenu> | ||
<MenuItem>Bearbeiten</MenuItem> | ||
<MenuItem>Löschen</MenuItem> | ||
</ContextMenu> | ||
</ContextMenuTrigger> | ||
<Align> | ||
<Avatar> | ||
<Initials>Max Mustermann</Initials> | ||
</Avatar> | ||
<Text> | ||
<b>Max Mustermann</b> | ||
Organisationsinhaber | ||
</Text> | ||
</Align> | ||
<Text>01.09.2024, 12:45</Text> | ||
</Header> | ||
|
||
<Content> | ||
<Text> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing | ||
elitr, sed diam nonumy eirmod tempor invidunt ut | ||
labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores | ||
et ea rebum. Stet clita kasd gubergren, no sea | ||
takimata sanctus est Lorem ipsum dolor sit amet. | ||
</Text> | ||
</Content> | ||
</Message>; |
46 changes: 46 additions & 0 deletions
46
packages/docs/src/content/03-components/content/message/examples/responder.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,46 @@ | ||
import { Message } from "@mittwald/flow-react-components/Message"; | ||
import { Header } from "@mittwald/flow-react-components/Header"; | ||
import { | ||
ContextMenu, | ||
ContextMenuTrigger, | ||
} from "@mittwald/flow-react-components/ContextMenu"; | ||
import { Button } from "@mittwald/flow-react-components/Button"; | ||
import MenuItem from "@mittwald/flow-react-components/MenuItem"; | ||
import { Align } from "@mittwald/flow-react-components/Align"; | ||
import { Avatar } from "@mittwald/flow-react-components/Avatar"; | ||
import { Initials } from "@mittwald/flow-react-components/Initials"; | ||
import { Text } from "@mittwald/flow-react-components/Text"; | ||
import { Content } from "@mittwald/flow-react-components/Content"; | ||
|
||
<Message type="responder"> | ||
<Header> | ||
<ContextMenuTrigger> | ||
<Button /> | ||
<ContextMenu> | ||
<MenuItem>Bearbeiten</MenuItem> | ||
<MenuItem>Löschen</MenuItem> | ||
</ContextMenu> | ||
</ContextMenuTrigger> | ||
<Align> | ||
<Avatar> | ||
<Initials>Max Mustermann</Initials> | ||
</Avatar> | ||
<Text> | ||
<b>Max Mustermann</b> | ||
Organisationsinhaber | ||
</Text> | ||
</Align> | ||
<Text>01.09.2024, 12:45</Text> | ||
</Header> | ||
|
||
<Content> | ||
<Text> | ||
Lorem ipsum dolor sit amet, consetetur sadipscing | ||
elitr, sed diam nonumy eirmod tempor invidunt ut | ||
labore et dolore magna aliquyam erat, sed diam | ||
voluptua. At vero eos et accusam et justo duo dolores | ||
et ea rebum. Stet clita kasd gubergren, no sea | ||
takimata sanctus est Lorem ipsum dolor sit amet. | ||
</Text> | ||
</Content> | ||
</Message>; |
Oops, something went wrong.