Skip to content

Commit

Permalink
feat(atoms): add feature to auto scroll body in the dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Nov 19, 2018
1 parent 5f00a45 commit 3e996ae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/atoms/Dialog/DialogBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ const name = 'dialogBody';
const theme = createTheme(name, {
modifiers: {
scrollable: {
maxHeight: 'calc(60vh - 14rem)',
overflow: 'auto',
},
},
defaults: {
scrollable: false,
scrollable: true,
},
});

const DialogBodyTag = createStyledTag(name, {});
const DialogBodyTag = createStyledTag(name, {
flexShrink: 1,
});

const DialogBody = ({ children, ...rest }: DialogBodyProps) => (
<DialogBodyTag tagName={ Card.Body } { ...rest }>
Expand Down
10 changes: 8 additions & 2 deletions src/atoms/Dialog/DialogPlate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type DialogPlateProps = {|
onOpen?: (any) => void,
shouldCloseOnOverlayClick?: boolean,
padding?: PropSizes,
tagName?: string,
|};

const name = 'dialogPlate';
Expand Down Expand Up @@ -48,6 +49,7 @@ const StyledTag = createStyledTag(name, {
borderRadius: '6px',
backgroundColor: '#FFFFFF',
boxShadow: '0 4px 8px 0 rgba(0,0,0,0.1)',
maxHeight: '90%',
});

function DialogPlate({
Expand All @@ -59,13 +61,14 @@ function DialogPlate({
shouldCloseOnOverlayClick,
size,
args,
tagName,
...rest
}: DialogPlateProps) {
return (
<Modal id={ id } isOpen={ isOpen } onOpen={ onOpen } onClose={ onClose } args={ args } shouldCloseOnOverlayClick={ shouldCloseOnOverlayClick }>
{
({ args, onClose }) => (
<StyledTag tagName="div" size={ size }>
<StyledTag tagName={ tagName } size={ size }>
<Card.Plate { ...rest } args={ args } onClose={ onClose }>
{ children }
</Card.Plate>
Expand All @@ -76,6 +79,9 @@ function DialogPlate({
);
}

DialogPlate.defaultProps = theme[name].defaults;
DialogPlate.defaultProps = {
...theme[name].defaults,
tagName: 'div',
};

export { DialogPlate, theme };
7 changes: 6 additions & 1 deletion src/atoms/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ const OverlayTag = createStyledTag(name, (props): * => ({
zIndex: props.theme.Z_INDEX.MODAL,
}));

const ModalTag = createStyledTag(name, {});
const ModalTag = createStyledTag(name, {
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
});

class Modal extends PureComponent<ModalProps, ModalState> {
static openedModals: number = 0;
Expand Down
1 change: 1 addition & 0 deletions src/atoms/Paper/Paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const theme = createTheme(name, (colors: *, sizes: *): * => ({
const StyledTag = createStyledTag(name, props => ({
display: 'flex',
flexDirection: 'column',
maxHeight: '100%',

...getThemeStyle(props, name).paper,
}));
Expand Down
17 changes: 17 additions & 0 deletions storybook/__tests__/__snapshots__/storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ exports[`Storyshots ATOMS/Card default 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -1954,6 +1955,7 @@ exports[`Storyshots ATOMS/Card with custom offsets 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -2033,6 +2035,7 @@ exports[`Storyshots ATOMS/Card with scrollable body 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -2168,6 +2171,7 @@ exports[`Storyshots ATOMS/Card without footer 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -2234,6 +2238,7 @@ exports[`Storyshots ATOMS/Card without header 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -2291,6 +2296,7 @@ exports[`Storyshots ATOMS/Card without multiple sections 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -12104,6 +12110,7 @@ exports[`Storyshots ATOMS/Dropdown with menu 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -14722,6 +14729,7 @@ exports[`Storyshots ATOMS/Paper with header and sections 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down Expand Up @@ -16461,6 +16469,10 @@ exports[`Storyshots ATOMS/Table table with data 1`] = `
height: 6rem;
}
.emotion-38:last-child {
border-bottom: none;
}
.emotion-15 {
display: -webkit-box;
display: -webkit-flex;
Expand Down Expand Up @@ -17138,6 +17150,10 @@ exports[`Storyshots ATOMS/Table table with scroll 1`] = `
height: 6rem;
}
.emotion-38:last-child {
border-bottom: none;
}
.emotion-15 {
display: -webkit-box;
display: -webkit-flex;
Expand Down Expand Up @@ -20243,6 +20259,7 @@ exports[`Storyshots MOLECULES/Menu with some items 1`] = `
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
max-height: 100%;
background: #FFFFFF;
color: #000000;
box-shadow: 0 1px 3px 0 rgba(50,50,93,.14),0 4px 6px 0 rgba(112,157,199,.08);
Expand Down

0 comments on commit 3e996ae

Please sign in to comment.