Skip to content

Commit 2084147

Browse files
committed
Refactored all the classNames into common file to avoid import loops
1 parent 0a480d4 commit 2084147

6 files changed

Lines changed: 27 additions & 34 deletions

File tree

src/components/Carousel.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { type ModalProps } from './Modal/Modal';
1818
import { className, isTouch } from '../utils';
1919
import formatters from '../formatters';
2020
import { type ViewsType } from '../types';
21+
import componentBaseClassNames from './componentBaseClassNames';
2122

2223
type SpringConfig = { [key: string]: number };
2324
export type fn = any => void;
@@ -87,14 +88,7 @@ const defaultProps = {
8788
},
8889
};
8990

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';
91+
export const trackBaseClassName = componentBaseClassNames.Track;
9892

9993
class Carousel extends Component<CarouselProps, CarouselState> {
10094
commonProps: any; // TODO

src/components/Footer.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { smallDevice } from './css-helpers';
77
import { Div, Span } from '../primitives';
88
import type { PropsWithStyles, ViewType } from '../types';
99
import { className } from '../utils';
10+
import componentBaseClassNames from './componentBaseClassNames';
1011

1112
type State = { isModal: boolean, interactionIsIdle: boolean };
1213
type Props = State &
@@ -42,12 +43,7 @@ export const footerCSS = ({ isModal, interactionIsIdle }: State) => ({
4243
},
4344
});
4445

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';
46+
const footerBaseClassName = componentBaseClassNames.Footer;
5147

5248
const Footer = (props: Props) => {
5349
const { components, getStyles, innerProps, isFullscreen, isModal } = props;

src/components/Header.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Button, Div } from '../primitives';
77
import { className } from '../utils';
88
import type { PropsWithStyles } from '../types';
99
import { Close, FullscreenEnter, FullscreenExit } from './svg';
10+
import componentBaseClassNames from './componentBaseClassNames';
1011

1112
type State = { interactionIsIdle: boolean };
1213
type Props = PropsWithStyles &
@@ -36,12 +37,7 @@ export const headerCSS = ({ interactionIsIdle }: State) => ({
3637
zIndex: 1,
3738
});
3839

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';
40+
export const headerBaseClassName = componentBaseClassNames.Header;
4541

4642
const Header = (props: Props) => {
4743
const {

src/components/Modal/Modal.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import {
1010
type ModalComponents,
1111
} from '../defaultComponents';
1212
import { Fade, SlideUp } from './Animation';
13-
import { type CarouselType, trackBaseClassName } from '../Carousel';
13+
import { type CarouselType } 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';
16+
import componentBaseClassNames from '../componentBaseClassNames';
1917

2018
type MouseOrKeyboardEvent = MouseEvent | KeyboardEvent;
2119
export type CloseType = (event: MouseOrKeyboardEvent) => void;
@@ -62,10 +60,10 @@ const defaultProps = {
6260
/** Classes that when clicked on, close the backdrop */
6361
const backdropClassNames = new Set(
6462
[
65-
viewBaseClassName,
66-
headerBaseClassName,
67-
footerBaseClassName,
68-
trackBaseClassName,
63+
componentBaseClassNames.View,
64+
componentBaseClassNames.Header,
65+
componentBaseClassNames.Footer,
66+
componentBaseClassNames.Track,
6967
].map(className),
7068
);
7169

src/components/View.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Div, Img } from '../primitives';
77
import { type PropsWithStyles } from '../types';
88
import { className } from '../utils';
99
import { getSource } from './component-helpers';
10+
import componentBaseClassNames from './componentBaseClassNames';
1011

1112
type Props = PropsWithStyles & {
1213
data: Object,
@@ -20,12 +21,7 @@ export const viewCSS = () => ({
2021
textAlign: 'center',
2122
});
2223

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';
24+
export const viewBaseClassName = componentBaseClassNames.View;
2925

3026
const View = (props: Props) => {
3127
const { data, formatters, getStyles, index, isFullscreen, isModal } = props;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Used to get the HTML class to select specific components.
3+
* We call `className()` in utils with each of these to get the full className,
4+
* with prefixes.
5+
*/
6+
const componentBaseClassNames = {
7+
Header: 'header',
8+
Footer: 'footer',
9+
View: 'view',
10+
Track: 'track',
11+
};
12+
13+
export default componentBaseClassNames;

0 commit comments

Comments
 (0)