Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 120f948

Browse files
committed
✨ feat: 使用 cssinjs 重构 SortableList
Breaking Change: 升级 antd 到 v5
1 parent eef6600 commit 120f948

File tree

12 files changed

+272
-269
lines changed

12 files changed

+272
-269
lines changed

packages/sortable-list/demos/Basic.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import React, { useState } from 'react';
2-
1+
/**
2+
* compact: true
3+
*/
34
import SortableList from '@arvinxu/sortable-list';
5+
import { useTheme } from 'antd-style';
6+
import { useState } from 'react';
7+
import { Flexbox } from 'react-layout-kit';
48

59
const Demo = () => {
610
const [list, setList] = useState([{ id: 'hello' }, { id: 'world' }]);
711

12+
const token = useTheme();
813
return (
9-
<SortableList dataSource={list} onChange={(value) => setList(value)} />
14+
<Flexbox padding={24} style={{ background: token.colorBgLayout }}>
15+
<SortableList dataSource={list} onChange={(value) => setList(value)} />
16+
</Flexbox>
1017
);
1118
};
1219

packages/sortable-list/demos/CustomRender.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { useState } from 'react';
2-
import { Badge, Button } from 'antd';
3-
41
import SortableList from '@arvinxu/sortable-list';
5-
import { Flexbox } from '@arvinxu/layout-kit';
2+
import { Badge, Button } from 'antd';
3+
import { useState } from 'react';
4+
import { Flexbox } from 'react-layout-kit';
65

76
interface Item {
87
id: string;
@@ -54,12 +53,7 @@ const Demo = () => {
5453
getItemStyles={() => ({ padding: '16px' })}
5554
renderItem={(item: Item, { onRemove, onAddItem, index }) => {
5655
return (
57-
<Flexbox
58-
horizontal
59-
width={'100%'}
60-
distribution={'space-between'}
61-
gap={12}
62-
>
56+
<Flexbox horizontal width={'100%'} distribution={'space-between'} gap={12}>
6357
<Flexbox horizontal gap={8}>
6458
<div>
6559
<Badge count={item.id} />

packages/sortable-list/demos/CustomStyle.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import React, { useState } from 'react';
2-
1+
/**
2+
* iframe: true
3+
*/
34
import SortableList from '@arvinxu/sortable-list';
5+
import { useState } from 'react';
46

57
const Demo = () => {
68
const [list, setList] = useState([
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
{
22
"name": "@arvinxu/sortable-list",
33
"version": "1.0.7",
4-
"files": [
5-
"dist"
4+
"homepage": "https://github.com/arvinxx/components/tree/master/packages/sortable-list#readme",
5+
"repository": "git+https://github.com/arvinxx/components.git",
6+
"sideEffects": [
7+
"*.less"
68
],
79
"main": "dist/index.js",
810
"module": "dist/index.js",
911
"types": "dist/index.d.ts",
10-
"sideEffects": [
11-
"*.less"
12+
"files": [
13+
"dist"
1214
],
13-
"homepage": "https://github.com/arvinxx/components/tree/master/packages/sortable-list#readme",
14-
"repository": "git+https://github.com/arvinxx/components.git",
15-
"publishConfig": {
16-
"registry": "https://registry.npmjs.org",
17-
"access": "public"
18-
},
1915
"scripts": {
2016
"build": "father build",
21-
"test": "jest",
22-
"test:update": "jest -u",
23-
"prepublishOnly": "pnpm run build",
17+
"clean": "rm -rf dist build coverage .umi",
2418
"cov": "jest --coverage",
25-
"clean": "rm -rf dist build coverage .umi"
19+
"prepublishOnly": "pnpm run build",
20+
"test": "jest",
21+
"test:update": "jest -u"
2622
},
2723
"dependencies": {
28-
"@arvinxu/layout-kit": "1.4.0",
2924
"@dnd-kit/core": "^5.0.1",
3025
"@dnd-kit/modifiers": "^5.0.0",
3126
"@dnd-kit/sortable": "^6.0.0",
32-
"antd": "^4.18.9",
3327
"classnames": "^2.3.1",
34-
"lodash.isequal": "^4.5.0",
28+
"lodash.isequal": "^4",
29+
"react-layout-kit": "^1",
3530
"zustand": "^3.7.1"
31+
},
32+
"peerDependencies": {
33+
"antd": ">=5"
34+
},
35+
"publishConfig": {
36+
"access": "public",
37+
"registry": "https://registry.npmjs.org"
3638
}
3739
}

packages/sortable-list/src/components/Action/index.less

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { CSSProperties, FC } from 'react';
22
import React from 'react';
3-
import classNames from 'classnames';
4-
5-
import styles from './index.less';
3+
import { useStyles } from './style';
64

75
export interface ActionProps extends React.HTMLAttributes<HTMLButtonElement> {
86
active?: {
@@ -12,24 +10,22 @@ export interface ActionProps extends React.HTMLAttributes<HTMLButtonElement> {
1210
cursor?: CSSProperties['cursor'];
1311
}
1412

15-
export const Action: FC<ActionProps> = ({
16-
active,
17-
className,
18-
cursor,
19-
style,
20-
...props
21-
}) => (
22-
<button
23-
{...props}
24-
className={classNames(styles.Action, className)}
25-
tabIndex={0}
26-
style={
27-
{
28-
...style,
29-
cursor,
30-
'--fill': active?.fill,
31-
'--background': active?.background,
32-
} as CSSProperties
33-
}
34-
/>
35-
);
13+
export const Action: FC<ActionProps> = ({ active, className, cursor, style, ...props }) => {
14+
const { styles, cx } = useStyles();
15+
return (
16+
<button
17+
type={'button'}
18+
{...props}
19+
className={cx(styles.action, className)}
20+
tabIndex={0}
21+
style={
22+
{
23+
...style,
24+
cursor,
25+
'--fill': active?.fill,
26+
'--background': active?.background,
27+
} as CSSProperties
28+
}
29+
/>
30+
);
31+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { createStyles } from 'antd-style';
2+
3+
export const useStyles = createStyles(({ token, css }) => ({
4+
action: css`
5+
display: flex;
6+
flex: 0 0 auto;
7+
align-items: center;
8+
justify-content: center;
9+
width: 12px;
10+
padding: 15px;
11+
background-color: transparent;
12+
border: none;
13+
border-radius: 5px;
14+
outline: none;
15+
cursor: var(--cursor, pointer);
16+
appearance: none;
17+
touch-action: none;
18+
-webkit-tap-highlight-color: transparent;
19+
20+
@media (hover: hover) {
21+
&:hover {
22+
background-color: var(--action-background, rgba(0, 0, 0, 0.05));
23+
24+
svg {
25+
fill: #6f7b88;
26+
}
27+
}
28+
}
29+
30+
svg {
31+
flex: 0 0 auto;
32+
height: 100%;
33+
margin: auto;
34+
overflow: visible;
35+
fill: ${token.colorTextTertiary};
36+
}
37+
38+
&:active {
39+
background-color: var(--background, ${token.colorFillTertiary});
40+
41+
svg {
42+
fill: var(--fill, ${token.colorTextSecondary});
43+
}
44+
}
45+
`,
46+
}));

packages/sortable-list/src/components/BaseItem/index.less

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)