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 Pager component (#1085)
Wenzhao Huc1d8f2b8f8de
diff --git a/packages/design/src/components/pager/Pager.stories.tsx b/packages/design/src/components/pager/Pager.stories.tsxnew file mode 100644index 0000000000..b7dabdafae--- /dev/null+++ b/packages/design/src/components/pager/Pager.stories.tsx@@ -0,0 +1,47 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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 React, { useState } from 'react';++import { Pager } from './Pager';++const meta: Meta = {+ title: 'Components / Pager',+ parameters: {+ layout: 'centered',+ },+ tags: ['autodocs'],+ args: {},+};++export default meta;++function PagerDemo() {+ const [count, setCount] = useState(1);++ return <Pager value={count} total={10} onChange={setCount} loop />;+}++export const Playground = {+ render: () => {+ return (+ <>+ <PagerDemo />+ </>+ );+ },+};diff --git a/packages/design/src/components/pager/Pager.tsx b/packages/design/src/components/pager/Pager.tsxnew file mode 100644index 0000000000..f0518aa829--- /dev/null+++ b/packages/design/src/components/pager/Pager.tsx@@ -0,0 +1,64 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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 React, { useMemo } from 'react';++import styles from './index.module.less';++export interface IPagerProps {+ value: number;+ total: number;+ loop?: boolean;++ onChange?(value: number): void;+}++export function Pager(props: IPagerProps) {+ const { value: current = 0, total: count = 0, loop } = props;+ const text = useMemo(() => `${current}/${count}`, [current, count]);++ const onClickLeftArrow = () => {+ if (current === 1) {+ if (loop) {+ props.onChange?.(count);+ }+ } else {+ props.onChange?.(current - 1);+ }+ };++ const onClickRightArrow = () => {+ if (current === count) {+ if (loop) {+ props.onChange?.(1);+ }+ } else {+ props.onChange?.(current + 1);+ }+ };++ return (+ <div className={styles.pager}>+ <div role="button" className={styles.pagerLeftArrow} onClick={onClickLeftArrow}>+ ⬅️+ </div>+ <div className={styles.pagerNumber}>{text}</div>+ <div role="button" className={styles.pagerRightArrow} onClick={onClickRightArrow}>+ ➡️+ </div>+ </div>+ );+}diff --git a/packages/design/src/components/pager/index.module.less b/packages/design/src/components/pager/index.module.lessnew file mode 100644index 0000000000..27e20d996d--- /dev/null+++ b/packages/design/src/components/pager/index.module.less@@ -0,0 +1,32 @@+.pager {+ display: flex;+ align-items: center;+ box-sizing: border-box;++ &-left-arrow,+ &-right-arrow {+ cursor: pointer;+ user-select: none;++ display: inline-flex;+ align-items: center;+ justify-content: center;++ width: 16px;+ height: 16px;++ font-size: 8px;++ border-radius: 4px;++ &:hover {+ background-color: rgb(var(--grey-50));+ }+ }++ &-number {+ margin: 0 4px;+ font-style: 13px;+ color: rgb(var(--text-color));+ }+}diff --git a/packages/design/src/components/pager/index.ts b/packages/design/src/components/pager/index.tsnew file mode 100644index 0000000000..245d27edeb--- /dev/null+++ b/packages/design/src/components/pager/index.ts@@ -0,0 +1,17 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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.+ */++export { type IPagerProps, Pager } from './Pager';diff --git a/packages/design/src/index.ts b/packages/design/src/index.tsindex 38a60fc0fd..e30ec302b3 100644--- a/packages/design/src/index.ts+++ b/packages/design/src/index.ts@@ -29,6 +29,7 @@ export { type IInputProps, Input } from './components/input';export { type IInputNumberProps, InputNumber } from './components/input-number';export { Menu, MenuItem, MenuItemGroup, SubMenu } from './components/menu';export { type IMessageMethodOptions, type IMessageProps, Message, MessageType } from './components/message';+export { type IPagerProps, Pager } from './components/pager';export { type IPopupProps, Popup } from './components/popup';export { type IRadioProps, Radio } from './components/radio';export { type IRadioGroupProps, RadioGroup } from './components/radio-group';