Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .babelrc.js

This file was deleted.

49 changes: 48 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,52 @@ module.exports = {
env: {
browser: 1
},
extends: ['seegno']
extends: ['seegno'],
overrides: [{
extends: [
'seegno',
'plugin:@typescript-eslint/recommended',
'plugin:typescript-sort-keys/recommended'
],
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module'
},
plugins: [
'@typescript-eslint',
'typescript-sort-keys'
],
rules: {
'@typescript-eslint/comma-dangle': 'error',
'@typescript-eslint/member-delimiter-style': 'error',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-parens': ['error', 'all', {
ignoreJSX: 'all'
}],
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-use-before-define': 'error',
'@typescript-eslint/semi': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'comma-dangle': 'off',
'no-extra-parens': 'off',
'no-use-before-define': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
semi: 'off'
}
}],
root: true,
rules: {
'react/jsx-first-prop-new-line': ['error', 'multiline'],
'react/jsx-sort-props': ['error', { ignoreCase: false }],
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off'
},
settings: {
react: {
version: 'detect'
}
}
};
11 changes: 0 additions & 11 deletions .flowconfig

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/coverage
/node_modules
.parcel-cache
.parcel-dist
11 changes: 11 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example app</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="index.tsx"></script>
</body>
</html>
115 changes: 115 additions & 0 deletions example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

/**
* Module dependencies.
*/

import { FormProvider, useField, useFormState } from '../src';
import ReactDOM from 'react-dom';

/**
* `Input` component.
*/

function Input({ label, name, type = 'text' }) {
const { meta, onBlur, onChange, onFocus, value } = useField(name);

return (
<label>
<span
style={{
color: meta.active ? 'rebeccapurple' : 'initial'
}}
>
{label}
</span>

<input
name={name}
onBlur={onBlur}
onChange={event => onChange(event.target.value)}
onFocus={onFocus}
type={type}
value={value ?? ''}
/>
</label>
);
}

/**
* `RerenderTester` component.
*/

function RerenderTester() {
console.log('RerenderTester rendered'); // eslint-disable-line no-console

return (
<div>
{'Re-render tester'}
</div>
);
}

/**
* `SubmitButton` component.
*/

function SubmitButton() {
const { isSubmitting } = useFormState();

return (
<button
disabled={isSubmitting}
type={'submit'}
>
{isSubmitting ? 'Submitting' : 'Submit'}
</button>
);
}

/**
* `App` component.
*/

function App() {
return (
<div>
<h1>{'Hello world!'}</h1>

<FormProvider
initialValues={{}}
jsonSchema={{}}
onSubmit={values => {
console.log('submit', values); // eslint-disable-line no-console

return new Promise(resolve => {
setTimeout(() => resolve, 5000);
});
}}
>
{({ submit }) => (
<form onSubmit={submit}>
<RerenderTester />

<Input
label={'Name'}
name={'name'}
/>

<Input
label={'Email'}
name={'email'}
/>

<SubmitButton />
</form>
)}
</FormProvider>
</div>
);
}

/**
* Render app.
*/

ReactDOM.render(<App />, document.getElementById('app'));
51 changes: 27 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"bundle": "rm -rf dist && babel src --out-dir dist",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to parcel right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Parcel is only used to bundle the example application. The module is still bundled using Babel.

"changelog": "github_changelog_generator --no-issues --header-label='# Changelog' --future-release=v$npm_config_future_release && sed -i '' -e :a -e '$d;N;2,4ba' -e 'P;D' CHANGELOG.md",
"coverage": "jest --coverage",
"lint": "eslint .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint-staged": "lint-staged",
"start-example": "parcel --dist-dir=.parcel-dist example/index.html",
"test": "jest",
"test-watch": "jest --watch --notify --onlyChanged",
"version": "NODE_ENV=production npm run bundle && npm run changelog --future-release=$npm_package_version && git add -A CHANGELOG.md dist"
Expand Down Expand Up @@ -56,38 +57,40 @@
"modulePaths": [
"<rootDir>/src/"
],
"preset": "ts-jest",
"setupFilesAfterEnv": [
"./test/utils/setup.js"
"./test/utils/setup.ts"
],
"testRegex": "(test/.*\\.test.js)$"
"testEnvironment": "jsdom",
"testRegex": "(test/.*\\.test.(ts|tsx))$"
},
"dependencies": {
"ajv": "^8.6.2",
"lodash": "^4.17.20"
"lodash": "^4.17.20",
"use-subscription": "^1.5.1"
},
"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
"@babel/preset-env": "^7.7.1",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.7.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/react-hooks": "^3.2.1",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "^5.16.0",
"eslint-config-seegno": "^15.0.0",
"flow-bin": "^0.112.0",
"flow-typed": "^2.6.2",
"jest": "^24.9.0",
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^12.1.4",
"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^27.4.1",
"@types/react": "^17.0.43",
"@types/use-subscription": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^7.14.0",
"eslint-config-seegno": "^16.0.0",
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"jest": "^27.5.1",
"lint-staged": "^9.4.3",
"parcel": "^2.4.0",
"pre-commit": "^1.2.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-test-renderer": "^16.12.0",
"sort-package-json": "^1.23.1"
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-test-renderer": "^17.0.2",
"sort-package-json": "^1.55.0",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
Expand Down
77 changes: 0 additions & 77 deletions src/components/form-provider.js

This file was deleted.

Loading