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: add `footer.addSheetButtonConfig` config (#6866)

wpxp1234564055e42530b0
diff --git a/packages/sheets-ui/src/config/config.ts b/packages/sheets-ui/src/config/config.ts
index 43e54e28fd..9a2f50cf85 100644
--- a/packages/sheets-ui/src/config/config.ts
+++ b/packages/sheets-ui/src/config/config.ts
@@ -49,21 +49,46 @@ export interface IUniverSheetsUIConfig {
* @default true
*/
sheetBar?: boolean;
+
/**
* statistic bar including statistic info current selections, such as count, sum, average, etc.
* @default true
*/
statisticBar?: boolean;
+
/**
* Including the menus in the footer. such as highlight, gridlines, etc.
* @default true
*/
menus?: boolean;
+
/**
* Zoom slider is the zoom slider in the footer.
* @default true
*/
zoomSlider?: boolean;
+
+ /**
+ * The config of the add sheet button in the sheet bar.
+ */
+ addSheetButtonConfig?: {
+ /**
+ * Whether to show the add sheet button in the sheet bar.
+ * When `footer` or `footer.sheetBar` is false, this config will not work because the sheet bar will not be rendered.
+ * @default true
+ */
+ show?: boolean;
+ /**
+ * The default row count of the new sheet created by the add sheet button.
+ * @default 1000
+ */
+ defaultRowCount?: number;
+ /**
+ * The default column count of the new sheet created by the add sheet button.
+ * @default 20
+ */
+ defaultColumnCount?: number;
+ };
};
/**
diff --git a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
index 4bbcd23fce..f7f89a831f 100644
--- a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
@@ -14,13 +14,15 @@
* limitations under the License.
*/
+import type { IUniverSheetsUIConfig } from '../../config/config';
import type { IScrollState } from './sheet-bar-tabs/utils/slide-tab-bar';
-import { ICommandService, IPermissionService, throttle } from '@univerjs/core';
+import { DEFAULT_WORKSHEET_COLUMN_COUNT, DEFAULT_WORKSHEET_ROW_COUNT, ICommandService, IPermissionService, throttle } from '@univerjs/core';
import { IncreaseIcon, MoreIcon } from '@univerjs/icons';
import { InsertSheetCommand, WorkbookCreateSheetPermission, WorkbookEditablePermission } from '@univerjs/sheets';
-import { useDependency, useObservable } from '@univerjs/ui';
+import { useConfigValue, useDependency, useObservable } from '@univerjs/ui';
import { useEffect, useState } from 'react';
import { useActiveWorkbook } from '../../components/hook';
+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../config/config';
import { ISheetBarService } from '../../services/sheet-bar/sheet-bar.service';
import { SheetBarButton } from './sheet-bar-button/SheetBarButton';
import { SheetBarMenu } from './sheet-bar-menu/SheetBarMenu';
@@ -42,6 +44,9 @@ export const SheetBar = () => {
const workbookEditablePermission = useObservable(permissionService.getPermissionPoint$(new WorkbookEditablePermission(unitId)?.id));
const workbookCreateSheetPermission = useObservable(permissionService.getPermissionPoint$(new WorkbookCreateSheetPermission(unitId)?.id));
+ const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
+ const { show: addSheetButtonShow = true, defaultRowCount = DEFAULT_WORKSHEET_ROW_COUNT, defaultColumnCount = DEFAULT_WORKSHEET_COLUMN_COUNT } = (config?.footer || {}).addSheetButtonConfig || {};
+
const updateScrollButtonState = (state: IScrollState) => {
const { leftEnd, rightEnd } = state;
setLeftScrollState(leftEnd);
@@ -60,7 +65,12 @@ export const SheetBar = () => {
// Complete the _addSheet, handleScrollLeft, and handleScrollRight functions
const addSheet = () => {
- commandService.executeCommand(InsertSheetCommand.id);
+ commandService.executeCommand(InsertSheetCommand.id, {
+ sheet: {
+ rowCount: defaultRowCount,
+ columnCount: defaultColumnCount,
+ },
+ });
setTimeout(() => {
sheetBarService.setAddSheet(0);
}, 0);
@@ -78,13 +88,15 @@ export const SheetBar = () => {
<div className="univer-relative univer-flex univer-h-full univer-min-w-0 univer-flex-1">
<div className="univer-flex univer-items-center">
{/* Add sheet button */}
- <SheetBarButton
- className="univer-mr-2"
- onClick={addSheet}
- disabled={!(workbookCreateSheetPermission?.value && workbookEditablePermission?.value)}
- >
- <IncreaseIcon />
- </SheetBarButton>
+ {addSheetButtonShow && (
+ <SheetBarButton
+ className="univer-mr-2"
+ onClick={addSheet}
+ disabled={!(workbookCreateSheetPermission?.value && workbookEditablePermission?.value)}
+ >
+ <IncreaseIcon />
+ </SheetBarButton>
+ )}
{/* All sheets button */}
<SheetBarMenu />
</div>