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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(design): add ButtonGroup component (#5077)
Wenzhao Hu6982e11bb260
diff --git a/packages/design/src/components/button/Button.stories.tsx b/packages/design/src/components/button/Button.stories.tsxindex b9ab71b1b6..de7d274fd2 100644--- a/packages/design/src/components/button/Button.stories.tsx+++ b/packages/design/src/components/button/Button.stories.tsx@@ -15,7 +15,6 @@*/import type { Meta } from '@storybook/react';-import { Button } from './Button';const meta: Meta<typeof Button> = {diff --git a/packages/design/src/components/button/Button.tsx b/packages/design/src/components/button/Button.tsxindex 44f6598711..d9d3e09dd6 100644--- a/packages/design/src/components/button/Button.tsx+++ b/packages/design/src/components/button/Button.tsx@@ -27,7 +27,7 @@ export const buttonVariants = cva(univer-justify-center univer-gap-2 univer-whitespace-nowrap univer-rounded-md univer-border univer-border-soliduniver-text-sm univer-font-medium univer-transition-colors[&_svg]:univer-pointer-events-none [&_svg]:univer-size-4 [&_svg]:univer-shrink-0- disabled:univer-pointer-events-none disabled:univer-opacity-50+ disabled:univer-pointer-events-none disabled:univer-cursor-not-allowed disabled:univer-opacity-50`,{variants: {diff --git a/packages/design/src/components/button/ButtonGroup.stories.tsx b/packages/design/src/components/button/ButtonGroup.stories.tsxnew file mode 100644index 0000000000..f9c90bb9b1--- /dev/null+++ b/packages/design/src/components/button/ButtonGroup.stories.tsx@@ -0,0 +1,46 @@+/**+ * 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 { Button } from './Button';+import { ButtonGroup } from './ButtonGroup';++const meta: Meta<typeof ButtonGroup> = {+ title: 'Components / ButtonGroup',+ component: ButtonGroup,+ parameters: {+ layout: 'centered',+ },+ tags: ['autodocs'],+};++export default meta;++export const ButtonGroupBasic = {+ render() {+ return (+ <>+ <div>+ <ButtonGroup>+ <Button variant="primary">Button 1</Button>+ <Button disabled>Button 2</Button>+ <Button>Button 3</Button>+ </ButtonGroup>+ </div>+ </>+ );+ },+};diff --git a/packages/design/src/components/button/ButtonGroup.tsx b/packages/design/src/components/button/ButtonGroup.tsxnew file mode 100644index 0000000000..f2a9c31c4d--- /dev/null+++ b/packages/design/src/components/button/ButtonGroup.tsx@@ -0,0 +1,73 @@+/**+ * 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.+ */++/* eslint-disable react/no-children-map */+/* eslint-disable react/no-children-count */+/* eslint-disable react/no-clone-element */++import type { ReactElement } from 'react';+import type { IButtonProps } from './Button';+import React, { Children, cloneElement } from 'react';+import { clsx } from '../../helper/clsx';++export interface IButtonGroupProps {+ className?: string;+ orientation?: 'horizontal' | 'vertical';+ children: ReactElement<IButtonProps>[];+}++export const ButtonGroup = ({+ className,+ orientation = 'horizontal',+ children,+}: IButtonGroupProps) => {+ const totalButtons = Children.count(children);+ const isHorizontal = orientation === 'horizontal';+ const isVertical = orientation === 'vertical';++ return (+ <div+ className={clsx(+ 'univer-flex',+ {+ 'univer-flex-col': isVertical,+ 'univer-w-fit': isVertical,+ },+ className+ )}+ >+ {Children.map(children, (child, index) => {+ const isFirst = index === 0;+ const isLast = index === totalButtons - 1;++ return cloneElement(child, {+ className: clsx(+ {+ 'univer-rounded-l-none': isHorizontal && !isFirst,+ 'univer-rounded-r-none': isHorizontal && !isLast,+ 'univer-border-l-0': isHorizontal && !isFirst,++ 'univer-rounded-t-none': isVertical && !isFirst,+ 'univer-rounded-b-none': isVertical && !isLast,+ 'univer-border-t-0': isVertical && !isFirst,+ },+ child.props.className+ ),+ });+ })}+ </div>+ );+};