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(sheet): sheet bar style and scroll (#487)

Dushusird43f558cd553
diff --git a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
index 1395d200ba..1eaeee3ac0 100644
--- a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
@@ -1,7 +1,7 @@
import { CommandType, ICommand } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
-import { ISheetBarService } from '../../services/sheetbar/sheetbar.service';
+import { ISheetBarService } from '../../services/sheet-bar/sheet-bar.service';
interface IRenameCommandParams {
worksheetId: string;
diff --git a/packages/ui-plugin-sheets/src/commands/commands/unhide.command.ts b/packages/ui-plugin-sheets/src/commands/commands/unhide.command.ts
index 2796ceb584..fac08ef933 100644
--- a/packages/ui-plugin-sheets/src/commands/commands/unhide.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/unhide.command.ts
@@ -1,7 +1,7 @@
import { CommandType, ICommand } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
-import { ISheetBarService } from '../../services/sheetbar/sheetbar.service';
+import { ISheetBarService } from '../../services/sheet-bar/sheet-bar.service';
export const ShowMenuListCommand: ICommand = {
id: 'ui-sheet.command.show-menu-list',
diff --git a/packages/ui-plugin-sheets/src/services/sheetbar/sheetbar.service.ts b/packages/ui-plugin-sheets/src/services/sheet-bar/sheet-bar.service.ts
similarity index 100%
rename from packages/ui-plugin-sheets/src/services/sheetbar/sheetbar.service.ts
rename to packages/ui-plugin-sheets/src/services/sheet-bar/sheet-bar.service.ts
diff --git a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
index 6c7b88fceb..be5d410778 100644
--- a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
+++ b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
@@ -35,8 +35,8 @@ import { EditorBridgeService, IEditorBridgeService } from './services/editor-bri
import { FormatPainterService, IFormatPainterService } from './services/format-painter/format-painter.service';
import { ScrollManagerService } from './services/scroll-manager.service';
import { ISelectionRenderService, SelectionRenderService } from './services/selection/selection-render.service';
+import { ISheetBarService, SheetBarService } from './services/sheet-bar/sheet-bar.service';
import { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';
-import { ISheetBarService, SheetBarService } from './services/sheetbar/sheetbar.service';
import { IStatusBarService, StatusBarService } from './services/status-bar.service';
import { SheetCanvasView } from './views/sheet-canvas-view';
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/SheetBar.tsx b/packages/ui-plugin-sheets/src/views/sheet-bar/SheetBar.tsx
index 2da08def96..dc14e3d5fb 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/SheetBar.tsx
@@ -4,7 +4,7 @@ import { IncreaseSingle, MoreSingle } from '@univerjs/icons';
import { useDependency } from '@wendellhu/redi/react-bindings';
import { useEffect, useState } from 'react';
-import { ISheetBarService } from '../../services/sheetbar/sheetbar.service';
+import { ISheetBarService } from '../../services/sheet-bar/sheet-bar.service';
import styles from './index.module.less';
import { SheetBarButton } from './sheet-bar-button/SheetBarButton';
import { SheetBarMenu } from './sheet-bar-menu/SheetBarMenu';
@@ -68,7 +68,7 @@ export const SheetBar = () => {
{/* Scroll arrows */}
{(!leftScrollState || !rightScrollState) && (
- <div className={styles.sheetBarOptions}>
+ <div className={`${styles.sheetBarOptions} ${styles.sheetBarOptionsDivider}`}>
<SheetBarButton disabled={leftScrollState} onClick={handleScrollLeft}>
<MoreSingle style={{ transform: 'rotateZ(180deg)' }} />
</SheetBarButton>
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/index.module.less
index 8dd77054fe..da64e0fac3 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/index.module.less
@@ -2,6 +2,7 @@
@sheet-bar-max-width: 1515px;
@status-bar-max-width: 332px;
@zoom-slider-width: 260px;
+@margin-right: -4px;
.sheet-bar {
position: relative;
@@ -13,16 +14,29 @@
min-width: calc(100% - @zoom-slider-width - @status-bar-max-width);
max-width: calc(100% - @zoom-slider-width);
height: 100%;
+ margin-right: @margin-right;
background-color: rgb(var(--bg-color));
-}
-.sheet-bar-options {
- display: flex;
- flex-direction: row;
- align-items: center;
+ &-options {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+
+ margin: var(--margin-xxs);
+
+ transition: display .2s;
+
+ &-divider::after {
+ content: "";
+
+ display: block;
- margin: var(--margin-xxs);
+ width: 1px;
+ height: 16px;
+ margin: 0 var(--margin-xs);
- transition: display .2s;
-}
+ background-color: rgb(var(--grey-400));
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
index 4674a787ec..8816eb8215 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
@@ -1,4 +1,4 @@
-@sheet-bar-btn-size: 28px;
+@sheet-bar-btn-size: 24px;
.sheet-bar-btn {
cursor: pointer;
@@ -11,8 +11,8 @@
height: @sheet-bar-btn-size;
padding: 0;
- font-size: var(--font-size-base);
- color: rgb(var(--text-color));
+ font-size: var(--font-size-lg);
+ color: rgb(var(--text-color-secondary));
background-color: transparent;
border: none;
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx
index 5b212746d6..22cf9e96a7 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx
@@ -20,7 +20,7 @@ import { CheckMarkSingle, ConvertSingle, EyelashSingle } from '@univerjs/icons';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
-import { ISheetBarService } from '../../../services/sheetbar/sheetbar.service';
+import { ISheetBarService } from '../../../services/sheet-bar/sheet-bar.service';
import { SheetBarButton } from '../sheet-bar-button/SheetBarButton';
import styles from './index.module.less';
@@ -147,7 +147,7 @@ export function SheetBarMenu(props: ISheetBarMenuProps) {
<CheckMarkSingle />
)}
</span>
- {item.label}
+ <span className={styles.sheetBarMenuItemLabel}>{item.label}</span>
</li>
))}
</ul>
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/index.module.less
index 6fe8b33766..9ad0074fe3 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-menu/index.module.less
@@ -1,4 +1,5 @@
-@padding-right: 28px;
+@padding-left-right: 24px;
+@line-height: 20px;
.sheet-bar-menu {
display: grid;
@@ -6,10 +7,7 @@
align-items: center;
box-sizing: border-box;
- padding: var(--padding-lg) var(--padding-base);
-
- font-size: var(--font-size-xs);
- font-weight: 500;
+ padding: var(--padding-sm);;
background-color: rgb(var(--bg-color-secondary));
border: 1px solid rgb(var(--border-color));
@@ -23,10 +21,12 @@
&-item {
cursor: pointer;
+ position: relative;
+
display: flex;
box-sizing: border-box;
- padding: var(--padding-xs) @padding-right var(--padding-xs) var(--padding-xs);
+ padding: var(--padding-xs) @padding-left-right;
color: rgb(var(--text-color));
@@ -39,8 +39,11 @@
}
&-icon {
- display: flex;
- margin-right: var(--margin-xs);
+ position: absolute;
+ top: 50%;
+ left: var(--margin-xxs);
+ transform: translateY(-50%);
+
color: transparent;
}
@@ -48,9 +51,20 @@
color: rgb(var(--grey-400));
}
- &-select &-icon, &-select{
+ &-select{
+ font-weight: 500;
+ color: rgb(var(--primary-color));
+ }
+
+ &-select &-icon {
color: rgb(var(--primary-color));
}
+ &-label {
+ font-size: var(--font-size-xs);
+ font-weight: 400;
+ line-height: @line-height;
+ }
+
}
}
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
index 35f71f5770..b9b9c45b3f 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
@@ -15,8 +15,7 @@ import { BooleanNumber, ICommandInfo, ICommandService, IUniverInstanceService, L
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useRef, useState } from 'react';
-import { ISheetBarService } from '../../../services/sheetbar/sheetbar.service';
-import sheetBarStyles from '../index.module.less';
+import { ISheetBarService } from '../../../services/sheet-bar/sheet-bar.service';
import styles from './index.module.less';
import { IBaseSheetBarProps, SheetBarItem } from './SheetBarItem';
import { IScrollState, SlideTabBar } from './utils/slide-tab-bar';
@@ -28,10 +27,11 @@ export function SheetBarTabs() {
const [activeKey, setActiveKey] = useState('');
const [boxShadow, setBoxShadow] = useState('');
const slideTabBarRef = useRef<{ slideTabBar: SlideTabBar | null }>({ slideTabBar: null });
+ const slideTabBarContainerRef = useRef<HTMLDivElement>(null);
const univerInstanceService = useDependency(IUniverInstanceService);
const commandService = useDependency(ICommandService);
- const sheetbarService = useDependency(ISheetBarService);
+ const sheetBarService = useDependency(ISheetBarService);
const localeService = useDependency(LocaleService);
const confirmService = useDependency(IConfirmService);
@@ -68,7 +68,7 @@ export function SheetBarTabs() {
slideTabBarItemClassName: styles.slideTabItem,
slideTabBarSpanEditClassName: styles.slideTabSpanEdit,
slideTabBarItemAutoSort: true,
- slideTabRootClassName: sheetBarStyles.sheetBar,
+ slideTabBarContainer: slideTabBarContainerRef.current,
currentIndex: 0,
onChangeName: (worksheetId: string, worksheetName: string) => {
commandService.executeCommand(SetWorksheetNameCommand.id, {
@@ -83,7 +83,7 @@ export function SheetBarTabs() {
commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId });
},
onScroll: (state: IScrollState) => {
- sheetbarService.setScroll(state);
+ sheetBarService.setScroll(state);
},
onEmptyAlert: () => {
const id = 'slideTabBarAlert';
@@ -150,22 +150,22 @@ export function SheetBarTabs() {
};
const setupSubscribeScroll = () =>
- sheetbarService.scroll$.subscribe((state: IScrollState) => {
+ sheetBarService.scroll$.subscribe((state: IScrollState) => {
updateScrollButtonState(state);
});
const setupSubscribeScrollX = () =>
- sheetbarService.scrollX$.subscribe((x: number) => {
- slideTabBarRef.current.slideTabBar?.setScroll(x);
+ sheetBarService.scrollX$.subscribe((x: number) => {
+ slideTabBarRef.current.slideTabBar?.flipPage(x);
});
const setupSubscribeRenameId = () =>
- sheetbarService.renameId$.subscribe(() => {
+ sheetBarService.renameId$.subscribe(() => {
slideTabBarRef.current.slideTabBar?.getActiveItem()?.editor();
});
const setupSubscribeAddSheet = () =>
- sheetbarService.addSheet$.subscribe(() => {
+ sheetBarService.addSheet$.subscribe(() => {
slideTabBarRef.current.slideTabBar?.getScrollbar().scrollRight();
});
@@ -187,7 +187,7 @@ export function SheetBarTabs() {
};
const buttonScroll = (slideTabBar: SlideTabBar) => {
- sheetbarService.setScroll({
+ sheetBarService.setScroll({
leftEnd: slideTabBar.isLeftEnd(),
rightEnd: slideTabBar.isRightEnd(),
});
@@ -195,7 +195,7 @@ export function SheetBarTabs() {
const resizeInit = (slideTabBar: SlideTabBar) => {
// Target element
- const slideTabBarContainer = document.querySelector(`.${styles.slideTabBar}`);
+ const slideTabBarContainer = slideTabBarContainerRef.current?.querySelector(`.${styles.slideTabBar}`);
if (!slideTabBarContainer) return;
// Create a Resizeobserver
@@ -208,7 +208,7 @@ export function SheetBarTabs() {
};
return (
- <div className={styles.slideTabBarContainer}>
+ <div className={styles.slideTabBarContainer} ref={slideTabBarContainerRef}>
<div className={styles.slideTabBar} style={{ boxShadow }}>
{sheetList.map((item) => (
<SheetBarItem {...item} key={item.sheetId} selected={activeKey === item.sheetId} />
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
index f413242234..26f657488f 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
@@ -14,6 +14,8 @@
align-items: center;
padding: var(--padding-xs) @padding-left-right;
+
+ transition: box-shadow 0.2s;
}
}
@@ -37,6 +39,10 @@ Tab Item, Put outside to be compatible with drag styles
border-radius: var(--border-radius-base);
+ &:not(.slide-tab-active):hover {
+ background-color: rgb(var(--bg-color-hover));
+ }
+
.slide-tab-span {
box-sizing: border-box;
padding: var(--padding-xs) var(--padding-sm);
@@ -62,6 +68,9 @@ Tab Item, Put outside to be compatible with drag styles
.slide-tab-active {
font-weight: 700;
color: rgb(var(--primary-color));
+
background-color: rgb(var(--bg-color-secondary));
box-shadow: @tab-shadow;
+
+ transition: box-shadow .2s;
}
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
index 2f2c902f21..53c26d60a4 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.ts
@@ -9,7 +9,7 @@ export interface SlideTabBarConfig {
slideTabBarItemActiveClassName: string;
slideTabBarItemClassName: string;
slideTabBarSpanEditClassName: string;
- slideTabRootClassName: string;
+ slideTabBarContainer: HTMLDivElement | null;
slideTabBarItemAutoSort: boolean;
currentIndex: number;
onSlideEnd: (event: MouseEvent, compareIndex: number) => void;
@@ -413,12 +413,12 @@ export class SlideTabBar {
protected _rightMoveX: number = 0;
constructor(config: Partial<SlideTabBarConfig>) {
- if (config.slideTabRootClassName == null) {
+ if (config.slideTabBarContainer == null) {
throw new Error('not found slide-tab-bar root element');
}
- const slideTabBar = document.querySelector(
- `.${config.slideTabRootClassName} .${config.slideTabBarClassName ?? 'slide-tab-bar'}`
+ const slideTabBar = config.slideTabBarContainer.querySelector(
+ `.${config.slideTabBarClassName ?? 'slide-tab-bar'}`
);
if (slideTabBar == null) {
throw new Error('not found slide-tab-bar');
@@ -662,6 +662,28 @@ export class SlideTabBar {
setScroll(x: number) {
this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + x);
+ if (x > 0) {
+ const left = this.calculateLeftScrollX();
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + left);
+ } else if (x < 0) {
+ const right = this.calculateRightScrollX();
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + right);
+ }
+
+ this._config.onScroll({
+ leftEnd: this.isLeftEnd(),
+ rightEnd: this.isRightEnd(),
+ });
+ }
+
+ flipPage(x: number) {
+ if (x > 0) {
+ const left = this.calculateLeftScrollX(true);
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + left);
+ } else if (x < 0) {
+ const right = this.calculateRightScrollX(true);
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + right);
+ }
this._config.onScroll({
leftEnd: this.isLeftEnd(),
@@ -669,6 +691,50 @@ export class SlideTabBar {
});
}
+ calculateLeftScrollX(shouldFlipPage?: boolean): number {
+ let scrollX = 0;
+ const padding = 4;
+ this._slideTabItems.some((item) => {
+ const containerRect = this._slideTabBar.getBoundingClientRect();
+ const containerPosition = containerRect.left + containerRect.width;
+ const itemReact = item.getSlideTabItem().getBoundingClientRect();
+ const itemLeft = itemReact.left;
+ const itemWidth = itemReact.width;
+ if (itemLeft < containerPosition && itemLeft + itemWidth + padding * 2 > containerPosition) {
+ scrollX = shouldFlipPage
+ ? itemLeft - containerRect.left - padding
+ : itemLeft + itemWidth - containerPosition + padding;
+
+ return true;
+ }
+ return false;
+ });
+
+ return scrollX;
+ }
+
+ calculateRightScrollX(shouldFlipPage?: boolean): number {
+ let scrollX = 0;
+ const padding = 4;
+ this._slideTabItems.some((item) => {
+ const containerRect = this._slideTabBar.getBoundingClientRect();
+ const containerPosition = containerRect.left;
+ const itemReact = item.getSlideTabItem().getBoundingClientRect();
+ const itemLeft = itemReact.left;
+ const itemWidth = itemReact.width;
+ if (itemLeft - padding * 2 < containerPosition && itemLeft + itemWidth > containerPosition) {
+ scrollX = shouldFlipPage
+ ? itemLeft + itemWidth - containerRect.left - containerRect.width + padding
+ : itemLeft - containerPosition - padding;
+
+ return true;
+ }
+ return false;
+ });
+
+ return scrollX;
+ }
+
destroy() {
this._downActionX = 0;
this._moveActionX = 0;