Skip to content

Commit

Permalink
Feat: mdx thumbs (#10)
Browse files Browse the repository at this point in the history
* File Thumb mdx file

* tests pass

* Image Thumb MDX

* attachment required + test patch
  • Loading branch information
alamorre authored Nov 9, 2021
1 parent c5ee8f7 commit 3078d3c
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 70 deletions.
7 changes: 5 additions & 2 deletions src/ChatFeed/FileThumb/.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Default as Thing } from './stories';

import { FileThumb as Thing } from '.';

import { fileAttachment } from '../../util/mocks';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.render(<Thing attachment={fileAttachment} />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
6 changes: 3 additions & 3 deletions src/ChatFeed/FileThumb/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { styles } from './styles';

export const FileThumb: React.FC<Props> = ({
attachment,
children,
isLoading = false,
children = 'Loading...',
style = {},
loadingStyle = {},
}) => {
Expand All @@ -25,7 +25,7 @@ export const FileThumb: React.FC<Props> = ({
if (isLoading || !attachment) {
return (
<div style={{ ...styles.loadingContainer, ...loadingStyle }}>
{children}
{children ? children : 'Loading...'}
</div>
);
}
Expand All @@ -40,7 +40,7 @@ export const FileThumb: React.FC<Props> = ({
onMouseLeave={() => setHovered(false)}
onClick={() => window.open(attachment.file)}
>
{getFileName(attachment.file)}
{children ? children : getFileName(attachment.file)}
</div>
);
};
2 changes: 1 addition & 1 deletion src/ChatFeed/FileThumb/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Properties } from 'csstype';
import { AttachmentProps } from '../../util/interfaces';

export interface Props {
attachment?: AttachmentProps;
attachment: AttachmentProps;
isLoading?: boolean;
children?: ReactNode;
style?: Properties;
Expand Down
105 changes: 105 additions & 0 deletions src/ChatFeed/FileThumb/stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { ArgsTable, Meta, Story, Canvas } from '@storybook/addon-docs';

import { FileOutlined } from '@ant-design/icons';

import { FileThumb } from '.';
import { Props } from './props';

import { fileAttachment } from '../../util/mocks';

<Meta title="ChatFeed/FileThumb" component={FileThumb} />

export const Template = ({
children,
isLoading,
attachment,
style,
loadingStyle,
}) => (
<FileThumb
attachment={attachment}
isLoading={isLoading}
style={style}
loadingStyle={loadingStyle}
>
{children}
</FileThumb>
);

# File Thumb

File Thumbs are used to display a file, which isn't an image, and was sent by a user.

A File Thumb will display the file's name, and will open the file in another tab once clicked.

The component requires an `attachment` prop to display the correct file info.

The component takes optional `isLoading`, `children`, `style`, and `loadingStyle` props.

## Default

<Story name="Default" args={{ attachment: fileAttachment }}>
{Template.bind({})}
</Story>

<ArgsTable story="Default" />

## Is Loading

You can set the `isLoading` prop to `true` and the message will appear to be loading/processing the file.

This is used when a message is sending and has not delivered yet.

<Canvas>
<Story
name="Is Loading"
args={{ attachment: fileAttachment, isLoading: true }}
>
{Template.bind({})}
</Story>
</Canvas>

## Children

You can put child props within the `<FileThumb>` component. This lets you customize what is in a file thumb's body.

<Canvas>
<Story
name="Children"
args={{
attachment: fileAttachment,
children: (
<div>
<FileOutlined /> Custom Text and Icon
</div>
),
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Custom Style

You can customize the CSS style of a file component too.

<Canvas>
<Story
name="Custom Style"
args={{
attachment: fileAttachment,
style: {
backgroundColor: 'rgb(74, 81, 98)',
border: 'none',
color: 'white',
},
loadingStyle: {
backgroundColor: 'rgb(74, 81, 98)',
border: 'none',
color: 'white',
},
}}
>
{Template.bind({})}
</Story>
</Canvas>
29 changes: 0 additions & 29 deletions src/ChatFeed/FileThumb/stories.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/ChatFeed/FileThumb/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const styles = {
loadingContainer: {
fontFamily: 'Avenir',
color: 'white',
padding: '14px',
padding: '13px',
display: 'inline-block',
borderRadius: '14px',
marginRight: '2px',
Expand Down
5 changes: 3 additions & 2 deletions src/ChatFeed/ImageThumb/.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { Default as Thing } from './stories';
import { ImageThumb as Thing } from '.';
import { imageAttachment } from '../../util/mocks';

describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
ReactDOM.render(<Thing attachment={imageAttachment} />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
4 changes: 2 additions & 2 deletions src/ChatFeed/ImageThumb/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { styles } from './styles';

export const ImageThumb: React.FC<Props> = ({
attachment,
children,
isLoading = false,
children = 'Loading...',
style = {},
loadingStyle = {},
}) => {
Expand All @@ -20,7 +20,7 @@ export const ImageThumb: React.FC<Props> = ({
if (isLoading || !attachment) {
return (
<div style={{ ...styles.loadingContainer, ...loadingStyle }}>
{children}
{children ? children : 'Loading...'}
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChatFeed/ImageThumb/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Properties } from 'csstype';
import { AttachmentProps } from '../../util/interfaces';

export interface Props {
attachment?: AttachmentProps;
attachment: AttachmentProps;
isLoading?: boolean;
children?: ReactNode;
style?: Properties;
Expand Down
105 changes: 105 additions & 0 deletions src/ChatFeed/ImageThumb/stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { ArgsTable, Meta, Story, Canvas } from '@storybook/addon-docs';

import { FileOutlined } from '@ant-design/icons';

import { ImageThumb } from '.';
import { Props } from './props';

import { imageAttachment } from '../../util/mocks';

<Meta title="ChatFeed/ImageThumb" component={ImageThumb} />

export const Template = ({
children,
isLoading,
attachment,
style,
loadingStyle,
}) => (
<ImageThumb
attachment={attachment}
isLoading={isLoading}
style={style}
loadingStyle={loadingStyle}
>
{children}
</ImageThumb>
);

# File Thumb

Image Thumbs are used to display an Image, and was sent by a user.

An Image Thumb will display a cropped version of the image, and will expand in another tab once clicked.

The component requires an `attachment` prop to display the correct image / info.

The component takes optional `isLoading`, `children`, `style`, and `loadingStyle` props.

## Default

<Story name="Default" args={{ attachment: imageAttachment }}>
{Template.bind({})}
</Story>

<ArgsTable story="Default" />

## Is Loading

You can set the `isLoading` prop to `true` and the message will appear to be loading/processing the file.

This is used when a message is sending and has not delivered yet.

<Canvas>
<Story
name="Is Loading"
args={{ attachment: imageAttachment, isLoading: true }}
>
{Template.bind({})}
</Story>
</Canvas>

## Children

You can put child props within the `<ImageThumb>` component. This lets you customize what is in an image thumb's body.

<Canvas>
<Story
name="Children"
args={{
attachment: imageAttachment,
isLoading: true,
children: (
<div style={{ color: 'black', padding: '12px' }}>
<FileOutlined /> Custom Text
</div>
),
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Custom Style

You can customize the CSS style of an image thumb component too.

<Canvas>
<Story
name="Custom Style"
args={{
attachment: imageAttachment,
style: {
backgroundColor: 'rgb(74, 81, 98)',
border: 'none',
},
loadingStyle: {
backgroundColor: 'rgb(74, 81, 98)',
border: 'none',
color: 'white',
},
}}
>
{Template.bind({})}
</Story>
</Canvas>
29 changes: 0 additions & 29 deletions src/ChatFeed/ImageThumb/stories.tsx

This file was deleted.

0 comments on commit 3078d3c

Please sign in to comment.