From e9910f269fde2738faf268a4b7332c24ac2e505d Mon Sep 17 00:00:00 2001 From: Bogdan Bodnar Date: Tue, 27 Aug 2019 17:46:45 +0200 Subject: [PATCH] Don't use default exports. --- .eslintrc.js | 9 +- babel.config.js | 7 +- package-lock.json | 33 ---- package.json | 2 - src/bootstrap/Alert.js | 2 +- src/bootstrap/Button.js | 2 +- src/bootstrap/Checkbox.js | 2 +- src/bootstrap/DataTimeInput.js | 4 +- src/bootstrap/EmailInput.js | 6 +- src/bootstrap/Input.js | 3 +- src/bootstrap/Modal.js | 3 +- src/bootstrap/NumberInput.js | 6 +- src/bootstrap/PasswordInput.js | 4 +- src/bootstrap/RadioSet.js | 2 +- src/bootstrap/Select.js | 2 +- src/bootstrap/TextInput.js | 6 +- src/bootstrap/__tests__/Button.test.js | 29 ++-- src/bootstrap/__tests__/Checkbox.test.js | 25 +-- src/bootstrap/__tests__/NumberInput.test.js | 15 +- src/bootstrap/__tests__/PasswordInput.test.js | 15 +- src/bootstrap/__tests__/RadioSet.test.js | 34 ++-- src/bootstrap/__tests__/Select.test.js | 40 +++-- src/bootstrap/__tests__/TextInput.test.js | 15 +- src/form/__tests__/hooks.test.js | 4 +- src/form/__tests__/validation.test.js | 154 ++++++++++++------ src/form/components/ForisForm.js | 2 +- src/form/components/SubmitButton.js | 5 +- src/form/components/alerts.js | 4 +- src/form/hooks.js | 2 +- src/index.js | 53 ++---- src/utils/Portal.js | 2 +- src/webSockets/WebSockets.js | 2 +- src/webSockets/hooks.js | 2 +- 33 files changed, 258 insertions(+), 238 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5dc0fd3..b5898b0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,14 +27,19 @@ module.exports = { "react/prop-types": "warn", "react/no-array-index-key": "warn", "react/button-has-type": "warn", + "import/prefer-default-export": "off", "import/no-unresolved": [ "error", // Ignore imports used only in tests - {ignore: ["mockWS", "customTestRender"]} + { ignore: ["mockWS", "customTestRender"] } ], "import/no-cycle": "warn", "no-console": "error", - "no-use-before-define": ["error", {functions: false, classes: true, variables: true}], + "no-use-before-define": ["error", { + functions: false, + classes: true, + variables: true + }], "no-restricted-syntax": "warn", // Should be enabled in the future "camelcase": "off", diff --git a/babel.config.js b/babel.config.js index 0bf9c14..9cb4b98 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,15 +1,10 @@ module.exports = { presets: [ - ["@babel/preset-env", { - targets: { - esmodules: true, - }, - }], + "@babel/preset-env", "@babel/preset-react", ], plugins: [ "@babel/plugin-transform-runtime", - "@babel/plugin-syntax-export-namespace-from", "@babel/plugin-syntax-export-default-from", ], }; diff --git a/package-lock.json b/package-lock.json index 49d3a49..643cbde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -123,20 +123,6 @@ "@babel/types": "^7.4.4" } }, - "@babel/helper-create-class-features-plugin": { - "version": "7.5.5", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.5.5.tgz", - "integrity": "sha512-ZsxkyYiRA7Bg+ZTRpPvB6AbOFKTFFK4LrvTet8lInm0V468MWCaSYJE+I7v2z2r8KNLtYiV+K5kTCnR7dvyZjg==", - "dev": true, - "requires": { - "@babel/helper-function-name": "^7.1.0", - "@babel/helper-member-expression-to-functions": "^7.5.5", - "@babel/helper-optimise-call-expression": "^7.0.0", - "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-replace-supers": "^7.5.5", - "@babel/helper-split-export-declaration": "^7.4.4" - } - }, "@babel/helper-define-map": { "version": "7.5.5", "resolved": "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.5.5.tgz", @@ -338,16 +324,6 @@ "@babel/plugin-syntax-async-generators": "^7.2.0" } }, - "@babel/plugin-proposal-class-properties": { - "version": "7.5.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.5.5.tgz", - "integrity": "sha512-AF79FsnWFxjlaosgdi421vmYG6/jg79bVD0dpD44QdgobzHKuLZ6S3vl8la9qIeSwGi8i1fS0O1mfuDAAdo1/A==", - "dev": true, - "requires": { - "@babel/helper-create-class-features-plugin": "^7.5.5", - "@babel/helper-plugin-utils": "^7.0.0" - } - }, "@babel/plugin-proposal-dynamic-import": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.5.0.tgz", @@ -426,15 +402,6 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, - "@babel/plugin-syntax-export-namespace-from": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-namespace-from/-/plugin-syntax-export-namespace-from-7.2.0.tgz", - "integrity": "sha512-1zGA3UNch6A+A11nIzBVEaE3DDJbjfB+eLIcf0GGOh/BJr/8NxL3546MGhV/r0RhH4xADFIEso39TKCfEMlsGA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.0.0" - } - }, "@babel/plugin-syntax-json-strings": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz", diff --git a/package.json b/package.json index 36d338e..026ecbe 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,7 @@ "devDependencies": { "@babel/cli": "^7.4.4", "@babel/core": "^7.4.5", - "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/plugin-syntax-export-default-from": "^7.2.0", - "@babel/plugin-syntax-export-namespace-from": "^7.2.0", "@babel/plugin-transform-runtime": "^7.4.4", "@babel/preset-env": "^7.4.5", "@babel/preset-react": "^7.0.0", diff --git a/src/bootstrap/Alert.js b/src/bootstrap/Alert.js index eead1f4..902bede 100644 --- a/src/bootstrap/Alert.js +++ b/src/bootstrap/Alert.js @@ -22,7 +22,7 @@ Alert.propTypes = { onDismiss: PropTypes.func, }; -export default function Alert({ +export function Alert({ type, message, onDismiss, children, }) { return ( diff --git a/src/bootstrap/Button.js b/src/bootstrap/Button.js index 7109286..887e05e 100644 --- a/src/bootstrap/Button.js +++ b/src/bootstrap/Button.js @@ -29,7 +29,7 @@ Button.propTypes = { ]).isRequired, }; -export default function Button({ +export function Button({ className, loading, forisFormSize, children, ...props }) { className = className ? `btn ${className}` : "btn btn-primary "; diff --git a/src/bootstrap/Checkbox.js b/src/bootstrap/Checkbox.js index 0ce12e9..8cc4658 100644 --- a/src/bootstrap/Checkbox.js +++ b/src/bootstrap/Checkbox.js @@ -27,7 +27,7 @@ CheckBox.defaultProps = { disabled: false, }; -export default function CheckBox({ +export function CheckBox({ label, helpText, useDefaultSize, disabled, ...props }) { const uid = useUID(); diff --git a/src/bootstrap/DataTimeInput.js b/src/bootstrap/DataTimeInput.js index 8bfbf01..9a79878 100644 --- a/src/bootstrap/DataTimeInput.js +++ b/src/bootstrap/DataTimeInput.js @@ -10,7 +10,7 @@ import PropTypes from "prop-types"; import Datetime from "react-datetime/DateTime"; import moment from "moment/moment"; -import Input from "./Input"; +import { Input } from "./Input"; DataTimeInput.propTypes = { /** Field label. */ @@ -35,7 +35,7 @@ DataTimeInput.propTypes = { const DEFAULT_DATE_FORMAT = "YYYY-MM-DD"; const DEFAULT_TIME_FORMAT = "HH:mm:ss"; -export default function DataTimeInput({ +export function DataTimeInput({ value, onChange, isValidDate, dateFormat, timeFormat, children, ...props }) { function renderInput(datetimeProps) { diff --git a/src/bootstrap/EmailInput.js b/src/bootstrap/EmailInput.js index 587fc0f..9e499cd 100644 --- a/src/bootstrap/EmailInput.js +++ b/src/bootstrap/EmailInput.js @@ -8,9 +8,9 @@ import React from "react"; import PropTypes from "prop-types"; -import Input from "./Input"; +import { Input } from "./Input"; -const EmailInput = ({ ...props }) => ; +export const EmailInput = ({ ...props }) => ; EmailInput.propTypes = { @@ -23,5 +23,3 @@ EmailInput.propTypes = { /** Email value. */ value: PropTypes.string, }; - -export default EmailInput; diff --git a/src/bootstrap/Input.js b/src/bootstrap/Input.js index cbf5aaa..6784503 100644 --- a/src/bootstrap/Input.js +++ b/src/bootstrap/Input.js @@ -8,6 +8,7 @@ import React from "react"; import { useUID } from "react-uid/dist/es5/index"; import PropTypes from "prop-types"; + import { formFieldsSize } from "./constants"; Input.propTypes = { @@ -23,7 +24,7 @@ Input.propTypes = { }; /** Base bootstrap input component. */ -export default function Input({ +export function Input({ type, label, helpText, error, className, children, ...props }) { const uid = useUID(); diff --git a/src/bootstrap/Modal.js b/src/bootstrap/Modal.js index d4138da..d0e02b0 100644 --- a/src/bootstrap/Modal.js +++ b/src/bootstrap/Modal.js @@ -7,7 +7,8 @@ import React, { useEffect, useRef } from "react"; import PropTypes from "prop-types"; -import Portal from "utils/Portal"; + +import { Portal } from "utils/Portal"; Modal.propTypes = { /** Is modal shown value */ diff --git a/src/bootstrap/NumberInput.js b/src/bootstrap/NumberInput.js index 0b6d2f8..6715690 100644 --- a/src/bootstrap/NumberInput.js +++ b/src/bootstrap/NumberInput.js @@ -8,9 +8,9 @@ import React from "react"; import PropTypes from "prop-types"; -import Input from "./Input"; +import { Input } from "./Input"; -const NumberInput = ({ ...props }) => ; +export const NumberInput = ({ ...props }) => ; NumberInput.propTypes = { /** Field label. */ @@ -25,5 +25,3 @@ NumberInput.propTypes = { PropTypes.number, ]), }; - -export default NumberInput; diff --git a/src/bootstrap/PasswordInput.js b/src/bootstrap/PasswordInput.js index a5104de..6670eaf 100644 --- a/src/bootstrap/PasswordInput.js +++ b/src/bootstrap/PasswordInput.js @@ -8,7 +8,7 @@ import React, { useState } from "react"; import PropTypes from "prop-types"; -import Input from "./Input"; +import { Input } from "./Input"; PasswordInput.propTypes = { /** Field label. */ @@ -23,7 +23,7 @@ PasswordInput.propTypes = { withEye: PropTypes.bool, }; -export default function PasswordInput({ withEye, ...props }) { +export function PasswordInput({ withEye, ...props }) { const [isHidden, setHidden] = useState(true); return ( ; +export const TextInput = ({ ...props }) => ; TextInput.propTypes = { @@ -22,5 +22,3 @@ TextInput.propTypes = { /** Help text message. */ helpText: PropTypes.string, }; - -export default TextInput; diff --git a/src/bootstrap/__tests__/Button.test.js b/src/bootstrap/__tests__/Button.test.js index 08684fd..8548422 100644 --- a/src/bootstrap/__tests__/Button.test.js +++ b/src/bootstrap/__tests__/Button.test.js @@ -5,25 +5,28 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {render} from 'customTestRender'; +import { render } from "customTestRender"; -import Button from '../Button' +import { Button } from "../Button"; -describe('); - expect(container.firstChild).toMatchSnapshot() +describe("); + expect(container.firstChild) + .toMatchSnapshot(); }); - it('Render button with custom classes', () => { - const {container} = render() - expect(container.firstChild).toMatchSnapshot() + it("Render button with custom classes", () => { + const { container } = render(); + expect(container.firstChild) + .toMatchSnapshot(); }); - it('Render button with spinner', () => { - const {container} = render() - expect(container.firstChild).toMatchSnapshot() + it("Render button with spinner", () => { + const { container } = render(); + expect(container.firstChild) + .toMatchSnapshot(); }); }); diff --git a/src/bootstrap/__tests__/Checkbox.test.js b/src/bootstrap/__tests__/Checkbox.test.js index 60d5803..b0bf09a 100644 --- a/src/bootstrap/__tests__/Checkbox.test.js +++ b/src/bootstrap/__tests__/Checkbox.test.js @@ -5,32 +5,35 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {render} from 'customTestRender'; +import { render } from "customTestRender"; -import CheckBox from '../Checkbox' +import { CheckBox } from "../Checkbox"; -describe('', () => { - it('Render checkbox', () => { - const {container} = render( +describe("", () => { + it("Render checkbox", () => { + const { container } = render( {}} + onChange={() => { + }} /> ); - expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild) + .toMatchSnapshot(); }); - it('Render uncheked checkbox', () => { - const {container} = render( + it("Render uncheked checkbox", () => { + const { container } = render( ); - expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild) + .toMatchSnapshot(); }); }); diff --git a/src/bootstrap/__tests__/NumberInput.test.js b/src/bootstrap/__tests__/NumberInput.test.js index 011f230..e328940 100644 --- a/src/bootstrap/__tests__/NumberInput.test.js +++ b/src/bootstrap/__tests__/NumberInput.test.js @@ -5,16 +5,16 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {render} from 'customTestRender'; +import { render } from "customTestRender"; -import NumberInput from '../NumberInput'; +import { NumberInput } from "../NumberInput"; -describe('', () => { - it('Render number input', () => { - const {container} = render( +describe("", () => { + it("Render number input", () => { + const { container } = render( ', () => { }} /> ); - expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild) + .toMatchSnapshot(); }); }); diff --git a/src/bootstrap/__tests__/PasswordInput.test.js b/src/bootstrap/__tests__/PasswordInput.test.js index 74beddf..3375e2a 100644 --- a/src/bootstrap/__tests__/PasswordInput.test.js +++ b/src/bootstrap/__tests__/PasswordInput.test.js @@ -5,15 +5,15 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {render} from 'customTestRender'; +import { render } from "customTestRender"; -import PasswordInput from '../PasswordInput'; +import { PasswordInput } from "../PasswordInput"; -describe('', () => { - it('Render password input', () => { - const {container} = render( +describe("", () => { + it("Render password input", () => { + const { container } = render( ', () => { }} /> ); - expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild) + .toMatchSnapshot(); }); }); diff --git a/src/bootstrap/__tests__/RadioSet.test.js b/src/bootstrap/__tests__/RadioSet.test.js index 39b91a9..330342a 100644 --- a/src/bootstrap/__tests__/RadioSet.test.js +++ b/src/bootstrap/__tests__/RadioSet.test.js @@ -5,31 +5,41 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {render} from 'customTestRender'; +import { render } from "customTestRender"; -import RadioSet from '../RadioSet'; +import { RadioSet } from "../RadioSet"; const TEST_CHOICES = [ - {label: 'label', value: 'value'}, - {label: 'another label', value: 'another value'}, - {label: 'another one label', value: 'another on value'} + { + label: "label", + value: "value" + }, + { + label: "another label", + value: "another value" + }, + { + label: "another one label", + value: "another on value" + } ]; -describe('', () => { - it('Render radio set', () => { - const {container} = render( +describe("", () => { + it("Render radio set", () => { + const { container } = render( { }} /> ); - expect(container.firstChild).toMatchSnapshot(); + expect(container.firstChild) + .toMatchSnapshot(); }); }); diff --git a/src/bootstrap/__tests__/Select.test.js b/src/bootstrap/__tests__/Select.test.js index c309172..6d7221e 100644 --- a/src/bootstrap/__tests__/Select.test.js +++ b/src/bootstrap/__tests__/Select.test.js @@ -5,23 +5,23 @@ * See /LICENSE for more information. */ -import React from 'react'; +import React from "react"; -import {fireEvent, getByDisplayValue, getByText, render} from 'customTestRender'; +import { fireEvent, getByDisplayValue, getByText, render } from "customTestRender"; -import Select from '../Select'; +import { Select } from "../Select"; const TEST_CHOICES = { - '1': 'one', - '2': 'two', - '3': 'three', + "1": "one", + "2": "two", + "3": "three", }; -describe('", () => { var selectContainer; const onChangeHandler = jest.fn(); beforeEach(() => { - const {container} = render( + const { container } = render(