Skip to content

Commit 0875de2

Browse files
committed
chore: style modification and some upgrades
1 parent fc0aa88 commit 0875de2

22 files changed

Lines changed: 156 additions & 119 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:root {
2-
--app-th-background-color: rgb(0 0 0 / 2%);
2+
--app-th-background-color: #f9f9f9;
33
--app-code-background-color: #f2f4f5;
44
}

packages/ui/src/components/_transition/transition.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ThrottleByAnimationFrame } from '../../hooks/throttle-and-debounce
44
import { isFunction, isNumber, isString } from 'lodash';
55
import React, { useImperativeHandle, useEffect, useLayoutEffect, useRef, useState } from 'react';
66
import { flushSync } from 'react-dom';
7-
import { count, first, mergeWith, take, timer } from 'rxjs';
7+
import { count, filter, first, mergeWith, take, timer } from 'rxjs';
88

99
import { useAsync, useThrottle, useImmer } from '../../hooks';
1010
import { CssRecord, getTransitinNum, getMaxTime } from './utils';
@@ -93,6 +93,7 @@ export const DTransition = React.forwardRef<DTransitionRef, DTransitionProps>((p
9393

9494
asyncCapture
9595
.fromEvent(dEl, 'transitionend')
96+
.pipe(filter((e) => e.target === dEl))
9697
.pipe(take(transitinNum), count())
9798
.pipe(mergeWith(timer(timeout + 5)))
9899
.pipe(first())

packages/ui/src/components/affix/demos/2.Target.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ export default function Demo() {
3333
height: 200px;
3434
overflow-y: scroll;
3535

36-
background-color: rgba(var(--d-color-primary-rgb) / 10%);
36+
background-color: var(--d-color-primary-background-6);
3737

3838
& > div {
3939
height: 600px;
4040
padding-top: 60px;
4141
}
4242

4343
.d-affix {
44-
background-color: rgba(var(--d-color-primary-rgb) / 20%);
44+
background-color: var(--d-color-primary-background);
4545
}
4646
}
4747
```

packages/ui/src/components/anchor/Anchor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getClassName, CustomScroll } from '../../utils';
99
export interface DAnchorContextData {
1010
anchorActiveHref: string | null;
1111
onLinkClick: (href: string) => void;
12-
onLinkChange: (href: string, el?: HTMLElement) => void;
12+
onLinkChange: (href: string, el?: HTMLElement | null) => void;
1313
}
1414
export const DAnchorContext = React.createContext<DAnchorContextData | null>(null);
1515

@@ -42,7 +42,7 @@ export function DAnchor(props: DAnchorProps) {
4242
//#endregion
4343

4444
const dataRef = useRef({
45-
links: new Map<string, HTMLElement>(),
45+
links: new Map<string, HTMLElement | null>(),
4646
});
4747

4848
const asyncCapture = useAsync();

packages/ui/src/components/anchor/AnchorLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function DAnchorLink(props: DAnchorLinkProps) {
3636
//#region DidUpdate
3737
useEffect(() => {
3838
if (linkEl && href) {
39-
onLinkChange?.(href, linkEl as HTMLElement);
39+
onLinkChange?.(href, linkEl);
4040
return () => {
4141
onLinkChange?.(href);
4242
};

packages/ui/src/components/drag-drop/Drop.tsx

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { DElementSelector } from '../../hooks/element-ref';
22
import type { DDragProps } from './Drag';
33

4-
import { isEqual, isUndefined } from 'lodash';
5-
import React, { useImperativeHandle, useRef } from 'react';
4+
import { cloneDeep, isEqual, isUndefined } from 'lodash';
5+
import React, { useImperativeHandle, useRef, useState } from 'react';
66
import { useEffect, useMemo } from 'react';
77

88
import { useDComponentConfig, useRefSelector, useImmer } from '../../hooks';
@@ -46,20 +46,14 @@ export const DDrop = React.forwardRef<DDropRef, DDropProps>((props, ref) => {
4646
onDragEnd,
4747
} = useDComponentConfig('drop', props);
4848

49-
const dataRef = useRef<
50-
DDropContextData['dropCurrentData'] & {
51-
order: string[];
52-
preOrder?: string[];
53-
}
54-
>({
49+
const dataRef = useRef<DDropContextData['dropCurrentData']>({
5550
drags: new Map(),
5651
placeholders: new Map(),
57-
order: Array<string>(),
5852
});
5953

60-
const [updateChildren, setUpdateChildren] = useImmer(0);
6154
const [isOuter, setIsOuter] = useImmer(false);
6255

56+
const [orderIds, setOrderIds] = useState<string[]>([]);
6357
const [orderChildren, setOrderChildren] = useImmer<React.ReactElement[]>([]);
6458

6559
const containerRef = useRefSelector(dContainer);
@@ -68,24 +62,27 @@ export const DDrop = React.forwardRef<DDropRef, DDropProps>((props, ref) => {
6862
useEffect(() => {
6963
const _childs = React.Children.toArray(children) as Array<React.ReactElement<DDragProps>>;
7064
const allIds = _childs.map((child) => child.props.dId as string);
71-
dataRef.current.order = dataRef.current.order.filter((id) => allIds.includes(id));
72-
dataRef.current.order.length = allIds.length;
73-
const addIndex = allIds.findIndex((id) => !dataRef.current.order.includes(id));
65+
const newOrderIds = cloneDeep(orderIds.filter((id) => allIds.includes(id)));
66+
newOrderIds.length = allIds.length;
67+
const addIndex = allIds.findIndex((id) => !newOrderIds.includes(id));
7468
if (addIndex !== -1) {
7569
const addIds: string[] = [];
7670
for (let n = addIndex; n < allIds.length; n++) {
77-
if (!dataRef.current.order.includes(allIds[n])) {
71+
if (!newOrderIds.includes(allIds[n])) {
7872
addIds.push(allIds[n]);
7973
} else {
8074
break;
8175
}
8276
}
83-
dataRef.current.order.splice(addIndex, 0, ...addIds);
77+
newOrderIds.splice(addIndex, 0, ...addIds);
8478
}
8579

80+
if (!isEqual(newOrderIds, orderIds)) {
81+
setOrderIds(newOrderIds);
82+
}
8683
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87-
setOrderChildren(dataRef.current.order.map((id) => _childs.find((child) => child.props.dId === id)!));
88-
}, [children, updateChildren, setOrderChildren]);
84+
setOrderChildren(newOrderIds.map((id) => _childs.find((child) => child.props.dId === id)!));
85+
}, [children, setOrderChildren, orderIds, setOrderIds]);
8986
//#endregion
9087

9188
const contextValue = useMemo<DDropContextData>(
@@ -145,7 +142,9 @@ export const DDrop = React.forwardRef<DDropRef, DDropProps>((props, ref) => {
145142
top: rect.top + rect.height / 2,
146143
left: rect.left + rect.width / 2,
147144
};
148-
dataRef.current.order.forEach((id, index) => {
145+
146+
let newOrderIds = cloneDeep(orderIds);
147+
newOrderIds.forEach((id, index) => {
149148
let el: HTMLElement | null = null;
150149
if (id === dragId) {
151150
const selector = dataRef.current.placeholders.get(id);
@@ -175,34 +174,32 @@ export const DDrop = React.forwardRef<DDropRef, DDropProps>((props, ref) => {
175174
}
176175
}
177176
});
178-
179177
if (!isUndefined(replaceIndex)) {
180-
dataRef.current.order.splice(
181-
dataRef.current.order.findIndex((id) => id === dragId),
178+
newOrderIds.splice(
179+
newOrderIds.findIndex((id) => id === dragId),
182180
1,
183181
// eslint-disable-next-line @typescript-eslint/no-explicit-any
184182
undefined as any
185183
);
186184

187-
dataRef.current.order.splice(replaceIndex, 0, dragId as string);
185+
newOrderIds.splice(replaceIndex, 0, dragId as string);
188186

189-
dataRef.current.order = dataRef.current.order.filter((id) => !!id);
187+
newOrderIds = newOrderIds.filter((id) => !!id);
188+
}
190189

191-
if (!isEqual(dataRef.current.preOrder, dataRef.current.order)) {
192-
dataRef.current.preOrder = [...dataRef.current.order];
193-
setUpdateChildren((prev) => prev + 1);
194-
onOrderChange?.(dataRef.current.order);
195-
}
190+
if (!isEqual(newOrderIds, orderIds)) {
191+
setOrderIds(newOrderIds);
192+
onOrderChange?.(newOrderIds);
196193
}
197194
},
198195
onDragEnd: (id) => {
199196
onDragEnd?.(id);
200197
},
201198
}),
202-
[dDirection, isOuter, dPlaceholder, onDragStart, onDrag, containerRef, setIsOuter, setUpdateChildren, onOrderChange, onDragEnd]
199+
[containerRef, dDirection, dPlaceholder, isOuter, onDrag, onDragEnd, onDragStart, onOrderChange, orderIds, setIsOuter, setOrderIds]
203200
);
204201

205-
useImperativeHandle(ref, () => dataRef.current.order, []);
202+
useImperativeHandle(ref, () => orderIds, [orderIds]);
206203

207204
return <DDropContext.Provider value={contextValue}>{orderChildren}</DDropContext.Provider>;
208205
});

packages/ui/src/components/drawer/demos/3.Container.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export default function Demo() {
4444
padding: 20px;
4545
border: 1px solid var(--d-divider-color);
4646

47-
background-color: rgba(var(--d-color-primary-rgb) / 10%);
47+
background-color: var(--d-color-primary-background-6);
4848
}
4949
```

packages/ui/src/components/drawer/demos/4.Nested.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,3 @@ export default function Demo() {
4949
);
5050
}
5151
```
52-
53-
```scss
54-
.container {
55-
height: 200px;
56-
padding: 20px;
57-
border: 1px solid var(--d-divider-color);
58-
59-
background-color: rgba(var(--d-color-primary-rgb) / 10%);
60-
}
61-
```

packages/ui/src/components/menu/MenuSub.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function DMenuSub(props: DMenuSubProps) {
118118
popupEl,
119119
targetEl,
120120
horizontal ? 'bottom' : 'right',
121-
horizontal ? 12 : inNav ? 10 : 18
121+
horizontal ? 12 : inNav ? 10 : 14
122122
);
123123
setMenuWidth(targetEl.getBoundingClientRect().width - 32);
124124
return {

packages/ui/src/components/menu/demos/3.Popup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default function Demo() {
9797
justify-content: center;
9898
height: 40px;
9999

100-
background-color: rgba(var(--d-color-primary-rgb) / 10%);
100+
background-color: var(--d-color-primary-background-6);
101101
cursor: pointer;
102102
}
103103
```

0 commit comments

Comments
 (0)