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,ui): add Panel component and enhance Sidebar with accessibility and resize (#6938)

白熱0a2654ec5f57
diff --git a/common/debugger/package.json b/common/debugger/package.json
index 08c2a9c4d1..52087e3613 100644
--- a/common/debugger/package.json
+++ b/common/debugger/package.json
@@ -35,7 +35,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/docs-drawing-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/mockdata": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-drawing-ui": "workspace:*",
diff --git a/common/shared/package.json b/common/shared/package.json
index 760ef7ec8a..447192ef68 100644
--- a/common/shared/package.json
+++ b/common/shared/package.json
@@ -51,7 +51,7 @@
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/icons-svg": "^1.2.0",
"@univerjs/protocol": "workspace:*",
"typescript": "^6.0.3",
diff --git a/examples/package.json b/examples/package.json
index 79dc192347..f20c144d3c 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -35,7 +35,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/find-replace": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/mockdata": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/rpc": "workspace:*",
diff --git a/packages/action-recorder/package.json b/packages/action-recorder/package.json
index be7fe446ed..e30e012e3f 100644
--- a/packages/action-recorder/package.json
+++ b/packages/action-recorder/package.json
@@ -76,7 +76,7 @@
"dependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/design/package.json b/packages/design/package.json
index 4678fdca2d..3beb8d2a8e 100644
--- a/packages/design/package.json
+++ b/packages/design/package.json
@@ -81,7 +81,7 @@
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-separator": "^1.1.8",
"@radix-ui/react-slot": "^1.2.4",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"react-transition-group": "^4.4.5",
diff --git a/packages/design/src/components/panel/Panel.stories.tsx b/packages/design/src/components/panel/Panel.stories.tsx
new file mode 100644
index 0000000000..ff50aa67ae
--- /dev/null
+++ b/packages/design/src/components/panel/Panel.stories.tsx
@@ -0,0 +1,78 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Meta } from '@storybook/react';
+import { Panel, PanelField, PanelSection } from './Panel';
+
+const meta: Meta<typeof Panel> = {
+ title: 'Components / Panel',
+ component: Panel,
+ parameters: {
+ layout: 'centered',
+ },
+ tags: ['autodocs'],
+};
+
+export default meta;
+
+export const PanelBasic = {
+ render() {
+ return (
+ <div className="univer-w-80">
+ <Panel>
+ <PanelSection title="Section A">
+ <PanelField label="Field 1">
+ <input
+ className="
+ univer-w-full univer-rounded univer-border univer-border-gray-300 univer-px-2
+ univer-py-1
+ "
+ />
+ </PanelField>
+ <PanelField label="Field 2" required>
+ <input
+ className="
+ univer-w-full univer-rounded univer-border univer-border-gray-300 univer-px-2
+ univer-py-1
+ "
+ />
+ </PanelField>
+ </PanelSection>
+ <PanelSection title="Section B" defaultExpanded={false}>
+ <PanelField label="Field 3">
+ <input
+ className="
+ univer-w-full univer-rounded univer-border univer-border-gray-300 univer-px-2
+ univer-py-1
+ "
+ />
+ </PanelField>
+ </PanelSection>
+ <PanelSection title="Section C (not collapsible)" collapsible={false}>
+ <PanelField label="Field 4" error="This field has an error">
+ <input
+ className="
+ univer-w-full univer-rounded univer-border univer-border-red-300 univer-px-2
+ univer-py-1
+ "
+ />
+ </PanelField>
+ </PanelSection>
+ </Panel>
+ </div>
+ );
+ },
+};
diff --git a/packages/design/src/components/panel/Panel.tsx b/packages/design/src/components/panel/Panel.tsx
new file mode 100644
index 0000000000..62c9daf315
--- /dev/null
+++ b/packages/design/src/components/panel/Panel.tsx
@@ -0,0 +1,144 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { CSSProperties, ReactNode } from 'react';
+import { DownIcon } from '@univerjs/icons';
+import { useId, useState } from 'react';
+import { clsx } from '../../helper/clsx';
+
+// ================= Panel =================
+export interface IPanelProps {
+ children: ReactNode;
+ className?: string;
+ style?: CSSProperties;
+}
+
+export function Panel(props: IPanelProps) {
+ const { children, className, style } = props;
+ return (
+ <div
+ data-u-comp="panel"
+ className={clsx('univer-flex univer-flex-col univer-gap-5 univer-py-2', className)}
+ style={style}
+ >
+ {children}
+ </div>
+ );
+}
+
+// ================= PanelSection =================
+export interface IPanelSectionProps {
+ title: ReactNode;
+ children: ReactNode;
+ className?: string;
+ defaultExpanded?: boolean;
+ collapsible?: boolean;
+}
+
+export function PanelSection(props: IPanelSectionProps) {
+ const { title, children, className, defaultExpanded = true, collapsible = true } = props;
+ const [expanded, setExpanded] = useState(defaultExpanded);
+ const contentId = useId();
+ const headerId = useId();
+
+ return (
+ <div
+ data-u-comp="panel-section"
+ className={clsx('univer-flex univer-flex-col', className)}
+ >
+ <button
+ id={headerId}
+ type="button"
+ aria-expanded={expanded}
+ aria-controls={contentId}
+ disabled={!collapsible}
+ className={clsx(`
+ univer-box-border univer-flex univer-w-full univer-items-center univer-gap-1.5 univer-border-none
+ univer-bg-transparent univer-p-0 univer-pb-2.5 univer-text-left univer-text-sm univer-font-medium
+ univer-text-gray-700
+ dark:!univer-text-gray-200
+ `, {
+ 'univer-cursor-pointer': collapsible,
+ 'univer-cursor-default': !collapsible,
+ })}
+ onClick={() => collapsible && setExpanded((v) => !v)}
+ >
+ {collapsible && (
+ <DownIcon
+ className={clsx('univer-size-2.5 univer-flex-shrink-0 univer-transition-transform', {
+ '-univer-rotate-90': !expanded,
+ 'univer-rotate-0': expanded,
+ })}
+ />
+ )}
+ <span>{title}</span>
+ </button>
+
+ <div
+ id={contentId}
+ role="region"
+ aria-labelledby={headerId}
+ className={clsx(`
+ univer-overflow-hidden univer-transition-[max-height,opacity] univer-duration-300 univer-ease-in-out
+ `, {
+ 'univer-max-h-[1000px] univer-opacity-100': expanded,
+ 'univer-max-h-0 univer-opacity-0': !expanded,
+ })}
+ >
+ <div className="univer-box-border univer-flex univer-flex-col univer-gap-3 univer-py-1">
+ {children}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+// ================= PanelField =================
+export interface IPanelFieldProps {
+ label: ReactNode;
+ children: ReactNode;
+ className?: string;
+ required?: boolean;
+ error?: string;
+}
+
+export function PanelField(props: IPanelFieldProps) {
+ const { label, children, className, required, error } = props;
+ return (
+ <div
+ data-u-comp="panel-field"
+ className={clsx('univer-flex univer-flex-col univer-gap-1.5', className)}
+ >
+ <div className="univer-flex univer-items-center univer-gap-1">
+ <span
+ className={`
+ univer-text-xs univer-text-gray-600
+ dark:!univer-text-gray-300
+ `}
+ >
+ {label}
+ </span>
+ {required && (
+ <span className="univer-text-xs univer-text-red-500">*</span>
+ )}
+ </div>
+ <div className="univer-w-full">{children}</div>
+ {error && (
+ <span className="univer-text-xs univer-text-red-500">{error}</span>
+ )}
+ </div>
+ );
+}
diff --git a/packages/design/src/components/panel/__tests__/Panel.spec.tsx b/packages/design/src/components/panel/__tests__/Panel.spec.tsx
new file mode 100644
index 0000000000..69f6d636e4
--- /dev/null
+++ b/packages/design/src/components/panel/__tests__/Panel.spec.tsx
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { fireEvent, render, screen } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+import { Panel, PanelField, PanelSection } from '../Panel';
+import '@testing-library/jest-dom/vitest';
+
+describe('Panel', () => {
+ it('should render children', () => {
+ render(
+ <Panel>
+ <div data-testid="child">Content</div>
+ </Panel>
+ );
+ expect(screen.getByTestId('child')).toBeInTheDocument();
+ });
+});
+
+describe('PanelSection', () => {
+ it('should render title and children', () => {
+ render(
+ <PanelSection title="Section Title">
+ <div data-testid="section-child">Section Content</div>
+ </PanelSection>
+ );
+ expect(screen.getByText('Section Title')).toBeInTheDocument();
+ expect(screen.getByTestId('section-child')).toBeInTheDocument();
+ });
+
+ it('should toggle content when clicked', () => {
+ render(
+ <PanelSection title="Toggle Me">
+ <div data-testid="toggle-child">Hidden Content</div>
+ </PanelSection>
+ );
+
+ const button = screen.getByRole('button', { name: /Toggle Me/i });
+ expect(button).toHaveAttribute('aria-expanded', 'true');
+
+ fireEvent.click(button);
+ expect(button).toHaveAttribute('aria-expanded', 'false');
+
+ fireEvent.click(button);
+ expect(button).toHaveAttribute('aria-expanded', 'true');
+ });
+
+ it('should not toggle when collapsible is false', () => {
+ render(
+ <PanelSection title="Static" collapsible={false}>
+ <div>Content</div>
+ </PanelSection>
+ );
+
+ const button = screen.getByRole('button', { name: /Static/i });
+ expect(button).toBeDisabled();
+ });
+});
+
+describe('PanelField', () => {
+ it('should render label and children', () => {
+ render(
+ <PanelField label="Field Label">
+ <input data-testid="field-input" />
+ </PanelField>
+ );
+ expect(screen.getByText('Field Label')).toBeInTheDocument();
+ expect(screen.getByTestId('field-input')).toBeInTheDocument();
+ });
+
+ it('should show required indicator', () => {
+ render(
+ <PanelField label="Required Field" required>
+ <input />
+ </PanelField>
+ );
+ expect(screen.getByText('*')).toBeInTheDocument();
+ });
+
+ it('should show error message', () => {
+ render(
+ <PanelField label="Field" error="Something went wrong">
+ <input />
+ </PanelField>
+ );
+ expect(screen.getByText('Something went wrong')).toBeInTheDocument();
+ });
+});
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index 04ae604a8f..c85f74dbee 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -43,6 +43,7 @@ export { type IInputProps, Input } from './components/input/Input';
export { type IKBDProps, KBD } from './components/kbd/Kbd';
export { type IMessageProps, message, Messager, MessageType, removeMessage } from './components/message/Message';
export { type IPagerProps, Pager } from './components/pager/Pager';
+export { type IPanelFieldProps, type IPanelProps, type IPanelSectionProps, Panel, PanelField, PanelSection } from './components/panel/Panel';
export { type IPopupProps, Popup } from './components/popup';
export { type IRadioGroupProps, RadioGroup } from './components/radio-group/RadioGroup';
export { type IRadioProps, Radio } from './components/radio/Radio';
diff --git a/packages/docs-hyper-link-ui/package.json b/packages/docs-hyper-link-ui/package.json
index 1d5863e28e..fba6628d6b 100644
--- a/packages/docs-hyper-link-ui/package.json
+++ b/packages/docs-hyper-link-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/docs-hyper-link": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/docs-quick-insert-ui/package.json b/packages/docs-quick-insert-ui/package.json
index a0825ec7b0..043485b8ff 100644
--- a/packages/docs-quick-insert-ui/package.json
+++ b/packages/docs-quick-insert-ui/package.json
@@ -83,7 +83,7 @@
"@univerjs/drawing": "workspace:*",
"@univerjs/drawing-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/docs-thread-comment-ui/package.json b/packages/docs-thread-comment-ui/package.json
index 97449e23bf..5477261061 100644
--- a/packages/docs-thread-comment-ui/package.json
+++ b/packages/docs-thread-comment-ui/package.json
@@ -72,7 +72,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/thread-comment": "workspace:*",
"@univerjs/thread-comment-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
diff --git a/packages/docs-ui/package.json b/packages/docs-ui/package.json
index 531eb83cc5..98da8f9636 100644
--- a/packages/docs-ui/package.json
+++ b/packages/docs-ui/package.json
@@ -90,7 +90,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/drawing-ui/package.json b/packages/drawing-ui/package.json
index ecf439add9..720bde8a4e 100644
--- a/packages/drawing-ui/package.json
+++ b/packages/drawing-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/find-replace/package.json b/packages/find-replace/package.json
index 4535b384f4..1178c5d957 100644
--- a/packages/find-replace/package.json
+++ b/packages/find-replace/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/sheets-conditional-formatting-ui/package.json b/packages/sheets-conditional-formatting-ui/package.json
index 47696da0ca..015a0d405a 100644
--- a/packages/sheets-conditional-formatting-ui/package.json
+++ b/packages/sheets-conditional-formatting-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
diff --git a/packages/sheets-crosshair-highlight/package.json b/packages/sheets-crosshair-highlight/package.json
index 9e4c936eae..625e8ae1a9 100644
--- a/packages/sheets-crosshair-highlight/package.json
+++ b/packages/sheets-crosshair-highlight/package.json
@@ -88,7 +88,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
diff --git a/packages/sheets-data-validation-ui/package.json b/packages/sheets-data-validation-ui/package.json
index 4cd336d891..081d1b8279 100644
--- a/packages/sheets-data-validation-ui/package.json
+++ b/packages/sheets-data-validation-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
diff --git a/packages/sheets-filter-ui/package.json b/packages/sheets-filter-ui/package.json
index 89d7a6d283..7cf01105fe 100644
--- a/packages/sheets-filter-ui/package.json
+++ b/packages/sheets-filter-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
diff --git a/packages/sheets-formula-ui/package.json b/packages/sheets-formula-ui/package.json
index 5af069970e..ad9c7ed2ef 100644
--- a/packages/sheets-formula-ui/package.json
+++ b/packages/sheets-formula-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-hyper-link-ui/package.json b/packages/sheets-hyper-link-ui/package.json
index 056d22c2fa..29d0188a80 100644
--- a/packages/sheets-hyper-link-ui/package.json
+++ b/packages/sheets-hyper-link-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
diff --git a/packages/sheets-note-ui/package.json b/packages/sheets-note-ui/package.json
index 1858d246ad..6392bb2664 100644
--- a/packages/sheets-note-ui/package.json
+++ b/packages/sheets-note-ui/package.json
@@ -74,7 +74,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-note": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-numfmt-ui/package.json b/packages/sheets-numfmt-ui/package.json
index 9772719d9e..00612ad69c 100644
--- a/packages/sheets-numfmt-ui/package.json
+++ b/packages/sheets-numfmt-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-sort-ui/package.json b/packages/sheets-sort-ui/package.json
index ee282dbadb..e8d402d27d 100644
--- a/packages/sheets-sort-ui/package.json
+++ b/packages/sheets-sort-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-sort": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-table-ui/package.json b/packages/sheets-table-ui/package.json
index 4d1f567ccc..a5e617e581 100644
--- a/packages/sheets-table-ui/package.json
+++ b/packages/sheets-table-ui/package.json
@@ -79,7 +79,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
"@univerjs/sheets-sort": "workspace:*",
diff --git a/packages/sheets-thread-comment-ui/package.json b/packages/sheets-thread-comment-ui/package.json
index ecb83eb6d9..47d92b3851 100644
--- a/packages/sheets-thread-comment-ui/package.json
+++ b/packages/sheets-thread-comment-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-thread-comment": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-ui/package.json b/packages/sheets-ui/package.json
index 068e693e3c..04ae70baec 100644
--- a/packages/sheets-ui/package.json
+++ b/packages/sheets-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/protocol": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/telemetry": "workspace:*",
diff --git a/packages/sheets-zen-editor/package.json b/packages/sheets-zen-editor/package.json
index 2fd531fa89..086ef2385d 100644
--- a/packages/sheets-zen-editor/package.json
+++ b/packages/sheets-zen-editor/package.json
@@ -90,7 +90,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
diff --git a/packages/slides-ui/package.json b/packages/slides-ui/package.json
index 870f727678..207c75d717 100644
--- a/packages/slides-ui/package.json
+++ b/packages/slides-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/slides": "workspace:*",
"@univerjs/ui": "workspace:*"
},
diff --git a/packages/thread-comment-ui/package.json b/packages/thread-comment-ui/package.json
index b95ebf87b6..9ebb9ec92c 100644
--- a/packages/thread-comment-ui/package.json
+++ b/packages/thread-comment-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@univerjs/thread-comment": "workspace:*",
"@univerjs/ui": "workspace:*"
},
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 21ffb302b2..3c7dbbb630 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -89,7 +89,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.3.0",
+ "@univerjs/icons": "1.4.0",
"@wendellhu/redi": "1.1.1",
"localforage": "^1.10.0"
},
diff --git a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
index a700374f46..b67fc50d0a 100644
--- a/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/desktop-sidebar.service.ts
@@ -28,6 +28,7 @@ export class DesktopSidebarService extends Disposable implements ISidebarService
private _container?: HTMLElement;
private _openAnimationFrameId: number | null = null;
+ private _width?: number;
get visible(): boolean {
return this._sidebarOptions.visible || false;
@@ -37,6 +38,14 @@ export class DesktopSidebarService extends Disposable implements ISidebarService
return this._sidebarOptions;
}
+ get width(): number | undefined {
+ return this._width;
+ }
+
+ setWidth(value: number): void {
+ this._width = value;
+ }
+
override dispose(): void {
super.dispose();
this.close();
diff --git a/packages/ui/src/services/sidebar/sidebar.service.ts b/packages/ui/src/services/sidebar/sidebar.service.ts
index fbf39ef2f7..dd6d676e55 100644
--- a/packages/ui/src/services/sidebar/sidebar.service.ts
+++ b/packages/ui/src/services/sidebar/sidebar.service.ts
@@ -32,6 +32,9 @@ export interface ISidebarService {
getContainer(): HTMLElement | undefined;
setContainer(element?: HTMLElement): void;
+
+ get width(): number | undefined;
+ setWidth(value: number): void;
}
export const ILeftSidebarService = createIdentifier<ISidebarService>('ui.left-sidebar.service');
diff --git a/packages/ui/src/views/components/sidebar/Sidebar.tsx b/packages/ui/src/views/components/sidebar/Sidebar.tsx
index 600371c970..3dff867873 100644
--- a/packages/ui/src/views/components/sidebar/Sidebar.tsx
+++ b/packages/ui/src/views/components/sidebar/Sidebar.tsx
@@ -18,7 +18,7 @@ import type { CSSProperties, ReactNode } from 'react';
import type { ICustomLabelProps } from '../../../components/custom-label/CustomLabel';
import { borderLeftBottomClassName, clsx, scrollbarClassName } from '@univerjs/design';
import { CloseIcon } from '@univerjs/icons';
-import { useEffect, useMemo, useRef } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { CustomLabel } from '../../../components/custom-label/CustomLabel';
import { ISidebarService } from '../../../services/sidebar/sidebar.service';
import { useDependency, useObservable } from '../../../utils/di';
@@ -38,10 +38,18 @@ export interface ISidebarMethodOptions {
onOpen?: () => void;
}
+const MIN_SIDEBAR_WIDTH = 280;
+const MAX_SIDEBAR_WIDTH = 800;
+const DEFAULT_SIDEBAR_WIDTH = 384;
+
export function Sidebar() {
const sidebarService = useDependency(ISidebarService);
const sidebarOptions = useObservable<ISidebarMethodOptions>(sidebarService.sidebarOptions$);
const scrollRef = useRef<HTMLDivElement>(null);
+ const sidebarRef = useRef<HTMLElement>(null);
+ const closeButtonRef = useRef<HTMLButtonElement>(null);
+ const [isDragging, setIsDragging] = useState(false);
+ const dragWidthRef = useRef<number | null>(null);
const options = useMemo(() => {
if (!sidebarOptions) {
@@ -58,10 +66,10 @@ export function Sidebar() {
const k = key as keyof ISidebarMethodOptions;
if (sidebarOptions[k]) {
- const { key, ...props } = sidebarOptions[k] as any;
+ const { key: itemKey, ...props } = sidebarOptions[k] as any;
if (props) {
- (copy as any)[k] = <CustomLabel key={key} {...props} />;
+ (copy as any)[k] = <CustomLabel key={itemKey} {...props} />;
}
}
}
@@ -69,6 +77,66 @@ export function Sidebar() {
return copy;
}, [sidebarOptions]);
+ // Focus management: move focus into the sidebar when it opens
+ useEffect(() => {
+ if (options?.visible && closeButtonRef.current) {
+ closeButtonRef.current.focus();
+ }
+ }, [options?.visible]);
+
+ // ESC key to close sidebar
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape' && sidebarService.visible) {
+ e.stopPropagation();
+ sidebarService.close();
+ }
+ };
+ document.addEventListener('keydown', handleKeyDown);
+ return () => document.removeEventListener('keydown', handleKeyDown);
+ }, [sidebarService]);
+
+ // Drag resize handlers
+ const handleResizeMouseDown = useCallback((e: React.MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setIsDragging(true);
+ document.body.style.cursor = 'col-resize';
+ document.body.style.userSelect = 'none';
+ }, []);
+
+ useEffect(() => {
+ if (!isDragging) {
+ document.body.style.cursor = '';
+ document.body.style.userSelect = '';
+ return;
+ }
+
+ const handleMouseMove = (e: MouseEvent) => {
+ if (!sidebarRef.current) return;
+ const rect = sidebarRef.current.getBoundingClientRect();
+ const newWidth = rect.right - e.clientX;
+ const clampedWidth = Math.max(MIN_SIDEBAR_WIDTH, Math.min(newWidth, MAX_SIDEBAR_WIDTH));
+ dragWidthRef.current = clampedWidth;
+ sidebarRef.current.style.width = `${clampedWidth}px`;
+ };
+
+ const handleMouseUp = () => {
+ setIsDragging(false);
+ if (dragWidthRef.current != null) {
+ sidebarService.setWidth(dragWidthRef.current);
+ dragWidthRef.current = null;
+ }
+ };
+
+ document.addEventListener('mousemove', handleMouseMove);
+ document.addEventListener('mouseup', handleMouseUp);
+ return () => {
+ document.removeEventListener('mousemove', handleMouseMove);
+ document.removeEventListener('mouseup', handleMouseUp);
+ };
+ }, [isDragging, sidebarService]);
+
useEffect(() => {
if (scrollRef.current) {
sidebarService.setContainer(scrollRef.current);
@@ -93,14 +161,22 @@ export function Sidebar() {
}, [sidebarService]);
const width = useMemo(() => {
+ if (isDragging && dragWidthRef.current != null) {
+ return `${dragWidthRef.current}px`;
+ }
if (!options?.visible) return 0;
+ const savedWidth = sidebarService.width;
+ if (savedWidth) {
+ return `${savedWidth}px`;
+ }
+
if (typeof options.width === 'number') {
return `${options.width}px`;
}
return options.width;
- }, [options]);
+ }, [isDragging, options, sidebarService]);
function handleClose() {
sidebarService.close(sidebarOptions?.id);
@@ -108,16 +184,53 @@ export function Sidebar() {
return (
<section
+ ref={sidebarRef}
data-u-comp="sidebar"
+ role="complementary"
+ aria-expanded={!!options?.visible}
+ aria-label="Sidebar panel"
className={clsx(`
- univer-relative univer-h-full univer-bg-white univer-text-gray-900
+ univer-relative univer-h-full univer-flex-shrink-0 univer-bg-white univer-text-gray-900
dark:!univer-bg-gray-900 dark:!univer-text-white
`, {
'univer-w-96 univer-translate-x-0': options?.visible,
'univer-w-0 univer-translate-x-full': !options?.visible,
})}
- style={{ width }}
+ style={{ width: isDragging ? undefined : width }}
>
+ {/* Resize handle */}
+ {options?.visible && (
+ <div
+ className={`
+ hover:univer-bg-primary-500/30
+ active:univer-bg-primary-500/50
+ univer-absolute univer-left-0 univer-top-0 univer-z-20 univer-h-full univer-w-1
+ univer-cursor-col-resize univer-transition-colors
+ `}
+ onMouseDown={handleResizeMouseDown}
+ role="separator"
+ aria-orientation="vertical"
+ aria-label="Resize sidebar"
+ tabIndex={0}
+ onKeyDown={(e) => {
+ if (!sidebarRef.current) return;
+ const currentWidth = sidebarRef.current.getBoundingClientRect().width;
+ let newWidth = currentWidth;
+ if (e.key === 'ArrowLeft') {
+ e.preventDefault();
+ newWidth = Math.max(MIN_SIDEBAR_WIDTH, currentWidth - 20);
+ } else if (e.key === 'ArrowRight') {
+ e.preventDefault();
+ newWidth = Math.min(MAX_SIDEBAR_WIDTH, currentWidth + 20);
+ }
+ if (newWidth !== currentWidth) {
+ sidebarRef.current.style.width = `${newWidth}px`;
+ sidebarService.setWidth(newWidth);
+ }
+ }}
+ />
+ )}
+
<section
ref={scrollRef}
className={clsx(`
@@ -135,15 +248,21 @@ export function Sidebar() {
>
{options?.header}
- <a
+ <button
+ ref={closeButtonRef}
+ type="button"
className={`
- univer-cursor-pointer univer-text-gray-500
+ focus:univer-ring-primary-500/50
+ univer-cursor-pointer univer-appearance-none univer-rounded-sm univer-border-none
+ univer-bg-transparent univer-p-0 univer-text-gray-500
+ focus:univer-outline-none focus:univer-ring-2
dark:!univer-text-gray-300
`}
onClick={handleClose}
+ aria-label="Close sidebar"
>
<CloseIcon />
- </a>
+ </button>
</header>
<section className="univer-box-border univer-cursor-default univer-px-4" style={options?.bodyStyle}>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bbe9eb342b..15e03dd35b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -127,8 +127,8 @@ importers:
specifier: workspace:*
version: link:../../packages/engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/mockdata':
specifier: workspace:*
version: link:../mockdata
@@ -379,8 +379,8 @@ importers:
specifier: ^11.0.4
version: 11.0.4
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/icons-svg':
specifier: ^1.2.0
version: 1.2.0
@@ -533,8 +533,8 @@ importers:
specifier: workspace:*
version: link:../packages/find-replace
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/mockdata':
specifier: workspace:*
version: link:../common/mockdata
@@ -735,8 +735,8 @@ importers:
specifier: workspace:*
version: link:../design
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -876,8 +876,8 @@ importers:
specifier: ^1.2.4
version: 1.2.4(@types/[email protected])([email protected])
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -1058,8 +1058,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1159,8 +1159,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1202,8 +1202,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/thread-comment':
specifier: workspace:*
version: link:../thread-comment
@@ -1254,8 +1254,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1328,8 +1328,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1442,8 +1442,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1632,8 +1632,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1687,8 +1687,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1773,8 +1773,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1942,8 +1942,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/rpc':
specifier: workspace:*
version: link:../rpc
@@ -2071,8 +2071,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2179,8 +2179,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2265,8 +2265,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2342,8 +2342,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2413,8 +2413,8 @@ importers:
specifier: workspace:*
version: link:../engine-formula
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2493,8 +2493,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2576,8 +2576,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2640,8 +2640,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/protocol':
specifier: workspace:*
version: link:../protocol
@@ -2698,8 +2698,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2775,8 +2775,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/slides':
specifier: workspace:*
version: link:../slides
@@ -2859,8 +2859,8 @@ importers:
specifier: workspace:*
version: link:../docs-ui
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@univerjs/thread-comment':
specifier: workspace:*
version: link:../thread-comment
@@ -2902,8 +2902,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.3.0
+ specifier: 1.4.0
'@wendellhu/redi':
specifier: 1.1.1
version: 1.1.1([email protected])
@@ -6391,8 +6391,8 @@ packages:
'@univerjs/[email protected]':
resolution: {integrity: sha512-Tm0cYbTQwP2VfpiZClyzff5HO7w9UCZ/Qi0YWZ/YWi16QBTLqsc47a80VPAZTwOgUPqejuGxpBKViz6Welht6w==}
- '@univerjs/[email protected]':
- resolution: {integrity: sha512-Bc+l4YzO033j4U5FcOsixhrnkkPkZlkmtPeGQBDdup5z55fQsjDK2hgedf5DpuUNwNe3GEIcyuWT3hmHznb3VA==}
+ '@univerjs/[email protected]':
+ resolution: {integrity: sha512-ohBfPk+EyLuSc+1Rvz06jiMDgEydwc6lLUOQyUjS/W3zBKYLhbXaEP4qq7/YQH8OhzkTsRQGvsTgYSg1roRXgg==}
peerDependencies:
react: 19.2.6
react-dom: 19.2.6
@@ -14492,7 +14492,7 @@ snapshots:
'@univerjs/[email protected]': {}
dependencies:
react: 19.2.6
react-dom: 19.2.6([email protected])