Skip to content

Commit

Permalink
fix: get rid of build warnings
Browse files Browse the repository at this point in the history
React doesn't support ES modules yet, it works just because Babel is smart enough. Better use it the "right" way until they decide to support it, otherwise something may break in the future. Also, react-ellipsis was exporting some internal utilities just for testing purposes, now they are kept private.
  • Loading branch information
Federico Zivolo committed Dec 10, 2018
1 parent 84dd827 commit 3d5076e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
16 changes: 5 additions & 11 deletions packages/react-ellipsis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@
* we may create an hidden `span` with a single letter inside to compute a line height
*/

import React, { Component, createRef, type Node } from 'react';

export function nlToBr(text: string): Array<string | Node> {
return text.split(/\n()/g).map((str, i) => (str ? str : <br key={i} />));
}

export function isWidthDifferentFn(element: ?HTMLElement, width: number) {
return !!element && width !== element.clientWidth;
}
import * as React from 'react';
import nlToBr from './nlToBr';
import isWidthDifferentFn from './isWidthDifferentFn';

type Children = string | null | boolean | void;

Expand All @@ -43,7 +37,7 @@ type State = {
bad: ?number,
};

export default class Ellipsis extends Component<Props, State> {
export default class Ellipsis extends React.Component<Props, State> {
props: Props;

static defaultProps = {
Expand All @@ -64,7 +58,7 @@ export default class Ellipsis extends Component<Props, State> {
bad: null,
};

element = createRef/*:: <HTMLElement> */();
element = React.createRef /*:: <HTMLElement> */();
width: number = 0;

componentDidMount() {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-ellipsis/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @flow
import React from 'react';
import * as React from 'react';
import { mount } from 'enzyme';
import Ellipsis, { nlToBr, isWidthDifferentFn } from './';
import Ellipsis from './';
import nlToBr from './nlToBr';
import isWidthDifferentFn from './isWidthDifferentFn';
import ReactDOM from 'react-dom';

it('converts \\n to <br />', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-ellipsis/src/isWidthDifferentFn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow
export default function isWidthDifferentFn(
element: ?HTMLElement,
width: number
) {
return !!element && width !== element.clientWidth;
}
6 changes: 6 additions & 0 deletions packages/react-ellipsis/src/nlToBr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow
import * as React from 'react';

export default function nlToBr(text: string): Array<string | React.Node> {
return text.split(/\n()/g).map((str, i) => (str ? str : <br key={i} />));
}
4 changes: 2 additions & 2 deletions packages/theme/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React, { type Node } from 'react';
import * as React from 'react';
import { ThemeProvider } from 'emotion-theming';

import themeData from './theme';
Expand All @@ -12,7 +12,7 @@ export { default as withFallback } from './withFallback';

type Props = {
theme?: 'dark' | 'light',
children: Node,
children: React.Node,
};

const QuidThemeProvider = ({ theme = 'light', children, ...props }: Props) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React from 'react';
import * as React from 'react';
import { shallow } from 'enzyme';
import { ThemeProvider } from 'emotion-theming';
import * as exps from './index';
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/textStyles.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React from 'react';
import * as React from 'react';
import styled from '@emotion/styled';
import { css } from '@emotion/core';
import { mount } from 'enzyme';
Expand Down

0 comments on commit 3d5076e

Please sign in to comment.