Skip to content

Commit d88ac14

Browse files
committed
use named exports
1 parent 3482d0b commit d88ac14

38 files changed

+65
-111
lines changed

__tests__/Bounds.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Bounds from '../src/classes/Bounds';
1+
import { Bounds } from '../src/classes/Bounds';
22

33
describe.each([
44
[

__tests__/Parallax.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import { Parallax } from '../src/components/Parallax';
4-
import ParallaxProvider from '../src/components/ParallaxProvider';
5-
import ParallaxController from '../src/classes/ParallaxController';
4+
import { ParallaxProvider } from '../src/components/ParallaxProvider';
5+
import { ParallaxController } from '../src/classes/ParallaxController';
66
import { VERTICAL } from '../src/constants';
77

8-
import MockProvider from './testUtils/MockProvider';
8+
import { MockProvider } from './testUtils/MockProvider';
99
import expectRenderError from './testUtils/expectRenderError';
1010
import createNodeMock from './testUtils/createNodeMock';
1111

__tests__/ParallaxBanner.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import renderer from 'react-test-renderer';
4-
import ParallaxBanner from '../src/components/ParallaxBanner';
5-
import ParallaxProvider from '../src/components/ParallaxProvider';
4+
import { ParallaxBanner } from '../src/components/ParallaxBanner';
5+
import { ParallaxProvider } from '../src/components/ParallaxProvider';
66
import createNodeMock from './testUtils/createNodeMock';
77

88
describe('Expect the <ParallaxBanner> component', () => {

__tests__/ParallaxController.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import ParallaxController from '../src/classes/ParallaxController';
1+
import { ParallaxController } from '../src/classes/ParallaxController';
22
import { Element } from '../src/classes/Element';
3-
import Rect from '../src/classes/Rect';
4-
import Bounds from '../src/classes/Bounds';
3+
import { Rect } from '../src/classes/Rect';
4+
import { Bounds } from '../src/classes/Bounds';
55
import { VERTICAL } from '../src/constants';
66

77
const addEventListener = window.addEventListener;

__tests__/ParallaxProvider.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import React from 'react';
44
import ReactDOM from 'react-dom';
55

6-
import ParallaxProvider from '../src/components/ParallaxProvider';
7-
import ParallaxController from '../src/classes/ParallaxController';
6+
import { ParallaxProvider } from '../src/components/ParallaxProvider';
7+
import { ParallaxController } from '../src/classes/ParallaxController';
88

99
describe('A <ParallaxProvider>', () => {
1010
it('to render children', () => {

__tests__/Rect.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Rect from '../src/classes/Rect';
1+
import { Rect } from '../src/classes/Rect';
22
import { createElementMock } from './testUtils/createElementMock';
33
describe.each([
44
[

__tests__/elementStyles.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setParallaxStyles } from '../src/helpers/elementStyles';
2-
import getOffsets from '../src/helpers/getOffsets';
2+
import { getOffsets } from '../src/helpers/getOffsets';
33
import createNodeMock from './testUtils/createNodeMock';
44

55
function createOffsets(x0, x1, y0, y1) {

__tests__/getOffsets.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import getOffsets from '../src/helpers/getOffsets';
2-
import parseValueAndUnit from '../src/utils/parseValueAndUnit';
1+
import { getOffsets } from '../src/helpers/getOffsets';
2+
import { parseValueAndUnit } from '../src/utils/parseValueAndUnit';
33

44
describe('getOffsets', () => {
55
it('returns the offset properties to an element with defaults', () => {

__tests__/getParallaxOffsets.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getParallaxOffsets } from '../src/helpers/getParallaxOffsets';
2-
import parseValueAndUnit from '../src/utils/parseValueAndUnit';
3-
import scaleBetween from '../src/utils/scaleBetween';
2+
import { parseValueAndUnit } from '../src/utils/parseValueAndUnit';
3+
import { scaleBetween } from '../src/utils/scaleBetween';
44

55
const offset = {
66
x0: parseValueAndUnit('-100px'),

__tests__/parseValueAndUnit.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import parseValueAndUnit from '../src/utils/parseValueAndUnit';
1+
import { parseValueAndUnit } from '../src/utils/parseValueAndUnit';
22

33
test('Parse a string to get the value and unit in either pixels or percent', () => {
44
expect(parseValueAndUnit('5px')).toEqual({ unit: 'px', value: 5 });

__tests__/scaleBetween.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import scaleBetween from '../src/utils/scaleBetween';
1+
import { scaleBetween } from '../src/utils/scaleBetween';
22

33
const oldMin = 0;
44
const oldMax = 1;

__tests__/serverTests.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import React from 'react';
66
import ReactDOMServer from 'react-dom/server';
7-
import ParallaxProvider from '../src/components/ParallaxProvider';
8-
import ParallaxController from '../src/classes/ParallaxController';
7+
import { ParallaxProvider } from '../src/components/ParallaxProvider';
8+
import { ParallaxController } from '../src/classes/ParallaxController';
99

1010
describe('Expect', () => {
1111
it('<ParallaxProvider> to not init the controller on the server', () => {

__tests__/testForPassiveScroll.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import testForPassiveScroll from '../src/utils/testForPassiveScroll';
1+
import { testForPassiveScroll } from '../src/utils/testForPassiveScroll';
22

33
const addEventListener = window.addEventListener;
44
const removeEventListener = window.removeEventListener;

__tests__/testUtils/MockProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import ParallaxContext from '../../src/helpers/ParallaxContext';
3+
import { ParallaxContext } from '../../src/context/ParallaxContext';
44

5-
export default class MockProvider extends Component {
5+
export class MockProvider extends Component {
66
static propTypes = {
77
children: PropTypes.node.isRequired,
88
controllerMock: PropTypes.object.isRequired,

src/classes/Bounds.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Bounds {
1+
export class Bounds {
22
totalDistY: number;
33
totalDistX: number;
44
top: number;
@@ -67,5 +67,3 @@ class Bounds {
6767
}
6868
}
6969
}
70-
71-
export default Bounds;

src/classes/Element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { VERTICAL } from '../constants';
2-
import Bounds from './Bounds';
3-
import Rect from './Rect';
2+
import { Bounds } from './Bounds';
3+
import { Rect } from './Rect';
44
import { ParallaxStartEndOffsets } from '../types';
5-
import getOffsets from '../helpers/getOffsets';
5+
import { getOffsets } from '../helpers/getOffsets';
66
import { isElementInView } from '../helpers/isElementInView';
77
import { percentMoved } from '../helpers/percentMoved';
88
import { setParallaxStyles } from '../helpers/elementStyles';

src/classes/ParallaxController.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View } from './View';
33
import { Scroll } from './Scroll';
44
import { Element } from './Element';
55
import { VERTICAL } from '../constants';
6-
import testForPassiveScroll from '../utils/testForPassiveScroll';
6+
import { testForPassiveScroll } from '../utils/testForPassiveScroll';
77

88
/**
99
* -------------------------------------------------------
@@ -17,7 +17,7 @@ import testForPassiveScroll from '../utils/testForPassiveScroll';
1717
* based on x/y offsets and current scroll position.
1818
*
1919
*/
20-
function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
20+
export function ParallaxController({ scrollAxis = VERTICAL, scrollContainer }) {
2121
// All parallax elements to be updated
2222
let elements = [];
2323

@@ -242,5 +242,3 @@ ParallaxController.init = function (options) {
242242

243243
return new ParallaxController(options);
244244
};
245-
246-
export default ParallaxController;

src/classes/Rect.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { View } from './View';
22
import { Scroll } from './Scroll';
33

4-
class Rect {
4+
export class Rect {
55
height: number;
66
width: number;
77
left: number;
@@ -36,5 +36,3 @@ class Rect {
3636
this.originTotalDistX = view.width + this.width;
3737
}
3838
}
39-
40-
export default Rect;

src/components/Parallax.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PropsWithChildren, useEffect, useRef, useState } from 'react';
2-
import ParallaxController from '../classes/ParallaxController';
3-
import { useController } from './useController';
2+
import { ParallaxController } from '../classes/ParallaxController';
3+
import { useController } from '../hooks/useController';
44

55
export interface ParallaxProps {
66
/**

src/components/ParallaxBanner.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface ParallaxBannerProps {
6060
style?: any;
6161
}
6262

63-
const ParallaxBanner = ({
63+
export const ParallaxBanner = ({
6464
children,
6565
className,
6666
layers,
@@ -143,5 +143,3 @@ const ParallaxBanner = ({
143143
ParallaxBanner.defaultProps = {
144144
disabled: false,
145145
};
146-
147-
export default ParallaxBanner;

src/components/ParallaxProvider.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, { Component } from 'react';
2-
import PropTypes from 'prop-types';
3-
import ParallaxContext from '../helpers/ParallaxContext';
4-
import ParallaxController from '../classes/ParallaxController';
5-
import { VERTICAL, HORIZONTAL } from '../constants';
6-
import validHTMLElement from '../utils/validHTMLElement';
2+
3+
import { ParallaxContext } from '../context/ParallaxContext';
4+
import { ParallaxController } from '../classes/ParallaxController';
5+
import { VERTICAL } from '../constants';
76

87
const createController = (options) => {
98
// Don't initialize on the server
@@ -26,23 +25,14 @@ export interface ParallaxProviderProps {
2625
* Optionally set the container that has overflow and will contain parallax elements. Defaults
2726
* to the HTML body
2827
*/
29-
scrollContainer?: any;
28+
scrollContainer?: HTMLElement;
3029
}
3130

32-
export default class ParallaxProvider extends Component<
33-
ParallaxProviderProps,
34-
{}
35-
> {
31+
export class ParallaxProvider extends Component<ParallaxProviderProps, {}> {
3632
static defaultProps = {
3733
scrollAxis: VERTICAL,
3834
};
3935

40-
static propTypes = {
41-
children: PropTypes.node.isRequired,
42-
scrollAxis: PropTypes.oneOf([VERTICAL, HORIZONTAL]),
43-
scrollContainer: validHTMLElement,
44-
};
45-
4636
constructor(props) {
4737
super(props);
4838
// @ts-ignore

src/context/ParallaxContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React from 'react';
2+
3+
export const ParallaxContext = React.createContext(null);

src/helpers/ParallaxContext.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/helpers/getOffsets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { ParallaxStartEndOffsets } from '../types';
2-
import parseValueAndUnit from '../utils/parseValueAndUnit';
2+
import { parseValueAndUnit } from '../utils/parseValueAndUnit';
33

44
/**
55
* Takes a parallax element and parses the offset props to get the value
66
* and unit. Sets these values as offset object accessible on the element.
77
*/
8-
export default function getOffsets(props: {
8+
export function getOffsets(props: {
99
x0: string | number;
1010
x1: string | number;
1111
y0: string | number;

src/helpers/getParallaxOffsets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OffsetShape, ParallaxStartEndOffsets } from '../types';
2-
import scaleBetween from '../utils/scaleBetween';
2+
import { scaleBetween } from '../utils/scaleBetween';
33

44
/**
55
* Gets the parallax X and Y offsets to be applied to an element

src/components/useController.ts renamed to src/hooks/useController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from 'react';
2-
import ParallaxContext from '../helpers/ParallaxContext';
2+
import { ParallaxContext } from '../context/ParallaxContext';
33
import { ParallaxController } from '../types';
44

55
export function useController(): ParallaxController {

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Parallax } from './components/Parallax';
2-
import ParallaxBanner from './components/ParallaxBanner';
3-
import ParallaxProvider from './components/ParallaxProvider';
4-
import ParallaxContext from './helpers/ParallaxContext';
2+
import { ParallaxBanner } from './components/ParallaxBanner';
3+
import { ParallaxProvider } from './components/ParallaxProvider';
4+
import { ParallaxContext } from './context/ParallaxContext';
55

6-
export { useController } from './components/useController';
6+
export { useController } from './hooks/useController';
77

88
export { Parallax, ParallaxBanner, ParallaxProvider, ParallaxContext };

src/utils/parseValueAndUnit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { OffsetShape } from '../types';
44
* Determines the unit of a string and parses the value
55
*/
66

7-
export default function parseValueAndUnit(
7+
export function parseValueAndUnit(
88
str: string | number,
99
out: OffsetShape = { value: 0, unit: 'px' }
1010
): OffsetShape {

src/utils/scaleBetween.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Scale between AKA normalize
2-
export default function scaleBetween(
2+
export function scaleBetween(
33
value: number,
44
newMin: number,
55
newMax: number,

src/utils/testForPassiveScroll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function testForPassiveScroll() {
1+
export function testForPassiveScroll() {
22
let supportsPassiveOption = false;
33
try {
44
const opts = Object.defineProperty({}, 'passive', {

src/utils/validHTMLElement.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

stories/Container.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React from 'react';
22
import { ParallaxProvider } from '../src';
33

4-
const Container = ({ children, scrollAxis, className }) => (
4+
export const Container = ({ children, scrollAxis, className }) => (
55
<ParallaxProvider scrollAxis={scrollAxis}>
66
<div className={scrollAxis}>
77
<div className={className}>{children}</div>
88
</div>
99
</ParallaxProvider>
1010
);
11-
12-
export default Container;

stories/Element/Element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import styles from './Element.module.scss';
33

4-
export default function Element(props) {
4+
export function Element(props) {
55
return (
66
<div className={styles.ratio}>
77
<div className={styles.inner}>

stories/Image/Image.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@ export const Image = (props) => {
1313
</div>
1414
);
1515
};
16-
17-
export default Image;

stories/Parallax/1_ParallaxVertical.stories.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { Parallax, ParallaxProvider } from '../../src';
3-
import Element from '../Element/Element';
4-
import Container from '../Container';
5-
import ScrollContainer from '../ScrollContainer';
3+
import { Element } from '../Element/Element';
4+
import { Container } from '../Container';
5+
import { ScrollContainer } from '../ScrollContainer';
66
import styles from './Parallax.module.scss';
77

88
export const WithYOffsets = (args) => {

stories/Parallax/2_ParallaxHorizontal.stories.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { Parallax, ParallaxProvider } from '../../src';
3-
import Element from '../Element/Element';
4-
import Container from '../Container';
5-
import ScrollContainer from '../ScrollContainer';
3+
import { Element } from '../Element/Element';
4+
import { Container } from '../Container';
5+
import { ScrollContainer } from '../ScrollContainer';
66
import styles from './Parallax.module.scss';
77

88
export const WithYOffsets = (args) => {

0 commit comments

Comments
 (0)