diff --git a/.eslintrc.js b/.eslintrc.js
index 599c3d16..da588a6a 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -9,14 +9,24 @@ module.exports = {
'plugin:jsx-a11y/recommended',
'prettier',
'plugin:prettier/recommended',
+ 'plugin:perfectionist/recommended-line-length',
],
- plugins: ['jsx-a11y'],
+ plugins: ['jsx-a11y', 'perfectionist'],
rules: {
// 'no-unused-vars': [ // 需要使用typescript的unused,否则会对enum误报
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],
+ 'perfectionist/sort-imports': [
+ 'error',
+ {
+ type: 'line-length',
+ order: 'desc',
+ groups: [],
+ 'newlines-between': 'never',
+ },
+ ],
},
overrides: [
{
diff --git a/.prettierrc.js b/.prettierrc.js
index 46b02684..367b4f99 100644
--- a/.prettierrc.js
+++ b/.prettierrc.js
@@ -31,7 +31,7 @@ module.exports = {
// 大括号内的首尾需要空格
bracketSpacing: true,
// 标签的反尖括号需要换行
- bracketSameLine: true,
+ bracketSameLine: false,
// 箭头函数,只有一个参数的时候,也需要括号
arrowParens: 'always',
// 每个文件格式化的范围是文件的全部内容
diff --git a/internal/playground/src/app/App.tsx b/internal/playground/src/app/App.tsx
index 3bfa8ebf..4581cedb 100644
--- a/internal/playground/src/app/App.tsx
+++ b/internal/playground/src/app/App.tsx
@@ -5,15 +5,16 @@ function App() {
return (
diff --git a/internal/playground/src/index.tsx b/internal/playground/src/index.tsx
index 3b81885b..19ae042f 100644
--- a/internal/playground/src/index.tsx
+++ b/internal/playground/src/index.tsx
@@ -1,9 +1,9 @@
-import React from 'react';
-import ReactDOM from 'react-dom/client';
import { RouterProvider } from 'react-router-dom';
-import './index.css';
+import ReactDOM from 'react-dom/client';
import '@pkg/components/index.scss';
import { router } from './router';
+import React from 'react';
+import './index.css';
// import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(
diff --git a/internal/playground/src/layouts/App.layout.tsx b/internal/playground/src/layouts/App.layout.tsx
index 2ec99ce2..8ba6f1dd 100644
--- a/internal/playground/src/layouts/App.layout.tsx
+++ b/internal/playground/src/layouts/App.layout.tsx
@@ -1,9 +1,9 @@
-import React from 'react';
-import { Link, Outlet, useLocation } from 'react-router-dom';
-import styles from './App.layout.module.scss';
+import { Header, Layout, Aside, Main } from '@pkg/components';
+import { useLocation, Outlet, Link } from 'react-router-dom';
import { getClassNames } from '@tool-pack/basic';
+import styles from './App.layout.module.scss';
import { baseRouter } from '../router';
-import { Aside, Header, Layout, Main } from '@pkg/components';
+import React from 'react';
export function AppLayout(): JSX.Element {
const location = useLocation();
@@ -15,7 +15,7 @@ export function AppLayout(): JSX.Element {
playground({location.pathname.replace(/^\//, '')})
-
- }>
+ } disabled>
Commit
}>Upload
@@ -123,12 +124,13 @@ const App: React.FC = () => {
+ }}
+ >
}>Delete
- }>
+ } disabled>
Commit
}>Upload
diff --git a/packages/components/src/button/demo/icon.tsx b/packages/components/src/button/demo/icon.tsx
index 56639260..89f4afcf 100644
--- a/packages/components/src/button/demo/icon.tsx
+++ b/packages/components/src/button/demo/icon.tsx
@@ -2,26 +2,26 @@
* title: 图标按钮
*/
+import { Divider, Button, Icons, Space, Icon } from '@tool-pack/react-ui';
import React from 'react';
-import { Button, Icons, Space, Divider, Icon } from '@tool-pack/react-ui';
const App: React.FC = () => {
return (
<>
- }>
+ } type="danger" size="small">
Delete
- }>
+ } type="success">
Commit
- }>
+ } size="large" type="info">
Upload
- } />
+ } type="primary" size="large" />
@@ -42,25 +42,26 @@ const App: React.FC = () => {
}
- rightIcon>
+ type="danger"
+ size="small"
+ rightIcon
+ >
Delete
- } rightIcon>
+ } type="success" rightIcon>
Commit
- } rightIcon>
+ } size="large" type="info" rightIcon>
Upload
}
type="primary"
size="large"
- icon={}
rightIcon
/>
diff --git a/packages/components/src/button/demo/loading.tsx b/packages/components/src/button/demo/loading.tsx
index 40344dd2..fc67bc73 100644
--- a/packages/components/src/button/demo/loading.tsx
+++ b/packages/components/src/button/demo/loading.tsx
@@ -2,8 +2,8 @@
* title: 加载中
*/
-import React, { useEffect, useState } from 'react';
import { Button, Icons, Space } from '@tool-pack/react-ui';
+import React, { useEffect, useState } from 'react';
const App: React.FC = () => {
const [loading, setLoading] = useState(false);
@@ -19,24 +19,25 @@ const App: React.FC = () => {
return (
setLoading(true)}
icon={}
- onClick={() => setLoading(true)}>
+ loading={loading}
+ type="danger"
+ size="small"
+ >
Delete
- setLoading(true)}>
+ setLoading(true)} loading={loading} type="success">
Commit
setLoading(true)}
+ icon={}
+ loading={loading}
type="primary"
size="large"
- loading={loading}
- icon={}
- onClick={() => setLoading(true)}
/>
);
diff --git a/packages/components/src/button/demo/plain.tsx b/packages/components/src/button/demo/plain.tsx
index b7477d6b..f7b2e6dd 100644
--- a/packages/components/src/button/demo/plain.tsx
+++ b/packages/components/src/button/demo/plain.tsx
@@ -3,17 +3,18 @@
* description: boolean | 'dashed' | 'text'。
*/
-import React from 'react';
import { Button, Layout } from '@tool-pack/react-ui';
+import React from 'react';
const App: React.FC = () => (
+ overflow: 'visible',
+ flexWrap: 'wrap',
+ gap: '8px',
+ }}
+ >
false
diff --git a/packages/components/src/button/demo/shape.tsx b/packages/components/src/button/demo/shape.tsx
index 290e36f5..412fe6d7 100644
--- a/packages/components/src/button/demo/shape.tsx
+++ b/packages/components/src/button/demo/shape.tsx
@@ -3,21 +3,22 @@
* description: 按钮有`none` `default` `round` `circle` 4种形状。
*/
-import React from 'react';
import { Button, Layout } from '@tool-pack/react-ui';
+import React from 'react';
const App: React.FC = () => (
+ overflow: 'visible',
+ flexWrap: 'wrap',
+ gap: '8px',
+ }}
+ >
none
default
round
-
+
circle
diff --git a/packages/components/src/button/demo/size.tsx b/packages/components/src/button/demo/size.tsx
index 756b10aa..eed81fa7 100644
--- a/packages/components/src/button/demo/size.tsx
+++ b/packages/components/src/button/demo/size.tsx
@@ -3,17 +3,18 @@
* description: 按钮有大、中、小三种尺寸。
通过设置 `size` 为 `large` `medium` `small` 分别把按钮设为大、中、小尺寸。若不设置 `size`,则尺寸为中。
*/
-import React from 'react';
import { Button, Layout } from '@tool-pack/react-ui';
+import React from 'react';
const App: React.FC = () => (
+ overflow: 'visible',
+ flexWrap: 'wrap',
+ gap: '8px',
+ }}
+ >
small
default
medium
diff --git a/packages/components/src/button/demo/type.tsx b/packages/components/src/button/demo/type.tsx
index 2bec3410..82b8069f 100644
--- a/packages/components/src/button/demo/type.tsx
+++ b/packages/components/src/button/demo/type.tsx
@@ -3,11 +3,11 @@
* description: 按钮有六种类型:默认按钮、主按钮、成功按钮、信息按钮、警告按钮和危险按钮。主按钮在同一个操作区域最多出现一次。
*/
-import React from 'react';
import { Button, Layout } from '@tool-pack/react-ui';
+import React from 'react';
const App: React.FC = () => (
-
+
Primary Button
Default Button
Success Button
diff --git a/packages/components/src/collapse-transition/CollapseTransition.tsx b/packages/components/src/collapse-transition/CollapseTransition.tsx
index a4d10e0b..f88a30a0 100644
--- a/packages/components/src/collapse-transition/CollapseTransition.tsx
+++ b/packages/components/src/collapse-transition/CollapseTransition.tsx
@@ -1,27 +1,27 @@
-import React, { useCallback, useMemo, useRef } from 'react';
-import type { CollapseTransitionProps } from './collapse-transition.types';
-import { getComponentClass } from '@pkg/shared';
-import type { RequiredPart } from '@tool-pack/types';
-import { getClassNames } from '@tool-pack/basic';
import {
- Transition,
TRANSITION_LIFE_CIRCLE,
TRANSITION_STATUS,
TransitionCB,
+ Transition,
} from '../transition';
+import type { CollapseTransitionProps } from './collapse-transition.types';
+import React, { useCallback, useMemo, useRef } from 'react';
+import type { RequiredPart } from '@tool-pack/types';
+import { getClassNames } from '@tool-pack/basic';
+import { getComponentClass } from '@pkg/shared';
const rootName = getComponentClass('collapse-transition');
export const CollapseTransition: React.FC = (
props,
) => {
- const { width, on, children, ...rest } = props as RequiredPart<
+ const { children, width, on, ...rest } = props as RequiredPart<
CollapseTransitionProps,
keyof typeof defaultProps
>;
const memorizedSize = useRef('');
- const sizeType: 'maxWidth' | 'maxHeight' = useMemo(
+ const sizeType: 'maxHeight' | 'maxWidth' = useMemo(
() => (width ? 'maxWidth' : 'maxHeight'),
[width],
);
@@ -105,15 +105,15 @@ export const CollapseTransition: React.FC = (
const Body = React.isValidElement(children)
? React.cloneElement(children as React.ReactElement, {
- key: rootName,
className: getClassNames(
rootName,
(children as React.ReactElement).props.className,
{
- [`${rootName}--w`]: width,
[`${rootName}--h`]: !width,
+ [`${rootName}--w`]: width,
},
),
+ key: rootName,
})
: children;
diff --git a/packages/components/src/collapse-transition/__tests__/CollapseTransition.test.tsx b/packages/components/src/collapse-transition/__tests__/CollapseTransition.test.tsx
index 6a8a30c8..5645711d 100644
--- a/packages/components/src/collapse-transition/__tests__/CollapseTransition.test.tsx
+++ b/packages/components/src/collapse-transition/__tests__/CollapseTransition.test.tsx
@@ -1,7 +1,7 @@
-import { render, fireEvent } from '@testing-library/react';
-import Demo from '../demo/basic';
+import { fireEvent, render } from '@testing-library/react';
import { testAttrs } from '~/testAttrs';
import { CollapseTransition } from '..';
+import Demo from '../demo/basic';
describe('CollapseTransition', () => {
testAttrs(({ attrs }) => (
diff --git a/packages/components/src/collapse-transition/__tests__/__snapshots__/CollapseTransition.test.tsx.snap b/packages/components/src/collapse-transition/__tests__/__snapshots__/CollapseTransition.test.tsx.snap
index 0bea5495..95bf0901 100644
--- a/packages/components/src/collapse-transition/__tests__/__snapshots__/CollapseTransition.test.tsx.snap
+++ b/packages/components/src/collapse-transition/__tests__/__snapshots__/CollapseTransition.test.tsx.snap
@@ -8,7 +8,7 @@ exports[`CollapseTransition basic 1`] = `
style="padding-bottom: 8px; text-align: center;"
>
收起
@@ -48,7 +48,7 @@ exports[`CollapseTransition basic 2`] = `
style="padding-bottom: 8px; text-align: center;"
>
展开
diff --git a/packages/components/src/collapse-transition/demo/basic.tsx b/packages/components/src/collapse-transition/demo/basic.tsx
index da62244c..ecb97022 100644
--- a/packages/components/src/collapse-transition/demo/basic.tsx
+++ b/packages/components/src/collapse-transition/demo/basic.tsx
@@ -3,9 +3,9 @@
* description: CollapseTransition 基础用法。
*/
-import React, { useState } from 'react';
-import { Button, CollapseTransition, Divider } from '@tool-pack/react-ui';
+import { CollapseTransition, Divider, Button } from '@tool-pack/react-ui';
import styles from './basic.module.scss';
+import React, { useState } from 'react';
const App: React.FC = () => {
const [show, setShow] = useState(true);
diff --git a/packages/components/src/collapse-transition/demo/fixed-width.tsx b/packages/components/src/collapse-transition/demo/fixed-width.tsx
index f0601fc8..be202dba 100644
--- a/packages/components/src/collapse-transition/demo/fixed-width.tsx
+++ b/packages/components/src/collapse-transition/demo/fixed-width.tsx
@@ -3,8 +3,8 @@
* description: 因为宽度变化会导致内容重新排列,所以相比垂直折叠需要多操作一步把内部的宽度固定住,限制内容随宽度排列。
*/
+import { CollapseTransition, Divider, Button } from '@tool-pack/react-ui';
import React, { useLayoutEffect, useState } from 'react';
-import { Button, CollapseTransition, Divider } from '@tool-pack/react-ui';
const App: React.FC = () => {
const [visible, setVisible] = useState(true);
useLayoutEffect(() => {
diff --git a/packages/components/src/collapse-transition/demo/padding.tsx b/packages/components/src/collapse-transition/demo/padding.tsx
index 57088c53..e4c43062 100644
--- a/packages/components/src/collapse-transition/demo/padding.tsx
+++ b/packages/components/src/collapse-transition/demo/padding.tsx
@@ -3,9 +3,9 @@
* debug: true
*/
-import React, { useState } from 'react';
-import { Button, CollapseTransition, Divider } from '@tool-pack/react-ui';
+import { CollapseTransition, Divider, Button } from '@tool-pack/react-ui';
import styles from './basic.module.scss';
+import React, { useState } from 'react';
const App: React.FC = () => {
const [show, setShow] = useState(true);
@@ -16,7 +16,7 @@ const App: React.FC = () => {
{/* 加了 padding 内容会滚动 */}
-
+
道冲而用之或不盈,渊兮似万物之宗。挫其锐,解其纷,和其光,同其尘。湛兮似或存,吾不知谁之子,象帝之先。
diff --git a/packages/components/src/collapse-transition/demo/width.tsx b/packages/components/src/collapse-transition/demo/width.tsx
index 7417ca70..33773c48 100644
--- a/packages/components/src/collapse-transition/demo/width.tsx
+++ b/packages/components/src/collapse-transition/demo/width.tsx
@@ -3,8 +3,8 @@
* description: 添加 width 属性,把 Collapse 改为宽度折叠。
*/
+import { CollapseTransition, Divider, Button } from '@tool-pack/react-ui';
import React, { useState } from 'react';
-import { Button, CollapseTransition, Divider } from '@tool-pack/react-ui';
const App: React.FC = () => {
const [visible, setVisible] = useState(true);
return (
diff --git a/packages/components/src/collapse/Collapse.tsx b/packages/components/src/collapse/Collapse.tsx
index d1070011..940c136a 100644
--- a/packages/components/src/collapse/Collapse.tsx
+++ b/packages/components/src/collapse/Collapse.tsx
@@ -1,12 +1,12 @@
-import React, { useCallback, useEffect, useState } from 'react';
import { getComponentClass, getSizeClassName } from '@pkg/shared';
+import React, { useCallback, useEffect, useState } from 'react';
+import { CollapseTransition } from '~/collapse-transition';
+import type { CollapseProps } from './collapse.types';
import type { RequiredPart } from '@tool-pack/types';
import { getClassNames } from '@tool-pack/basic';
-import type { CollapseProps } from './collapse.types';
-import { CollapseTransition } from '~/collapse-transition';
-import { Icon } from '~/icon';
-import { Right } from '@pkg/icons';
import { Space } from '@pkg/components';
+import { Right } from '@pkg/icons';
+import { Icon } from '~/icon';
const rootName = getComponentClass('collapse');
@@ -15,18 +15,18 @@ export const Collapse: React.FC
= React.forwardRef<
CollapseProps
>((props, ref) => {
const {
+ iconPlacement,
+ destroyOnHide,
attrs = {},
- icon,
- size,
- extra,
- title,
- header,
children,
disabled,
expanded,
onChange,
- iconPlacement,
- destroyOnHide,
+ header,
+ extra,
+ title,
+ icon,
+ size,
} = props as RequiredPart;
const [visible, setVisible] = useState(expanded || false);
@@ -36,8 +36,8 @@ export const Collapse: React.FC = React.forwardRef<
}, [expanded]);
const Content = (
-
-
+
@@ -49,7 +49,8 @@ export const Collapse: React.FC
= React.forwardRef<
+ })}
+ >
));
@@ -75,28 +76,31 @@ export const Collapse: React.FC = React.forwardRef<
return (
+ )}
+ role={attrs.role || 'tab'}
+ ref={ref}
+ >
+ >
{HeaderContent}
+ name={rootName}
+ >
{destroyOnHide === true ? expanded && Content : Content}
@@ -105,8 +109,8 @@ export const Collapse: React.FC = React.forwardRef<
const defaultProps = {
destroyOnHide: 'mixed',
- size: 'medium',
iconPlacement: 'start',
+ size: 'medium',
} satisfies Partial;
Collapse.defaultProps = defaultProps;
Collapse.displayName = 'Collapse';
diff --git a/packages/components/src/collapse/CollapseGroup.tsx b/packages/components/src/collapse/CollapseGroup.tsx
index d6ca0f2f..e3b5ba28 100644
--- a/packages/components/src/collapse/CollapseGroup.tsx
+++ b/packages/components/src/collapse/CollapseGroup.tsx
@@ -1,8 +1,8 @@
-import React, { useEffect, useRef } from 'react';
import { getComponentClass, useForceUpdate } from '@pkg/shared';
+import type { CollapseGroupProps } from './collapse.types';
import type { RequiredPart } from '@tool-pack/types';
+import React, { useEffect, useRef } from 'react';
import { getClassNames } from '@tool-pack/basic';
-import type { CollapseGroupProps } from './collapse.types';
import { Collapse } from './Collapse';
const rootName = getComponentClass('collapse-group');
@@ -13,11 +13,11 @@ export const CollapseGroup: React.FC = React.forwardRef<
>((props, ref) => {
const {
collapseProps,
- onChange,
+ attrs = {},
accordion,
+ onChange,
items,
tag,
- attrs = {},
} = props as RequiredPart;
const list = useRef(items);
@@ -42,8 +42,8 @@ export const CollapseGroup: React.FC = React.forwardRef<
tag,
{
...attrs,
- ref,
className: getClassNames(rootName, attrs.className),
+ ref,
},
list.current.map(({ onChange, ...rest }, i) => {
const opts = { ...collapseProps, ...rest };
diff --git a/packages/components/src/collapse/__tests__/Collapse.test.tsx b/packages/components/src/collapse/__tests__/Collapse.test.tsx
index 185eacb9..0caf9257 100644
--- a/packages/components/src/collapse/__tests__/Collapse.test.tsx
+++ b/packages/components/src/collapse/__tests__/Collapse.test.tsx
@@ -1,7 +1,7 @@
import { render } from '@testing-library/react';
-import { Collapse } from '..';
-import { Left } from '@pkg/icons';
import { testAttrs } from '~/testAttrs';
+import { Left } from '@pkg/icons';
+import { Collapse } from '..';
describe('Collapse', () => {
testAttrs(Collapse);
@@ -78,7 +78,7 @@ describe('Collapse', () => {
test('icon', () => {
expect(
render(
- }>
+ } title={'第十四章'}>
视之不见名曰夷,听之不闻名曰希,搏之不得名曰微。
,
).container.firstChild,
@@ -88,7 +88,7 @@ describe('Collapse', () => {
test('icon-placement', () => {
expect(
render(
- } iconPlacement="end">
+ } iconPlacement="end" title={'第十四章'}>
视之不见名曰夷,听之不闻名曰希,搏之不得名曰微。
,
).container.firstChild,
diff --git a/packages/components/src/collapse/__tests__/CollapseGroup.test.tsx b/packages/components/src/collapse/__tests__/CollapseGroup.test.tsx
index 6ae0a1fc..3dc753b6 100644
--- a/packages/components/src/collapse/__tests__/CollapseGroup.test.tsx
+++ b/packages/components/src/collapse/__tests__/CollapseGroup.test.tsx
@@ -1,64 +1,64 @@
+import { CollapseGroupItem, CollapseGroup } from '..';
import { render } from '@testing-library/react';
-import { CollapseGroup, CollapseGroupItem } from '..';
import { Left } from '@pkg/icons';
describe('CollapseGroup', () => {
test('all', () => {
const nest: CollapseGroupItem[] = [
{
- key: '4',
- title: '第二十三章',
- icon: () => ,
- iconPlacement: 'end',
children:
'希言自然。故飘风不终朝(zhāo),骤雨不终日。孰为此者?天地。天地尚不能久,而况于人乎?故从事于道者,道者同于道,德者同于德,失者同于失。同于道者,道亦乐得之;同于德者,德亦乐得之;同于失者,失亦乐得之。信不足焉,有不信焉。',
+ icon: () => ,
+ iconPlacement: 'end',
+ title: '第二十三章',
+ key: '4',
},
{
- key: '5',
- title: '第二十四章',
- disabled: true,
children:
'企者不立,跨者不行,自见(xiàn)者不明,自是者不彰,自伐者无功,自矜者不长。其在道也,曰余食赘(zhuì)行。物或恶(wù)之,故有道者不处(chǔ)。',
+ title: '第二十四章',
+ disabled: true,
+ key: '5',
},
{
- key: '6',
- title: '第二十五章',
- extra: ,
children:
'有物混(hùn)成,先天地生。寂兮寥兮,独立不改,周行而不殆,可以为天下母。吾不知其名,字之曰道,强(qiǎng)为之名曰大。大曰逝,逝曰远,远曰反。故道大,天大,地大,王亦大。域中有四大,而王居其一焉。人法地,地法天,天法道,道法自然。',
+ extra: ,
+ title: '第二十五章',
+ key: '6',
},
];
const items: CollapseGroupItem[] = [
{
- key: '1',
- title: '第二十一章',
children:
'孔德之容,惟道是从。道之为物,惟恍惟惚。惚兮恍兮,其中有象;恍兮惚兮,其中有物。窈(yǎo)兮冥兮,其中有精;其精甚真,其中有信。自古及今,其名不去,以阅众甫。吾何以知众甫之状哉?以此。',
+ title: '第二十一章',
+ key: '1',
},
{
- key: '2',
- title: '第二十二章',
children:
'曲则全,枉则直,洼则盈,敝则新,少则得,多则惑。是以圣人抱一,为天下式。不自见(xiàn)故明,不自是故彰,不自伐故有功,不自矜故长。夫唯不争,故天下莫能与之争。古之所谓曲则全者,岂虚言哉!诚全而归之。',
+ title: '第二十二章',
+ key: '2',
},
{
- key: '3',
- title: '第二十三至二十五章',
- extra: '嵌套',
- expanded: true,
children: (
),
+ title: '第二十三至二十五章',
+ expanded: true,
+ extra: '嵌套',
+ key: '3',
},
];
expect(
render(
,
).container.firstChild,
).toMatchSnapshot();
diff --git a/packages/components/src/collapse/__tests__/__snapshots__/Collapse.test.tsx.snap b/packages/components/src/collapse/__tests__/__snapshots__/Collapse.test.tsx.snap
index c0c1c20f..98b083d4 100644
--- a/packages/components/src/collapse/__tests__/__snapshots__/Collapse.test.tsx.snap
+++ b/packages/components/src/collapse/__tests__/__snapshots__/Collapse.test.tsx.snap
@@ -7,7 +7,7 @@ exports[`Collapse basic 1`] = `
>