Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Modal #349

Merged
merged 9 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
63 changes: 44 additions & 19 deletions packages/fuselage/.storybook/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,53 @@ import React from 'react';

import { Box } from '../src';

export function PropsVariationSection({ component: Component, common = {}, xAxis = {}, yAxis = {} }) {
return <Box is='table' marginBlock='x16' marginInline='auto' style={{ borderCollapse: 'collapse' }}>
<Box is='thead'>
<Box is='tr'>
<Box is='th' />
{Object.keys(xAxis).map((xVariation, key) =>
<Box key={key} is='th' color='hint' fontScale='c1'>{xVariation}</Box>)}
</Box>
</Box>
<Box is='tbody'>
{Object.entries(yAxis).map(([yVariation, yProps], y) => (
<Box key={y} is='tr'>
<Box is='th' color='hint' fontScale='c1'>{yVariation}</Box>
{Object.values(xAxis).map((xProps, x) => <Box key={x} is='td' margin='none' paddingBlock='x8' paddingInline='x16'>
<Box display='flex' alignItems='center' justifyContent='center'>
<Component {...common} {...xProps} {...yProps} />
export function PropsVariationSection({
component: Component,
common = {},
xAxis = {},
yAxis = {},
}) {
return (
<Box
is='table'
marginBlock='x16'
marginInline='auto'
style={{ borderCollapse: 'collapse' }}
>
<Box is='thead'>
<Box is='tr'>
<Box is='th' />
{Object.keys(xAxis).map((xVariation, key) => (
<Box key={key} is='th' color='hint' fontScale='c1'>
{xVariation}
</Box>
</Box>)}
))}
</Box>
))}
</Box>
<Box is='tbody'>
{Object.entries(yAxis).map(([yVariation, yProps], y) => (
<Box key={y} is='tr'>
<Box is='th' color='hint' fontScale='c1'>
{yVariation}
</Box>
{Object.values(xAxis).map((xProps, x) => (
<Box
key={x}
is='td'
margin='none'
paddingBlock='x8'
paddingInline='x16'
>
<Box display='flex' alignItems='center' justifyContent='center'>
<Component {...common} {...xProps} {...yProps} />
</Box>
</Box>
))}
</Box>
))}
</Box>
</Box>
</Box>;
);
}

export const exampleAvatar = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAA
Expand Down
7 changes: 3 additions & 4 deletions packages/fuselage/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ module.exports = {
addons: [
'@storybook/addon-actions',
'@storybook/addon-backgrounds',
'@storybook/addon-controls',
'@storybook/addon-docs',
'@storybook/addon-knobs',
'@storybook/addon-viewport',
...process.env.NODE_ENV === 'production' ? ['@storybook/addon-jest'] : [],
],
stories: [
'../src/**/*.stories.{mdx,js}',
...(process.env.NODE_ENV === 'production' ? ['@storybook/addon-jest'] : []),
],
stories: ['../src/**/*.stories.{mdx,js}'],
webpackFinal: (config) => {
config.module.rules.push({
test: /\.scss$/,
Expand Down
35 changes: 19 additions & 16 deletions packages/fuselage/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@ import '@rocket.chat/icons/dist/rocketchat.css';
import '@rocket.chat/fuselage-polyfills';

addParameters({
background: {
grid: {
cellSize: 4,
},
},
docs: {
container: DocsContainer,
page: DocsPage,
},
grid: {
cellSize: 4,
},
options: {
showRoots: true,
storySort: ([, a], [, b]) =>
a.kind.localeCompare(b.kind),
storySort: ([, a], [, b]) => a.kind.localeCompare(b.kind),
},
viewport: {
viewports: Object.entries(breakpointTokens).reduce((obj, [name, { minViewportWidth }]) => ({
...obj,
[name]: {
name,
styles: {
width: `${ minViewportWidth }px`,
height: '90%',
viewports: Object.entries(breakpointTokens).reduce(
(obj, [name, { minViewportWidth }]) => ({
...obj,
[name]: {
name,
styles: {
width: `${minViewportWidth}px`,
height: '90%',
},
type: 'desktop',
},
type: 'desktop',
},
}), {}),
}),
{}
),
},
});

Expand Down
17 changes: 10 additions & 7 deletions packages/fuselage/fuselage.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module '@rocket.chat/fuselage' {
import { css } from '@rocket.chat/css-in-js';
import type { css } from '@rocket.chat/css-in-js';

import {
AllHTMLAttributes,
Context,
Expand Down Expand Up @@ -226,19 +227,21 @@ declare module '@rocket.chat/fuselage' {
};

type ModalProps = BoxProps;
type ModalHeaderProps = BoxProps;
type ModalTitleProps = BoxProps;
type ModalBackdropProps = BoxProps;
type ModalCloseProps = BoxProps;
type ModalContentProps = BoxProps;
type ModalFooterProps = BoxProps;
type ModalBackdropProps = BoxProps;
type ModalHeaderProps = BoxProps;
type ModalThumbProps = BoxProps;
type ModalTitleProps = BoxProps;
export const Modal: ForwardRefExoticComponent<ModalProps> & {
Header: ForwardRefExoticComponent<ModalHeaderProps>;
Title: ForwardRefExoticComponent<ModalTitleProps>;
Backdrop: ForwardRefExoticComponent<ModalBackdropProps>;
Close: ForwardRefExoticComponent<ModalCloseProps>;
Content: ForwardRefExoticComponent<ModalContentProps>;
Footer: ForwardRefExoticComponent<ModalFooterProps>;
Backdrop: ForwardRefExoticComponent<ModalBackdropProps>;
Header: ForwardRefExoticComponent<ModalHeaderProps>;
Thumb: ForwardRefExoticComponent<ModalThumbProps>;
Title: ForwardRefExoticComponent<ModalTitleProps>;
};

type NumberInputProps = BoxProps;
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@rocket.chat/fuselage-polyfills": "^0.19.0",
"@storybook/addon-actions": "^6.0.21",
"@storybook/addon-backgrounds": "^6.0.21",
"@storybook/addon-controls": "^6.1.10",
"@storybook/addon-docs": "^6.0.21",
"@storybook/addon-jest": "^6.0.21",
"@storybook/addon-knobs": "^6.0.21",
Expand Down
11 changes: 11 additions & 0 deletions packages/fuselage/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

import { Box } from '../Box';

export const Modal = React.forwardRef(({ children, ...props }, ref) => (
<Box is='dialog' rcx-modal {...props}>
<Box ref={ref} rcx-modal__inner elevation='2'>
{children}
</Box>
</Box>
));
10 changes: 10 additions & 0 deletions packages/fuselage/src/components/Modal/Modal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { Modal } from '../..';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Modal />, div);
ReactDOM.unmountComponentAtNode(div);
});
28 changes: 28 additions & 0 deletions packages/fuselage/src/components/Modal/Modal.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { ButtonGroup, Button, Modal } from '../..';

export default {
title: 'Containers/Modal',
component: Modal,
parameters: {
jest: ['Modal/Modal.spec.js'],
},
};

export const _Modal = () => (
<Modal>
<Modal.Header>
<Modal.Thumb url='data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==' />
<Modal.Title>Modal Header</Modal.Title>
<Modal.Close />
</Modal.Header>
<Modal.Content>Modal Body</Modal.Content>
<Modal.Footer>
<ButtonGroup align='end'>
<Button>Cancel</Button>
<Button primary>Submit</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>
);
54 changes: 0 additions & 54 deletions packages/fuselage/src/components/Modal/Modal.stories.mdx

This file was deleted.

74 changes: 74 additions & 0 deletions packages/fuselage/src/components/Modal/Modal.styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@use '../../styles/colors.scss';
@use '../../styles/lengths.scss';
@use '../../styles/typography.scss';

.rcx-modal {
position: static;

display: flex;

width: 100%;
max-height: 100%;
margin: auto;

background: none;

&__inner {
display: flex;
flex-direction: column;
flex-grow: 1;

min-width: 0;
padding: 0;

color: colors.foreground(default);
border-radius: 2px;
background-color: colors.surface();
@include typography.use-font-scale(p1);
}

&__header {
margin: 32px;
}

&__header-inner {
display: flex;
flex-wrap: nowrap;
align-items: center;

margin: -8px;
}

&__title {
@include typography.use-text-ellipsis;
flex-grow: 1;
flex-shrink: 1;

white-space: nowrap;

color: colors.foreground('default');
@include typography.use-font-scale(h1);
}

&__backdrop {
position: fixed;

z-index: 100;
inset: 0;

background-color: colors.neutral(800, $alpha: 0.5);
}

&__footer {
margin: 32px;
}

&__content-wrapper {
margin-inline: 32px;
}

@include on-breakpoint(sm) {
max-width: lengths.size(640);
padding: lengths.padding(16);
}
}
5 changes: 5 additions & 0 deletions packages/fuselage/src/components/Modal/ModalBackdrop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

import { Box } from '../Box';

export const ModalBackdrop = (props) => <Box rcx-modal__backdrop {...props} />;
10 changes: 10 additions & 0 deletions packages/fuselage/src/components/Modal/ModalClose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

import { Button } from '../Button';
import { Icon } from '../Icon';

export const ModalClose = (props) => (
<Button small ghost flexShrink={0} {...props}>
<Icon name='cross' size='x24' />
</Button>
);
13 changes: 13 additions & 0 deletions packages/fuselage/src/components/Modal/ModalContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

import { Box, Scrollable } from '../Box';

export const ModalContent = ({ children, onScrollContent, ...props }) => (
<Scrollable vertical onScrollContent={onScrollContent}>
<Box rcx-modal__content>
<Box rcx-modal__content-wrapper {...props}>
{children}
</Box>
</Box>
</Scrollable>
);
Loading