Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(design): add selected icon for tree component (#743)

Dushusir0f88a4eb9263
diff --git a/packages/design/src/components/tree/Tree.tsx b/packages/design/src/components/tree/Tree.tsx
index 51b6881149..ed104955c5 100644
--- a/packages/design/src/components/tree/Tree.tsx
+++ b/packages/design/src/components/tree/Tree.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { DropdownSingle } from '@univerjs/icons';
+import { CheckMarkSingle, DropdownSingle } from '@univerjs/icons';
import clsx from 'clsx';
import React, { useEffect, useMemo, useState } from 'react';
@@ -26,7 +26,7 @@ export enum TreeSelectionMode {
ALL,
}
-interface ITreeNodeProps {
+export interface ITreeNodeProps {
title: string;
key: string;
children?: ITreeNodeProps[];
@@ -138,13 +138,20 @@ export function Tree(props: ITreeProps) {
[styles.treeListItemContentSelected]: _selected,
})}
>
- <span
- className={clsx(styles.treeIcon, {
- [styles.treeIconExpand]: _expand,
- })}
- >
- {children && <DropdownSingle />}
- </span>
+ {children && children.length > 0 && (
+ <span
+ className={clsx(styles.treeIcon, {
+ [styles.treeIconExpand]: _expand,
+ })}
+ >
+ <DropdownSingle />
+ </span>
+ )}
+ {_selected && (
+ <span className={styles.treeListItemContentSelectedIcon}>
+ <CheckMarkSingle />
+ </span>
+ )}
<span>{title}</span>
</a>
{children && (
diff --git a/packages/design/src/components/tree/index.module.less b/packages/design/src/components/tree/index.module.less
index 5376c6aab4..9827aaecd3 100644
--- a/packages/design/src/components/tree/index.module.less
+++ b/packages/design/src/components/tree/index.module.less
@@ -1,19 +1,22 @@
.tree {
+ user-select: none;
position: relative;
color: rgb(var(--text-color));
&-icon {
position: absolute;
- top: 7px;
- left: 0;
- transform: rotate(-90deg);
+ top: 50%;
+ left: calc(-1 * var(--padding-lg));
+ transform: translateY(-50%) rotateZ(-90deg) ;
- margin-right: 8px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
font-size: 8px;
&-expand {
- transform: rotate(0deg);
+ transform: translateY(-50%);
}
}
@@ -33,10 +36,11 @@
&-item {
position: relative;
- padding-left: var(--padding-lg);
+ padding-left: var(--padding-xl);
> a {
cursor: pointer;
+ position: relative;
display: block;
}
@@ -46,7 +50,22 @@
&-selected {
font-weight: 500;
color: rgb(var(--primary-color));
+
+ &-icon {
+ position: absolute;
+ top: 50%;
+ left: calc(-1 * var(--padding-xl));
+ transform: translateY(-50%);
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ font-size: var(--font-size-lg);
+ }
}
+
+
}
}
}
diff --git a/packages/design/src/components/tree/index.ts b/packages/design/src/components/tree/index.ts
index 31029b0937..a93b37f9f9 100644
--- a/packages/design/src/components/tree/index.ts
+++ b/packages/design/src/components/tree/index.ts
@@ -14,4 +14,4 @@
* limitations under the License.
*/
-export { type ITreeProps, Tree, TreeSelectionMode } from './Tree';
+export { type ITreeNodeProps, type ITreeProps, Tree, TreeSelectionMode } from './Tree';
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index 27bddc2f1b..38a60fc0fd 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -37,7 +37,7 @@ export { type ISelectProps, Select } from './components/select';
export { type ISelectListProps, SelectList } from './components/select-list';
export { type ISliderProps, Slider } from './components/slider';
export { type ITooltipProps, Tooltip } from './components/tooltip';
-export { type ITreeProps, Tree, TreeSelectionMode } from './components/tree';
+export { type ITreeNodeProps, type ITreeProps, Tree, TreeSelectionMode } from './components/tree';
export { enUS, zhCN } from './locale';
export { type ILocale } from './locale/interface';
export { defaultTheme, greenTheme, themeInstance } from './themes';