diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..b95848a2b --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,37 @@ +const OFF = 0 +const WARN = 1 +const ERROR = 2 + +module.exports = { + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: 2020, + sourceType: "module", + ecmaFeatures: { + jsx: true, + }, + }, + extends: [ + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + // "plugin:jsx-a11y/recommended", // TODO + "prettier/@typescript-eslint", + "plugin:prettier/recommended", + ], + settings: { + react: { + version: "detect", + }, + }, + rules: { + // typescript + "@typescript-eslint/explicit-function-return-type": OFF, + "@typescript-eslint/interface-name-prefix": OFF, + "@typescript-eslint/explicit-module-boundary-types": OFF, + // react + "react/display-name": OFF, + "react/prop-types": OFF, + "react/jsx-no-target-blank": WARN, + "react/no-unescaped-entities": WARN, + }, +} diff --git a/gatsby-config.js b/gatsby-config.js index e67eff775..05b6522e7 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires const languages = require("./src/data/languages") module.exports = { diff --git a/package.json b/package.json index 9b8aef112..0256a6df3 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,51 @@ { "name": "react-hook-form-website", "description": "React hooks for form validation without the hassle.", - "version": "3.1.0", + "version": "6.0.0", "author": "beier luo", "engines": { "node": "12.x" }, "dependencies": { - "gatsby": "2.21.21", - "gatsby-image": "2.4.3", - "gatsby-plugin-google-analytics": "2.3.1", + "@hookform/devtools": "2.0.0-beta.1", + "gatsby": "2.23.3", + "gatsby-image": "2.4.7", + "gatsby-plugin-google-analytics": "2.3.4", "gatsby-plugin-gtag": "1.0.13", "gatsby-plugin-i18n": "^1.0.1", - "gatsby-plugin-manifest": "2.4.2", - "gatsby-plugin-nprogress": "^2.3.1", - "gatsby-plugin-react-helmet": "3.3.1", - "gatsby-plugin-sharp": "2.6.2", - "gatsby-plugin-sitemap": "2.4.2", - "gatsby-plugin-typescript": "2.4.2", - "gatsby-source-filesystem": "2.3.1", - "gatsby-transformer-sharp": "2.5.2", - "little-state-machine": "^3.0.0", + "gatsby-plugin-manifest": "2.4.11", + "gatsby-plugin-nprogress": "^2.3.4", + "gatsby-plugin-react-helmet": "3.3.4", + "gatsby-plugin-sharp": "2.6.11", + "gatsby-plugin-sitemap": "2.4.5", + "gatsby-plugin-typescript": "2.4.6", + "gatsby-source-filesystem": "2.3.11", + "gatsby-transformer-sharp": "2.5.5", + "gatsby-transformer-typescript-css-modules": "^1.0.14", + "little-state-machine": "^3.0.2", "prismjs": "^1.20.0", "ptz-i18n": "^1.0.0", "react": "16.13.1", "react-dom": "16.13.1", "react-github-btn": "1.2.0", "react-helmet": "5.2.1", - "react-hook-form": "4.9.3", - "react-hook-form-devtools": "1.0.2-beta.2", - "react-simple-animate": "^3.3.4", + "react-hook-form": "6.0.0-rc.1", + "react-simple-animate": "^3.3.9", "react-simple-img": "2.3.7", "react-sortablejs": "1.5.1", "sortablejs": "1.10.2" }, "devDependencies": { - "gatsby-plugin-offline": "^3.2.1", + "@typescript-eslint/eslint-plugin": "^3.4.0", + "@typescript-eslint/parser": "^3.4.0", + "eslint": "^7.3.1", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-jsx-a11y": "^6.3.1", + "eslint-plugin-prettier": "^3.1.4", + "eslint-plugin-react": "^7.20.0", + "gatsby-plugin-offline": "^3.2.9", "husky": "^4.2.5", - "lint-staged": "^10.2.2", + "lint-staged": "^10.2.9", "prettier": "2.0.5" }, "keywords": [ @@ -52,7 +60,8 @@ "start": "npm run develop", "serve": "gatsby serve", "now-build": "npm run build", - "prettier": "prettier --write './src/**/*.ts' './src/**/*.tsx' --config ./.prettierrc" + "prettier": "prettier --write './src/**/*.ts' './src/**/*.tsx' --config ./.prettierrc", + "lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix" }, "repository": { "type": "git", @@ -68,8 +77,7 @@ }, "lint-staged": { "*.{ts,tsx}": [ - "npm run format", - "npm run prettier" + "npm run format" ] } } diff --git a/src/components/AdvancedPage.tsx b/src/components/AdvancedPage.tsx index 5dec63510..ad1c38291 100644 --- a/src/components/AdvancedPage.tsx +++ b/src/components/AdvancedPage.tsx @@ -4,32 +4,26 @@ import SideMenu from "./SideMenu" import Footer from "./Footer" import fieldArray from "./codeExamples/fieldArray" import unregisterControlledComponent from "./codeExamples/unregisterControlledComponent" -import copyClipBoard from "./utils/copyClipBoard" -import schemaValidation from "./codeExamples/schemaValidation" +import conditionalComponent from "./codeExamples/conditionalComponent" import connectForm from "./codeExamples/connectForm" import formContextPerformance from "./codeExamples/formContextPerformance" import StarRepo from "./StarRepo" -import generic from "../data/generic" import { useStateMachine } from "little-state-machine" -import advancedContent from "../data/advanced" +import advancedEn from "../data/en/advanced" import controlledMixedUncontrolled from "./codeExamples/controlledMixedUncontrolled" import TabGroup from "./TabGroup" import unregisterWrapControlledComponent from "./codeExamples/unregisterWrapControlledComponent" import controlledMixedUncontrolledInput from "./codeExamples/controlledMixedUncontrolledInput" import useFieldArray from "./codeExamples/useFieldArray" import typographyStyles from "../styles/typography.module.css" -import codeAreaStyles from "./CodeArea.module.css" import containerStyles from "../styles/container.module.css" -import getStartedStyles from "./GetStarted.module.css" const { useRef } = React -const advancedEn = advancedContent["en"] const enLinks = [ advancedEn.accessibility, advancedEn.wizard, advancedEn.smartForm, advancedEn.fieldArrays, - advancedEn.schema, advancedEn.errorMessage, advancedEn.connectForm, advancedEn.formContext, @@ -37,15 +31,20 @@ const enLinks = [ advancedEn.controlledMixedWithUnControlled, advancedEn.customHookWithValidationResolver, advancedEn.workingWithVirtualizedList, + advancedEn.testingForm, ] -function Advanced({ defaultLang }: { defaultLang: string }) { +interface Props { + defaultLang: string + advanced: any +} + +function Advanced({ defaultLang, advanced }: Props) { const pageContentRef = useRef({ AccessibilityA11y: null, WizardFormFunnel: null, SmartFormComponent: null, FieldArrays: null, - SchemaValidation: null, ConnectForm: null, FormContextPerformance: null, ErrorMessages: null, @@ -53,6 +52,7 @@ function Advanced({ defaultLang }: { defaultLang: string }) { ControlledmixedwithUncontrolledComponents: null, CustomHookwithValidationResolver: null, Workingwithvirtualizedlists: null, + TestingForm: null, }) const { @@ -62,14 +62,12 @@ function Advanced({ defaultLang }: { defaultLang: string }) { language && language.currentLanguage ? language : { currentLanguage: defaultLang } - const advanced = advancedContent[currentLanguage] const links = [ advanced.accessibility, advanced.wizard, advanced.smartForm, advanced.fieldArrays, - advanced.schema, advanced.errorMessage, advanced.connectForm, advanced.formContext, @@ -77,6 +75,7 @@ function Advanced({ defaultLang }: { defaultLang: string }) { advanced.controlledMixedWithUnControlled, advanced.customHookWithValidationResolver, advanced.workingWithVirtualizedList, + advanced.testingForm, ] const goToSection = (name) => { @@ -189,39 +188,6 @@ function Advanced({ defaultLang }: { defaultLang: string }) {
-

(pageContentRef.current.SchemaValidation = ref)} - > - {advanced.schema.title} -

- - {advanced.schema.description} - - {advanced.schema.step1} - - - npm install yup - - - - {advanced.schema.step2} - - - -
-

(pageContentRef.current.ErrorMessages = ref)} @@ -298,7 +264,11 @@ function Advanced({ defaultLang }: { defaultLang: string }) { {advanced.conditionalControlledComponent.description} - + + + +

(pageContentRef.current.TestingForm = ref)} + > + {advanced.testingForm.title} +

+ + {/* TODO: record a video */} + + {/*

+ In this video tutorial, I have demonstrated how to test with React + Hook Form. +

*/} + + {/*