import type { Meta, StoryFn } from '@storybook/react' import React from 'react' import { LocalMessage } from 'stream-chat' import { now } from '../../stories/decorators/storyTime' import { MessageTag } from './MessageTag' type ComponentProps = React.ComponentProps const meta: Meta = { title: 'MessageTag', component: MessageTag, parameters: { layout: 'centered', }, } export default meta interface MockMessageOptions { metadata?: { custom_type?: 'MESSAGE_CHATBOT' | 'MESSAGE_PAID' amount_text?: string } text?: string } const createMockMessage = (options?: MockMessageOptions): LocalMessage => ({ id: 'msg-1', text: options?.text ?? 'Hello world', type: 'regular', created_at: now(), updated_at: now(), metadata: options?.metadata, }) as LocalMessage const Template: StoryFn = (args) => { return (
) } // Per-variant stories stay in Storybook for browsing/design review but are // individually covered by rows in AllVariants — skip in Chromatic to keep // the variant matrix as the single snapshot source of truth. const skipInChromatic = { chromatic: { disableSnapshot: true } } export const ChatbotReceiverText: StoryFn = Template.bind({}) ChatbotReceiverText.args = { message: createMockMessage({ metadata: { custom_type: 'MESSAGE_CHATBOT' } }), } ChatbotReceiverText.parameters = skipInChromatic export const ChatbotSenderText: StoryFn = (args) => { return (
) } ChatbotSenderText.args = { message: createMockMessage({ metadata: { custom_type: 'MESSAGE_CHATBOT' } }), isMyMessage: true, } ChatbotSenderText.parameters = skipInChromatic export const ChatbotSenderAttachment: StoryFn = Template.bind( {} ) ChatbotSenderAttachment.args = { message: createMockMessage({ metadata: { custom_type: 'MESSAGE_CHATBOT' } }), isMyMessage: true, hasAttachment: true, } ChatbotSenderAttachment.parameters = skipInChromatic export const Paid: StoryFn = Template.bind({}) Paid.args = { message: createMockMessage({ metadata: { custom_type: 'MESSAGE_PAID', amount_text: '$10.00' }, }), } Paid.parameters = skipInChromatic export const NoTag: StoryFn = Template.bind({}) NoTag.args = { message: createMockMessage(), } NoTag.parameters = skipInChromatic export const AllVariants: StoryFn = () => { return (
Chatbot (receiver):
Chatbot (sender):
Chatbot (attachment):
Paid:
No tag: (renders nothing)
) } // AllVariants is the single Chromatic snapshot for message tags: the per-variant // stories above are skipped (kept for local browsing + controls) and this grid is // the visual-regression guard — one snapshot covering every tag layout at once. AllVariants.parameters = { chromatic: { disableSnapshot: false } }