import React, { ReactElement } from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import Message, { MessageProps } from './Message';
import TextBubble from './Bubble/TextBubble/TextBubble';
import FileBubble from './Bubble/FileBubble/FileBubble';
import ImageBubble from './Bubble/ImageBubble/ImageBubble';
import AudioBubble from './Bubble/AudioBubble/AudioBubble';
import VideoBubble from './Bubble/VideoBubble/VideoBubble';
function createBubbleByType(
type: 'incoming' | 'outgoing',
children?: ReactElement,
) {
const isTextBubbleType = children?.type === TextBubble;
const isFileBubbleType = children?.type === FileBubble;
const isImageBubbleType = children?.type === ImageBubble;
const isAudioBubbleType = children?.type === AudioBubble;
const isVideoBubbleType = children?.type === VideoBubble;
if (isTextBubbleType) {
return (
);
}
if (isFileBubbleType) {
return (
);
}
if (isImageBubbleType) {
return (
);
}
if (isAudioBubbleType) {
return (
);
}
if (isVideoBubbleType) {
return (
);
}
return undefined;
}
function getChildrenByType(type: string, children?: ReactElement) {
if ((type === 'incoming' || type === 'outgoing') && children) {
return createBubbleByType(type, children);
}
return undefined;
}
// const meta: Meta = {
const meta: Meta = {
tags: ['autodocs'],
title: '@quickblox-react-ui-kit/Presentation/ui-components/Message',
component: Message,
decorators: [
(StoryFn, context) => {
const { type, children } = context.args;
const modifiedArgs = {
...context.args,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
children: getChildrenByType(type, children),
};
return ;
},
],
parameters: {
viewport: {
viewports: INITIAL_VIEWPORTS,
},
},
args: {
userName: 'Nate',
time: '16:58',
type: 'incoming',
status: undefined,
enableSelect: true,
isSelect: false,
disabled: false,
// bottomPart: (
// {
// console.log('orig');
// }}
// originalTextMessage={false}
// waitAIWidget={false}
// onTranslate={() => {
// console.log('translate');
// }}
// />
// ),
// additionalPart: (
// {
// console.log('ai-assist');
// }}
// waitAIWidget={false}
// />
// ),
},
argTypes: {
userName: {
table: {
type: { summary: 'string' },
defaultValue: {
summary: '',
},
},
description: 'User name',
},
avatar: {
control: false,
table: {
type: { summary: 'ReactElement' },
},
description: 'Message sender avatar',
},
time: {
table: {
type: { summary: 'string' },
defaultValue: {
summary: '',
},
},
description: 'Time of sending the message',
},
type: {
table: {
type: { summary: 'outgoing | incoming' },
defaultValue: {
summary: 'incoming',
},
},
control: 'radio',
options: ['incoming', 'outgoing'],
description: 'The type of message can be either outgoing or incoming',
},
enableSelect: {
description: 'Enables the option to select a message',
},
isSelect: {
description: 'The status of message selection',
},
disabled: {
description: 'Active',
},
status: {
table: {
type: { summary: 'sent | delivered | viewed | error' },
defaultValue: {
summary: '',
},
},
control: 'select',
options: ['sent', 'delivered', 'viewed', 'error'],
description: 'The status of the message',
},
children: {
table: {
type: { summary: 'ReactElement' },
},
description: 'Message bubble',
control: 'select',
options: [
'TextMessage',
'FileMessage',
'ImageMessage',
'AudioMessage',
'VideoMessage',
],
mapping: {
TextMessage: (
),
FileMessage: (
),
ImageMessage: (
),
AudioMessage: (
),
VideoMessage: (
),
},
},
subtype: {
description: 'Additional message subtype',
},
onSelect: {
table: {
type: { summary: 'function' },
},
description: 'The function responsible for message selection',
},
bottomPart: {
table: {
type: { summary: 'ReactElement' },
},
control: false,
description: 'The bottom part of the message layout',
},
additionalPart: {
table: {
type: { summary: 'ReactElement' },
},
control: false,
description: 'Additional section of the message layout',
},
},
};
export default meta;
type Story = StoryObj;
export const MessageText: Story = {
args: {
children: ,
},
};
export const MessageImage: Story = {
args: {
children: (
),
},
};
// export const MessageVideo: Story = {
// args: {
// children: (
//
// ),
// },
// };
export const MessageFile: Story = {
args: {
children: (
),
},
};
// export const MessageTextWithAIfeatures: Story = {
// args: {
// children: ,
// bottomPart: (
// console.log('Function not implemented.')}
// onError={() => console.log('Function not implemented.')}
// onLoading={() => console.log('Function not implemented.')}
// />
// ),
// additionalPart: (
// console.log('Function not implemented.')}
// onLoading={() => console.log('Function not implemented.')}
// />
// ),
// },
// };