From 5897ebd46988692830a8fcab5fa8e88489ea576a Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:14:04 +0800 Subject: [PATCH 1/9] chore: code style lint --- package.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6df3c9f..ec1b4a4 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "prepublishOnly": "npm run compile && np --yolo --no-publish", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", "start": "dumi dev", - "test": "rc-test" + "test": "rc-test", + "prepare": "husky install" }, "dependencies": { "@babel/runtime": "^7.10.1", @@ -55,8 +56,10 @@ "dumi": "^2.1.1", "eslint": "^7.11.0", "father": "^4.1.3", + "husky": "^8.0.3", "jest": "^29.1.2", "less": "^3.12.2", + "lint-staged": "^13.1.0", "np": "^6.0.0", "prettier": "^2.1.2", "rc-test": "^7.0.14", @@ -67,5 +70,9 @@ "peerDependencies": { "react": ">=16.9.0", "react-dom": ">=16.9.0" + }, + "lint-staged": { + "*.{ts,tsx,js,jsx}": "npm run lint -- --fix", + "*.{json,less,md}": "npm run prettier -- --ignore-unknown" } -} +} \ No newline at end of file From 0318c57361c8b143450d8df2246e362a52879423 Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:18:07 +0800 Subject: [PATCH 2/9] test: git hook --- src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index dcf24b0..b33849a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ import Collapse from './Collapse'; -export type { +export { CollapseProps, CollapsePanelProps } from './interface'; From 7e39154b724cac01fe788140a578dae121bb7654 Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:20:17 +0800 Subject: [PATCH 3/9] chore: test rule --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 387bb2c..c96e286 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,5 +14,6 @@ module.exports = { 'jsx-a11y/label-has-for': 0, 'jsx-a11y/no-noninteractive-tabindex': 0, 'import/no-extraneous-dependencies': 0, + '@typescript-eslint/consistent-type-exports': 2, }, }; From c9047bc26e10361f8111c9e8d146893914529b6d Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:21:25 +0800 Subject: [PATCH 4/9] test: ci --- src/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.tsx b/src/index.tsx index b33849a..12bae6d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,6 @@ import Collapse from './Collapse'; + export { CollapseProps, CollapsePanelProps From 9318e63bd84c7ea4f7bc3e204c871cc2578cd1fe Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:29:15 +0800 Subject: [PATCH 5/9] chore: update --- .husky/pre-commit | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..d37daa0 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx --no-install lint-staged From 8089cf1d7f4ccc7285de436149f737d4ebbd89ae Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:29:47 +0800 Subject: [PATCH 6/9] fix: code style --- src/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 12bae6d..dcf24b0 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,6 @@ import Collapse from './Collapse'; - -export { +export type { CollapseProps, CollapsePanelProps } from './interface'; From 8d2ab77606b9ae784032df572023e289669691e8 Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:31:14 +0800 Subject: [PATCH 7/9] chore: update code style npm run prettier --- docs/examples/_util/motionUtil.ts | 2 +- docs/examples/custom-icon.tsx | 68 ++++++++++----------- docs/examples/fragment.tsx | 2 +- docs/examples/simple.tsx | 99 ++++++++++++------------------- package.json | 14 ++--- src/Collapse.tsx | 4 +- src/Panel.tsx | 6 +- src/PanelContent.tsx | 2 +- src/index.tsx | 5 +- tests/index.spec.tsx | 6 +- 10 files changed, 88 insertions(+), 120 deletions(-) diff --git a/docs/examples/_util/motionUtil.ts b/docs/examples/_util/motionUtil.ts index f68ad80..c822ca9 100644 --- a/docs/examples/_util/motionUtil.ts +++ b/docs/examples/_util/motionUtil.ts @@ -1,4 +1,4 @@ -import type { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion'; +import type { CSSMotionProps, MotionEndEventHandler, MotionEventHandler } from 'rc-motion'; const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 }); const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 }); diff --git a/docs/examples/custom-icon.tsx b/docs/examples/custom-icon.tsx index b51f01b..ea3df8e 100644 --- a/docs/examples/custom-icon.tsx +++ b/docs/examples/custom-icon.tsx @@ -1,7 +1,7 @@ -import * as React from 'react'; import Collapse, { Panel } from 'rc-collapse'; -import motion from './_util/motionUtil'; +import * as React from 'react'; import '../../assets/index.less'; +import motion from './_util/motionUtil'; const initLength = 3; @@ -48,40 +48,32 @@ const App: React.FC = () => { const time = random(); - const panelItems = Array - .from( - { length: initLength }, - (_, i) => { - const key = i + 1; - return ( - -

{text.repeat(time)}

-
- ) - }) - .concat( - - - -

{text}

-
-
-
, - - - -
- - -
-
-
+ const panelItems = Array.from({ length: initLength }, (_, i) => { + const key = i + 1; + return ( + +

{text.repeat(time)}

); - + }).concat( + + + +

{text}

+
+
+
, + + + +
+ + +
+
+
+
, + ); const tools = ( <> @@ -90,7 +82,7 @@ const App: React.FC = () => {

-
@@ -101,7 +93,7 @@ const App: React.FC = () => {

- ) + ); return ( <> @@ -116,7 +108,7 @@ const App: React.FC = () => { {panelItems} - ) -} + ); +}; export default App; diff --git a/docs/examples/fragment.tsx b/docs/examples/fragment.tsx index 2d31f4c..bb38c5b 100644 --- a/docs/examples/fragment.tsx +++ b/docs/examples/fragment.tsx @@ -1,6 +1,6 @@ +import Collapse, { Panel } from 'rc-collapse'; import * as React from 'react'; import { Fragment } from 'react'; -import Collapse, { Panel } from 'rc-collapse'; import '../../assets/index.less'; const App = () => ( diff --git a/docs/examples/simple.tsx b/docs/examples/simple.tsx index 3e7c341..5353415 100644 --- a/docs/examples/simple.tsx +++ b/docs/examples/simple.tsx @@ -1,8 +1,8 @@ -import * as React from 'react'; import type { CollapseProps } from 'rc-collapse'; import Collapse, { Panel } from 'rc-collapse'; -import motion from './_util/motionUtil'; +import * as React from 'react'; import '../../assets/index.less'; +import motion from './_util/motionUtil'; const initLength = 3; @@ -50,65 +50,44 @@ const App: React.FC = () => { const time = random(); - const panelItems = Array - .from( - { length: initLength }, - (_, i) => { - const key = i + 1; - return ( - -

{text.repeat(time)}

-
- ) - }) - .concat( - - - -

{text}

-
-
-
, - - - -
- - -
-
-
-
, - Extra Node} - > -

Panel with extra

+ const panelItems = Array.from({ length: initLength }, (_, i) => { + const key = i + 1; + return ( + +

{text.repeat(time)}

); + }).concat( + + + +

{text}

+
+
+
, + + + +
+ + +
+
+
+
, + Extra Node} + > +

Panel with extra

+
, + ); const handleCollapsibleChange = (e: React.ChangeEvent) => { const values = [undefined, 'header', 'icon', 'disabled']; - setCollapsible(values[e.target.value]) - } + setCollapsible(values[e.target.value]); + }; const tools = ( <> @@ -117,7 +96,7 @@ const App: React.FC = () => {

-
@@ -138,7 +117,7 @@ const App: React.FC = () => {

- ) + ); return ( <> @@ -154,7 +133,7 @@ const App: React.FC = () => { {panelItems} - ) -} + ); +}; export default App; diff --git a/package.json b/package.json index ec1b4a4..932ac04 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,15 @@ "compile": "father build && lessc assets/index.less assets/index.css", "coverage": "npm test -- --coverage", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", + "prepare": "husky install", "prepublishOnly": "npm run compile && np --yolo --no-publish", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", "start": "dumi dev", - "test": "rc-test", - "prepare": "husky install" + "test": "rc-test" + }, + "lint-staged": { + "*.{ts,tsx,js,jsx}": "npm run lint -- --fix", + "*.{json,less,md}": "npm run prettier -- --ignore-unknown" }, "dependencies": { "@babel/runtime": "^7.10.1", @@ -70,9 +74,5 @@ "peerDependencies": { "react": ">=16.9.0", "react-dom": ">=16.9.0" - }, - "lint-staged": { - "*.{ts,tsx,js,jsx}": "npm run lint -- --fix", - "*.{json,less,md}": "npm run prettier -- --ignore-unknown" } -} \ No newline at end of file +} diff --git a/src/Collapse.tsx b/src/Collapse.tsx index 3466d0e..4f1bc24 100644 --- a/src/Collapse.tsx +++ b/src/Collapse.tsx @@ -1,9 +1,9 @@ -import React from 'react'; import classNames from 'classnames'; import toArray from 'rc-util/lib/Children/toArray'; import useMergedState from 'rc-util/lib/hooks/useMergedState'; -import CollapsePanel from './Panel'; +import React from 'react'; import type { CollapseProps, CollapsibleType } from './interface'; +import CollapsePanel from './Panel'; function getActiveKeysArray(activeKey: React.Key | React.Key[]) { let currentActiveKey = activeKey; diff --git a/src/Panel.tsx b/src/Panel.tsx index 7d87fd7..1daf893 100644 --- a/src/Panel.tsx +++ b/src/Panel.tsx @@ -1,8 +1,8 @@ -import React from 'react'; import classNames from 'classnames'; -import type { CollapsePanelProps } from './interface'; -import KeyCode from 'rc-util/lib/KeyCode'; import CSSMotion from 'rc-motion'; +import KeyCode from 'rc-util/lib/KeyCode'; +import React from 'react'; +import type { CollapsePanelProps } from './interface'; import PanelContent from './PanelContent'; const CollapsePanel = React.forwardRef((props, ref) => { diff --git a/src/PanelContent.tsx b/src/PanelContent.tsx index bdaf4b3..ba6d36e 100644 --- a/src/PanelContent.tsx +++ b/src/PanelContent.tsx @@ -1,5 +1,5 @@ -import React from 'react'; import classnames from 'classnames'; +import React from 'react'; import type { CollapsePanelProps } from './interface'; const PanelContent = React.forwardRef< diff --git a/src/index.tsx b/src/index.tsx index dcf24b0..8cda2ed 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,9 +1,6 @@ import Collapse from './Collapse'; -export type { - CollapseProps, - CollapsePanelProps -} from './interface'; +export type { CollapsePanelProps, CollapseProps } from './interface'; export default Collapse; export const { Panel } = Collapse; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index a76b01b..b4ec8ae 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -1,5 +1,5 @@ -import { fireEvent, render } from '@testing-library/react'; import type { RenderResult } from '@testing-library/react'; +import { fireEvent, render } from '@testing-library/react'; import KeyCode from 'rc-util/lib/KeyCode'; import React, { Fragment } from 'react'; import Collapse, { Panel } from '../src/index'; @@ -623,11 +623,11 @@ describe('collapse', () => { const { container } = render( {null} - +

Panel 1 content

{0} - +

Panel 2 content

{undefined} From 172f97489609b57378b495de0954c1ea4cbdc8ce Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 17:36:24 +0800 Subject: [PATCH 8/9] chore: update config --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 932ac04..3c8cd18 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,10 @@ "test": "rc-test" }, "lint-staged": { - "*.{ts,tsx,js,jsx}": "npm run lint -- --fix", + "*.{ts,tsx,js,jsx}": [ + "npm run prettier -- --ignore-unknown", + "npm run lint -- --fix" + ], "*.{json,less,md}": "npm run prettier -- --ignore-unknown" }, "dependencies": { From b621614460a0c0a1c29fa3a679b48d212a7c10a1 Mon Sep 17 00:00:00 2001 From: wuxh Date: Fri, 13 Jan 2023 18:00:33 +0800 Subject: [PATCH 9/9] chore: update config --- package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index 3c8cd18..0c6b4ff 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,7 @@ "test": "rc-test" }, "lint-staged": { - "*.{ts,tsx,js,jsx}": [ - "npm run prettier -- --ignore-unknown", - "npm run lint -- --fix" - ], - "*.{json,less,md}": "npm run prettier -- --ignore-unknown" + "**/*.{ts,tsx,js,jsx,json,md}": "npm run prettier" }, "dependencies": { "@babel/runtime": "^7.10.1",