generic modal
This commit is contained in:
1 parent
dc955fcee3
commit
48aae0bf98
3 files changed
+93
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { Modal } from ".";
|
||||
import { useState } from 'react';
|
||||
import { Button } from "components/Inputs/Button";
|
||||
|
||||
|
||||
export default {
|
||||
title: 'Modal',
|
||||
component: Modal,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
args: {
|
||||
open: true
|
||||
}
|
||||
} as ComponentMeta<typeof Modal>
|
||||
|
||||
export const Simple: ComponentStory<typeof Modal> = args => {
|
||||
return <>
|
||||
<Modal {...args}>
|
||||
<div>Hello World!</div>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
export const WithButtons: ComponentStory<typeof Modal> = args => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <>
|
||||
<Button onClick={() => setOpen(!open)}>Open Me!</Button>
|
||||
<Modal open={open}>
|
||||
<div>Hello World!</div>
|
||||
<Button onClick={() => setOpen(!open)}>Close Me!</Button>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { FC } from "react";
|
||||
import { createAppUseStyles } from "styles/theme";
|
||||
import Color from 'chroma-js';
|
||||
|
||||
export interface ModalStyleProps {
|
||||
open: boolean;
|
||||
}
|
||||
export interface Props extends ModalStyleProps {
|
||||
}
|
||||
const useModalStyle = createAppUseStyles<ModalStyleProps>(theme => ({
|
||||
root: ({ open }) => ({
|
||||
display: open ? 'flex' : 'none',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
zIndex: open ? 10 : -1,
|
||||
position: 'absolute',
|
||||
height: '100vh',
|
||||
width: '100vw',
|
||||
top: 0,
|
||||
left: 0,
|
||||
}),
|
||||
background: {
|
||||
zIndex: 5,
|
||||
position: 'absolute',
|
||||
height: '100vh',
|
||||
width: '100vw',
|
||||
top: 0,
|
||||
left: 0,
|
||||
backgroundColor: Color(theme.secondary).alpha(0.5).hex(),
|
||||
},
|
||||
inner: {
|
||||
zIndex: 10,
|
||||
maxWidth: '80%',
|
||||
maxHeight: '60%',
|
||||
minHeight: '200px',
|
||||
minWidth: '200px',
|
||||
padding: '15px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: theme.primary,
|
||||
borderSize: '1px',
|
||||
borderStyle: 'solid',
|
||||
borderColor: theme.primaryAccent,
|
||||
borderRadius: '10px',
|
||||
color: theme.primaryAccent,
|
||||
}
|
||||
}));
|
||||
export const Modal: FC<Props> = ({
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
const { classes } = useModalStyle(props);
|
||||
return <div className={classes.root}>
|
||||
<div className={classes.background} />
|
||||
<div className={classes.inner}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
Reference in new issue
Block a user