diff --git a/apps/web/test/unit-tests/components/structures/__snapshots__/MessagePanel-test.tsx.snap b/apps/web/test/unit-tests/components/structures/__snapshots__/MessagePanel-test.tsx.snap index 931f952a9c..0a33547b8c 100644 --- a/apps/web/test/unit-tests/components/structures/__snapshots__/MessagePanel-test.tsx.snap +++ b/apps/web/test/unit-tests/components/structures/__snapshots__/MessagePanel-test.tsx.snap @@ -63,7 +63,7 @@ exports[`MessagePanel should handle lots of membership events quickly 1`] = `
You can't see earlier messages
diff --git a/apps/web/test/unit-tests/components/structures/__snapshots__/RoomView-test.tsx.snap b/apps/web/test/unit-tests/components/structures/__snapshots__/RoomView-test.tsx.snap index 72faba944c..17371b4e02 100644 --- a/apps/web/test/unit-tests/components/structures/__snapshots__/RoomView-test.tsx.snap +++ b/apps/web/test/unit-tests/components/structures/__snapshots__/RoomView-test.tsx.snap @@ -154,7 +154,7 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`] class="mx_NewRoomIntro" >
End-to-end encryption isn't enabled
@@ -351,7 +351,7 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] = class="mx_NewRoomIntro" >
End-to-end encryption isn't enabled
@@ -754,7 +754,7 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t style="height: 400px;" >
Encryption enabled
Messages in this chat will be end-to-end encrypted.
diff --git a/apps/web/test/unit-tests/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap b/apps/web/test/unit-tests/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap index 2565ee90d6..f93e0dd1c4 100644 --- a/apps/web/test/unit-tests/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap +++ b/apps/web/test/unit-tests/components/views/messages/__snapshots__/RoomPredecessorTile-test.tsx.snap @@ -3,7 +3,7 @@ exports[` Renders as expected 1`] = `
Renders as expected 1`] = ` />
This room is a continuation of another conversation.
* { + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + line-clamp: 2; + overflow: hidden; + text-overflow: ellipsis; +} + /* Slot wrappers are the public styling boundary. The supplied content may be a component, fragment, or multiple elements and does not need to forward layout props. */ @@ -77,6 +108,19 @@ z-index: 1; } +.slotNotificationRoomLabel { + flex: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.slotFooter { + display: flex; + align-items: center; + gap: var(--cpd-space-2x, 8px); +} + /* Shared structural containers. */ .senderDetails { display: flex; @@ -117,7 +161,8 @@ } &.stateSelected .line, - &.stateEditing .line { + &.stateEditing .line, + &.stateActionBarFocused .line { background-color: var(--event-tile-state-selected-background); } @@ -163,7 +208,7 @@ .slotTimestamp { position: absolute; inset-inline-start: 0; - width: var(--MessageTimestamp-width, 46px); + width: var(--event-tile-group-timestamp-width); text-align: center; } @@ -181,7 +226,19 @@ .slotReplyChain { margin-inline-start: 0; - margin-bottom: var(--cpd-space-2x, 8px); + margin-inline-end: 10px; + } + + .line, + .slotReplyChain { + position: relative; + border-radius: 8px; + } + + /* Reply-chain spacing belongs to the group shell; nested reply content + remains application-owned. */ + &.stateHasReply .slotReplyChain { + margin-block-end: var(--cpd-space-2x, 8px); } .slotFooter { @@ -199,9 +256,127 @@ overflow: visible; } + /* Informational events use a smaller metadata row while retaining the + normal group slot order. */ + &.stateInfo { + padding-top: 0; + + .slotAvatar, + .slotPadlock { + line-height: 1; + margin-block: 3px 2px; + } + + .slotAvatar { + inset-block-start: auto; + inset-inline-start: var(--event-tile-group-gutter); + height: 14px; + } + + .line { + padding-block: 3px 2px; + padding-inline-start: calc(var(--event-tile-group-gutter) + 20px); + } + + .slotTimestamp, + .slotPadlock { + inset-block-start: 0; + } + } + &.stateContinuation .line { clear: both; } + + /* The legacy bubble-container grid is a group-layout shell. The action + bar remains intentionally inside the full-width line in this view, so + its line-local absolute placement is owned by .slotActionBar. */ + &.stateBubbleContainer { + display: grid; + grid-template-columns: minmax(0, 1fr) 100px; + + .line { + grid-column: 1 / 3; + margin-inline-end: 0; + padding: 0; + padding-inline-start: var(--event-tile-group-gutter); + } + + > .slotReceipt { + grid-column: 2; + } + + .slotActionBar { + position: absolute; + } + + &:hover .line { + background: inherit; + } + } + + &.densityCompact { + padding-top: var(--cpd-space-1x, 4px); + + .line { + padding-block: 0; + } + + .slotAvatar { + inset-block-start: var(--cpd-space-0-5x, 2px); + } + + .slotPadlock { + margin: 0; + } + + .slotSender { + font-size: 13px; + } + + &.stateInfo { + padding-top: 0; + font-size: 13px; + + .slotAvatar, + .slotPadlock { + inset-block-start: 0; + margin-block: 0; + } + + .line { + line-height: 20px; + } + } + + &.stateEmote { + padding-top: var(--cpd-space-2x, 8px); + + .slotAvatar { + inset-block-start: var(--cpd-space-0-5x, 2px); + } + + .line { + padding-bottom: 1px; + } + + &.stateContinuation .line { + padding-bottom: 0; + } + } + + &.stateContinuation { + padding-top: 0; + } + + .slotReplyChain { + margin-block-end: var(--cpd-space-1x, 4px); + } + + .slotReceipt { + inset-block-start: -2rem; + } + } } /* IRC layout. */ @@ -221,7 +396,8 @@ } &.stateSelected .line, - &.stateEditing .line { + &.stateEditing .line, + &.stateActionBarFocused .line { background-color: var(--event-tile-state-selected-background); } @@ -292,29 +468,93 @@ flex-grow: 1; flex-shrink: 1; padding-block: 1px; + position: relative; + border-radius: 8px; } .slotReplyChain { + position: relative; margin: 0; + border-radius: 8px; + } + + .slotBody, + .slotPadlock { + padding-block: 1px; + } + + .slotReceipt { + order: 5; + position: relative; + inset-block-start: -0.3rem; } .slotFooter { margin-block: var(--cpd-space-1-5x, 6px); } + + &.stateBubbleContainer { + align-items: center; + + .line { + width: 100%; + max-width: 100%; + margin: 0; + padding: 0; + background: transparent; + } + } + + &.stateEmote .slotAvatar { + margin-inline-start: calc( + var(--event-tile-irc-name-width) + var(--event-tile-irc-icon-width) + var(--event-tile-irc-right-padding) + ); + } + + &.stateContinuation .line { + clear: both; + } + + &.stateInfo { + padding-top: 0; + + .slotAvatar { + inset-block-start: 0; + inset-inline-start: var(--event-tile-irc-info-offset); + margin-inline-end: var(--event-tile-irc-right-padding); + transform: translateY(-50%); + margin-block-start: -2px; + padding-block: 1px; + } + + .slotPadlock { + inset-block-start: 0; + } + + .line { + margin-inline-start: var(--event-tile-irc-info-offset); + line-height: 12px; + + .slotBody { + width: auto; + font-size: 12px; + } + } + } } /* Bubble layout. */ .root.layoutBubble { max-width: unset; - margin-inline: var(--EventTile_bubble-margin-inline-start, 49px) var(--EventTile_bubble-margin-inline-end, 60px); + margin-inline: var(--event-tile-bubble-margin-inline-start) var(--event-tile-bubble-margin-inline-end); padding-top: 0; &::before { content: ""; position: absolute; z-index: -1; - inset: -1px calc(-1 * var(--EventTile_bubble-margin-inline-end, 60px)) -1px - calc(-1 * var(--EventTile_bubble-margin-inline-start, 49px)); + inset: -1px calc(-1 * var(--event-tile-bubble-margin-inline-end)) -1px + calc(-1 * var(--event-tile-bubble-margin-inline-start)); border-radius: 4px; pointer-events: none; } @@ -327,15 +567,47 @@ width: fit-content; max-width: 70%; margin-block: 0; - margin-inline: -9px -12px; + margin-inline: var(--event-tile-bubble-line-margin-inline-start) var(--event-tile-bubble-line-margin-inline-end); border-radius: var(--event-tile-bubble-corner-radius) var(--event-tile-bubble-corner-radius) 0 0; line-height: 18px; + position: relative; padding: calc(var(--event-tile-bubble-gutter) - 1px); padding-inline-end: 60px; background: var(--event-tile-bubble-other-background); border-end-end-radius: var(--event-tile-bubble-corner-radius); } + .slotTimestamp { + position: absolute; + z-index: 3; + inset-block-end: 0; + inset-inline-end: 0; + max-width: 80px; + padding: 4px 8px; + } + + /* Media bodies provide their own appearance and dimensions. The shell + removes message padding while retaining the normal bubble width. */ + .lineMedia { + padding: 0; + background: transparent; + max-width: var(--event-tile-bubble-line-max-width); + } + + .lineMedia.lineImage .slotTimestamp { + border-radius: 8px; + background-color: rgb(0 0 0 / 60%); + color: #fff; + padding: 0 4px; + } + + /* Stickers are un-bubbled content, so their timestamp sits immediately + after the line instead of over its lower-right corner. */ + .lineSticker .slotTimestamp { + inset-inline-start: 100%; + inset-inline-end: auto; + } + .slotAvatar { position: absolute; z-index: 9; @@ -351,14 +623,10 @@ box-shadow: 0 0 0 3px var(--cpd-color-bg-canvas-default, #fff); } - .slotSender, - .line { + .slotSender { width: fit-content; max-width: 70%; line-height: 18px; - } - - .slotSender { position: relative; inset-block-start: -2px; inset-inline-start: 2px; @@ -366,14 +634,6 @@ white-space: normal; } - .slotTimestamp { - position: absolute; - z-index: 3; - inset-block-end: 0; - inset-inline-end: 0; - padding: 4px 8px; - } - > .slotReceipt { position: absolute; z-index: 1; @@ -398,7 +658,7 @@ display: flex; align-items: center; margin-block: var(--cpd-space-1-5x, 6px); - margin-inline: -9px -12px; + margin-inline: var(--event-tile-bubble-line-margin-inline-start) var(--event-tile-bubble-line-margin-inline-end); } .slotThreadInfo { @@ -411,6 +671,12 @@ clear: both; } + /* Reply-chain spacing belongs to the bubble shell; nested reply content + remains application-owned. */ + &.stateHasReply .slotReplyChain { + margin-block-end: var(--cpd-space-2x, 8px); + } + /* Own-event modifiers. */ &.stateOwnEvent .slotSender { display: none; @@ -423,6 +689,16 @@ margin-inline-start: auto; } + &.stateOwnEvent .lineMedia { + margin-block: 0; + margin-inline: 0 var(--event-tile-bubble-line-margin-inline-end); + background: transparent; + } + + &.stateOwnEvent .lineSticker { + margin-inline-end: 32px; + } + &.stateOwnEvent .slotAvatar { inset-block-start: -19px; inset-inline-start: auto; @@ -510,6 +786,160 @@ border-end-start-radius: 0; border-end-end-radius: var(--event-tile-bubble-corner-radius); } + + /* Bubble-column events without a normal message bubble keep their column + placement but do not paint the bubble background. */ + &.stateNoBubble .line { + background: transparent; + padding: 0; + } + + &.stateNoBubble .lineEmote { + padding-inline-end: 60px; + font-style: italic; + + .slotBody { + padding-block: 4px; + } + + .slotTimestamp { + inset-block: auto; + align-self: center; + font-style: normal; + } + } + + /* Events without sender details use the same avatar placement as an own + message whose sender row is hidden. */ + &.stateNoSender .slotAvatar { + inset-block-start: -19px; + } + + /* Hidden/bubble-container events are full-width shell rows. Their content + remains application-owned; only the wrapper placement is changed here. */ + &.stateBubbleContainer, + &.stateLeftAlignedBubble { + display: flex; + align-items: center; + justify-content: flex-start; + padding-block: 5px; + + .line { + width: 100%; + max-width: 100%; + margin: 0; + padding: 0; + background: transparent; + } + + .slotAvatar { + position: static; + order: -1; + display: inline-flex; + margin-inline-end: var(--event-tile-bubble-gap); + } + + .slotPadlock { + margin-inline-start: 0; + align-self: center; + } + + .slotTimestamp { + inset-block: auto; + inset-inline: -77px auto; + align-self: center; + } + } + + /* These events span the space between the two bubble columns. */ + &.stateAlignedBetweenBubbles { + margin-inline-start: calc( + var(--event-tile-bubble-margin-inline-start) + var(--event-tile-bubble-line-margin-inline-start) + ); + margin-inline-end: calc( + var(--event-tile-bubble-margin-inline-end) + var(--event-tile-bubble-line-margin-inline-end) + ); + + .line { + width: 100%; + max-width: 100%; + margin: 0; + } + } + + /* Informational bubble rows are metadata rows, not message bubbles. */ + &.stateInfo { + display: flex; + align-items: center; + justify-content: flex-start; + padding-block: 5px; + + .slotAvatar { + position: static; + order: -1; + display: inline-flex; + margin-inline-end: var(--event-tile-bubble-gap); + border: 0; + } + + .line { + min-width: 100%; + margin: 0; + background: transparent; + } + + .slotTimestamp { + inset-block: auto; + inset-inline: -77px auto; + align-self: center; + } + + .slotPadlock { + margin-inline-start: 0; + align-self: center; + } + } + + /* UTD events have a shell-owned two-row grid. The decryption body keeps + its application-owned appearance and only receives its grid area here. */ + &.stateEncryptionFailure { + &:hover::before { + background: transparent; + } + + .line { + display: grid; + grid-template: + "reply reply" auto + "shield body" auto + / auto 1fr; + } + + .slotPadlock { + grid-area: shield; + margin-block: auto; + } + + .slotBody { + grid-area: body; + } + + .slotReplyChain { + grid-area: reply; + } + + &.stateInfo .line { + gap: 0 9px; + align-items: center; + grid-template: + "shield source" auto + / auto 1fr; + } + + &.stateInfo .slotBody { + grid-area: source; + } + } } /* ThreadView adds a narrower group timeline around EventTile. */ @@ -556,10 +986,59 @@ margin-inline-end: 8px; } } + + &.stateInfo { + .senderDetails .slotAvatar { + position: absolute; + inset-block-start: 50%; + transform: translateY(-50%); + margin-block-start: -2px; + margin-block-end: 0; + } + + .line { + padding-inline-start: 0; + line-height: 12px; + + .slotBody { + width: auto; + font-size: 12px; + } + } + + &.layoutGroup, + &.layoutIrc { + padding-top: 0; + + .senderDetails .slotAvatar { + inset-inline-start: calc(var(--event-tile-irc-timestamp-width) + 14px - 4px); + z-index: 9; + } + + .slotTimestamp { + inset-block-start: 2px; + } + + .line .slotBody { + margin-inline-start: 20px; + } + } + + &.layoutBubble { + .senderDetails .slotAvatar { + inset-inline-start: 0; + } + + .line .slotBody { + margin-inline-start: calc(56px + 14px + 6px); + } + } + } } -/* ThreadsList layout. */ -.root.shapeThreadsList { +/* Preview-shaped layouts. */ +.root.shapeThreadsList, +.root.shapeNotification { display: flex; flex-flow: row wrap; align-items: center; @@ -645,90 +1124,16 @@ } } -/* Notification layout. */ -.root.shapeNotification { - display: flex; - flex-flow: row wrap; - align-items: center; - margin-block: 13px; - padding: 8px; - border-radius: 8px; - - &:hover { - background-color: var(--cpd-color-bg-subtle-primary, #f0f1f2); +/* ThreadsList-only action-bar behavior. */ +.root.shapeThreadsList { + .slotActionBar { + visibility: hidden; } - &::after { - content: ""; - position: absolute; - inset: auto -8px -13px 56px; - height: 1px; - } - - &:last-child::after { - content: unset; - } - - &:first-child { - margin-top: 0; - } - - &:last-child { - margin-bottom: 0; - } - - .details { - width: calc(100% - var(--event-tile-preview-offset)); - margin-inline-start: var(--event-tile-preview-offset); - overflow: hidden; - } - - .slotSender { - /* In preview tiles the sender is a metadata-row profile, not the - group-layout sender above the event line. */ - display: inline-flex; - align-items: center; - flex: 1; - max-width: 100%; - min-height: 0; - margin-inline-start: 0; - line-height: normal; - } - - .slotAvatar { - position: absolute; - inset: 8px auto auto 8px; - } - - .line { - width: 100%; - box-sizing: border-box; - padding-inline-start: var(--event-tile-preview-offset); - padding-bottom: 0; - } - - .slotThreadInfo { - /* The preview is inside the padded line in these modes; it does not use - the group-layout thread-summary gutter. */ - margin-inline-start: 0; - } - - .slotTimestamp { - display: block; - font-size: 12px; - overflow: hidden; - margin-inline-start: auto; - align-self: flex-start; - position: initial; - inset: auto; - width: unset; - text-align: initial; - text-overflow: ellipsis; - } - - &.layoutGroup:hover .line { - background-color: inherit; - box-shadow: none; + &:hover .slotActionBar, + &:focus-within .slotActionBar, + &.stateActionBarFocused .slotActionBar { + visibility: visible; } } diff --git a/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.state.stories.tsx b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.state.stories.tsx new file mode 100644 index 0000000000..e5706e4a5d --- /dev/null +++ b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.state.stories.tsx @@ -0,0 +1,403 @@ +/* + * Copyright 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +import React from "react"; +import type { Meta, StoryObj } from "@storybook/react-vite"; + +import layoutMeta from "./EventTileView.stories"; + +const { + bubbleGlobals, + EventTileViewStory, + eventTileStoryDefaults, + groupGlobals, + ircGlobals, + StoryDecryptionFailureBody, + StoryDecryptionFailurePadlock, + StoryEditedBody, + StoryEmoteBody, + StoryHighlightedBody, + StoryInformationalBody, + StoryLinkedTimestamp, + StoryMediaBody, + StoryReplyChain, + StoryStickerBody, +} = layoutMeta.storyHelpers; + +const meta = { + title: "Timeline/EventTileView/States", + component: EventTileViewStory, + tags: ["autodocs"], + render: (args) => , + argTypes: { + shape: { table: { disable: true } }, + classNames: { table: { disable: true } }, + state: { table: { disable: true } }, + line: { table: { disable: true } }, + roomMessages: { table: { disable: true } }, + slots: { table: { category: "Slots" } }, + }, + args: { + shape: "Room", + state: {}, + ...eventTileStoryDefaults, + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +const interactiveTags = ["skip-test", "!snapshot"]; +const visualTags = ["!dev", "!autodocs", "snapshot"]; + +const minimalRoomSlots = { + body: eventTileStoryDefaults.slots.body, +}; + +const threadStateSlots = { + sender: eventTileStoryDefaults.slots.sender, + avatar: eventTileStoryDefaults.slots.avatar, + body: eventTileStoryDefaults.slots.body, + timestamp: , +}; + +const searchStateSlots = { + sender: eventTileStoryDefaults.slots.sender, + avatar: eventTileStoryDefaults.slots.avatar, + body: eventTileStoryDefaults.slots.body, + timestamp: , +}; + +export const Highlighted: Story = { + tags: interactiveTags, + args: { shape: "Thread", state: { highlighted: true }, slots: threadStateSlots }, +}; + +export const HighlightedSearch: Story = { + tags: interactiveTags, + args: { + shape: "Search", + state: { highlighted: true }, + slots: { ...searchStateSlots, body: }, + }, +}; + +export const Selected: Story = { + tags: interactiveTags, + args: { shape: "Thread", state: { selected: true }, slots: threadStateSlots }, +}; + +export const SelectedRoom: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "alice", + state: { selected: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const Informational: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { info: true, hasReply: false }, + slots: { body: }, + }, +}; + +export const EncryptionFailure: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "alice", + state: { encryptionFailure: true, hasReply: false }, + slots: { + body: , + padlock: , + }, + }, +}; + +export const ReplyChain: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "alice", + state: { hasReply: true }, + slots: { ...minimalRoomSlots, replyChain: }, + }, +}; + +export const BubbleContainer: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { bubbleContainer: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const LeftAlignedBubble: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { leftAlignedBubble: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const AlignedBetweenBubbles: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { alignedBetweenBubbles: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const NoBubble: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { noBubble: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const NoSender: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { noSender: true, hasReply: false }, + slots: minimalRoomSlots, + }, +}; + +export const Editing: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + state: { editing: true, hasReply: false }, + slots: { ...minimalRoomSlots, body: }, + }, +}; + +export const Emote: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + line: { emote: true }, + state: { emote: true, noBubble: true, hasReply: false }, + slots: { ...minimalRoomSlots, body: }, + }, +}; + +export const Media: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "bob", + line: { media: true }, + state: { hasReply: false }, + slots: { ...minimalRoomSlots, body: }, + }, +}; + +export const Sticker: Story = { + tags: interactiveTags, + args: { + shape: "Room", + roomMessages: "alice", + line: { sticker: true }, + state: { hasReply: false }, + slots: { ...minimalRoomSlots, body: }, + }, +}; + +export const HighlightedGroup: Story = { + name: "Highlighted - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: Highlighted.args, +}; + +export const SelectedGroup: Story = { + name: "Selected - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: Selected.args, +}; + +export const HighlightedSearchGroup: Story = { + name: "Highlighted search - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: HighlightedSearch.args, +}; + +export const SelectedRoomGroup: Story = { + name: "Selected room - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: SelectedRoom.args, +}; + +export const InformationalBubble: Story = { + name: "Informational - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: Informational.args, +}; + +export const InformationalGroup: Story = { + name: "Informational - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: Informational.args, +}; + +export const InformationalIrc: Story = { + name: "Informational - IRC - Default", + tags: visualTags, + globals: ircGlobals, + args: Informational.args, +}; + +export const EncryptionFailureBubble: Story = { + name: "Encryption failure - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: EncryptionFailure.args, +}; + +export const EncryptionFailureGroup: Story = { + name: "Encryption failure - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: EncryptionFailure.args, +}; + +export const ReplyChainBubble: Story = { + name: "Reply chain - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: ReplyChain.args, +}; + +export const ReplyChainGroup: Story = { + name: "Reply chain - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: ReplyChain.args, +}; + +export const BubbleContainerBubble: Story = { + name: "Bubble container - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: BubbleContainer.args, +}; + +export const BubbleContainerGroup: Story = { + name: "Bubble container - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: BubbleContainer.args, +}; + +export const BubbleContainerIrc: Story = { + name: "Bubble container - IRC - Default", + tags: visualTags, + globals: ircGlobals, + args: BubbleContainer.args, +}; + +export const LeftAlignedBubbleVisual: Story = { + name: "Left-aligned bubble - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: LeftAlignedBubble.args, +}; + +export const AlignedBetweenBubblesVisual: Story = { + name: "Aligned between bubbles - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: AlignedBetweenBubbles.args, +}; + +export const NoBubbleVisual: Story = { + name: "No bubble - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: NoBubble.args, +}; + +export const NoSenderVisual: Story = { + name: "No sender - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: NoSender.args, +}; + +export const EditingBubble: Story = { + name: "Editing - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: Editing.args, +}; + +export const EditingGroup: Story = { + name: "Editing - Group - Default", + tags: visualTags, + globals: groupGlobals, + args: Editing.args, +}; + +export const EditingIrc: Story = { + name: "Editing - IRC - Default", + tags: visualTags, + globals: ircGlobals, + args: Editing.args, +}; + +export const EmoteBubble: Story = { + name: "Emote - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: Emote.args, +}; + +export const EmoteIrc: Story = { + name: "Emote - IRC - Default", + tags: visualTags, + globals: ircGlobals, + args: Emote.args, +}; + +export const MediaBubble: Story = { + name: "Media - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: Media.args, +}; + +export const StickerBubble: Story = { + name: "Sticker - Bubble - Default", + tags: visualTags, + globals: bubbleGlobals, + args: Sticker.args, +}; diff --git a/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.module.css b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.module.css index 8ea63a9de1..cef3d70c1c 100644 --- a/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.module.css +++ b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.module.css @@ -108,6 +108,19 @@ white-space: nowrap; } +.searchThreadInfo { + display: inline-flex; + align-items: center; + gap: var(--cpd-space-2x, 8px); + color: var(--cpd-color-text-secondary, #626a73); + font: var(--cpd-font-body-sm-regular); +} + +.searchThreadInfo svg { + width: 18px; + height: 18px; +} + /* Match the application IRC profile treatment without adding application selectors to the shared EventTileView stylesheet. */ .ircSender { @@ -139,15 +152,6 @@ font-size: 12px; } -.notificationDot { - display: block; - flex: 0 0 8px; - width: 8px; - height: 8px; - border-radius: 50%; - background-color: var(--cpd-color-icon-success-primary, #0d9f6e); -} - .receiptAvatar { display: inline-flex; align-items: center; @@ -217,6 +221,12 @@ line-height: 1.45; } +.stickerBody { + padding: 0; + font-size: 72px; + line-height: 1; +} + .replyChain { display: grid; gap: 2px; @@ -237,6 +247,12 @@ display: flex; } +.pinnedFooter { + display: flex; + align-items: center; + gap: var(--cpd-space-2x, 8px); +} + .storyEventTile.storyOwnEvent.storyLayoutBubble .storyReactions { justify-content: flex-end; } diff --git a/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.tsx b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.tsx index 9997d61057..350c927494 100644 --- a/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.tsx +++ b/packages/shared-components/src/room/timeline/event-tile/EventTileView/EventTileView.stories.tsx @@ -13,8 +13,12 @@ import { Avatar } from "@vector-im/compound-web"; import { ThreadsIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import { useMockedViewModel } from "../../../../core/viewmodel"; -import { useEventPresentation } from "../../EventPresentation"; +import { useEventPresentation, type EventLayout } from "../../EventPresentation"; import { withViewDocs } from "../../../../../.storybook/withViewDocs"; +import { + NotificationBadgeView, + type NotificationBadgeViewSnapshot, +} from "../../../../notifications/NotificationBadgeView"; import { EventTileView, type EventTileViewProps } from "./index"; import { E2ePadlock, E2ePadlockIcon } from "./E2ePadlock"; import { DisambiguatedProfileView } from "./DisambiguatedProfile"; @@ -23,12 +27,30 @@ import { MessageTimestampView } from "../timestamp/MessageTimestampView"; import { ReactionsRowView } from "../reactions/ReactionsRow"; import { ReactionsRowButtonView } from "../reactions/ReactionsRowButton"; import { type ReactionsRowButtonTooltipViewModel } from "../reactions/ReactionsRowButtonTooltip"; +import { ImageBodyView, ImageBodyViewState, type ImageBodyViewSnapshot } from "../body/MImageBodyView"; +import { + FileBodyView, + FileBodyViewInfoIcon, + FileBodyViewState, + type FileBodyViewSnapshot, +} from "../body/MFileBodyView"; +import { + DecryptionFailureBodyView, + DecryptionFailureReason, + type DecryptionFailureBodyViewSnapshot, +} from "../body/DecryptionFailureBodyView"; +import { EventContentBodyView, type EventContentBodyViewSnapshot } from "../body/EventContentBodyView"; +import { TextualBodyView, TextualBodyViewKind, type TextualBodyViewSnapshot } from "../body/TextualBodyView"; import { ThreadSummaryView, ThreadMessagePreviewView, type ThreadMessagePreviewViewSnapshot, } from "./ThreadSummary/ThreadSummaryView"; +import { EventPreviewView, type EventPreviewViewSnapshot } from "./EventPreviewView"; +import { PinnedMessageBadge } from "./PinnedMessageBadge"; +import { TextualEventView, type TextualEventViewSnapshot } from "./TextualEventView"; import styles from "./EventTileView.stories.module.css"; +import storyMediaSrc from "../../../../../static/image-body/install-spinner.png"; type StoryBoundary = HTMLElement; const eventTileSlotTestIdPrefix = "event-tile-slot-"; @@ -138,7 +160,7 @@ const StorySender = ({ const createStorySender = ( isOwnEvent: boolean, - layout: EventTileViewProps["root"]["layout"], + layout: EventLayout, showSenderAndAvatar: boolean, ): React.ReactElement | undefined => { if (!showSenderAndAvatar) return undefined; @@ -151,49 +173,214 @@ const createStorySender = ( const createStoryAvatar = ( isOwnEvent: boolean, - layout: EventTileViewProps["root"]["layout"], + layout: EventLayout, showSenderAndAvatar: boolean, + sizeOverride?: string, ): React.ReactElement | undefined => { if (!showSenderAndAvatar) return undefined; const label = isOwnEvent ? "A" : "B"; - const size = layout === "irc" ? "14px" : "30px"; + const size = sizeOverride ?? (layout === "irc" ? "14px" : "30px"); return ; }; const StoryTimestamp = ({ className, visible = true, + linked = false, }: { className?: string; visible?: boolean; + linked?: boolean; }): React.ReactElement | null => { const vm = useMockedViewModel( - { ts: "12:34", tsSentAt: "Tuesday, 4 August 2026 at 12:34", inhibitTooltip: true }, - {}, + { + ts: "12:34", + tsSentAt: "Tuesday, 4 August 2026 at 12:34", + inhibitTooltip: true, + href: linked ? "https://example.org/event-tile-story" : undefined, + }, + linked ? { onClick: fn(), onContextMenu: fn() } : {}, ); return visible ? : null; }; -const StoryBody = (): React.ReactElement => ( -
-
Here is a realistic event tile body with enough text to show the available width.
-
This second line makes wrapping and vertical rhythm visible in Storybook.
-
-); +const StoryLinkedTimestamp = (): React.ReactElement => ; +const StoryBody = (): React.ReactElement => { + const contentSnapshot: EventContentBodyViewSnapshot = { + body: [ +
+ Here is a realistic event tile body with enough text to show the available width. +
, +
This second line makes wrapping and vertical rhythm visible in Storybook.
, + ], + className: styles.body, + }; + const contentVm = useMockedViewModel(contentSnapshot, {}); + const bodySnapshot: TextualBodyViewSnapshot = { kind: TextualBodyViewKind.TEXT }; + const bodyVm = useMockedViewModel(bodySnapshot, {}); + + return } />; +}; +const StoryPreviewBody = (): React.ReactElement => { + const snapshot: EventPreviewViewSnapshot = { + isVisible: true, + previewContent: "Can you review the draft?", + previewTooltip: "Can you review the draft?", + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StorySearchBody = (): React.ReactElement => { + const contentSnapshot: EventContentBodyViewSnapshot = { + body: [ +
+ Can you review the draft before the meeting? +
, +
The highlighted term represents the matching search result.
, + ], + className: styles.body, + }; + const contentVm = useMockedViewModel(contentSnapshot, {}); + const bodyVm = useMockedViewModel({ kind: TextualBodyViewKind.TEXT } satisfies TextualBodyViewSnapshot, {}); + return } />; +}; +const StoryFileBody = (): React.ReactElement => { + const snapshot: FileBodyViewSnapshot = { + state: FileBodyViewState.UNENCRYPTED, + showInfo: true, + infoLabel: "spec.pdf", + infoTooltip: "spec.pdf (22 KB)", + infoIcon: FileBodyViewInfoIcon.ATTACHMENT, + infoHref: "https://example.org/spec.pdf", + showDownload: true, + downloadLabel: "Download file", + downloadTitle: "Download spec.pdf", + downloadHref: "https://example.org/download/spec.pdf", + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryInformationalBody = (): React.ReactElement => { + const snapshot: TextualEventViewSnapshot = { + content: ( + <> +
Alex changed the room name to Example room.
+
This informational event demonstrates the shared textual event styling.
+ + ), + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryHighlightedBody = (): React.ReactElement => { + const contentSnapshot: EventContentBodyViewSnapshot = { + body: "Message with a highlighted word.", + formattedBody: 'Message with a highlighted word.', + className: styles.body, + }; + const contentVm = useMockedViewModel(contentSnapshot, {}); + const bodyVm = useMockedViewModel({ kind: TextualBodyViewKind.TEXT }, {}); + + return } />; +}; +const StoryEditedBody = (): React.ReactElement => { + const contentSnapshot: EventContentBodyViewSnapshot = { + body: "This message is currently being edited.", + className: styles.body, + }; + const contentVm = useMockedViewModel(contentSnapshot, {}); + const bodyVm = useMockedViewModel( + { + kind: TextualBodyViewKind.TEXT, + showEditedMarker: true, + editedMarkerText: "(edited)", + editedMarkerAriaLabel: "Edited", + editedMarkerTooltip: "This message was edited", + }, + { onEditedMarkerClick: fn() }, + ); + + return } />; +}; +const StoryEmoteBody = (): React.ReactElement => { + const contentSnapshot: EventContentBodyViewSnapshot = { + body: "waves hello to the room", + className: styles.body, + }; + const contentVm = useMockedViewModel(contentSnapshot, {}); + const bodyVm = useMockedViewModel( + { kind: TextualBodyViewKind.EMOTE, emoteSenderName: "Bob" }, + { onEmoteSenderClick: fn() }, + ); + + return } />; +}; const StoryReplyChain = (): React.ReactElement => (
Taylor Example Earlier message quoted in this reply.
); -const StoryActionBar = (): React.ReactElement | null => { +const StoryMediaBody = (): React.ReactElement => { + const snapshot: ImageBodyViewSnapshot = { + state: ImageBodyViewState.READY, + alt: "Example media", + src: storyMediaSrc, + thumbnailSrc: storyMediaSrc, + maxWidth: 320, + maxHeight: 180, + aspectRatio: "16 / 9", + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryStickerBody = (): React.ReactElement => { + const snapshot: ImageBodyViewSnapshot = { + state: ImageBodyViewState.READY, + alt: "Example sticker", + src: storyMediaSrc, + thumbnailSrc: storyMediaSrc, + maxWidth: 240, + maxHeight: 240, + aspectRatio: "1 / 1", + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryDecryptionFailureBody = (): React.ReactElement => { + const snapshot: DecryptionFailureBodyViewSnapshot = { + decryptionFailureReason: DecryptionFailureReason.UNABLE_TO_DECRYPT, + isLocalDeviceVerified: true, + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryDecryptionFailurePadlock = (): React.ReactElement => ( + +); +const StoryNotificationBadge = (): React.ReactElement => { + const snapshot: NotificationBadgeViewSnapshot = { + shouldRender: true, + isVisible: true, + isNotification: true, + isHighlight: false, + isKnocked: false, + badgeType: "dot", + symbol: null, + isClickable: false, + showUnsentTooltip: false, + }; + const vm = useMockedViewModel(snapshot, {}); + return ; +}; +const StoryActionBar = ({ isPinned = false }: { isPinned?: boolean } = {}): React.ReactElement | null => { const vm = useMockedViewModel( { actions: [ActionBarAction.React, ActionBarAction.Reply, ActionBarAction.Options], presentation: "icon" as const, isDownloadEncrypted: false, isDownloadLoading: false, - isPinned: false, + isPinned, isQuoteExpanded: false, isThreadReplyAllowed: true, }, @@ -201,6 +388,22 @@ const StoryActionBar = (): React.ReactElement | null => { ); return ; }; +const StoryPinnedActionBar = (): React.ReactElement => ; +const StoryThreadListActionBar = (): React.ReactElement => { + const vm = useMockedViewModel( + { + actions: [ActionBarAction.ViewInRoom, ActionBarAction.CopyLink], + presentation: "icon" as const, + isDownloadEncrypted: false, + isDownloadLoading: false, + isPinned: false, + isQuoteExpanded: false, + isThreadReplyAllowed: false, + }, + { onViewInRoomClick: fn(), onCopyLinkClick: fn() }, + ); + return ; +}; const useStoryReactionTooltipVm = (caption: string): ReactionsRowButtonTooltipViewModel => useMockedViewModel({ formattedSenders: "Alice Example and Bob Example", caption }, {}); @@ -243,6 +446,12 @@ const StoryFooter = (): React.ReactElement => { ); }; +const StoryPinnedFooter = (): React.ReactElement => ( +
+ + +
+); const storyThreadPreview: ThreadMessagePreviewViewSnapshot = { isVisible: true, avatar: { @@ -275,7 +484,7 @@ const StoryThreadInfo = (): React.ReactElement => { /** The ThreadsList view uses the compact inline replies preview, not ThreadSummaryView. */ const StoryThreadListInfo = (): React.ReactElement => { - const previewVm = useMockedViewModel(storyThreadPreview, {}); + const previewVm = useMockedViewModel({ ...storyThreadPreview, showDisplayName: false }, {}); return (
@@ -285,6 +494,12 @@ const StoryThreadListInfo = (): React.ReactElement => {
); }; +const StorySearchThreadInfo = (): React.ReactElement => ( +
+ + View in thread + +); const StoryReceipt = (): React.ReactElement => ( @@ -330,9 +545,8 @@ const baseRoot: EventTileViewProps["root"] = { scrollToken: "event-tile-story", permalink: "https://example.org/event-tile-story", eventId: "$event-tile-story", - layout: "group", shape: "Room", - state: { isOwnEvent: false, hasReply: true }, + state: { isOwnEvent: false, hasReply: false }, }; const roomSlots: EventTileViewProps["slots"] = { @@ -341,7 +555,6 @@ const roomSlots: EventTileViewProps["slots"] = { body: , timestamp: , padlock: , - replyChain: , actionBar: , footer: , threadInfo: , @@ -349,19 +562,38 @@ const roomSlots: EventTileViewProps["slots"] = { contextMenu: , }; +/** Slots for the default Room-like shapes without a context menu fixture. */ +const defaultShapeSlots: EventTileViewProps["slots"] = { + sender: , + avatar: , + body: , + timestamp: , + padlock: , + actionBar: , + footer: , + threadInfo: , + receipt: , +}; + +const threadSlots: EventTileViewProps["slots"] = { + ...defaultShapeSlots, + avatar: , + threadInfo: undefined, +}; + type EventTileStoryProps = Omit & { shape: EventTileViewProps["root"]["shape"]; state?: Partial; - roomMessages?: "boundaries" | "alice"; + roomMessages?: "boundaries" | "alice" | "bob"; }; const createStoryTimestamp = ( - layout: EventTileViewProps["root"]["layout"], + layout: EventLayout, isLast: boolean, showActionBar: boolean, ): React.ReactElement | undefined => { const showTimestamp = layout === "irc" || isLast || showActionBar; - return showTimestamp ? : undefined; + return showTimestamp ? : undefined; }; const createRoomStorySlots = ({ @@ -439,8 +671,12 @@ function EventTileViewStoryContent({ const showActionBar = interaction.hovered || interaction.focused; const timestamp = createStoryTimestamp(layout, isLast, showActionBar); const showSenderAndAvatar = layout === "irc" || !tileState.continuation; - const sender = createStorySender(isOwnEvent, layout, showSenderAndAvatar); - const avatar = createStoryAvatar(isOwnEvent, layout, showSenderAndAvatar); + const sender = createStorySender( + isOwnEvent, + layout, + showSenderAndAvatar && !tileState.noSender && !tileState.info, + ); + const avatar = createStoryAvatar(isOwnEvent, layout, showSenderAndAvatar, tileState.info ? "14px" : undefined); const slots = shape === "Room" ? createRoomStorySlots({ @@ -474,7 +710,6 @@ function EventTileViewStoryContent({ id: `${baseRoot.id}-${suffix}`, scrollToken: `${baseRoot.scrollToken}-${suffix}`, eventId: `${baseRoot.eventId}-${suffix}`, - layout, shape, state: { ...baseRoot.state, @@ -509,6 +744,10 @@ function EventTileViewStoryContent({ return renderTile(true, "alice-single", { continuation: false, lastInSection: true }, true); } + if (roomMessages === "bob") { + return renderTile(false, "bob-single", { continuation: false, lastInSection: true }, true); + } + return ( <> {renderTile(false, "bob-first", { continuation: false, lastInSection: false })} @@ -543,20 +782,43 @@ const eventTileStoryDefaults = { slots: roomSlots, }; +const groupGlobals = { eventLayout: "group", eventDensity: "default" } as const; +const bubbleGlobals = { + eventLayout: "bubble", + eventDensity: "default", +} as const; +const ircGlobals = { eventLayout: "irc", eventDensity: "default" } as const; +const compactGroupGlobals = { eventLayout: "group", eventDensity: "compact" } as const; + +const storyHelpers = { + EventTileViewStory, + eventTileStoryDefaults, + bubbleGlobals, + groupGlobals, + ircGlobals, + compactGroupGlobals, + StoryDecryptionFailureBody, + StoryDecryptionFailurePadlock, + StoryEditedBody, + StoryEmoteBody, + StoryHighlightedBody, + StoryInformationalBody, + StoryLinkedTimestamp, + StoryMediaBody, + StoryReplyChain, + StoryStickerBody, +}; + const meta = { - title: "Timeline/EventTileView", + title: "Timeline/EventTileView/Shapes", component: EventTileViewStory, tags: ["autodocs"], render: (args) => , argTypes: { shape: { - control: "select", - options: ["Room", "Thread", "ThreadsList", "File", "Notification", "Search", "Pinned"], + table: { disable: true }, }, classNames: { table: { disable: true } }, - state: { - control: "object", - }, onMouseEnter: { table: { disable: true } }, onMouseLeave: { table: { disable: true } }, onFocus: { table: { disable: true } }, @@ -570,88 +832,167 @@ const meta = { }, args: { shape: "Room", - state: {}, ...eventTileStoryDefaults, }, -} satisfies Meta; + storyHelpers, +} satisfies Meta & { storyHelpers: typeof storyHelpers }; export default meta; type Story = StoryObj; -export const Room: Story = {}; +const interactiveTags = ["skip-test", "!snapshot"]; +const visualTags = ["!dev", "!autodocs", "snapshot"]; + +export const Room: Story = { tags: interactiveTags }; export const ThreadsList: Story = { + tags: interactiveTags, args: { shape: "ThreadsList", slots: { sender: , - avatar: , - body: , + avatar: , + body: , timestamp: , - notificationBadge: