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 Accordion (#5163)

白熱6748e6f7eef9
diff --git a/packages/design/src/components/accordion/Accordion.stories.tsx b/packages/design/src/components/accordion/Accordion.stories.tsx
new file mode 100644
index 0000000000..9a07e1c930
--- /dev/null
+++ b/packages/design/src/components/accordion/Accordion.stories.tsx
@@ -0,0 +1,76 @@
+/**
+ * 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 { Accordion } from './Accordion';
+
+const meta: Meta<typeof Accordion> = {
+ title: 'Components / Accordion',
+ component: Accordion,
+ parameters: {
+ layout: 'centered',
+ },
+ tags: ['autodocs'],
+};
+
+export default meta;
+
+export const AccordionBasic = {
+ render() {
+ const items = [{
+ label: (
+ <span>
+ Accordion A
+ </span>
+ ),
+ children: (
+ <div>
+ Content A
+ </div>
+ ),
+ }, {
+ label: (
+ <span>
+ Accordion B
+ </span>
+ ),
+ children: (
+ <div>
+ Content B
+ </div>
+ ),
+ }, {
+ label: (
+ <span>
+ Accordion C
+ </span>
+ ),
+ children: (
+ <div>
+ Content C
+ </div>
+ ),
+ }];
+
+ return (
+ <>
+ <div>
+ <Accordion items={items} />
+ </div>
+ </>
+ );
+ },
+};
diff --git a/packages/design/src/components/accordion/Accordion.tsx b/packages/design/src/components/accordion/Accordion.tsx
new file mode 100644
index 0000000000..fb3580e0ff
--- /dev/null
+++ b/packages/design/src/components/accordion/Accordion.tsx
@@ -0,0 +1,87 @@
+/**
+ * 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 { ReactNode } from 'react';
+import { DownSingle } from '@univerjs/icons';
+import { useState } from 'react';
+import { clsx } from '../../helper/clsx';
+
+interface IAccordionItem {
+ label: ReactNode;
+ children: ReactNode;
+}
+
+export interface IAccordionProps {
+ className?: string;
+ items: IAccordionItem[];
+}
+
+export function Accordion(props: IAccordionProps) {
+ const { className, items } = props;
+ const [openIndex, setOpenIndex] = useState<number | null>(null);
+
+ const toggleItem = (index: number) => {
+ setOpenIndex(openIndex === index ? null : index);
+ };
+
+ return (
+ <div
+ data-u-comp="accordion"
+ className={clsx(`
+ univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200
+ dark:univer-divide-gray-600
+ `, className)}
+ >
+ {items.map((item, index) => (
+ <div key={index}>
+ <button
+ className={`
+ univer-box-border univer-flex univer-w-full univer-cursor-pointer univer-items-center
+ univer-gap-1.5 univer-border-none univer-bg-transparent univer-p-4 univer-text-left
+ univer-text-gray-700
+ dark:univer-text-gray-200 dark:hover:univer-text-white
+ focus:univer-outline-none
+ hover:univer-text-gray-900
+ `}
+ type="button"
+ onClick={() => toggleItem(index)}
+ >
+ <DownSingle
+ className={clsx('univer-size-2.5 univer-flex-shrink-0 univer-transition-transform', {
+ '-univer-rotate-90': openIndex !== index,
+ 'univer-rotate-0': openIndex === index,
+ })}
+ />
+ <span className="univer-font-medium">{item.label}</span>
+ </button>
+ <div
+ className={clsx(
+ `
+ univer-overflow-hidden univer-transition-[max-height,opacity] univer-duration-500
+ univer-ease-in-out
+ `,
+ openIndex === index
+ ? 'univer-max-h-screen'
+ : 'univer-max-h-0'
+ )}
+ >
+ <div className="univer-box-border univer-px-4 univer-py-1.5">{item.children}</div>
+ </div>
+ </div>
+ ))}
+ </div>
+ );
+}
diff --git a/packages/design/src/components/dropdown-menu/DropdownMenu.tsx b/packages/design/src/components/dropdown-menu/DropdownMenu.tsx
index 047e5bb4cd..2a9d55235e 100644
--- a/packages/design/src/components/dropdown-menu/DropdownMenu.tsx
+++ b/packages/design/src/components/dropdown-menu/DropdownMenu.tsx
@@ -172,7 +172,7 @@ export function DropdownMenu(props: IDropdownMenuProps) {
<DropdownMenuTrigger asChild>
{children}
</DropdownMenuTrigger>
- <DropdownMenuContent {...restProps}>
+ <DropdownMenuContent {...restProps} onWheel={(e) => e.stopPropagation()}>
{items.map((item, index) => renderMenuItem(item, index))}
</DropdownMenuContent>
</DropdownMenuPrimitive>
diff --git a/packages/design/src/components/select-list/SelectList.tsx b/packages/design/src/components/select-list/SelectList.tsx
index c8e79a6b59..ff9ca1911f 100644
--- a/packages/design/src/components/select-list/SelectList.tsx
+++ b/packages/design/src/components/select-list/SelectList.tsx
@@ -96,9 +96,11 @@ export function SelectList(props: ISelectListProps) {
className={clsx(`
univer-relative univer-block univer-cursor-pointer univer-select-none univer-rounded
univer-py-1.5 univer-pl-8 univer-pr-2 univer-text-sm univer-transition-colors
+ univer-text-gray-900
+ dark:univer-text-white dark:hover:univer-bg-gray-600
hover:univer-bg-gray-100
`, optionClassName, {
- 'univer-bg-gray-200': checked,
+ 'univer-bg-gray-200 dark:univer-bg-gray-500': checked,
})}
onClick={() => handleSelect(option.value)}
>
diff --git a/packages/design/src/components/select/MultipleSelect.tsx b/packages/design/src/components/select/MultipleSelect.tsx
index 911b980c30..a7d93f2f14 100644
--- a/packages/design/src/components/select/MultipleSelect.tsx
+++ b/packages/design/src/components/select/MultipleSelect.tsx
@@ -125,19 +125,20 @@ export function MultipleSelect(props: IMultipleSelectProps) {
<div
data-u-comp="multiple-select"
className={clsx(`
- univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-cursor-pointer
- univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-border
- univer-border-solid univer-border-gray-200 univer-bg-white univer-px-2.5 univer-transition-colors
- univer-duration-200
+ univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center
+ univer-justify-between univer-rounded-lg univer-border univer-border-solid univer-border-gray-200
+ univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200
dark:univer-border-gray-600 dark:univer-bg-gray-700 dark:univer-text-white
- hover:univer-border-primary-600
`, {
'univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-600/20': open && !borderless,
'univer-border-transparent univer-bg-transparent hover:univer-border-transparent': borderless,
+ 'univer-cursor-not-allowed': disabled,
+ 'hover:univer-border-primary-600': !disabled && !borderless,
+ 'univer-cursor-pointer': !disabled && !open,
}, className)}
>
<div
- className="univer-flex univer-flex-1 univer-gap-2"
+ className="univer-flex univer-gap-2 univer-box-border univer-pr-2 univer-w-[calc(100%-16px)]"
>
{displayValue}
</div>
diff --git a/packages/design/src/components/select/Select.stories.tsx b/packages/design/src/components/select/Select.stories.tsx
index 5dc701f49e..97898e6e20 100644
--- a/packages/design/src/components/select/Select.stories.tsx
+++ b/packages/design/src/components/select/Select.stories.tsx
@@ -39,6 +39,23 @@ export const SelectBasic = {
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3 Option 3 Option 3 Option 3 Option 3 Option 3', value: 'option3' },
+ { label: 'Option 4', value: 'option4' },
+ { label: 'Option 5', value: 'option5' },
+ { label: 'Option 6', value: 'option6' },
+ { label: 'Option 7', value: 'option7' },
+ { label: 'Option 8', value: 'option8' },
+ { label: 'Option 9', value: 'option9' },
+ { label: 'Option 10', value: 'option10' },
+ { label: 'Option 11', value: 'option11' },
+ { label: 'Option 12', value: 'option12' },
+ { label: 'Option 13', value: 'option13' },
+ { label: 'Option 14', value: 'option14' },
+ { label: 'Option 15', value: 'option15' },
+ { label: 'Option 16', value: 'option16' },
+ { label: 'Option 17', value: 'option17' },
+ { label: 'Option 18', value: 'option18' },
+ { label: 'Option 19', value: 'option19' },
+ { label: 'Option 20', value: 'option20' },
];
function handleChange(value: string | number | boolean) {
diff --git a/packages/design/src/components/select/Select.tsx b/packages/design/src/components/select/Select.tsx
index 853dbe078b..eebc6feb26 100644
--- a/packages/design/src/components/select/Select.tsx
+++ b/packages/design/src/components/select/Select.tsx
@@ -149,15 +149,16 @@ export function Select(props: ISelectProps) {
<div
data-u-comp="select"
className={clsx(`
- univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-cursor-pointer
- univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-border
- univer-border-solid univer-border-gray-200 univer-bg-white univer-px-2.5 univer-transition-colors
- univer-duration-200
+ univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center
+ univer-justify-between univer-gap-2 univer-rounded-lg univer-border univer-border-solid
+ univer-border-gray-200 univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200
dark:univer-border-gray-600 dark:univer-bg-gray-700 dark:univer-text-white
- hover:univer-border-primary-600
`, {
'univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-600/20': open && !borderless,
'univer-border-transparent univer-bg-transparent hover:univer-border-transparent': borderless,
+ 'univer-cursor-not-allowed': disabled,
+ 'hover:univer-border-primary-600': !disabled && !borderless,
+ 'univer-cursor-pointer': !disabled && !open,
}, className)}
>
<div
diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts
index bc7b14d68f..49aeff4805 100644
--- a/packages/design/src/index.ts
+++ b/packages/design/src/index.ts
@@ -44,6 +44,7 @@ export { DropdownMenu, type IDropdownMenuProps } from './components/dropdown-men
export { Separator } from './components/separator/Separator';
export { type IKBDProps, KBD } from './components/kbd/Kbd';
export { type IToasterProps, toast, Toaster } from './components/toaster/Toaster';
+export { Accordion, type IAccordionProps } from './components/accordion/Accordion';
export { DatePanel, DatePicker, type IDatePanelProps, type IDatePickerProps } from './components/date-picker';
export { DropdownLegacy, type IDropdownLegacyProps } from './components/dropdown-legacy';
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
index 096ad38580..852712c895 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
@@ -74,17 +74,14 @@ export function FilterPanel() {
className={`
univer-box-border univer-flex univer-h-[432px] univer-w-[312px] univer-flex-col univer-rounded-lg
univer-bg-white univer-p-4 univer-shadow-lg
- dark:univer-bg-black
+ dark:univer-border-gray-600 dark:univer-bg-gray-700
`}
>
<ComponentContainer
components={FilterPanelEmbedPointPart}
sharedProps={{ range, colIndex, onClose: onCancel }}
/>
- <div
- data-u-comp="sheets-filter-panel"
- className="univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0"
- >
+ <div className="univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0">
<Segmented
value={filterBy}
items={items}