Skip to content

Commit b5e1155

Browse files
committed
Made clicking on more parts of the backdrop dismiss it
1 parent c66321d commit b5e1155

5 files changed

Lines changed: 57 additions & 12 deletions

File tree

src/components/Carousel.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ const defaultProps = {
8787
},
8888
};
8989

90+
/**
91+
* Used to get the className to select the track (area above and below the
92+
* carousel) in other components.
93+
*
94+
* This className is we call `className()` in utils with to get the full
95+
* className.
96+
*/
97+
export const trackBaseClassName = 'track';
98+
9099
class Carousel extends Component<CarouselProps, CarouselState> {
91100
commonProps: any; // TODO
92101
components: CarouselComponents;
@@ -381,7 +390,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
381390
{...this.getTrackProps(this.props)}
382391
style={{ display: 'flex', alignItems: 'center' }}
383392
currentView={currentIndex}
384-
className={className('track')}
393+
className={className(trackBaseClassName)}
385394
onViewChange={this.handleViewChange}
386395
ref={this.getTrack}
387396
>

src/components/Footer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export const footerCSS = ({ isModal, interactionIsIdle }: State) => ({
4242
},
4343
});
4444

45+
/**
46+
* Used to get the className to select the footer in other components.
47+
* This className is we call `className()` in utils with to get the full
48+
* className.
49+
*/
50+
export const footerBaseClassName = 'footer';
51+
4552
const Footer = (props: Props) => {
4653
const { components, getStyles, innerProps, isFullscreen, isModal } = props;
4754

@@ -51,12 +58,12 @@ const Footer = (props: Props) => {
5158

5259
const state = { isFullscreen, isModal };
5360
const cn = {
54-
container: className('footer', state),
61+
container: className(footerBaseClassName, state),
5562
caption: className('footer__caption', state),
5663
count: className('footer__count', state),
5764
};
5865
const css = {
59-
container: getStyles('footer', props),
66+
container: getStyles(footerBaseClassName, props),
6067
caption: getStyles('footerCaption', props),
6168
count: getStyles('footerCount', props),
6269
};

src/components/Header.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export const headerCSS = ({ interactionIsIdle }: State) => ({
3636
zIndex: 1,
3737
});
3838

39+
/**
40+
* Used to get the className to select the header in other components.
41+
* This className is we call `className()` in utils with to get the full
42+
* className.
43+
*/
44+
export const headerBaseClassName = 'header';
45+
3946
const Header = (props: Props) => {
4047
const {
4148
components,
@@ -61,8 +68,8 @@ const Header = (props: Props) => {
6168

6269
return (
6370
<Div
64-
css={getStyles('header', props)}
65-
className={className('header', state)}
71+
css={getStyles(headerBaseClassName, props)}
72+
className={className(headerBaseClassName, state)}
6673
// TODO glam prefixer fails on gradients
6774
// https://github.com/threepointone/glam/issues/35
6875
style={{

src/components/Modal/Modal.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import {
1010
type ModalComponents,
1111
} from '../defaultComponents';
1212
import { Fade, SlideUp } from './Animation';
13-
import { type CarouselType } from '../Carousel';
13+
import { type CarouselType, trackBaseClassName } from '../Carousel';
1414
import { defaultModalStyles, type ModalStylesConfig } from '../../styles';
1515
import { isTouch, className } from '../../utils';
16+
import { headerBaseClassName } from '../Header';
17+
import { footerBaseClassName } from '../Footer';
18+
import { viewBaseClassName } from '../View';
1619

1720
type MouseOrKeyboardEvent = MouseEvent | KeyboardEvent;
1821
export type CloseType = (event: MouseOrKeyboardEvent) => void;
@@ -55,6 +58,17 @@ const defaultProps = {
5558
preventScroll: true,
5659
styles: {},
5760
};
61+
62+
/** Classes that when clicked on, close the backdrop */
63+
const backdropClassNames = new Set(
64+
[
65+
viewBaseClassName,
66+
headerBaseClassName,
67+
footerBaseClassName,
68+
trackBaseClassName,
69+
].map(className),
70+
);
71+
5872
class Modal extends Component<Props, State> {
5973
commonProps: any; // TODO
6074
components: ModalComponents;
@@ -106,10 +120,11 @@ class Modal extends Component<Props, State> {
106120
if (allowClose) this.handleClose(event);
107121
};
108122
handleBackdropClick = (event: MouseEvent) => {
109-
if (
110-
!event.target.classList.contains(className('view')) ||
111-
!this.props.closeOnBackdropClick
112-
) {
123+
const hasBackdropClassName = event.target.classList.some(className =>
124+
backdropClassNames.has(className),
125+
);
126+
127+
if (!hasBackdropClassName || !this.props.closeOnBackdropClick) {
113128
return;
114129
}
115130

src/components/View.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export const viewCSS = () => ({
2020
textAlign: 'center',
2121
});
2222

23+
/**
24+
* Used to get the className to select the view in other components.
25+
* This className is we call `className()` in utils with to get the full
26+
* className.
27+
*/
28+
export const viewBaseClassName = 'view';
29+
2330
const View = (props: Props) => {
2431
const { data, formatters, getStyles, index, isFullscreen, isModal } = props;
2532
const innerProps = {
@@ -29,8 +36,8 @@ const View = (props: Props) => {
2936

3037
return (
3138
<Div
32-
css={getStyles('view', props)}
33-
className={className('view', { isFullscreen, isModal })}
39+
css={getStyles(viewBaseClassName, props)}
40+
className={className(viewBaseClassName, { isFullscreen, isModal })}
3441
>
3542
<Img
3643
{...innerProps}

0 commit comments

Comments
 (0)