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.

refactor(base-ui): components refactoring (#136)

白熱98f3f405a494
diff --git a/packages/base-ui/.storybook/main.js b/packages/base-ui/.storybook/main.js
index 54f05a0378..9ae6593dd1 100644
--- a/packages/base-ui/.storybook/main.js
+++ b/packages/base-ui/.storybook/main.js
@@ -15,13 +15,14 @@ const config = {
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
+ getAbsolutePath('@storybook/addon-docs'),
],
framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
docs: {
- autodocs: 'tag',
+ autodocs: true,
},
async viteFinal(config, options) {
config.css = {
diff --git a/packages/base-ui/package.json b/packages/base-ui/package.json
index 7f4d63af5f..d5d14e2c76 100644
--- a/packages/base-ui/package.json
+++ b/packages/base-ui/package.json
@@ -41,6 +41,7 @@
"build-storybook": "storybook build"
},
"devDependencies": {
+ "@storybook/addon-docs": "^7.4.1",
"@storybook/addon-essentials": "^7.4.1",
"@storybook/addon-interactions": "^7.4.1",
"@storybook/addon-links": "^7.4.1",
diff --git a/packages/base-ui/src/Components/Avatar/Avatar.stories.tsx b/packages/base-ui/src/Components/Avatar/Avatar.stories.tsx
index fc640d7337..985776160e 100644
--- a/packages/base-ui/src/Components/Avatar/Avatar.stories.tsx
+++ b/packages/base-ui/src/Components/Avatar/Avatar.stories.tsx
@@ -1,17 +1,30 @@
+import type { Meta } from '@storybook/react';
+
import { Avatar } from './Avatar';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Avatar',
+const meta: Meta<typeof Avatar> = {
+ title: 'Components / Avatar',
component: Avatar,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
- args: {},
+ args: {
+ shape: 'circle',
+ size: 'default',
+ fit: 'fill',
+ },
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
+
+export const UsingSrc = {
+ title: 'Using Src',
+ args: {
+ src: 'https://avatars.githubusercontent.com/u/20630676?s=60&v=4',
+ },
+};
diff --git a/packages/base-ui/src/Components/Avatar/Avatar.tsx b/packages/base-ui/src/Components/Avatar/Avatar.tsx
index 7ee9021ebc..374dcc5214 100644
--- a/packages/base-ui/src/Components/Avatar/Avatar.tsx
+++ b/packages/base-ui/src/Components/Avatar/Avatar.tsx
@@ -1,68 +1,89 @@
-import React from 'react';
-
-import { BaseComponentProps } from '../../BaseComponent';
-import { joinClassNames } from '../../Utils';
-import styles from './Style/index.module.less';
-
-type Shape = 'circle' | 'square';
-// type BreakPoint = 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs';
-// type AvatatScreen = Partial<Record<BreakPoint, number>>;
-// type AvatarSize = number | 'large' | 'small' | 'default' | AvatatScreen;
-type AvatarSize = number | 'large' | 'small' | 'default';
-type ImageFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
-
-export interface BaseAvatarProps extends BaseComponentProps {
- alt?: string;
- shape?: Shape;
- size?: AvatarSize;
- src?: string;
- style?: React.CSSProperties;
- fit?: ImageFit;
- children?: any;
- onError?: () => void;
- onLoad?: () => void;
- title?: string;
-}
-
-export function Avatar(props: BaseAvatarProps) {
- const { alt, shape = 'circle', size, src, onError, style, fit = 'fill', children, onLoad, title } = props;
-
- // const responseSize = () => {
- // if (size instanceof Object) {
- // }
- // };
-
- const sizeStyle =
- typeof size === 'number'
- ? {
- width: size,
- height: size,
- lineHeight: `${size}px`,
- }
- : {};
-
- const prefix = styles.avatar;
-
- const classes = joinClassNames(prefix, {
- [`${prefix}-${shape}`]: shape,
- [`${prefix}-image`]: src,
- [`${prefix}-lg`]: size === 'large',
- [`${prefix}-sm`]: size === 'small',
- });
-
- const fitStyle = fit ? { objectFit: fit } : {};
- if (src) {
- return (
- <span className={classes} style={{ ...sizeStyle, ...style, ...fitStyle }}>
- <img src={src} title={title} alt={alt} onError={onError} onLoad={onLoad} />
- {children}
- </span>
- );
- }
-
- return (
- <span className={classes} style={{ ...sizeStyle, ...style }}>
- {children}
- </span>
- );
-}
+import { BaseComponentProps } from '../../BaseComponent';
+import { joinClassNames } from '../../Utils';
+import styles from './Style/index.module.less';
+
+type Shape = 'circle' | 'square';
+type AvatarSize = number | 'large' | 'small' | 'default';
+type ImageFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
+
+export interface BaseAvatarProps extends BaseComponentProps {
+ children?: React.ReactNode;
+
+ /** Semantic DOM style */
+ style?: React.CSSProperties;
+
+ /** The title of the image avatar */
+ title?: string;
+
+ /** Image description */
+ alt?: string;
+
+ /**
+ * The shape of the avatar
+ * @default 'circle'
+ */
+ shape?: Shape;
+
+ /**
+ * The size of the avatar
+ * @default 'default'
+ */
+ size?: AvatarSize;
+
+ /** The address of the image for an image avatar or image element */
+ src?: string;
+
+ /**
+ * The fit of the image avatar
+ * @default fill
+ */
+ fit?: ImageFit;
+
+ /** Handler when img load error */
+ onError?: () => void;
+
+ /** Handler when img load success */
+ onLoad?: () => void;
+}
+
+/**
+ * Avatar Component
+ */
+export function Avatar(props: BaseAvatarProps) {
+ const { children, style, title, alt, shape = 'circle', size = 'default', src, fit = 'fill', onError, onLoad } = props;
+
+ const sizeStyle =
+ typeof size === 'number'
+ ? {
+ width: size,
+ height: size,
+ lineHeight: `${size}px`,
+ }
+ : {};
+
+ const prefix = styles.avatar;
+
+ const classes = joinClassNames(prefix, {
+ [`${prefix}-${shape}`]: shape,
+ [`${prefix}-image`]: src,
+ [`${prefix}-lg`]: size === 'large',
+ [`${prefix}-sm`]: size === 'small',
+ });
+
+ const fitStyle = fit ? { objectFit: fit } : {};
+
+ if (src) {
+ return (
+ <span className={classes} style={{ ...sizeStyle, ...style, ...fitStyle }}>
+ <img src={src} title={title} alt={alt} onError={onError} onLoad={onLoad} />
+ {children}
+ </span>
+ );
+ }
+
+ return (
+ <span className={classes} style={{ ...sizeStyle, ...style }}>
+ {children}
+ </span>
+ );
+}
diff --git a/packages/base-ui/src/Components/Avatar/avatar-zh.md b/packages/base-ui/src/Components/Avatar/avatar-zh.md
deleted file mode 100644
index 891ba348b3..0000000000
--- a/packages/base-ui/src/Components/Avatar/avatar-zh.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-category: Components
-type: 通用
-title: Checkbox
-subtitle: 头像框
-cover: ''
----
-
-## 介绍
-
-头像框组件
-
-## API
-
-属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| alt | 图像无法显示时的替代文本 | string | - |
-| shape | 头像形状 | 'circle'\|'square' | - |
-| size | 头像尺寸 | number\|'large'\|'small'\|'default' | - |
-| src | 图片来源 | string | - |
-| style | 组件样式 | JSX.CSSProperties | - |
-| fit | 图片包含方式 | 'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down' | - |
-| children | 子内容 | any | - |
-| onError | 图片加载失败回调 | (event) => void | - |
-| onLoad | 图片加载后回调 | (event) => void | - |
-| title | 图片 title | string | - |
-
-## 案例
-
-```jsx
-import { Avatar } from '@univerjs/style-univer';
-
-<Avatar size="small" />;
-```
diff --git a/packages/base-ui/src/Components/Avatar/avatar.md b/packages/base-ui/src/Components/Avatar/avatar.md
deleted file mode 100644
index 4dd415845d..0000000000
--- a/packages/base-ui/src/Components/Avatar/avatar.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-category: Components
-type: 通用
-title: Checkbox
-subtitle: 头像框
-cover: ''
----
-
-## Introduce
-
-Avatar Component
-
-## API
-
-Property Introduction:
-
-| Property | Description | Type | Default |
-
-| alt | This attribute defines the alternative text describing the image | string | - |
-| shape | shape of avatar | 'circle'\|'square' | - |
-| size | avatar's size | number\|'large'\|'small'\|'default' | - |
-| src | image source | string | - |
-| style | css style | JSX.CSSProperties | - |
-| fit | how to fit image | 'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down' | - |
-| children | avatar content or child nodes | any | - |
-| onError | Handler when img load error, return false to prevent default fallback behavior | (event) => void | - |
-| onLoad | Handler when img loaded | (event) => void | - |
-| title | title of image | string | - |
-
-## 案例
-
-```jsx
-import { Avatar } from '@univerjs/style-univer';
-
-<Avatar size="small" />;
-```
diff --git a/packages/base-ui/src/Components/Avatar/test/index.test.tsx b/packages/base-ui/src/Components/Avatar/test/index.test.tsx
index 6d443f46ac..89d10e06c6 100644
--- a/packages/base-ui/src/Components/Avatar/test/index.test.tsx
+++ b/packages/base-ui/src/Components/Avatar/test/index.test.tsx
@@ -3,15 +3,18 @@ import { render } from '@testing-library/react';
import { Avatar } from '..';
describe('Avatar', () => {
- test('should display initial Avatar', () => {
- const { container } = render(<Avatar size="small">哈哈</Avatar>);
+ test('renders correctly', () => {
+ const { container } = render(<Avatar size="small">Jane Doe</Avatar>);
expect(container);
});
+
test('should display initial Avatar', () => {
let a = 1;
+
const { container } = render(
<Avatar src="https//www.baidu.com/img/PC_880906d2a4ad95f5fafb2e540c5cdad7.png" title="a" alt="a" fit="fill" onLoad={() => a++} onError={() => a++}></Avatar>
);
+
expect(container);
});
});
diff --git a/packages/base-ui/src/Components/Button/Button.stories.tsx b/packages/base-ui/src/Components/Button/Button.stories.tsx
index d1260a7567..b020d134a0 100644
--- a/packages/base-ui/src/Components/Button/Button.stories.tsx
+++ b/packages/base-ui/src/Components/Button/Button.stories.tsx
@@ -1,19 +1,28 @@
+import type { Meta } from '@storybook/react';
+
import { Button } from './Button';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Button',
+const meta: Meta<typeof Button> = {
+ title: 'Components / Button',
component: Button,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: 'Button',
+ type: 'default',
+ size: 'middle',
+ danger: false,
+ disabled: false,
+ block: false,
+ loading: false,
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
- args: {},
+ args: {
+ children: 'Button',
+ },
};
diff --git a/packages/base-ui/src/Components/Button/Button.tsx b/packages/base-ui/src/Components/Button/Button.tsx
index 1397e91650..21f752dd4e 100644
--- a/packages/base-ui/src/Components/Button/Button.tsx
+++ b/packages/base-ui/src/Components/Button/Button.tsx
@@ -1,190 +1,110 @@
-import { useEffect, useState } from 'react';
-
import { BaseComponentProps } from '../../BaseComponent';
import { joinClassNames } from '../../Utils/util';
import { LoadingIcon } from '../Icon';
import styles from './Style/index.module.less';
// Components interface
-const ButtonTypes: string[] = ['default', 'primary'];
export type ButtonType = 'default' | 'primary';
-const ButtonShapes: string[] = ['circle', 'round'];
export type ButtonShape = 'circle' | 'round';
-const SizeTypes: string[] = ['small', 'middle', 'large'];
export type SizeType = 'small' | 'middle' | 'large';
-const ButtonHTMLTypes: string[] = ['submit', 'reset', 'button'];
export type ButtonHTMLType = 'submit' | 'reset' | 'button';
-export interface BaseButtonProps extends BaseComponentProps {
+export interface IBaseButtonProps extends BaseComponentProps {
+ children?: React.ReactNode;
+
+ /** Semantic DOM class */
+ className?: string;
+
+ /** Semantic DOM style */
+ style?: React.CSSProperties;
+
+ /**
+ * Set button type
+ * @default 'default'
+ */
type?: ButtonType;
+
+ /** Can be set button shape */
shape?: ButtonShape;
+
+ /**
+ * Set the size of button
+ * @default 'middle'
+ */
size?: SizeType;
+
+ /** Set the original html `type` of button, see: [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type) */
+ htmlType?: ButtonHTMLType;
+
+ /**
+ * Set the danger status of button
+ * @default false
+ */
danger?: boolean;
+
+ /**
+ * Disabled state of button
+ * @default false
+ */
disabled?: boolean;
+
+ /**
+ * Option to fit button width to its parent width
+ * @default false
+ */
block?: boolean;
+
+ /**
+ * Set the loading status of button
+ * @default false
+ */
loading?: boolean;
- active?: boolean;
- htmlType?: ButtonHTMLType;
- onClick?: Function;
- children?: any;
- className?: string;
- style?: React.CSSProperties;
- unActive?: boolean;
-}
-// component class
-
-// interface IState {
-// isActive: boolean;
-// }
-
-// class Button extends Component<BaseButtonProps, IState> {
-// constructor(props: BaseButtonProps) {
-// super();
-// this.state = {
-// isActive: props.active ?? false,
-// };
-// }
-
-// getSizeCls() {
-// const { size } = this.props;
-// let sizeCls = '';
-// switch (size) {
-// case 'large':
-// sizeCls = 'lg';
-// break;
-// case 'small':
-// sizeCls = 'sm';
-// break;
-// default:
-// break;
-// }
-// return sizeCls;
-// }
-
-// getClass() {
-// const { isActive } = this.state;
-// const { type, shape, danger, block, loading, size, className } = this.props;
-// return joinClassNames(
-// styles.btn,
-// {
-// [`${styles.btn}-${type}`]: type,
-// [`${styles.btn}-${shape}`]: shape,
-// [`${styles.btn}-${this.getSizeCls()}`]: size,
-// [`${styles.btn}-danger`]: !!danger,
-// [`${styles.btn}-block`]: block,
-// [`${styles.btn}-loading`]: loading,
-// [`${styles.btn}-active`]: isActive,
-// },
-// className
-// );
-// }
-
-// handleClick = (e: MouseEvent) => {
-// const { disabled, onClick, unActive = true } = this.props;
-
-// if (disabled) {
-// e.preventDefault();
-// return;
-// }
-
-// if (unActive) {
-// onClick?.(e);
-// return;
-// }
-
-// this.setState(
-// {
-// isActive: !this.state.isActive,
-// },
-// () => {
-// if (onClick) {
-// onClick.call(null, e, this.state.isActive);
-// }
-// }
-// );
-// };
-
-// override UNSAFE_componentWillReceiveProps(props: BaseButtonProps) {
-// this.setState({
-// isActive: props.active,
-// });
-// }
-
-// render() {
-// const { htmlType, disabled, style, loading, children } = this.props;
-// return (
-// <button type={htmlType} onClick={this.handleClick} className={this.getClass()} disabled={disabled} style={style}>
-// {loading ? <LoadingIcon /> : ''}
-// {children}
-// </button>
-// );
-// }
-// }
-
-export function Button(props: BaseButtonProps) {
- const [isActive, setIsActive] = useState(props.active ?? false);
-
- useEffect(() => {
- setIsActive(props.active ?? false);
- }, [props.active]);
-
- const getSizeCls = () => {
- const { size } = props;
- let sizeCls = '';
- switch (size) {
- case 'large':
- sizeCls = 'lg';
- break;
- case 'small':
- sizeCls = 'sm';
- break;
- default:
- break;
- }
- return sizeCls;
- };
+ /** Set the handler to handle `click` event */
+ onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
+}
- const getClass = () => {
- const { type, shape, danger, block, loading, size, className } = props;
- return joinClassNames(
- styles.btn,
- {
- [`${styles.btn}-${type}`]: type,
- [`${styles.btn}-${shape}`]: shape,
- [`${styles.btn}-${getSizeCls()}`]: size,
- [`${styles.btn}-danger`]: !!danger,
- [`${styles.btn}-block`]: block,
- [`${styles.btn}-loading`]: loading,
- [`${styles.btn}-active`]: isActive,
- },
- className
- );
- };
+const getSizeClass = (size?: SizeType) => {
+ switch (size) {
+ case 'large':
+ return 'lg';
+ case 'small':
+ return 'sm';
+ default:
+ return '';
+ }
+};
+
+/**
+ * Button Component
+ */
+export function Button(props: IBaseButtonProps) {
+ const { children, className, style, type = 'default', shape, size, htmlType, danger = false, disabled = false, block = false, loading = false, onClick } = props;
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
- const { disabled, onClick, unActive = true } = props;
-
if (disabled) {
e.preventDefault();
return;
}
- if (unActive) {
- onClick?.(e);
- return;
- }
-
- setIsActive(!isActive);
-
- if (onClick) {
- onClick.call(e, isActive);
- }
+ onClick && onClick(e);
};
- const { htmlType, disabled, style, loading, children } = props;
+ const _className = joinClassNames(
+ styles.btn,
+ {
+ [`${styles.btn}-${type}`]: type,
+ [`${styles.btn}-${shape}`]: shape,
+ [`${styles.btn}-${getSizeClass(size)}`]: size,
+ [`${styles.btn}-danger`]: !!danger,
+ [`${styles.btn}-block`]: block,
+ [`${styles.btn}-loading`]: loading,
+ },
+ className
+ );
+
return (
- <button type={htmlType} onClick={handleClick} className={getClass()} disabled={disabled} style={style}>
+ <button className={_className} style={style} disabled={disabled} type={htmlType} onClick={handleClick}>
{loading ? <LoadingIcon /> : ''}
{children}
</button>
diff --git a/packages/base-ui/src/Components/Button/Style/index.module.less b/packages/base-ui/src/Components/Button/Style/index.module.less
index dc53895f8a..556a0dd99e 100644
--- a/packages/base-ui/src/Components/Button/Style/index.module.less
+++ b/packages/base-ui/src/Components/Button/Style/index.module.less
@@ -21,14 +21,6 @@
.btn-text();
}
- &-active {
- color: var(--text-color);
- background: var(--bg-hover);
- border-color: var(--border-color-base);
- text-shadow: none;
- box-shadow: none;
- }
-
&-round {
.btn-round();
}
@@ -64,4 +56,4 @@
&:active>span {
position: relative;
}
-}
\ No newline at end of file
+}
diff --git a/packages/base-ui/src/Components/Button/button-zh.md b/packages/base-ui/src/Components/Button/button-zh.md
deleted file mode 100644
index 31292c822c..0000000000
--- a/packages/base-ui/src/Components/Button/button-zh.md
+++ /dev/null
@@ -1,64 +0,0 @@
----
-category: Components
-type: 通用
-title: Button
-subtitle: 按钮
-cover: ''
----
-
-## 介绍
-
-通用按钮组件
-
-按钮类型
-
-- 主按钮:类型`primary`,一般用于弹窗的确定按钮,每行的确认按钮,一个操作区域只能有一个主按钮
-- 默认按钮:工具栏按钮
-- 文本按钮:取消功能
-
-按钮状态
-
-- 禁用:工具栏禁用状态
-- 加载中:异步操作等待状态
-
-## API
-
-通过设置 Button 的属性来产生不同的按钮样式,推荐顺序为:`type` -> `shape` -> `size` -> `loading` -> `disabled`。
-
-按钮的属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-| --------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | --------- |
-| block | 将按钮宽度调整为其父宽度的选项 | boolean | false |
-| danger | 设置危险按钮 | boolean | false |
-| disabled | 按钮失效状态 | boolean | false |
-| htmlType | 设置 `button` 原生的 `type` 值,可选值请参考 [HTML 标准](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type) | string | `button` |
-| loading | 设置按钮载入状态 | boolean \| { delay: number } | false |
-| shape | 设置按钮形状 | `circle` \| `round` | - |
-| size | 设置按钮大小 | `large` \| `middle` \| `small` | `middle` |
-| type | 设置按钮类型 | `primary` \| `ghost` \| `dashed` \| `link` \| `text` \| `default` | `default` |
-| onClick | 点击按钮时的回调 | (event) => void | - |
-| children | 按钮内容或者子节点 | any | - |
-| className | 点击按钮时的回调 | string | - |
-
-支持原生 button 的其他所有属性。
-
-## 案例
-
-```jsx
-import { Button } from '@univerjs/style-univer';
-
-const Toolbar = () => {
- const buttonText = '确认';
- return (
- <Button
- type="primary"
- onClick={() => {
- this.handleClick();
- }}
- >
- {buttonText}
- </Button>
- );
-};
-```
diff --git a/packages/base-ui/src/Components/Button/button.md b/packages/base-ui/src/Components/Button/button.md
deleted file mode 100644
index 4c9c22cd72..0000000000
--- a/packages/base-ui/src/Components/Button/button.md
+++ /dev/null
@@ -1,61 +0,0 @@
----
-category: Components
-type: General
-title: Button
-cover: ''
----
-
-## Introduction
-
-General button component
-
-Button type
-
-- Primary button: type `primary`, generally used for the confirm button of the pop-up window, each row of the confirm button, an operation area can only have one primary button
-- Default button: toolbar button
-- Text button: cancel function
-
-Button state
-
-- Disabled: Toolbar is disabled
-- Loading: Asynchronous operation waiting state
-
-## API
-
-Different button styles can be generated by setting Button properties. The recommended order is: `type` -> `shape` -> `size` -> `loading` -> `disabled`.
-
-| Property | Description | Type | Default |
-| ---------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | --------- |
-| block | Option to fit button width to its parent width | boolean | false |
-| danger | Set the danger status of button | boolean | false |
-| disabled | Disabled state of button | boolean | false |
-| htmlType | Set the original html `type` of `button`, see: [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type) | string | `button` |
-| loading | Set the loading status of button | boolean \| { delay: number } | false |
-| shape | Can be set button shape | `circle` \| `round` | - |
-| size | Set the size of button | `large` \| `middle` \| `small` | `middle` |
-| type | Can be set to `primary` `ghost` `dashed` `link` `text` `default` | string | `default` |
-| onClick | Set the handler to handle `click` event | (event) => void | - |
-| children: | Button content or child nodes | any | - |
-| className: | className | string | - |
-
-It accepts all props which native buttons support.
-
-## Case
-
-```jsx
-import { Button } from '@univerjs/style-univer';
-
-const Toolbar = () => {
- const buttonText = 'Confirm';
- return (
- <Button
- type="primary"
- onClick={() => {
- this.handleClick();
- }}
- >
- {buttonText}
- </Button>
- );
-};
-```
diff --git a/packages/base-ui/src/Components/Button/test/index.test.tsx b/packages/base-ui/src/Components/Button/test/index.test.tsx
index 1075517ef6..618fb00f7f 100644
--- a/packages/base-ui/src/Components/Button/test/index.test.tsx
+++ b/packages/base-ui/src/Components/Button/test/index.test.tsx
@@ -3,30 +3,49 @@ import { fireEvent, render, screen } from '@testing-library/react';
import { Button } from '..';
describe('Button', () => {
- test('should display initial Button', () => {
+ test('renders correctly', () => {
const { container } = render(
<Button type="primary" onClick={() => {}}>
- 哈哈
+ lol
</Button>
);
expect(container);
});
- test('click onSwitch function', async () => {
+
+ test('click onClick function', () => {
let a = 1;
render(
<Button
- type="default"
onClick={() => {
a++;
}}
>
- 哈哈
+ lol
</Button>
);
- fireEvent.click(screen.getByText('哈哈'));
+ fireEvent.click(screen.getByText('lol'));
expect(a).toEqual(2);
});
+
+ test('should prevent event when button is disabled', () => {
+ let a = 1;
+
+ render(
+ <Button
+ disabled
+ onClick={() => {
+ a++;
+ }}
+ >
+ lol
+ </Button>
+ );
+
+ fireEvent.click(screen.getByText('lol'));
+
+ expect(a).toEqual(1);
+ });
});
diff --git a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.stories.tsx b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.stories.tsx
index 985d0101d7..2256f18ef3 100644
--- a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.stories.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { CanvasIcon } from './CanvasIcon';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/CanvasIcon',
+const meta: Meta<typeof CanvasIcon> = {
+ title: 'Components / CanvasIcon',
component: CanvasIcon,
parameters: {
layout: 'centered',
@@ -20,7 +21,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/CellRange/CellRange.stories.tsx b/packages/base-ui/src/Components/CellRange/CellRange.stories.tsx
index 7979f8ed18..82b66dc610 100644
--- a/packages/base-ui/src/Components/CellRange/CellRange.stories.tsx
+++ b/packages/base-ui/src/Components/CellRange/CellRange.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { CellRange } from './CellRange';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/CellRange',
+const meta: Meta<typeof CellRange> = {
+ title: 'Components / CellRange',
component: CellRange,
parameters: {
layout: 'centered',
@@ -11,7 +12,8 @@ export default {
args: {},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Checkbox/Checkbox.stories.tsx b/packages/base-ui/src/Components/Checkbox/Checkbox.stories.tsx
index 03703eee40..91e04a26b5 100644
--- a/packages/base-ui/src/Components/Checkbox/Checkbox.stories.tsx
+++ b/packages/base-ui/src/Components/Checkbox/Checkbox.stories.tsx
@@ -1,17 +1,29 @@
+import type { Meta } from '@storybook/react';
+
import { Checkbox } from './Checkbox';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Checkbox',
+const meta: Meta<typeof Checkbox> = {
+ title: 'Components / Checkbox',
component: Checkbox,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
- args: {},
+ args: {
+ checked: false,
+ disabled: false,
+ },
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
+
+export const UsingSlot = {
+ title: 'Using Slot',
+ args: {
+ children: <strong>Apple</strong>,
+ },
+};
diff --git a/packages/base-ui/src/Components/Checkbox/Checkbox.tsx b/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
index c8b527af78..c0b959687f 100644
--- a/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
+++ b/packages/base-ui/src/Components/Checkbox/Checkbox.tsx
@@ -3,79 +3,40 @@ import { useEffect, useState } from 'react';
import { BaseComponentProps } from '../../BaseComponent';
import { joinClassNames } from '../../Utils';
import styles from './index.module.less';
-// export type CheckboxBaseProps = {
-// value?: string;
-// checked?: boolean;
-// className?: string;
-// disabled?: boolean;
-// name?: string;
-// onChange?: (e: Event) => void;
-// children?: string | JSX.Element;
-// };
-
-// type CheckboxState = {
-// classes: string;
-// check: boolean;
-// };
-
-// export class Checkbox extends Component<BaseCheckboxProps, CheckboxState> {
-// override state = {
-// classes: this.props.className ? `${this.props.className} ${styles.checkBox}` : styles.checkBox,
-// check: true,
-// };
-
-// handleStyle = (checked?: boolean, disabled?: boolean) => {
-// // Decide whether to check or disable based on the checkbox style
-// const classGroup = joinClassNames(styles.checkBox, {
-// [`${styles.checkBox}-checked`]: checked,
-// [`${styles.checkBox}-disabled`]: disabled,
-// }) as string;
-
-// this.setState((prevState) => ({ classes: classGroup, check: checked }));
-// };
-
-// override UNSAFE_componentWillMount() {
-// this.handleStyle(this.props.checked, this.props.disabled);
-// }
-
-// override UNSAFE_componentWillReceiveProps(nextProps: BaseCheckboxProps) {
-// this.handleStyle(nextProps.checked, nextProps.disabled);
-// }
-
-// handleChange = (e: Event) => {
-// const target = e.target as HTMLInputElement;
-
-// this.handleStyle(target.checked, this.props.disabled);
-
-// this.props.onChange?.(e);
-// };
-
-// render() {
-// const { classes, check } = this.state;
-// const { value, name, disabled, children } = this.props;
-// return (
-// <label className={styles.checkboxWrapper}>
-// <span className={classes}>
-// <span className={styles.checkboxInner}></span>
-// <input type="checkbox" name={name} checked={check} disabled={disabled} className={styles.checkboxInput} value={value} onChange={this.handleChange} />
-// </span>
-// {children && <span>{children}</span>}
-// </label>
-// );
-// }
-// }
+
export interface BaseCheckboxProps extends BaseComponentProps {
+ children?: React.ReactNode;
+
+ /** Semantic DOM class */
+ className?: string;
+
+ /** Used for setting the currently selected value */
value?: string;
+
+ /** The name of the checkbox */
+ name?: string;
+
+ /**
+ * Specifies whether the checkbox is selected
+ * @default false
+ */
checked?: boolean;
- className?: string;
+
+ /**
+ * If disable checkbox
+ * @default false
+ */
disabled?: boolean;
- name?: string;
+
+ /** The callback function that is triggered when the state changes */
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
- children?: React.ReactNode;
}
+/**
+ * Checkbox Component
+ */
export function Checkbox(props: BaseCheckboxProps) {
- const { className, checked: initialChecked, disabled, name, onChange, children, value } = props;
+ const { children, className, value, name, checked: initialChecked = false, disabled = false, onChange } = props;
const [checked, setChecked] = useState(initialChecked);
const [classes, setClasses] = useState(className ? `${className} ${styles.checkBox}` : styles.checkBox);
@@ -105,8 +66,8 @@ export function Checkbox(props: BaseCheckboxProps) {
return (
<label className={styles.checkboxWrapper}>
<span className={classes}>
- <span className={styles.checkboxInner}></span>
- <input type="checkbox" name={name} checked={checked} disabled={disabled} className={styles.checkboxInput} value={value} onChange={handleChange} />
+ <span className={styles.checkboxInner} />
+ <input className={styles.checkboxInput} type="checkbox" name={name} checked={checked} disabled={disabled} value={value} onChange={handleChange} />
</span>
{children && <span>{children}</span>}
</label>
diff --git a/packages/base-ui/src/Components/Checkbox/CheckboxGroup.stories.tsx b/packages/base-ui/src/Components/Checkbox/CheckboxGroup.stories.tsx
index d8032e4dd5..15ff304cc1 100644
--- a/packages/base-ui/src/Components/Checkbox/CheckboxGroup.stories.tsx
+++ b/packages/base-ui/src/Components/Checkbox/CheckboxGroup.stories.tsx
@@ -1,13 +1,23 @@
+import type { Meta } from '@storybook/react';
+
import { CheckboxGroup } from './CheckboxGroup';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/CheckboxGroup',
+const meta: Meta<typeof CheckboxGroup> = {
+ title: 'Components / CheckboxGroup',
component: CheckboxGroup,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
+ args: {
+ disabled: false,
+ options: [],
+ },
+};
+
+export default meta;
+
+export const Playground = {
args: {
options: [
{
@@ -24,8 +34,3 @@ export default {
],
},
};
-
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
-export const Playground = {
- args: {},
-};
diff --git a/packages/base-ui/src/Components/Checkbox/CheckboxGroup.tsx b/packages/base-ui/src/Components/Checkbox/CheckboxGroup.tsx
index d2472d0fb7..983cfc983a 100644
--- a/packages/base-ui/src/Components/Checkbox/CheckboxGroup.tsx
+++ b/packages/base-ui/src/Components/Checkbox/CheckboxGroup.tsx
@@ -5,22 +5,43 @@ import { Checkbox } from './Checkbox';
import styles from './index.module.less';
export type BaseCheckboxGroupOptions = {
+ label?: React.ReactNode;
+
checked?: boolean;
+
disabled?: boolean;
+
name?: string;
- label?: React.ReactNode;
+
value?: string;
};
+// TODO: where is the `value`?
+
export interface BaseCheckboxGroupProps extends BaseComponentProps {
- disabled?: boolean;
+ /** The `name` property of all `input[type="checkbox"]` children */
name?: string;
+
+ /**
+ * Specifies options
+ * @default []
+ */
options: BaseCheckboxGroupOptions[];
+
+ /**
+ * If disable all checkboxes
+ * @default false
+ */
+ disabled?: boolean;
+
onChange?: (value: string[]) => void;
}
+/**
+ * CheckboxGroup Component
+ */
export function CheckboxGroup(props: BaseCheckboxGroupProps) {
- const { options, onChange, disabled, name } = props;
+ const { name, options = [], disabled = false, onChange } = props;
const ref = useRef<HTMLDivElement>(null);
if (disabled) {
diff --git a/packages/base-ui/src/Components/Checkbox/checkbox-zh.md b/packages/base-ui/src/Components/Checkbox/checkbox-zh.md
deleted file mode 100644
index 2feaebb7f1..0000000000
--- a/packages/base-ui/src/Components/Checkbox/checkbox-zh.md
+++ /dev/null
@@ -1,67 +0,0 @@
----
-category: Components
-type: 通用
-title: Checkbox CheckboxGroup
-subtitle: 复选框 复选框组合
-cover: ''
----
-
-## 介绍
-
-复选框组件
-
-复选框状态
-
-- checked 选中
-- disabled 禁止选中
-
-## API
-
-属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| disabled | 复选框失效状态 | boolean | false |
-| onChange | 勾选的回调 | (event) => void | - |
-| children | 复选框内容或者子节点 | any | - |
-| className | 复选框父容器类名 | string | - |
-| value | 复选框 value | string | - |
-
-## 介绍
-
-复选框组合
-
-## API
-
-属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-type options = {
-checked?: boolean;
-disabled?: boolean;
-name?: string;
-label?: string | JSX.Element;
-value?: string;
-};
-
-| disabled | 复选框失效状态 | boolean | false |
-| onChange | 勾选的回调 | (event) => void | - |
-| options | 复选框组合内容(类型为 type options) | Array<options> | - |
-
-## 案例
-
-```jsx
-import { Checkbox, CheckboxGroup } from '@univerjs/style-univer';
-
-let options = {
- checked?: boolean;
- disabled?: boolean;
- name?: string;
- label?: string | JSX.Element;
- value?: string;
-};
-
-<CheckboxGroup options={[options]} onChange={()=>{}}></CheckboxGroup>
-<Checkbox value={`Header`} checked={true}>Header</Checkbox>
-```
diff --git a/packages/base-ui/src/Components/Checkbox/checkbox.md b/packages/base-ui/src/Components/Checkbox/checkbox.md
deleted file mode 100644
index e7e7b81384..0000000000
--- a/packages/base-ui/src/Components/Checkbox/checkbox.md
+++ /dev/null
@@ -1,66 +0,0 @@
----
-category: Components
-type: General
-title: Checkbox CheckboxGroup
-cover: ''
----
-
-## Introduction
-
-Checkbox Component
-
-Checkbox Type
-
-- checked
-- disabled
-
-## API
-
-Property Introduction:
-
-| Property | Description | Type | Default |
-
-| disabled | Disabled state of checkbox | boolean | false |
-| onChange | Set the handler to handle `change` event | (event) => void | - |
-| children | Button content or child nodes | any | - |
-| className | Classname of parent | string | - |
-| value | Checkbox value | string | - |
-
-## Introduction
-
-Checkbox Group
-
-## API
-
-Property Introduction:
-
-| Property | Description | Type | Default |
-
-type options = {
-checked?: boolean;
-disabled?: boolean;
-name?: string;
-label?: string | JSX.Element;
-value?: string;
-};
-
-| disabled | Disabled state of checkbox | boolean | false |
-| onChange | Set the handler to handle `change` event | (event) => void | - |
-| options | Component Content(type: options) | Array<options> | - |
-
-## Case
-
-```jsx
-import { Checkbox, CheckboxGroup } from '@univerjs/style-univer';
-
-let options = {
- checked?: boolean;
- disabled?: boolean;
- name?: string;
- label?: string | JSX.Element;
- value?: string;
-};
-
-<CheckboxGroup options={[options]} onChange={()=>{}}></CheckboxGroup>
-<Checkbox value={`Header`} checked={true}>Header</Checkbox>
-```
diff --git a/packages/base-ui/src/Components/Checkbox/test/index.test.tsx b/packages/base-ui/src/Components/Checkbox/test/index.test.tsx
index 8482734859..f5172e62ec 100644
--- a/packages/base-ui/src/Components/Checkbox/test/index.test.tsx
+++ b/packages/base-ui/src/Components/Checkbox/test/index.test.tsx
@@ -6,11 +6,12 @@ describe('checkbox', () => {
test('checkbox', () => {
const { container } = render(
<Checkbox value={`Header`} checked={true}>
- Header
+ foo
</Checkbox>
);
expect(container);
});
+
test('checkbox group', () => {
let a = 1;
const checkGroups = [
@@ -18,13 +19,13 @@ describe('checkbox', () => {
checked: true,
disabled: false,
name: '123',
- label: '哈哈',
+ label: 'agree',
value: '1',
},
];
const { container } = render(<CheckboxGroup options={checkGroups} onChange={() => a++}></CheckboxGroup>);
expect(container);
- fireEvent.click(screen.getByText('哈哈'));
+ fireEvent.click(screen.getByText('agree'));
expect(a).toEqual(2);
});
});
diff --git a/packages/base-ui/src/Components/Collapse/Collapse.stories.tsx b/packages/base-ui/src/Components/Collapse/Collapse.stories.tsx
index aff35b2cdd..d645ccb840 100644
--- a/packages/base-ui/src/Components/Collapse/Collapse.stories.tsx
+++ b/packages/base-ui/src/Components/Collapse/Collapse.stories.tsx
@@ -1,28 +1,22 @@
-import { Collapse, Panel } from './Collapse';
+import type { Meta } from '@storybook/react';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Collapse',
+import { Collapse } from './Collapse';
+
+const meta: Meta<typeof Collapse> = {
+ title: 'Components / Collapse',
component: Collapse,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: (
- <>
- <Panel header="test">
- <div>test Collapse</div>
- </Panel>
- <Panel header="test1">
- <div>test Collapse1</div>
- </Panel>
- </>
- ),
+ children: 'Collapse Content',
+ header: 'Collapse Header',
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Collapse/Collapse.tsx b/packages/base-ui/src/Components/Collapse/Collapse.tsx
index 598e55a21c..891f50ec1c 100644
--- a/packages/base-ui/src/Components/Collapse/Collapse.tsx
+++ b/packages/base-ui/src/Components/Collapse/Collapse.tsx
@@ -4,15 +4,19 @@ import { joinClassNames } from '../../Utils';
import { NextIcon } from '../Icon/Format';
import Style from './index.module.less';
-export interface BasePanelProps {
- children: React.ReactNode;
- header?: React.ReactNode;
-}
-
export interface BaseCollapseProps {
children: React.ReactNode;
+
+ /**
+ * Set the header of collapse
+ */
+ header: string;
}
-export function Panel(props: BasePanelProps) {
+
+/**
+ * Collapse Component
+ */
+export function Collapse(props: BaseCollapseProps) {
const { header, children } = props;
const [panelBodyClassName, setPanelBodyClassName] = useState(joinClassNames(Style.panelBody));
@@ -37,9 +41,3 @@ export function Panel(props: BasePanelProps) {
</div>
);
}
-
-export function Collapse(props: BaseCollapseProps) {
- const { children } = props;
-
- return <div className={Style.collapseWrapper}>{children}</div>;
-}
diff --git a/packages/base-ui/src/Components/Collapse/collapse-zh.md b/packages/base-ui/src/Components/Collapse/collapse-zh.md
deleted file mode 100644
index ab7b6c8dcf..0000000000
--- a/packages/base-ui/src/Components/Collapse/collapse-zh.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-category: Components
-type: 通用
-title: Collapse
-subtitle: 折叠面板
-cover: ''
----
-
-## 介绍
-
-折叠面板
-
-## API
-
-属性说明如下:
-
-```jsx
-interface PanelProps {
- children: ComponentChildren;
- header?: ComponentChildren;
-}
-```
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| header | 标题 | ComponentChildren | - |
-
-## 案例
-
-```jsx
-import { Collapse, Panel } from '@univerjs/style-univer';
-
-<Collapse>
- <Panel header="title"></Panel>
-</Collapse>;
-```
diff --git a/packages/base-ui/src/Components/Collapse/test/index.test.tsx b/packages/base-ui/src/Components/Collapse/test/index.test.tsx
new file mode 100644
index 0000000000..98e3b7fe84
--- /dev/null
+++ b/packages/base-ui/src/Components/Collapse/test/index.test.tsx
@@ -0,0 +1,12 @@
+// test Collapse
+
+import { render } from '@testing-library/react';
+
+import { Collapse } from '../Collapse';
+
+describe('Collapse', () => {
+ test('renders correctly', () => {
+ const { container } = render(<Collapse header="Collapse Header">Collapse Content</Collapse>);
+ expect(container);
+ });
+});
diff --git a/packages/base-ui/src/Components/ColorPicker/ColorPicker.stories.tsx b/packages/base-ui/src/Components/ColorPicker/ColorPicker.stories.tsx
index 1422077f1f..a7d1e005f2 100644
--- a/packages/base-ui/src/Components/ColorPicker/ColorPicker.stories.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/ColorPicker.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { ColorPicker } from './ColorPicker';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/ColorPicker',
+const meta: Meta<typeof ColorPicker> = {
+ title: 'Components / ColorPicker',
component: ColorPicker,
parameters: {
layout: 'centered',
@@ -11,7 +12,8 @@ export default {
args: {},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
index 8120d5bc0d..cbcca44129 100644
--- a/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
+++ b/packages/base-ui/src/Components/ColorPicker/ColorPicker.tsx
@@ -309,8 +309,8 @@ export function ColorPicker(props: BaseColorPickerProps) {
return { left, top };
};
- const onSwitch = (e: Event) => {
- e.stopImmediatePropagation();
+ const onSwitch = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
+ (e as unknown as MouseEvent).stopImmediatePropagation();
new Promise((resolve, reject) => {
setSetting(!setting);
@@ -381,7 +381,7 @@ export function ColorPicker(props: BaseColorPickerProps) {
<CustomLabel label="colorPicker.cancelColor" />
</Button>
<Button
- onClick={(e: MouseEvent) => {
+ onClick={(e) => {
e.stopPropagation();
setRgb(!rgb);
}}
diff --git a/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.stories.tsx b/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.stories.tsx
index 6e4325c7d0..dc88aa7b70 100644
--- a/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.stories.tsx
+++ b/packages/base-ui/src/Components/ColorPickerCircleButton/ColorPickerCircleButton.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { ColorPickerCircleButton } from './ColorPickerCircleButton';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/ColorPickerCircleButton',
+const meta: Meta<typeof ColorPickerCircleButton> = {
+ title: 'Components / ColorPickerCircleButton',
component: ColorPickerCircleButton,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Confirm/Confirm.stories.tsx b/packages/base-ui/src/Components/Confirm/Confirm.stories.tsx
index 99f26a7b66..234bb8b5e5 100644
--- a/packages/base-ui/src/Components/Confirm/Confirm.stories.tsx
+++ b/packages/base-ui/src/Components/Confirm/Confirm.stories.tsx
@@ -1,19 +1,21 @@
+import type { Meta } from '@storybook/react';
+
import { Confirm } from './Confirm';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Confirm',
+const meta: Meta<typeof Confirm> = {
+ title: 'Components / Confirm',
component: Confirm,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- color: '#abcdef',
+ content: '#abcdef',
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Container/Container.stories.tsx b/packages/base-ui/src/Components/Container/Container.stories.tsx
index 868207d928..dba3800f86 100644
--- a/packages/base-ui/src/Components/Container/Container.stories.tsx
+++ b/packages/base-ui/src/Components/Container/Container.stories.tsx
@@ -1,19 +1,21 @@
+import type { Meta } from '@storybook/react';
+
import { Container } from './Container';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Container',
+const meta: Meta<typeof Container> = {
+ title: 'Components / Container',
component: Container,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: 'test container',
+ children: 'main container',
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Container/Container.tsx b/packages/base-ui/src/Components/Container/Container.tsx
index f0effab1d4..f5811af5db 100644
--- a/packages/base-ui/src/Components/Container/Container.tsx
+++ b/packages/base-ui/src/Components/Container/Container.tsx
@@ -4,17 +4,28 @@ import { BaseComponentProps } from '../../BaseComponent';
interface BaseContainerProps extends BaseComponentProps {
children?: React.ReactNode;
- style?: {};
+
+ /** Semantic DOM class */
className?: string;
+
+ /** Semantic DOM style */
+ style?: React.CSSProperties;
+
+ /** Set the handler to handle `click` event */
onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
+
+ /** Set the handler to handle `onContextMenu` event */
onContextMenu?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
}
+/**
+ * Container Component
+ */
export const Container = forwardRef((props: BaseContainerProps, ref: Ref<HTMLDivElement>) => {
- const { children, style = {}, className = '', onClick, onContextMenu } = props;
+ const { children, className, style, onClick, onContextMenu } = props;
return (
- <div onContextMenu={onContextMenu} ref={ref} style={style} className={className} onClick={onClick}>
+ <div ref={ref} style={style} className={className} onClick={onClick} onContextMenu={onContextMenu}>
{children}
</div>
);
diff --git a/packages/base-ui/src/Components/Container/container-zh.md b/packages/base-ui/src/Components/Container/container-zh.md
deleted file mode 100644
index f104efa10b..0000000000
--- a/packages/base-ui/src/Components/Container/container-zh.md
+++ /dev/null
@@ -1,42 +0,0 @@
----
-category: Components
-type: 通用
-title: Container
-subtitle: 容器
-cover: ''
----
-
-## 介绍
-
-通用容器组件,一个容器内可以包含任何其他组件
-
-## API
-
-容器的属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-| --------- | --------------------- | --------------------------- | ------ |
-| onClick | 点击按钮时的回调 | `(e: MouseEvent) => void` | - |
-| children | 按钮内容或者子节点 | `ComponentChildren` | - |
-| className | 类名 | `string` | - |
-| styles | 自定义 css 央样式对象 | `JSX.CSSProperties` | - |
-| ref | preact refs 引用 | `RefObject<HTMLDivElement>` | - |
-
-## 案例
-
-```jsx
-import { Container } from '@univerjs/style-univer';
-
-const Toolbar = () => {
- const containerText = 'container';
- return (
- <Container
- onClick={() => {
- this.handleClick();
- }}
- >
- {containerText}
- </Container>
- );
-};
-```
diff --git a/packages/base-ui/src/Components/Container/container.md b/packages/base-ui/src/Components/Container/container.md
deleted file mode 100644
index 71682e763e..0000000000
--- a/packages/base-ui/src/Components/Container/container.md
+++ /dev/null
@@ -1,41 +0,0 @@
----
-category: Components
-type: General
-title: Container
-cover: 'Container'
----
-
-## Introduction
-
-General container components, a container can contain any other components
-
-## API
-
-The properties of the device are described as follows:
-
-| Property | Description | Type | Default Value |
-| --------- | ----------------------------------- | --------------------------- | ------------- |
-| onClick | Callback when the button is clicked | `(e: MouseEvent) => void` | - |
-| children | Button content or child nodes | `ComponentChildren` | - |
-| className | Class name | `string` | - |
-| styles | Custom css central style object | `JSX.CSSProperties` | - |
-| ref | preact refs reference | `RefObject<HTMLDivElement>` | - |
-
-## Case
-
-```jsx
-import { Container } from '@univerjs/style-univer';
-
-const Toolbar = () => {
- const containerText = 'container';
- return (
- <Container
- onClick={() => {
- this.handleClick();
- }}
- >
- {containerText}
- </Container>
- );
-};
-```
diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.stories.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.stories.tsx
index b9799da1bc..34632c6802 100644
--- a/packages/base-ui/src/Components/CustomLabel/CustomLabel.stories.tsx
+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { CustomLabel } from './CustomLabel';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/CustomLabel',
+const meta: Meta<typeof CustomLabel> = {
+ title: 'Components / CustomLabel',
component: CustomLabel,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
index be24a81226..b9abc765dd 100644
--- a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx
@@ -2,7 +2,7 @@ import { isValidElement, JSX, useContext } from 'react';
import { AppContext, AppContextValues, ICustomComponent } from '../../Common';
import { IMenuSelectorItem } from '../../services/menu/menu';
-import { Input } from '../Input/input';
+import { Input } from '../Input';
import { Item } from '../Item/Item';
import { DisplayTypes } from '../Select';
import styles from './CustomLabel.module.less';
diff --git a/packages/base-ui/src/Components/Drag/Drag.stories.tsx b/packages/base-ui/src/Components/Drag/Drag.stories.tsx
index f8196785ab..6acee9f955 100644
--- a/packages/base-ui/src/Components/Drag/Drag.stories.tsx
+++ b/packages/base-ui/src/Components/Drag/Drag.stories.tsx
@@ -1,20 +1,54 @@
-import { Drag } from './Drag';
+// import type { Meta } from '@storybook/react';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Drag',
+// import { Drag } from './Drag';
+
+// const meta: Meta<typeof Drag> = {
+// title: 'Components / Drag',
+// component: Drag,
+// parameters: {
+// layout: 'centered',
+// },
+// tags: ['autodocs'],
+// args: {
+// children: <div>test drag</div>,
+// },
+// };
+
+// export default meta;
+
+// export const Playground = {
+// args: {},
+// };
+
+// Drag.stories.js
+import { Meta, StoryFn } from '@storybook/react';
+
+import { Container } from '../Container/Container'; // Introduction to components for parent containers
+import { BaseDragProps, Drag } from './Drag';
+
+const meta: Meta<typeof Drag> = {
+ title: 'Components / Drag',
component: Drag,
parameters: {
- layout: 'centered',
+ layout: 'left',
},
tags: ['autodocs'],
- args: {
- isDrag: true,
- children: <div>test drag</div>,
- },
+ decorators: [
+ (Story) => (
+ <Container style={{ height: '300px' }}>
+ <Story />
+ </Container>
+ ),
+ ],
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
-export const Playground = {
- args: {},
+export default meta;
+// 创建一个模板
+const Template: StoryFn<BaseDragProps> = (args) => <Drag {...args} />;
+
+// 添加一些默认属性
+export const Default: StoryFn<BaseDragProps> = Template.bind({});
+Default.args = {
+ // 在这里设置您的组件的默认属性
+ children: <div>test drag</div>,
};
diff --git a/packages/base-ui/src/Components/Drag/Drag.tsx b/packages/base-ui/src/Components/Drag/Drag.tsx
index 1b518149af..86c243ade8 100644
--- a/packages/base-ui/src/Components/Drag/Drag.tsx
+++ b/packages/base-ui/src/Components/Drag/Drag.tsx
@@ -1,142 +1,28 @@
-// interface IState {}
-// export interface BaseDragProps {
-// isDrag: boolean;
-// className: string;
-// children: React.ReactNode;
-// }
-// export class Drag extends Component<BaseDragProps, IState> {
-// root = createRef();
-// initDragDialog() {
-// // Drag and drop function (mainly to trigger three events: onpointerdown\onpointermove\onpointerup)
-// const drag = this.root.current;
-// // move to center
-// const { top, left } = this.getPosition();
-// drag.style.top = `${top}px`;
-// drag.style.left = `${left}px`;
-// const divMask = drag.querySelector(`.${styles.dragMask}`);
-// const dragBarTop = drag.querySelector(`.${styles.dragBarTop}`);
-// const dragBarBottom = drag.querySelector(`.${styles.dragBarBottom}`);
-// const dragBarLeft = drag.querySelector(`.${styles.dragBarLeft}`);
-// const dragBarRight = drag.querySelector(`.${styles.dragBarRight}`);
-// dragBarTop.addEventListener('pointerdown', pointerDownListener);
-// dragBarBottom.addEventListener('pointerdown', pointerDownListener);
-// dragBarLeft.addEventListener('pointerdown', pointerDownListener);
-// dragBarRight.addEventListener('pointerdown', pointerDownListener);
-// // When you click on an object, you can use the drag object. Move and up are the global area, that is, the entire document is common. The document object should be used instead of the drag object (otherwise, when the drag object is used, the object can only move to the right or down )
-// function pointerDownListener(e: PointerEvent) {
-// e = e || window.event; // Compatible with IE browser
-// const diffX = e.clientX - drag.offsetLeft; // The distance from the moment the mouse clicks on the object relative to the left border of the object = the distance of the position when clicked relative to the leftmost left of the browser - the distance of the left border of the object relative to the leftmost left of the browser
-// const diffY = e.clientY - drag.offsetTop;
-// /* Low version IE bug: When an object is dragged out of the browser’s visual window, a scroll bar will appear,
-// The solution is to use two unique methods setCapture()\releaseCapture() in IE browser, these two methods,
-// You can let the mouse slide outside the browser to capture the event, and our bug is when the mouse moves out of the browser,
-// The function that the limit is exceeded becomes invalid. In this way, this problem can be solved. Note: These two methods are used in onpointerdown and onpointerup */
-// if (typeof drag.setCapture !== 'undefined') {
-// drag.setCapture();
-// }
-// // Cover the pop-up window
-// divMask.style.width = '100%';
-// divMask.style.height = '100%';
-// // Prevent the selected event from being triggered when the dragging speed is too fast
-// document.body.style.userSelect = 'none';
-// document.addEventListener('pointermove', pointerMoveListener);
-// document.addEventListener('pointerup', pointerUpListener);
-// function pointerMoveListener(e: PointerEvent) {
-// e = e || window.event; // Compatible with IE browser
-// let left = e.clientX - diffX;
-// let top = e.clientY - diffY;
-// // Control the range of dragged objects can only be in the browser window, and scroll bars are not allowed
-// // if (left <0) {
-// // left = 0
-// // } else if (left> window.innerWidth-drag.offsetWidth) {
-// // left = window.innerWidth-drag.offsetWidth
-// // }
-// // if (top <0) {
-// // top = 0
-// // } else if (top> window.innerHeight-drag.offsetHeight) {
-// // top = window.innerHeight-drag.offsetHeight
-// // }
-// if (left < -drag.offsetWidth + 100) {
-// left = -drag.offsetWidth + 100;
-// } else if (left > window.innerWidth - 100) {
-// left = window.innerWidth - 100;
-// }
-// if (top < -drag.offsetHeight + 100) {
-// top = -drag.offsetHeight + 100;
-// } else if (top > window.innerHeight - 100) {
-// top = window.innerHeight - 100;
-// }
-// // Regain the distance of the object when moving, and solve the phenomenon of shaking when dragging
-// drag.style.left = `${left}px`;
-// drag.style.top = `${top}px`;
-// drag.style.transform = '';
-// }
-// function pointerUpListener(e: PointerEvent) {
-// document.removeEventListener('pointermove', pointerMoveListener);
-// document.removeEventListener('pointerup', pointerUpListener);
-// // Prevent the mouse from looping after it pops up (that is, prevent the mouse from moving when it is put on)
-// // Fix low version ie bug
-// if (typeof drag.releaseCapture !== 'undefined') {
-// drag.releaseCapture();
-// }
-// // Restore the hidden mask layer
-// divMask.style.width = '0';
-// divMask.style.height = '0';
-// document.body.style.userSelect = '';
-// }
-// }
-// }
-// getPosition() {
-// const w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
-// const h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
-// const rootW = this.root.current.offsetWidth;
-// const rootH = this.root.current.offsetHeight;
-// const top = (h - rootH) / 2;
-// const left = (w - rootW) / 2;
-// return {
-// top,
-// left,
-// };
-// }
-// componentDidMount() {
-// if (this.props.isDrag) {
-// this.initDragDialog();
-// }
-// }
-// render() {
-// const { isDrag, className = '' } = this.props;
-// return (
-// <>
-// {isDrag ? (
-// <div className={styles.dragContainer}>
-// <div ref={this.root} className={`${styles.dragDialog} ${className}`}>
-// {this.props.children}
-// <div className={styles.dragBarLeft}></div>
-// <div className={styles.dragBarRight}></div>
-// <div className={styles.dragBarTop}></div>
-// <div className={styles.dragBarBottom}></div>
-// <div className={styles.dragMask}></div>
-// </div>
-// </div>
-// ) : (
-// this.props.children
-// )}
-// </>
-// );
-// }
-// }
import { IKeyValue } from '@univerjs/core';
import React, { useEffect, useRef } from 'react';
import styles from './index.module.less';
-interface BaseDragProps {
- isDrag: boolean;
- className: string;
+export interface BaseDragProps {
children: React.ReactNode;
+
+ /**
+ * Semantic DOM class
+ * @default ''
+ * */
+ className?: string;
+
+ /**
+ * Whether to enable drag
+ * @default true
+ */
+ isDrag?: boolean;
}
-export function Drag({ isDrag, className = '', children }: BaseDragProps) {
+/**
+ * Drag Component
+ */
+export function Drag({ isDrag = true, className = '', children }: BaseDragProps) {
const rootRef = useRef<HTMLDivElement | null>(null);
const getPosition = () => {
@@ -169,6 +55,7 @@ export function Drag({ isDrag, className = '', children }: BaseDragProps) {
e = e || window.event;
const diffX = e.clientX - drag.offsetLeft;
const diffY = e.clientY - drag.offsetTop;
+ console.info('diffX', e, drag.offsetLeft, diffX);
if (typeof (drag as IKeyValue).setCapture !== 'undefined') {
(drag as IKeyValue).setCapture();
@@ -232,8 +119,8 @@ export function Drag({ isDrag, className = '', children }: BaseDragProps) {
return (
<>
{isDrag ? (
- <div className={styles.dragContainer}>
- <div ref={rootRef} className={`${styles.dragDialog} ${className}`}>
+ <div className={styles.dragContainer} ref={rootRef}>
+ <div className={`${styles.dragDialog} ${className}`}>
{children}
<div className={styles.dragBarLeft}></div>
diff --git a/packages/base-ui/src/Components/Drag/drag-zh.md b/packages/base-ui/src/Components/Drag/drag-zh.md
deleted file mode 100644
index 8cb4836b80..0000000000
--- a/packages/base-ui/src/Components/Drag/drag-zh.md
+++ /dev/null
@@ -1,35 +0,0 @@
----
-category: Components
-type: 通用
-title: drag
-subtitle: 拖拽
-cover: ''
----
-
-## 介绍
-
-拖拽
-
-## API
-
-属性说明如下:
-
-```jsx
-interface IProps {
- isDrag: boolean;
-}
-```
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| isDrag | 是否拖拽 | boolean | - |
-
-## 案例
-
-```jsx
-import { Drag } from '@univerjs/style-univer';
-
-<Drag isDrag={true}>
- <div>container</div>
-</Drag>;
-```
diff --git a/packages/base-ui/src/Components/Drag/index.module.less b/packages/base-ui/src/Components/Drag/index.module.less
index d8e1c9f62a..c6ad4f50bb 100644
--- a/packages/base-ui/src/Components/Drag/index.module.less
+++ b/packages/base-ui/src/Components/Drag/index.module.less
@@ -52,9 +52,10 @@
left: 0;
z-index: 4;
}
-.drag-dialog{
- position:absolute;
-}
+
+// .drag-dialog{
+// position:absolute;
+// }
.drag-bar-left{
background:transparent;
diff --git a/packages/base-ui/src/Components/Drag/test/Drag.test.tsx b/packages/base-ui/src/Components/Drag/test/Drag.test.tsx
new file mode 100644
index 0000000000..a7268e00b1
--- /dev/null
+++ b/packages/base-ui/src/Components/Drag/test/Drag.test.tsx
@@ -0,0 +1,11 @@
+import { render } from '@testing-library/react';
+
+import { Drag } from '../Drag';
+
+describe('Drag', () => {
+ test('should display initial Drag', () => {
+ const { container } = render(<Drag>drag content text</Drag>);
+
+ expect(container.textContent).toMatch('drag content text');
+ });
+});
diff --git a/packages/base-ui/src/Components/Dropdown/Dropdown.stories.tsx b/packages/base-ui/src/Components/Dropdown/Dropdown.stories.tsx
index e407d3a386..f7caa5f207 100644
--- a/packages/base-ui/src/Components/Dropdown/Dropdown.stories.tsx
+++ b/packages/base-ui/src/Components/Dropdown/Dropdown.stories.tsx
@@ -1,9 +1,10 @@
-import { Input } from '../Input/input';
+import type { Meta } from '@storybook/react';
+
+import { Input } from '../Input';
import { Dropdown } from './Dropdown';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Dropdown',
+const meta: Meta<typeof Dropdown> = {
+ title: 'Components / Dropdown',
component: Dropdown,
parameters: {
layout: 'centered',
@@ -28,7 +29,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Icon/Icon.stories.tsx b/packages/base-ui/src/Components/Icon/Icon.stories.tsx
index 176c423744..9ac10923d0 100644
--- a/packages/base-ui/src/Components/Icon/Icon.stories.tsx
+++ b/packages/base-ui/src/Components/Icon/Icon.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Icon } from './AddIcon';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Icon',
+const meta: Meta<typeof Icon> = {
+ title: 'Components / Icon',
component: Icon,
parameters: {
layout: 'centered',
@@ -22,7 +23,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Input/Input.stories.tsx b/packages/base-ui/src/Components/Input/Input.stories.tsx
index f22c079ccf..7d8488c73e 100644
--- a/packages/base-ui/src/Components/Input/Input.stories.tsx
+++ b/packages/base-ui/src/Components/Input/Input.stories.tsx
@@ -1,8 +1,9 @@
-import { Input } from './input';
+import type { Meta } from '@storybook/react';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Input',
+import { Input } from './Input';
+
+const meta: Meta<typeof Input> = {
+ title: 'Components / Input',
component: Input,
parameters: {
layout: 'centered',
@@ -11,10 +12,12 @@ export default {
args: {
placeholder: 'Your Content',
bordered: true,
+ type: 'text',
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Input/input.tsx b/packages/base-ui/src/Components/Input/Input.tsx
similarity index 73%
rename from packages/base-ui/src/Components/Input/input.tsx
rename to packages/base-ui/src/Components/Input/Input.tsx
index 9106291c5f..06db08f7dd 100644
--- a/packages/base-ui/src/Components/Input/input.tsx
+++ b/packages/base-ui/src/Components/Input/Input.tsx
@@ -1,29 +1,92 @@
-import React, { RefObject, useEffect, useMemo, useRef, useState } from 'react';
+import React, { useEffect, useMemo, useRef, useState } from 'react';
import { BaseComponentProps } from '../../BaseComponent';
import { joinClassNames } from '../../Utils/util';
import styles from './Style/index.module.less';
+// Component Interface
export interface BaseInputProps extends BaseComponentProps {
+ /**
+ * The type of input
+ * @default 'text'
+ */
type?: 'text' | 'button' | 'checkbox' | 'file' | 'hidden' | 'image' | 'password' | 'radio' | 'reset' | 'submit' | 'number';
+
+ /**
+ * The input content value
+ */
value?: string;
+
+ /**
+ * The input content placeholder
+ */
placeholder?: string;
+
+ /**
+ *
+ * Callback when user input
+ */
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
+
+ /**
+ * The callback function that is triggered when Enter key is pressed
+ */
onPressEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
+
+ /**
+ * Whether has border style
+ * @default true
+ */
bordered?: boolean;
+
+ /**
+ * Whether the input is disabled
+ * @default false
+ */
disabled?: boolean;
- // maxLength?: number;
- // onPressEnter?: KeyboardEvent;
+
+ /**
+ * The maximum number of characters in Input
+ */
+ maxLength?: number;
+
+ /**
+ * Whether the input is focused
+ */
onFocus?: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
+
+ /**
+ * Whether the input is blur
+ */
onBlur?: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
+
+ /**
+ * Whether the input is clicked
+ */
onClick?: (e: React.MouseEvent<HTMLInputElement, MouseEvent>) => void;
+
onValueChange?: (value: string) => void;
+
+ /**
+ * Input's class name
+ */
className?: string;
+
+ /**
+ * Whether the input is read only
+ * @default false
+ */
readonly?: boolean;
+
+ /**
+ * Input's id
+ */
id?: string;
- ref?: RefObject<HTMLInputElement>;
}
+/**
+ * Input Component
+ */
export function Input(props: BaseInputProps) {
const ref = useRef<HTMLInputElement>(null);
const [value, setValue] = useState(props.value);
@@ -79,7 +142,7 @@ export function Input(props: BaseInputProps) {
const getValue = () => ref.current?.value;
- const { id, disabled, type, placeholder, bordered = true, className = '', readonly } = props;
+ const { id, disabled, type = 'text', placeholder, bordered = true, className = '', readonly, maxLength } = props;
const classes = joinClassNames(
styles.input,
@@ -96,6 +159,7 @@ export function Input(props: BaseInputProps) {
onBlur={onBlur}
onFocus={onFocus}
className={classes}
+ maxLength={maxLength}
placeholder={placeholder}
disabled={disabled}
ref={ref}
diff --git a/packages/base-ui/src/Components/Input/index.ts b/packages/base-ui/src/Components/Input/index.ts
index e3365cb906..ba9fe7ebc6 100644
--- a/packages/base-ui/src/Components/Input/index.ts
+++ b/packages/base-ui/src/Components/Input/index.ts
@@ -1 +1 @@
-export * from './input';
+export * from './Input';
diff --git a/packages/base-ui/src/Components/Input/input-zh.md b/packages/base-ui/src/Components/Input/input-zh.md
deleted file mode 100644
index 295144735f..0000000000
--- a/packages/base-ui/src/Components/Input/input-zh.md
+++ /dev/null
@@ -1,38 +0,0 @@
----
-category: Components
-type: 通用
-title: Input
-subtitle: 输入框
-cover: ''
----
-
-## 介绍
-
-输入框组件
-
-## API
-
-属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| disabled | 输入框失效状态 | boolean | false |
-| onChange | 输入框值改变时的回调 | (event) => void | - |
-| onFocus | 输入框聚焦时的回调 | (event) => void | - |
-| onBlur | 输入框值失焦时的回调 | (event) => void | - |
-| onClick | 输入框值点击时的回调 | (event) => void | - |
-| className | 输入框类名 | string | - |
-| id | 输入框 id | string | - |
-| value | 输入框 value | string | - |
-| type | 输入框类型 | 'text' | 'button' | 'checkbox' | 'file' | 'hidden' | 'image' | 'password' | 'radio' | 'reset' | 'submit' | - |
-| placeholder | 占位符 | string | - |
-| border | 输入框边框 | boolean | true |
-| readonly | 输入框是否只读 | boolean | false |
-
-## 案例
-
-```jsx
-import { Input } from '@univerjs/style-univer';
-
-<Input onChange={() => {}} type="text" placeholder="哈哈" value="1"></Input>;
-```
diff --git a/packages/base-ui/src/Components/Input/input.md b/packages/base-ui/src/Components/Input/input.md
deleted file mode 100644
index 92982f1bfc..0000000000
--- a/packages/base-ui/src/Components/Input/input.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-category: Components
-type: General
-title: Input
-cover: ''
----
-
-## Introduce
-
-Input Component
-
-## API
-
-Property Introduction:
-
-| Property | Description | Type | Default |
-
-| disabled | Disabled state of input | boolean | false |
-| onChange | Set the handler to handle `change` event | (event) => void | - |
-| onFocus | Set the handler to handle `focue` event | (event) => void | - |
-| onBlur | Set the handler to handle `blur` event | (event) => void | - |
-| onClick | Set the handler to handle `click` event | (event) => void | - |
-| className | input className | string | - |
-| id | input id | string | - |
-| value | input value | string | - |
-| type | type of input | 'text' | 'button' | 'checkbox' | 'file' | 'hidden' | 'image' | 'password' | 'radio' | 'reset' | 'submit' | - |
-| placeholder | placeholder | string | - |
-| border | set border of input | boolean | true |
-| readonly | input is readonly | boolean | false |
-
-## Case
-
-```jsx
-import { Input } from '@univerjs/style-univer';
-
-<Input onChange={() => {}} type="text" placeholder="good" value="1"></Input>;
-```
diff --git a/packages/base-ui/src/Components/InputNumber/InputNumber.stories.tsx b/packages/base-ui/src/Components/InputNumber/InputNumber.stories.tsx
new file mode 100644
index 0000000000..eb0247f3d7
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/InputNumber.stories.tsx
@@ -0,0 +1,23 @@
+import type { Meta } from '@storybook/react';
+
+import { InputNumber } from './InputNumber';
+
+const meta: Meta<typeof InputNumber> = {
+ title: 'Components / InputNumber',
+ component: InputNumber,
+ parameters: {
+ layout: 'centered',
+ },
+ tags: ['autodocs'],
+ args: {
+ value: 1,
+ min: 0,
+ max: 10,
+ },
+};
+
+export default meta;
+
+export const Playground = {
+ args: {},
+};
diff --git a/packages/base-ui/src/Components/InputNumber/InputNumber.tsx b/packages/base-ui/src/Components/InputNumber/InputNumber.tsx
new file mode 100644
index 0000000000..3a5a6090b7
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/InputNumber.tsx
@@ -0,0 +1,158 @@
+import React, { useRef, useState } from 'react';
+
+import { BaseComponentProps } from '../../BaseComponent';
+import { joinClassNames } from '../../Utils/util';
+import styles from './Style/index.module.less';
+
+export interface BaseInputNumberProps extends BaseComponentProps {
+ /**
+ * The input content value
+ */
+ value?: number;
+
+ /**
+ * minimum value
+ */
+ min?: number;
+
+ /**
+ * maximum number
+ */
+ max?: number;
+
+ /**
+ * Whether the input is read only
+ * @default false
+ */
+ readonly?: boolean;
+
+ /**
+ * Whether the input is disabled
+ * @default false
+ */
+ disabled?: boolean;
+
+ /**
+ * Whether has border style
+ * @default true
+ */
+ bordered?: boolean;
+
+ /**
+ * Callback when user input
+ */
+ onChange?: (value: number) => void;
+
+ /**
+ * The callback function that is triggered when Enter key is pressed
+ */
+ onPressEnter?: (value: number) => void;
+
+ /**
+ * Whether the input is blur
+ */
+ onBlur?: (value: number) => void;
+}
+
+/**
+ * Input Number Component
+ */
+export const InputNumber: React.FC<BaseInputNumberProps> = ({
+ value = 0,
+ onChange,
+ min = -Infinity,
+ max = Infinity,
+ onPressEnter,
+ onBlur,
+ readonly = false,
+ disabled = false,
+ bordered = true,
+}) => {
+ const [inputValue, setInputValue] = useState(value);
+ const ref = useRef<HTMLInputElement>(null);
+
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ let newValue = parseFloat(e.target.value);
+ if (isNaN(newValue)) {
+ newValue = 0;
+ }
+ if (newValue < min) {
+ newValue = min;
+ } else if (newValue > max) {
+ newValue = max;
+ }
+ setInputValue(newValue);
+ if (onChange) {
+ onChange(newValue);
+ }
+ };
+
+ const handleIncrement = () => {
+ if (readonly) return;
+
+ const newValue = inputValue + 1;
+ if (newValue <= max) {
+ setInputValue(newValue);
+ if (onChange) {
+ onChange(newValue);
+ }
+ }
+ };
+
+ const handleDecrement = () => {
+ if (readonly) return;
+
+ const newValue = inputValue - 1;
+ if (newValue >= min) {
+ setInputValue(newValue);
+ if (onChange) {
+ onChange(newValue);
+ }
+ }
+ };
+
+ const handlePressEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === 'Enter' && onPressEnter) {
+ onPressEnter(inputValue);
+ ref.current?.blur();
+ }
+ };
+
+ const handleBlur = (e: React.FocusEvent<HTMLInputElement, Element>) => {
+ if (onBlur) {
+ onBlur(inputValue);
+ }
+ };
+
+ const classes = joinClassNames(styles.input, {
+ [`${styles.input}-disable`]: disabled,
+ [`${styles.input}-borderless`]: !bordered,
+ });
+
+ return (
+ <div className={styles.inputNumber}>
+ <div className={styles.inputWrap}>
+ <input
+ ref={ref}
+ type="text"
+ value={inputValue}
+ disabled={disabled}
+ onChange={handleInputChange}
+ className={classes}
+ onKeyUp={handlePressEnter}
+ onBlur={handleBlur}
+ readOnly={readonly}
+ />
+ </div>
+
+ <div className={styles.inputButtons} style={{ display: disabled ? 'none' : 'flex' }}>
+ <button onClick={handleIncrement} className={styles.inputButton}>
+ <span>+</span>
+ </button>
+ <button onClick={handleDecrement} className={styles.inputButton}>
+ <span>-</span>
+ </button>
+ </div>
+ </div>
+ );
+};
diff --git a/packages/base-ui/src/Components/InputNumber/Style/index.module.less b/packages/base-ui/src/Components/InputNumber/Style/index.module.less
new file mode 100644
index 0000000000..2e912cbdd4
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/Style/index.module.less
@@ -0,0 +1,61 @@
+@import '../../../Basics/CSS/Skin/base.module.less';
+@import './mixin.less';
+
+.input {
+ .input();
+}
+
+
+.input-number {
+ position: relative;
+ display: flex;
+ align-items: center;
+ width: 150px;
+ height: 30px;
+
+ &:hover {
+ .input-buttons {
+ opacity: 1;
+ }
+ }
+}
+
+
+.input-wrap {
+ position: absolute;
+ right: 0;
+}
+
+.input-buttons {
+ position: absolute;
+ right: 1px;
+ display: flex;
+ opacity: 0;
+ flex-direction: column;
+ transition: opacity 0.1s linear;
+
+ .input-button {
+ background-color: var(--bg);
+ border-style: solid;
+ border-color: var(--border-color-base);
+ color: var(--text-color);
+ cursor: pointer;
+ height: 13px;
+
+ span {
+ display: block;
+ font-size: 7px;
+ text-align: center;
+ line-height: 0;
+ }
+
+ }
+
+ .input-button:first-child {
+ border-width: 0px 0px 1px 1px;
+ }
+
+ .input-button:last-child {
+ border-width: 0px 0px 0px 1px;
+ }
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/InputNumber/Style/mixin.less b/packages/base-ui/src/Components/InputNumber/Style/mixin.less
new file mode 100644
index 0000000000..f47f42a750
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/Style/mixin.less
@@ -0,0 +1,71 @@
+@import '../../../Basics/CSS/Skin/base.module.less';
+
+.active() {
+ border-right-width: @border-width-base !important;
+ outline: 0;
+ box-shadow: var(--box-shadow-base);
+}
+
+.hover(@color: var(--primary-color-hover)) {
+ border-color: @color;
+ border-right-width: @border-width-base !important;
+}
+
+.disabled() {
+ color: var(--disabled-color);
+ background-color: var(--disabled-bg);
+ border-color: var(--border-color-base);
+ box-shadow: none;
+ cursor: not-allowed;
+ opacity: 1;
+
+ &:hover {
+ .hover(var(--border-color-base));
+ }
+}
+
+.input() {
+ position: relative;
+ display: inline-block;
+ width: 100%;
+ min-width: 0;
+ box-sizing: border-box;
+ padding: 2px 7px;
+ color: var(--text-color);
+ font-size: @font-size-base;
+ line-height: @line-height-base;
+ background-color: var(--bg);
+ background-image: none;
+ border: @border-width-base @border-style-base var(--border-color-base);
+ border-radius: @border-radius-base;
+ transition: all 0.3s;
+
+ &:hover {
+ .hover();
+ }
+
+ &:focus,
+ &-focused {
+ .active();
+ }
+
+ &[disabled] {
+ .disabled();
+ }
+
+ &-disabled {
+ .disabled();
+ }
+
+ &-borderless {
+ border: none;
+ box-shadow: none;
+
+ &:focus,
+ &-focused {
+ border-width: 0;
+ outline: 0;
+ box-shadow: none;
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/InputNumber/index.ts b/packages/base-ui/src/Components/InputNumber/index.ts
new file mode 100644
index 0000000000..69c441376d
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/index.ts
@@ -0,0 +1 @@
+export * from './InputNumber';
diff --git a/packages/base-ui/src/Components/InputNumber/test/index.test.tsx b/packages/base-ui/src/Components/InputNumber/test/index.test.tsx
new file mode 100644
index 0000000000..5b7a4582f9
--- /dev/null
+++ b/packages/base-ui/src/Components/InputNumber/test/index.test.tsx
@@ -0,0 +1,68 @@
+import { fireEvent, render } from '@testing-library/react';
+
+import { InputNumber } from '../InputNumber';
+
+describe('input number', () => {
+ test('render', () => {
+ const { container } = render(<InputNumber value={0} />);
+ expect(container);
+ });
+ test('min max', () => {
+ const { container } = render(<InputNumber value={0} min={0} max={5} />);
+ const input = container.querySelector('input');
+ const buttonAddition = container?.querySelectorAll('button')[0];
+ const buttonSubtraction = container?.querySelectorAll('button')[1];
+
+ // buttonAddition clicked 10 times
+ for (let i = 0; i < 10; i++) {
+ fireEvent.click(buttonAddition!);
+ }
+
+ // Test the value of the input
+ expect(input!.value).toBe('5');
+
+ // buttonSubtraction click 10 times
+ for (let i = 0; i < 10; i++) {
+ fireEvent.click(buttonSubtraction!);
+ }
+
+ // Test the value of the input
+ expect(input!.value).toBe('0');
+ });
+
+ test('input/change event', () => {
+ const { container } = render(<InputNumber value={0} />);
+ const input = container.querySelector('input');
+ fireEvent.input(input!, { target: { value: 1 } });
+ expect(input!.value).toBe('1');
+ fireEvent.change(input!, { target: { value: 2 } });
+ expect(input!.value).toBe('2');
+ });
+
+ test('blur event', () => {
+ let a = 1;
+ const { container } = render(<InputNumber value={0} onBlur={() => a++} disabled />);
+ fireEvent.click(document.querySelector('input')!);
+ fireEvent.blur(document.querySelector('input')!);
+ expect(a).toEqual(2);
+ });
+ test('press enter event', () => {
+ let a = 0;
+ const { container } = render(
+ <InputNumber
+ value={1}
+ onPressEnter={(v) => {
+ a = v;
+ }}
+ />
+ );
+ const input = container.querySelector('input');
+ fireEvent.keyUp(input!, {
+ key: 'Enter',
+ code: 'Enter',
+ keyCode: 13,
+ charCode: 13,
+ });
+ expect(a).toEqual(1);
+ });
+});
diff --git a/packages/base-ui/src/Components/Item/Item.stories.tsx b/packages/base-ui/src/Components/Item/Item.stories.tsx
index 63084ebf54..e0d51401c7 100644
--- a/packages/base-ui/src/Components/Item/Item.stories.tsx
+++ b/packages/base-ui/src/Components/Item/Item.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Item } from './Item';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Item',
+const meta: Meta<typeof Item> = {
+ title: 'Components / Item',
component: Item,
parameters: {
layout: 'centered',
@@ -14,7 +15,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Layout/Layout.stories.tsx b/packages/base-ui/src/Components/Layout/Layout.stories.tsx
index a684f1ff64..a1620640b8 100644
--- a/packages/base-ui/src/Components/Layout/Layout.stories.tsx
+++ b/packages/base-ui/src/Components/Layout/Layout.stories.tsx
@@ -1,19 +1,38 @@
-import { Layout } from './Layout';
+import type { Meta } from '@storybook/react';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Layout',
+import { Content, Footer, Header, Layout, Sider } from './Layout';
+
+const meta: Meta<typeof Layout> = {
+ title: 'Components / Layout',
component: Layout,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: <div>test layout</div>,
+ children: <div>basic layout</div>,
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
+
+export const SiderLayout = {
+ title: 'Sider',
+ args: {
+ style: { width: '640px', height: '320px' },
+ children: (
+ <>
+ <Sider style={{ color: '#fff', background: '#001529' }}>aside</Sider>
+ <Content style={{ padding: '24px', background: '#f5f5f5', display: 'flex', flexDirection: 'column' }}>
+ <Header style={{ color: '#fff', background: '#001529' }}>header</Header>
+ <Content style={{ background: '#fff' }}>content</Content>
+ <Footer style={{ color: '#fff', background: '#001529' }}>footer</Footer>
+ </Content>
+ </>
+ ),
+ },
+};
diff --git a/packages/base-ui/src/Components/Layout/Layout.tsx b/packages/base-ui/src/Components/Layout/Layout.tsx
index 59df692655..afe252f791 100644
--- a/packages/base-ui/src/Components/Layout/Layout.tsx
+++ b/packages/base-ui/src/Components/Layout/Layout.tsx
@@ -1,30 +1,51 @@
-// Types for props
-// type BaseLayoutProps = {
-// children?: ComponentChildren;
-// className?: string;
-// style?: {};
-// };
-// Types for state
-import React, { forwardRef, Ref, useEffect, useRef, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { BaseComponentProps } from '../../BaseComponent';
-import { getFirstChildren } from '../../Utils';
+import { joinClassNames } from '../../Utils';
import styles from './index.module.less';
+function getFirstChild(obj: HTMLElement) {
+ const objChild = [];
+ const objs = obj.getElementsByTagName('*');
+
+ for (let i = 0, j = objs.length; i < j; ++i) {
+ if (objs[i].nodeType !== Node.ELEMENT_NODE) {
+ continue;
+ }
+ const node = objs[i].parentNode;
+ if (node && node.nodeType === 1) {
+ if (node === obj) {
+ objChild[objChild.length] = objs[i];
+ }
+ } else if (node && node.parentNode === obj) {
+ objChild[objChild.length] = objs[i];
+ }
+ }
+
+ return objChild;
+}
+
export interface BaseLayoutProps extends BaseComponentProps {
children?: React.ReactNode;
+
+ /** Semantic DOM class */
className?: string;
- style?: {};
+
+ /** Semantic DOM style */
+ style?: React.CSSProperties;
}
-export function Layout({ children, style, className = '' }: BaseLayoutProps) {
+/**
+ * Layout Component
+ */
+export function Layout({ children, style, className }: BaseLayoutProps) {
const [isAside, setIsAside] = useState(false);
const ref = useRef<HTMLTableSectionElement>(null);
// If the first child element contains the `aside` component, the layout needs to be changed to horizontal arrangement
useEffect(() => {
if (ref.current) {
- const children = getFirstChildren(ref.current);
+ const children = getFirstChild(ref.current);
const childrens = children instanceof Array ? children : [children];
for (const ele of childrens) {
@@ -36,15 +57,26 @@ export function Layout({ children, style, className = '' }: BaseLayoutProps) {
}
}, []);
+ const classes = joinClassNames(
+ styles.layoutWrapper,
+ {
+ [styles.layoutWrapperHasSider]: isAside,
+ },
+ className
+ );
+
return (
- <section style={style} ref={ref} className={isAside ? `${styles.layoutWrapper} ${styles.layoutWrapperHasSider} ${className}` : `${styles.layoutWrapper} ${className}`}>
+ <section style={style} ref={ref} className={classes}>
{children}
</section>
);
}
+/**
+ * Header Component
+ */
const Header = (props: BaseLayoutProps) => {
- const { children, style, className = '' } = props;
+ const { children, className, style } = props;
return (
<header style={style} className={`${styles.headerWrapper} ${className}`}>
@@ -52,33 +84,47 @@ const Header = (props: BaseLayoutProps) => {
</header>
);
};
+
+/**
+ * Footer Component
+ */
const Footer = (props: BaseLayoutProps) => {
- const { children, style, className = '' } = props;
+ const { children, className, style } = props;
+
+ const classes = joinClassNames(styles.footerWrapper, className);
return (
- <footer style={style} className={`${styles.footerWrapper} ${className}`}>
+ <footer className={classes} style={style}>
{children}
</footer>
);
};
/**
- * use forwardRef, get hold of a specific reference further down the tree
+ * Content Component
*/
-const Content = forwardRef((props: BaseLayoutProps, ref: Ref<HTMLElement>) => {
- const { children, style, className = '' } = props;
+const Content = (props: BaseLayoutProps) => {
+ const { children, className, style } = props;
+
+ const classes = joinClassNames(styles.contentWrapper, className);
return (
- <main ref={ref} style={style} className={`${styles.contentWrapper} ${className}`}>
+ <main className={classes} style={style}>
{children}
</main>
);
-});
+};
+
+/**
+ * Sider Component
+ */
const Sider = (props: BaseLayoutProps) => {
- const { children, style, className = '' } = props;
+ const { children, className, style } = props;
+
+ const classes = joinClassNames(styles.siderWrapper, className);
return (
- <aside style={style} className={`${styles.siderWrapper} ${className}`}>
+ <aside className={classes} style={style}>
{children}
</aside>
);
diff --git a/packages/base-ui/src/Components/Layout/index.module.less b/packages/base-ui/src/Components/Layout/index.module.less
index c948e67d15..df04db31cc 100644
--- a/packages/base-ui/src/Components/Layout/index.module.less
+++ b/packages/base-ui/src/Components/Layout/index.module.less
@@ -7,7 +7,6 @@
flex-direction: column;
overflow: hidden;
min-height: 0;
- // background: @gray-5;
&&-has-sider {
flex-direction: row;
@@ -16,26 +15,19 @@
.header-wrapper {
flex: 0 0 auto;
- // height: 10%;
- background: aquamarine;
user-select: none;
}
.footer-wrapper {
- // flex: 0 0 auto;
- // height: 10%;
- background: yellow;
+ flex: 0 0 auto;
}
.content-wrapper {
flex: auto;
- flex: 1;
- // background: dodgerblue;
+ min-height: 0;
}
.sider-wrapper {
flex-direction: row;
width: 200px;
- // width: 15%;
- // background: lightcoral;
}
diff --git a/packages/base-ui/src/Components/Menu/Menu.stories.tsx b/packages/base-ui/src/Components/Menu/Menu.stories.tsx
index 1e63ccea77..4560598e11 100644
--- a/packages/base-ui/src/Components/Menu/Menu.stories.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Menu } from './Menu';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Menu',
+const meta: Meta<typeof Menu> = {
+ title: 'Components / Menu',
component: Menu,
parameters: {
layout: 'centered',
@@ -24,7 +25,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Modal/Modal.stories.tsx b/packages/base-ui/src/Components/Modal/Modal.stories.tsx
index c441288ef4..1d47f2ef14 100644
--- a/packages/base-ui/src/Components/Modal/Modal.stories.tsx
+++ b/packages/base-ui/src/Components/Modal/Modal.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Modal } from './Modal';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Modal',
+const meta: Meta<typeof Modal> = {
+ title: 'Components / Modal',
component: Modal,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Radio/Radio-zh.md b/packages/base-ui/src/Components/Radio/Radio-zh.md
deleted file mode 100644
index dbcf3c8362..0000000000
--- a/packages/base-ui/src/Components/Radio/Radio-zh.md
+++ /dev/null
@@ -1,58 +0,0 @@
----
-category: Radio
-type: 通用
-title: Radio
-subtitle: 单选
-cover: ''
----
-
-## 介绍
-
-模态框
-
-## RadioGroup API
-
-`RadioGroup` 的属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-| --------- | -------------- | -------------------- | ------ |
-| active | 默认选中 | `string` \| `number` | - |
-| vertical | 是否垂直排列 | `boolean` | false |
-| className | 单选组类名 | `string` | - |
-| onChange | 切换选项时触发 | `function` | - |
-
-## 案例
-
-```jsx
-import { RadioGroup, Radio } from '@univerjs/style-univer';
-
-const Demo = () => {
- return (
- <RadioGroup>
- <Radio></Radio>
- <Radio></Radio>
- </RadioGroup>
- );
-};
-```
-
-## Radio API
-
-`Radio` 的属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-| --------- | -------- | -------------------- | ------ |
-| value | 当前的值 | `string` | - |
-| label | 显示的值 | `string` | - |
-| active | 是否选中 | `string` \| `number` | - |
-| className | 单选类名 | `string` | - |
-
-## 案例
-
-```jsx
-import { Radio } from '@univerjs/style-univer';
-
-const Demo = () => {
- return <Radio></Radio>;
-};
-```
diff --git a/packages/base-ui/src/Components/Radio/Radio.stories.tsx b/packages/base-ui/src/Components/Radio/Radio.stories.tsx
new file mode 100644
index 0000000000..36c8655a2e
--- /dev/null
+++ b/packages/base-ui/src/Components/Radio/Radio.stories.tsx
@@ -0,0 +1,21 @@
+import type { Meta } from '@storybook/react';
+
+import { Radio } from './Radio';
+
+const meta: Meta<typeof Radio> = {
+ title: 'Components / Radio',
+ component: Radio,
+ parameters: {
+ layout: 'centered',
+ },
+ tags: ['autodocs'],
+ args: {
+ value: 'value',
+ },
+};
+
+export default meta;
+
+export const Playground = {
+ args: {},
+};
diff --git a/packages/base-ui/src/Components/Radio/Radio.tsx b/packages/base-ui/src/Components/Radio/Radio.tsx
index 9022526510..708e4e9e76 100644
--- a/packages/base-ui/src/Components/Radio/Radio.tsx
+++ b/packages/base-ui/src/Components/Radio/Radio.tsx
@@ -3,30 +3,72 @@ import React from 'react';
import styles from './index.module.less';
export interface BaseRadioIProps {
+ children?: React.ReactNode[];
+
+ /** Semantic DOM style */
+ style?: React.CSSProperties;
+
+ /**
+ * Used for setting the currently selected value
+ */
value: string;
+
+ /**
+ * Specifies whether the radio is selected
+ * @default false
+ */
active?: boolean;
+
+ /**
+ * Set the handler to handle `click` event
+ */
onClick?: (value: string) => void;
+
+ /**
+ * The label content displayed
+ * @default ''
+ */
label?: string;
- children?: React.ReactNode[];
}
export interface BaseRadioGroupProps {
+ children: React.ReactNode[];
+
+ /**
+ * Semantic DOM class
+ * @default ''
+ */
className?: string;
- active?: string | number;
+
+ /**
+ * Define which radio is selected
+ */
+ active: string;
+
+ /**
+ * Whether to arrange vertically
+ * @default false
+ */
vertical?: boolean;
+
+ /**
+ * The callback function triggered when switching options
+ */
onChange: (value: string) => void;
- children: React.ReactNode[];
}
+/**
+ * RadioGroup Component
+ */
export function RadioGroup(props: BaseRadioGroupProps) {
- const { vertical, className = '', active, onChange } = props;
+ const { vertical = false, className = '', active, onChange } = props;
const handleActiveChange = (value: string) => {
onChange(value);
};
return (
- <div className={`${vertical ? styles.radioGroup : ''} ${className || ''}`}>
+ <div className={`${vertical ? styles.radioGroup : ''} ${className}`}>
{React.Children.map(props.children, (child, index) => {
if (React.isValidElement<BaseRadioIProps>(child)) {
const isActive = active === child.props.value;
@@ -37,6 +79,7 @@ export function RadioGroup(props: BaseRadioGroupProps) {
value: child.props.value,
active: isActive,
onClick: handleActiveChange,
+ style: child.props.style,
});
}
return child;
@@ -45,11 +88,14 @@ export function RadioGroup(props: BaseRadioGroupProps) {
);
}
-export function Radio({ value, active, onClick, label, children }: BaseRadioIProps) {
+/**
+ * Radio Component
+ */
+export function Radio({ value, active, onClick, label = 'Radio', children, style }: BaseRadioIProps) {
return (
- <div className={styles.radioWrap}>
- <div className={styles.radioLeft}>
- <div onClick={onClick && (() => onClick(value))}>
+ <div className={styles.radioWrap} style={style}>
+ <div>
+ <div className={styles.radioLeft} onClick={onClick && (() => onClick(value))}>
<div className={`${styles.circle} ${active && styles.active}`}>
<div className={styles.fork}></div>
</div>
diff --git a/packages/base-ui/src/Components/Radio/RadioGroup.stories.tsx b/packages/base-ui/src/Components/Radio/RadioGroup.stories.tsx
index a0d6a000c7..665c21ccec 100644
--- a/packages/base-ui/src/Components/Radio/RadioGroup.stories.tsx
+++ b/packages/base-ui/src/Components/Radio/RadioGroup.stories.tsx
@@ -1,19 +1,21 @@
+import type { Meta } from '@storybook/react';
+
import { Radio, RadioGroup } from './Radio';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/RadioGroup',
+const meta: Meta<typeof RadioGroup> = {
+ title: 'Components / RadioGroup',
component: RadioGroup,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: [<Radio value="test" label="test"></Radio>, <Radio value="test1" label="test1"></Radio>],
+ children: [<Radio value="test" label="test"></Radio>, <Radio value="test1" label="test1" style={{ marginLeft: '10px' }}></Radio>],
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Radio/index.module.less b/packages/base-ui/src/Components/Radio/index.module.less
index 59393cb8d6..a51eeda5a2 100644
--- a/packages/base-ui/src/Components/Radio/index.module.less
+++ b/packages/base-ui/src/Components/Radio/index.module.less
@@ -11,6 +11,7 @@
.radio-left {
display: inline-flex;
align-items: center;
+ justify-content: center;
.circle {
display: inline-block;
@@ -42,9 +43,9 @@
.label {
margin-left: 0.5em;
display: inline-block;
- height: 22px;
- line-height: 22px;
- font-size: 14px;
+ height: 16px;
+ line-height: 16px;
+ font-size: 16px;
}
}
}
diff --git a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.stories.tsx b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.stories.tsx
index 63f13501bb..8e5e7e64be 100644
--- a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.stories.tsx
+++ b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { ResizeDialog } from './ResizeDialog';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/ResizeDialog',
+const meta: Meta<typeof ResizeDialog> = {
+ title: 'Components / ResizeDialog',
component: ResizeDialog,
parameters: {
layout: 'centered',
@@ -18,7 +19,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
index 6ae3cc84dc..0160927b53 100644
--- a/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
+++ b/packages/base-ui/src/Components/ResizeDialog/ResizeDialog.tsx
@@ -3,15 +3,47 @@ import { useEffect, useRef } from 'react';
import { BaseComponentProps } from '../../BaseComponent';
import styles from './index.module.less';
+// Component Interface
export interface BaseResizeDialogProps extends BaseComponentProps {
- left: number;
- top: number;
- width: number;
- height: number;
+ /**
+ * Distance from the top left corner of the parent element.
+ * @default 0
+ */
+ left?: number;
+
+ /**
+ * Distance from the top left corner of the parent element.
+ * @default 0
+ */
+ top?: number;
+
+ /**
+ * Resize dialog's width
+ * @default 100
+ */
+ width?: number;
+
+ /**
+ * Resize dialog's height
+ * @default 50
+ */
+ height?: number;
+
+ /**
+ * Resize dialog's children
+ */
children: React.ReactNode;
- ratio: number;
+
+ /**
+ * Resize dialog's ratio
+ * @default 1
+ */
+ ratio?: number;
}
+/**
+ * Resize Dialog Component
+ */
export const ResizeDialog = (props: BaseResizeDialogProps) => {
let { left = 0, top = 0 } = props;
const { width = 100, height = 50, children, ratio = 1 } = props;
@@ -66,7 +98,7 @@ export const ResizeDialog = (props: BaseResizeDialogProps) => {
const handleClick = (e: MouseEvent) => {
e.stopPropagation();
cancelHighlight();
- highLight(e);
+ highLight(e as unknown as React.MouseEvent<HTMLDivElement, MouseEvent>);
};
const mouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
window.addEventListener('mousemove', mouseMove);
@@ -100,6 +132,7 @@ export const ResizeDialog = (props: BaseResizeDialogProps) => {
left = parseFloat(dialog.style.left) + currentMove[0] - pastMove[0];
left = left < 0 ? 0 : left;
+
if (left + ref.current.offsetWidth > parent.offsetWidth) {
left = parent.offsetWidth - ref.current.offsetWidth;
}
diff --git a/packages/base-ui/src/Components/ResizeDialog/test/index.test.tsx b/packages/base-ui/src/Components/ResizeDialog/test/index.test.tsx
new file mode 100644
index 0000000000..ae007064fa
--- /dev/null
+++ b/packages/base-ui/src/Components/ResizeDialog/test/index.test.tsx
@@ -0,0 +1,14 @@
+import { render } from '@testing-library/react';
+
+import { ResizeDialog } from '../ResizeDialog';
+
+describe('ResizeDialog', () => {
+ test('renders correctly', () => {
+ const { container } = render(
+ <ResizeDialog>
+ <div>test resize dialog</div>
+ </ResizeDialog>
+ );
+ expect(container);
+ });
+});
diff --git a/packages/base-ui/src/Components/Select/Select.stories.tsx b/packages/base-ui/src/Components/Select/Select.stories.tsx
index 58e233f807..966fdb445a 100644
--- a/packages/base-ui/src/Components/Select/Select.stories.tsx
+++ b/packages/base-ui/src/Components/Select/Select.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Select } from './Select';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Select',
+const meta: Meta<typeof Select> = {
+ title: 'Components / Select',
component: Select,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Separator/Separator.stories.tsx b/packages/base-ui/src/Components/Separator/Separator.stories.tsx
index 46b071fe78..6582254b30 100644
--- a/packages/base-ui/src/Components/Separator/Separator.stories.tsx
+++ b/packages/base-ui/src/Components/Separator/Separator.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Separator } from './Separator';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Separator',
+const meta: Meta<typeof Separator> = {
+ title: 'Components / Separator',
component: Separator,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/SiderModal/SiderModal.stories.tsx b/packages/base-ui/src/Components/SiderModal/SiderModal.stories.tsx
index a0cd913b6c..83a7b71792 100644
--- a/packages/base-ui/src/Components/SiderModal/SiderModal.stories.tsx
+++ b/packages/base-ui/src/Components/SiderModal/SiderModal.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { SiderModal } from './SiderModal';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/SiderModal',
+const meta: Meta<typeof SiderModal> = {
+ title: 'Components / SiderModal',
component: SiderModal,
parameters: {
layout: 'centered',
@@ -15,7 +16,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Slider/Slider.stories.tsx b/packages/base-ui/src/Components/Slider/Slider.stories.tsx
index d47d1ccec3..4446b31221 100644
--- a/packages/base-ui/src/Components/Slider/Slider.stories.tsx
+++ b/packages/base-ui/src/Components/Slider/Slider.stories.tsx
@@ -1,17 +1,24 @@
+import type { Meta } from '@storybook/react';
+
import { Slider } from './Slider';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Slider',
+const meta: Meta<typeof Slider> = {
+ title: 'Components / Slider',
component: Slider,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
- args: {},
+ args: {
+ min: 0,
+ max: 100,
+ step: 1,
+ range: false,
+ },
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Slider/Slider.tsx b/packages/base-ui/src/Components/Slider/Slider.tsx
index acfaa76c11..e179ecda85 100644
--- a/packages/base-ui/src/Components/Slider/Slider.tsx
+++ b/packages/base-ui/src/Components/Slider/Slider.tsx
@@ -1,155 +1,56 @@
-// export class Slider extends Component<BaseSliderRangeProps | BaseSliderSingleProps, SliderState> {
-// idPrev: string;
-// idNext: string;
-// width: number;
-// ref = createRef();
-// constructor(props: BaseSliderSingleProps | BaseSliderRangeProps) {
-// super();
-// this.initialize(props);
-// }
-// initialize(props: BaseSliderSingleProps | BaseSliderRangeProps) {
-// this.state = {
-// valuePrev: 0,
-// valueNext: 0,
-// };
-// }
-// onInput = (index: number, e: Event) => {
-// const target = e.target as HTMLInputElement;
-// const value = target.value;
-// this.changeInputValue(index, value);
-// this.props.onChange?.call(this, e);
-// };
-// /**
-// * 返回改变后的值
-// */
-// onClick = (index: number, e: MouseEvent) => {
-// const { min = 0, max = 100, step = 1 } = this.props;
-// const target = e.currentTarget as HTMLElement;
-// const track = e.offsetX;
-// const width = target.offsetWidth;
-// if (track < 0 || track > width) return;
-// let value = (track / this.width) * (max - min);
-// if (value % step) {
-// value += step - (value % step);
-// }
-// this.changeInputValue(index, value);
-// this.props.onClick?.call(this, e, value);
-// };
-// /**
-// *
-// * @param index 改变值的input index
-// * @param value 改变的值
-// * 控制input样式
-// */
-// changeInputValue = (index: number, value: number | string) => {
-// const parentNode = this.ref.current;
-// const input = parentNode.getElementsByTagName('input')[index];
-// const id = input.id;
-// parentNode.style.setProperty(`--${id}`, value);
-// if (!index) {
-// this.setValue({ valuePrev: value });
-// } else {
-// this.setValue({ valueNext: value });
-// }
-// };
-// setValue = (value: object, fn?: () => void) => {
-// this.setState(
-// (prevState) => ({
-// ...value,
-// }),
-// fn
-// );
-// };
-// UNSAFE_componentWillMount() {
-// // 生成随机id
-// this.idPrev = randomId('slider');
-// this.idNext = randomId('slider');
-// }
-// componentDidMount() {
-// const { min = 0, max = 100, range } = this.props;
-// const diff = max - min;
-// const slider = this.ref.current;
-// this.width = slider.offsetWidth;
-// slider.style.cssText += `--${this.idPrev}: ${this.state.valuePrev}; --${this.idNext}: ${this.state.valueNext}`;
-// document.styleSheets[0].addRule(
-// `.${styles.slider}::after`,
-// `margin-left: calc((var(--${this.idNext}) - ${min})/${diff}*100%); width: calc((var(--${this.idPrev}) - var(--${this.idNext}))/${diff}*100%);`
-// );
-// document.styleSheets[0].insertRule(
-// `.${styles.slider}::after {margin-left: calc((var(--${this.idNext}) - ${min})/${diff}*100%); width: calc((var(--${this.idPrev}) - var(--${this.idNext}))/${diff}*100%);}`,
-// 0
-// );
-// document.styleSheets[0].addRule(
-// `.${styles.slider}::before`,
-// `margin-left: calc((var(--${this.idPrev}) - ${min})/${diff}*100%);width: calc((var(--${this.idNext}) - var(--${this.idPrev}))/${diff}*100%);`
-// );
-// document.styleSheets[0].insertRule(
-// `.${styles.slider}::before {margin-left: calc((var(--${this.idPrev}) - ${min})/${diff}*100%);width: calc((var(--${this.idNext}) - var(--${this.idPrev}))/${diff}*100%);}`,
-// 0
-// );
-// // 初始化input值和样式
-// if (range) {
-// let { value } = this.props as BaseSliderRangeProps;
-// value = value || [0, 0];
-// this.setValue({
-// valuePrev: value![0],
-// valueNext: value![1],
-// });
-// } else {
-// let { value } = this.props as BaseSliderSingleProps;
-// value = value || 0;
-// this.changeInputValue(0, value);
-// }
-// }
-// render() {
-// const { valuePrev, valueNext } = this.state;
-// const { step = 1, min = 0, max = 100, range = false } = this.props;
-// if (range) {
-// return (
-// <div className={styles.slider} role="group" aria-labelledby="multi-lbl" style={{ '--min': min, '--max': max }} ref={this.ref}>
-// <label className="sr-only" htmlFor={this.idPrev}></label>
-// <input id={this.idPrev} type="range" min={min} value={valuePrev} max={max} step={step} onInput={(e) => this.onInput(0, e)} />
-// <label className="sr-only" htmlFor={this.idNext}></label>
-// <input id={this.idNext} type="range" min={min} value={valueNext} max={max} step={step} onInput={(e) => this.onInput(1, e)} />
-// </div>
-// );
-// }
-// return (
-// <div className={styles.slider} role="group" aria-labelledby="multi-lbl" style={{ '--min': min, '--max': max }} ref={this.ref} onClick={(e) => this.onClick(0, e)}>
-// <label className="sr-only" htmlFor={this.idPrev}></label>
-// <input id={this.idPrev} type="range" min={min} value={valuePrev} max={max} step={step} onInput={(e) => this.onInput(0, e)} />
-// </div>
-// );
-// }
-// }
import React, { CSSProperties, useEffect, useRef, useState } from 'react';
import { randomId } from '../../Utils';
import styles from './index.module.less';
-interface SliderBaseProps {
+// Component Interface
+
+// Base Slider Props
+interface BaseSliderProps {
+ id?: string;
+ /**
+ * The minimum value the slider can slide to
+ * @default 0
+ */
min?: number;
+
+ /** The maximum value the slider can slide to
+ * @default 100
+ */
max?: number;
+
+ /**
+ * The granularity the slider can step through values. Must greater than 0, and be divided by (max - min) . When marks no null, step can be null
+ * @default 1
+ */
step?: number;
+
+ /** slider class name */
className?: string;
+
+ /** slider style */
style?: React.CSSProperties;
-}
-export interface BaseSliderSingleProps extends SliderBaseProps {
- range?: false;
- value?: number;
- onChange?: (e: Event) => void;
- onClick?: (e: Event, value: number | string) => void;
-}
+ /**
+ * Dual thumb mode
+ * @default false
+ * */
+ range?: boolean;
+
+ /** The value of slider. When range is false, use number, otherwise, use [number, number] */
+ value?: number | [number, number];
-export interface BaseSliderRangeProps extends SliderBaseProps {
- range: true;
- value?: [number, number];
+ /** (value) => void */
onChange?: (e: Event) => void;
+
+ /** (value) => void */
onClick?: (e: Event, value: number | string) => void;
}
-export function Slider(props: BaseSliderRangeProps | BaseSliderSingleProps) {
+/**
+ * Slider Component
+ */
+export function Slider(props: BaseSliderProps) {
const [valuePrev, setValuePrev] = useState<number>(0);
const [valueNext, setValueNext] = useState<number>(0);
const idPrevRef = useRef<string>(randomId('slider'));
@@ -159,56 +60,82 @@ export function Slider(props: BaseSliderRangeProps | BaseSliderSingleProps) {
const { min = 0, max = 100, step = 1, range = false, value } = props;
useEffect(() => {
- // 初始化input值和样式
- if (range) {
- let { value } = props as BaseSliderRangeProps;
- value = value || [0, 0];
- setValuePrev(value[0]);
- setValueNext(value[1]);
- } else {
- let { value } = props as BaseSliderSingleProps;
- value = value || 0;
- changeInputValue(0, value);
- }
-
const diff = max - min;
const slider = sliderRef.current;
if (slider) {
- const width = slider.offsetWidth;
slider.style.cssText += `--${idPrevRef.current}: ${valuePrev}; --${idNextRef.current}: ${valueNext}`;
const styleSheet = document.styleSheets[0];
- if (styleSheet) {
- // document.styleSheets[0].addRule(
- // `.${styles.slider}::after`,
- // `margin-left: calc((var(--${idNextRef.current}) - ${min})/${diff}*100%); width: calc((var(--${idPrevRef.current}) - var(--${idNextRef.current}))/${diff}*100%);`
- // );
+ if (styleSheet) {
styleSheet.insertRule(
`.${styles.slider}::after {margin-left: calc((var(--${idNextRef.current}) - ${min})/${diff}*100%); width: calc((var(--${idPrevRef.current}) - var(--${idNextRef.current}))/${diff}*100%);}`,
0
);
-
- // document.styleSheets[0].addRule(
- // `.${styles.slider}::before`,
- // `margin-left: calc((var(--${idPrevRef.current}) - ${min})/${diff}*100%);width: calc((var(--${idNextRef.current}) - var(--${idPrevRef.current}))/${diff}*100%);`
- // );
-
styleSheet.insertRule(
`.${styles.slider}::before {margin-left: calc((var(--${idPrevRef.current}) - ${min})/${diff}*100%);width: calc((var(--${idNextRef.current}) - var(--${idPrevRef.current}))/${diff}*100%);}`,
0
);
}
}
- }, [value]);
- const onInput = (index: number, e: React.FormEvent<HTMLInputElement>) => {
+ // 初始化input值和样式
+ if (range) {
+ const { value = [0, 0] } = props;
+ if (!Array.isArray(value)) {
+ throw Error('Type of value must be array');
+ }
+ const realValue = value;
+ changeInputValue(0, realValue[0]);
+ changeInputValue(1, realValue[1]);
+ } else {
+ const { value = 0 } = props;
+ if (Array.isArray(value)) {
+ throw Error('Type of value must be string');
+ }
+ changeInputValue(0, value);
+ }
+ }, []);
+
+ // 组件卸载时删除stylesheet
+ useEffect(
+ () => () => {
+ const styleSheet = document.styleSheets[0];
+ if (!styleSheet) return;
+ const beforeIndex = Array.from(styleSheet.rules).findIndex((item) => {
+ if ('selectorText' in item) {
+ return item.selectorText === `.${styles.slider}::before`;
+ }
+ return false;
+ });
+ if (beforeIndex > -1) styleSheet.deleteRule(beforeIndex);
+
+ const afterIndex = Array.from(styleSheet.rules).findIndex((item) => {
+ if ('selectorText' in item) {
+ return item.selectorText === `.${styles.slider}::after`;
+ }
+ return false;
+ });
+ if (afterIndex > -1) styleSheet.deleteRule(afterIndex);
+ },
+ []
+ );
+
+ const onInput = (e: React.FormEvent<HTMLInputElement>) => {
const value = Number((e.target as HTMLInputElement).value);
+ let index = 0;
+ if (Array.isArray(props.value)) {
+ if (value >= (valueNext - valuePrev) / 2 + valuePrev) {
+ index = 1;
+ }
+ }
+
changeInputValue(index, value);
+
props.onChange?.(e.nativeEvent);
};
- const onClick = (index: number, e: React.MouseEvent<HTMLDivElement>) => {
+ const onClick = (e: React.MouseEvent<HTMLDivElement>) => {
const { min = 0, max = 100, step = 1 } = props;
const target = e.currentTarget;
const track = e.nativeEvent.offsetX;
@@ -218,6 +145,14 @@ export function Slider(props: BaseSliderRangeProps | BaseSliderSingleProps) {
if (value % step) {
value += step - (value % step);
}
+ let index = 0;
+ if (Array.isArray(props.value)) {
+ // Todo: 为何onInput触发的onClick值会有几px误差?
+ if (value >= (valueNext - valuePrev) / 2 + valuePrev) {
+ index = 1;
+ }
+ }
+
changeInputValue(index, value);
props.onClick?.(e.nativeEvent, value);
};
@@ -229,6 +164,7 @@ export function Slider(props: BaseSliderRangeProps | BaseSliderSingleProps) {
const id = input.id;
parentNode.style.setProperty(`--${id}`, String(value));
+
if (!index) {
setValuePrev(value);
} else {
@@ -239,18 +175,18 @@ export function Slider(props: BaseSliderRangeProps | BaseSliderSingleProps) {
return (
<div
className={styles.slider}
- role="group"
+ role="slider-group"
aria-labelledby="multi-lbl"
style={{ '--min': min, '--max': max } as CSSProperties}
ref={sliderRef}
- onClick={(e) => onClick(0, e)}
+ onClick={(e) => onClick(e)}
>
<label className="sr-only" htmlFor={idPrevRef.current}></label>
- <input id={idPrevRef.current} type="range" min={min} value={valuePrev} max={max} step={step} onInput={(e) => onInput(0, e)} />
+ <input id={idPrevRef.current} type="range" min={min} value={valuePrev} max={max} step={step} onInput={(e) => onInput(e)} />
{range && (
<>
<label className="sr-only" htmlFor={idNextRef.current}></label>
- <input id={idNextRef.current} type="range" min={min} value={valueNext} max={max} step={step} onInput={(e) => onInput(1, e)} />
+ <input id={idNextRef.current} type="range" min={min} value={valueNext} max={max} step={step} onInput={(e) => onInput(e)} />
</>
)}
</div>
diff --git a/packages/base-ui/src/Components/Slider/slider-zh.md b/packages/base-ui/src/Components/Slider/slider-zh.md
deleted file mode 100644
index 39780bffab..0000000000
--- a/packages/base-ui/src/Components/Slider/slider-zh.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-category: Components
-type: 通用
-title: slider
-subtitle: 滑块组件
-cover: ''
----
-
-## 介绍
-
-滑块组件
-
-- 用 css 写的滑块组件,IE 和火狐样式会错乱
-
-## API
-
-属性说明如下:
-
-| 属性 | 说明 | 类型 | 默认值 |
-
-| min | 最小值 | number | 0 |
-| max | 最大值 | number | 100 |
-| step | 步长,取值必须大于 0,并且可被 (max - min) 整除 | number | 1 |
-| className | 类名 | string | - |
-| style | css style | cssStyle | - |
-| value | 设置当前值 | number | - |
-| onChange | 改变滑块值的回调 | (e: Event) => void | - |
-| onClick | 点击滑块的回调 | (e: Event, value: number | string) => void | - |
-
-## 案例
-
-```jsx
-import { Slider } from '@univerjs/style-univer';
-
-<Slider onChange={this.onChange} value={zoom} min={this.min} max={this.max} onClick={this.handleClick} />;
-```
diff --git a/packages/base-ui/src/Components/Slider/slider.md b/packages/base-ui/src/Components/Slider/slider.md
deleted file mode 100644
index 179ba90695..0000000000
--- a/packages/base-ui/src/Components/Slider/slider.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-category: Components
-type: 通用
-title: slider
-subtitle: 滑块组件
-cover: ''
----
-
-## Introduce
-
-Slider Component
-
-- Slider components written in CSS. It will be distorted when IE and Firefox
-
-## API
-
-Property Introduction:
-
-| Property | Description | Type | Default |
-
-| min | The maximum value the slider can slide to | number | 0 |
-| max | The minimum value the slider can slide to | number | 100 |
-| step | The granularity the slider can step through values. Must greater than 0, and be divided by (max - min) | number | 1 |
-| className | className | string | - |
-| style | css style | cssStyle | - |
-| value | The value of slider | number | - |
-| onChange | Callback function that is fired when the user changes the slider's value | (e: Event) => void | - |
-| onClick | Callback function that is fired when the user click the slider | (e: Event, value: number | string) => void | - |
-
-## Case
-
-```jsx
-import { Slider } from '@univerjs/style-univer';
-
-<Slider onChange={this.onChange} value={zoom} min={this.min} max={this.max} onClick={this.handleClick} />;
-```
diff --git a/packages/base-ui/src/Components/Slider/test/index.test.tsx b/packages/base-ui/src/Components/Slider/test/index.test.tsx
index a12e40fab5..89e8b395dc 100644
--- a/packages/base-ui/src/Components/Slider/test/index.test.tsx
+++ b/packages/base-ui/src/Components/Slider/test/index.test.tsx
@@ -1,11 +1,27 @@
-import { render } from '@testing-library/react';
+import { fireEvent, render, screen } from '@testing-library/react';
-import { Slider } from '..';
-
-describe('input', () => {
- test('input', () => {
- const { container } = render(<Slider value={2} min={10} max={200} step={1} className="slider" style={{ color: 'red' }} />);
+import { Slider } from '../Slider';
+describe('Slider', () => {
+ test('renders correctly', () => {
+ const { container } = render(<Slider min={0} max={50}></Slider>);
expect(container);
});
+
+ test('click onClick function', () => {
+ let a = 1;
+
+ render(
+ <Slider
+ id={'test'}
+ onClick={() => {
+ a++;
+ }}
+ ></Slider>
+ );
+
+ fireEvent.click(screen.getByRole('slider-group'));
+
+ expect(a).toEqual(2);
+ });
});
diff --git a/packages/base-ui/src/Components/Slot/Slot.stories.tsx b/packages/base-ui/src/Components/Slot/Slot.stories.tsx
index c563929af2..135392c36e 100644
--- a/packages/base-ui/src/Components/Slot/Slot.stories.tsx
+++ b/packages/base-ui/src/Components/Slot/Slot.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Slot } from './Slot';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Slot',
+const meta: Meta<typeof Slot> = {
+ title: 'Components / Slot',
component: Slot,
parameters: {
layout: 'centered',
@@ -13,7 +14,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Tabs/Tabs.stories.tsx b/packages/base-ui/src/Components/Tabs/Tabs.stories.tsx
index bc1efb0ad5..b538245bce 100644
--- a/packages/base-ui/src/Components/Tabs/Tabs.stories.tsx
+++ b/packages/base-ui/src/Components/Tabs/Tabs.stories.tsx
@@ -1,28 +1,29 @@
+import type { Meta } from '@storybook/react';
+
import { Tab, TabPane } from './Tabs';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Tab',
+const meta: Meta<typeof Tab> = {
+ title: 'Components / Tabs',
component: Tab,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
args: {
- children: (
- <>
- <TabPane tab="test">
- <div>test</div>
- </TabPane>
- <TabPane tab="test1">
- <div>test1</div>
- </TabPane>
- </>
- ),
+ children: [
+ <TabPane label="test" keys="test" active>
+ <div>test content</div>
+ </TabPane>,
+ <TabPane label="test1" keys="test1">
+ <div>test1 content</div>
+ </TabPane>,
+ ],
+ activeKey: 'test1',
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/Tabs/Tabs.tsx b/packages/base-ui/src/Components/Tabs/Tabs.tsx
index c016cd1624..f265d8827b 100644
--- a/packages/base-ui/src/Components/Tabs/Tabs.tsx
+++ b/packages/base-ui/src/Components/Tabs/Tabs.tsx
@@ -1,133 +1,90 @@
-// export class Tab extends PureComponent<BaseTabProps> {
-// state = {
-// active: '',
-// };
-// setValue = (value: object, fn?: () => void) => {
-// this.setState(
-// (prevState) => ({
-// ...value,
-// }),
-// fn
-// );
-// };
-// UNSAFE_componentWillMount() {
-// this.setValue({ active: this.props.activeKey, children: this.props.children });
-// }
-// // generate tab navlist
-// parseNavList = () => {
-// const { active } = this.state;
-// return toChildArray(this.props.children).map((node) => {
-// const { tab, keys } = (node as JSX.Element).props;
-// const id = `${randomId('tab')}-${keys}`;
-// if (active === keys) {
-// return (
-// <div key={id} id={id} onClick={this.handleClick} className={joinClassNames(styles.tabsTab, styles.tabsTabActive)}>
-// {tab}
-// </div>
-// );
-// }
-// return (
-// <div key={id} id={id} onClick={this.handleClick} className={styles.tabsTab}>
-// {tab}
-// </div>
-// );
-// });
-// };
-// handleClick = (e: Event) => {
-// const id = (e.target as HTMLElement).id;
-// const index = id.lastIndexOf('-');
-// const value = id.slice(index + 1);
-// this.setValue({ active: value });
-// this.props.onTabClick?.(value, e);
-// };
-// render() {
-// const { children, type = 'line', className = '' } = this.props;
-// const classes = joinClassNames(
-// styles.tabs,
-// {
-// [`${styles.tabs}-card`]: type === 'card',
-// },
-// className
-// );
-// // if (type == 'line') {
-// // return <div></div>;
-// // }
-// return (
-// <div className={classes}>
-// <div className={styles.tabsNav}>
-// <div className={styles.tabsNavWrap}>
-// <div className={styles.tabsNavList}>{this.parseNavList()}</div>
-// </div>
-// </div>
-// <div className={styles.tabsContent}>
-// {children.map((item: JSX.Element, index: number) => (
-// <TabPane key={index} keys={item.props.keys} active={item.props.keys === this.state.active}>
-// {item.props.children}
-// </TabPane>
-// ))}
-// </div>
-// </div>
-// );
-// }
-// }
-
-// interface IProps {
-// className?: string;
-// style?: JSX.CSSProperties;
-// children?: any;
-// }
-// interface TabBaseProps extends IProps {
-// // type?: 'line' | 'card';
-// type?: 'card';
-// activeKey?: string;
-// // defaultActiveKey?: string;
-// // tabBarGutter?: number;
-// // tabBarStyle?: Record<string, string>;
-// // tabPosition?: 'left' | 'right' | 'top' | 'bottom';
-// // onChange?: (activeKey: string) => void;
-// onTabClick?: (activeKey: string, e: Event) => void;
-// }
-// interface TabPaneProps {
-// active?: boolean;
-// tab?: JSX.Element | string;
-// keys?: string;
-// id?: string;
-// className?: string;
-// style?: JSX.CSSProperties;
-// children?: ComponentChildren;
-// }
-import React, { useEffect, useState } from 'react';
+import React, { ReactNode, useEffect, useState } from 'react';
import { BaseComponentProps } from '../../BaseComponent';
import { joinClassNames, randomId } from '../../Utils';
import styles from './index.module.less';
-interface IProps {
- className?: string;
- style?: React.CSSProperties;
- children?: any;
-}
+// Components interface
+// Props of tab pane
export interface BaseTabPaneProps {
+ /**
+ * TabPane's head display content
+ */
+ label: ReactNode;
+
+ /**
+ * Active status of tab pane
+ */
active?: boolean;
- tab?: JSX.Element | string;
+
+ /**
+ * TabPane's key
+ */
keys?: string;
+
+ /**
+ * TabPane's id
+ */
id?: string;
+
+ /**
+ * Class name of tab pane
+ */
className?: string;
+
+ /**
+ * Style of tab pane
+ */
style?: React.CSSProperties;
- children?: any;
+
+ /**
+ * TabPane's head display content
+ */
+ children?: ReactNode;
}
-export interface BaseTabProps extends IProps, BaseComponentProps {
+// Props of tabs
+export interface BaseTabProps extends BaseComponentProps {
+ /**
+ * Basic style of tabs
+ */
type?: 'card';
+
+ /**
+ * Current TabPane's key
+ */
activeKey?: string;
+
+ /**
+ * Callback executed when tab is clicked
+ */
onTabClick?: (activeKey: string, e: Event) => void;
+
+ /**
+ * Class name of tab container
+ */
+ className?: string;
+
+ /**
+ * Style of tab container
+ */
+ style?: React.CSSProperties;
+
+ /**
+ * Content of tab
+ */
+ children: Array<React.ReactElement<BaseTabPaneProps, string>>;
}
+// Todo: rename component name
+/**
+ * Tabs Component
+ */
export function Tab(props: BaseTabProps) {
- const { children, type = 'line', className = '' } = props;
+ const { type = 'line', className = '' } = props;
const [active, setActive] = useState<string>(props.activeKey || ''); // Initialize active with the provided activeKey
- const [tabChildren, setTabChildren] = useState<any>(props.children);
+ const [tabChildren, setTabChildren] = useState<Array<React.ReactElement<BaseTabPaneProps, string>>>(props.children);
useEffect(() => {
props.activeKey && setActive(props.activeKey); // Update active state when props.activeKey changes
@@ -138,14 +95,14 @@ export function Tab(props: BaseTabProps) {
}, [props.children]);
const parseNavList = () =>
- React.Children.map(tabChildren, (child) => {
- const { tab, keys } = (child as React.ReactElement).props;
+ tabChildren.map((child) => {
+ const { label, keys } = child.props;
const id = `${randomId('tab')}-${keys}`;
const tabClassName = active === keys ? `${styles.tabsTab} ${styles.tabsTabActive}` : styles.tabsTab;
return (
<div key={id} id={id} onClick={handleClick} className={tabClassName}>
- {tab}
+ {label}
</div>
);
});
@@ -170,9 +127,9 @@ export function Tab(props: BaseTabProps) {
</div>
</div>
<div className={styles.tabsContent}>
- {React.Children.map(tabChildren, (child, index) => (
- <TabPane key={index} keys={(child as React.ReactElement).props.keys} active={(child as React.ReactElement).props.keys === active}>
- {(child as React.ReactElement).props.children}
+ {tabChildren.map((child, index) => (
+ <TabPane label={child.props.label} key={index} keys={child.props.keys} active={child.props.keys === active}>
+ {child.props.children}
</TabPane>
))}
</div>
diff --git a/packages/base-ui/src/Components/Tabs/test/index.test.tsx b/packages/base-ui/src/Components/Tabs/test/index.test.tsx
index ccb4879ac3..19abd67e53 100644
--- a/packages/base-ui/src/Components/Tabs/test/index.test.tsx
+++ b/packages/base-ui/src/Components/Tabs/test/index.test.tsx
@@ -1,15 +1,15 @@
-import { render } from '@testing-library/react';
+import { fireEvent, render, screen } from '@testing-library/react';
import { Tab, TabPane } from '..';
describe('tab', () => {
- test('tab', () => {
+ test('tab render', () => {
const { container } = render(
<Tab activeKey="tab" type="card">
- <TabPane tab="tab1" keys="tab">
+ <TabPane label="tab1" keys="tab">
test tab
</TabPane>
- <TabPane tab="tab2" keys="tabs">
+ <TabPane label="tab2" keys="tabs">
test tabs
</TabPane>
</Tab>
@@ -17,4 +17,23 @@ describe('tab', () => {
expect(container);
});
+
+ test('click onTabClick function', () => {
+ let a = 1;
+
+ render(
+ <Tab activeKey="tab" type="card" onTabClick={() => a++}>
+ <TabPane label="tab1" keys="tab">
+ test tab
+ </TabPane>
+ <TabPane label="tab2" keys="tabs">
+ test tabs
+ </TabPane>
+ </Tab>
+ );
+
+ fireEvent.click(screen.getByText('tab1'));
+
+ expect(a).toEqual(2);
+ });
});
diff --git a/packages/base-ui/src/Components/Tooltip/Tooltip.stories.tsx b/packages/base-ui/src/Components/Tooltip/Tooltip.stories.tsx
index c59e99530d..1a4b8239bd 100644
--- a/packages/base-ui/src/Components/Tooltip/Tooltip.stories.tsx
+++ b/packages/base-ui/src/Components/Tooltip/Tooltip.stories.tsx
@@ -1,8 +1,9 @@
+import type { Meta } from '@storybook/react';
+
import { Tooltip } from './Tooltip';
-// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
-export default {
- title: 'Components/Tooltip',
+const meta: Meta<typeof Tooltip> = {
+ title: 'Components / Tooltip',
component: Tooltip,
parameters: {
layout: 'centered',
@@ -14,7 +15,8 @@ export default {
},
};
-// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
+export default meta;
+
export const Playground = {
args: {},
};
diff --git a/packages/base-ui/src/Components/index.ts b/packages/base-ui/src/Components/index.ts
index a993d6b0c2..32207d73bb 100644
--- a/packages/base-ui/src/Components/index.ts
+++ b/packages/base-ui/src/Components/index.ts
@@ -12,6 +12,7 @@ export * from './Container';
export * from './CustomLabel';
export * from './Dropdown';
export * from './Input';
+export * from './InputNumber';
export * from './Item/Item';
export * from './Layout';
export * from './Menu';
diff --git a/packages/base-ui/src/Utils/util.ts b/packages/base-ui/src/Utils/util.ts
index 0667d4e873..9f26850ad5 100644
--- a/packages/base-ui/src/Utils/util.ts
+++ b/packages/base-ui/src/Utils/util.ts
@@ -90,30 +90,6 @@ export function randomId(prefix: string) {
);
}
-/**
- * 获取第一级子元素
- * @param obj
- * @returns
- */
-export function getFirstChildren(obj: HTMLElement) {
- const objChild = [];
- const objs = obj.getElementsByTagName('*');
- for (let i = 0, j = objs.length; i < j; ++i) {
- if (objs[i].nodeType !== 1) {
- // alert(objs[i].nodeType);
- continue;
- }
- const temp: HTMLElement | any = objs[i].parentNode;
- if (temp && temp.nodeType === 1) {
- if (temp === obj) {
- objChild[objChild.length] = objs[i];
- }
- } else if (temp && temp.parentNode === obj) {
- objChild[objChild.length] = objs[i];
- }
- }
- return objChild;
-}
/**
* join className
*/
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 6587d32975..a2adcc89ea 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -2,7 +2,7 @@ import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager
import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';
import { Disposable } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
-import { ComponentChildren } from 'react';
+import React from 'react';
import { SHEET_UI_PLUGIN_NAME, SheetToolbarConfig } from '../Basics';
import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';
@@ -51,7 +51,7 @@ export interface IToolbarItemProps extends BaseToolbarSelectProps {
toolbarType?: ToolbarType;
tooltip?: string; //tooltip文字
border?: boolean;
- suffix?: ComponentChildren;
+ suffix?: React.ReactNode;
}
export class ToolbarUIController extends Disposable {
diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
index d5eac7d2c0..5fd1437c36 100644
--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
@@ -20,7 +20,7 @@ interface CountBarProps extends BaseComponentProps {
export class CountBar extends Component<CountBarProps, CountState> {
static override contextType = AppContext;
- max = 400;
+ max = 100;
min = 0;
@@ -98,7 +98,7 @@ export class CountBar extends Component<CountBarProps, CountState> {
<Icon.Math.AddIcon />
</Button>
<div className={styles.countSlider}>
- <Slider onChange={this.onChange} value={zoom} min={this.min} max={this.max} onClick={this.handleClick} />
+ <Slider onChange={this.onChange} value={[20, 50]} min={this.min} max={this.max} range onClick={this.handleClick} />
</div>
<Button onClick={this.reduceZoom}>
<Icon.Math.ReduceIcon />
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ad1f47eb7e..b5e52efba4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -733,6 +733,9 @@ importers:
specifier: ^7.8.1
version: 7.8.1
devDependencies:
+ '@storybook/addon-docs':
+ specifier: ^7.4.1
'@storybook/addon-essentials':
specifier: ^7.4.1
@@ -1520,7 +1523,7 @@ packages:
'@babel/parser': 7.22.15
'@babel/template': 7.22.15
'@babel/traverse': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
convert-source-map: 1.9.0
debug: 4.3.4
gensync: 1.0.0-beta.2
@@ -1534,7 +1537,7 @@ packages:
resolution: {integrity: sha512-Zu9oWARBqeVOW0dZOjXc3JObrzuqothQ3y/n1kUtrjCoCPLkXUwMvOo/F/TCfoHMbWIFlWwpZtkZVb9ga4U2pA==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
'@jridgewell/gen-mapping': 0.3.3
'@jridgewell/trace-mapping': 0.3.19
jsesc: 2.5.2
@@ -1544,7 +1547,7 @@ packages:
resolution: {integrity: sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -1620,28 +1623,28 @@ packages:
engines: {node: '>=6.9.0'}
dependencies:
'@babel/template': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-qLNsZbgrNh0fDQBCPocSL8guki1hcPvltGDv/NxvUoABwFq7GkKSu1nRXeJkVZc+wJvne2E0RKQz+2SQrz6eAA==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-0pYVBnDKZO2fnSPCrgM/6WMc7eS20Fbok+0r88fp+YtWVLZrp4CkafFGIp+W0VKw4a22sgebPT99y+FDNMdP4w==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -1662,7 +1665,7 @@ packages:
resolution: {integrity: sha512-HBwaojN0xFRx4yIvpwGqxiV2tUfl7401jlok564NgB9EHS1y6QT17FmKWm4ztqjeVdXLuC4fSvHc5ePpQjoTbw==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -1698,21 +1701,21 @@ packages:
resolution: {integrity: sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==}
engines: {node: '>=6.9.0'}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -1745,7 +1748,7 @@ packages:
dependencies:
'@babel/template': 7.22.15
'@babel/traverse': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
transitivePeerDependencies:
- supports-color
dev: true
@@ -1764,7 +1767,7 @@ packages:
engines: {node: '>=6.0.0'}
hasBin: true
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.22.15(@babel/[email protected]):
@@ -2866,7 +2869,7 @@ packages:
dependencies:
'@babel/code-frame': 7.22.13
'@babel/parser': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -2880,7 +2883,7 @@ packages:
'@babel/helper-hoist-variables': 7.22.5
'@babel/helper-split-export-declaration': 7.22.6
'@babel/parser': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
debug: 4.3.4
globals: 11.12.0
transitivePeerDependencies:
@@ -6412,7 +6415,7 @@ packages:
resolution: {integrity: sha512-aACu/U/omhdk15O4Nfb+fHgH/z3QsfQzpnvRZhYhThms83ZnAOZz7zZAWO7mn2yyNQaA4xTO8GLK3uqFU4bYYw==}
dependencies:
'@babel/parser': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
'@types/babel__generator': 7.6.4
'@types/babel__template': 7.4.1
'@types/babel__traverse': 7.20.1
@@ -6421,20 +6424,20 @@ packages:
resolution: {integrity: sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==}
dependencies:
'@babel/parser': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
resolution: {integrity: sha512-MitHFXnhtgwsGZWtT68URpOvLN4EREih1u3QtQiN4VdAxWKRVvGCSvw/Qth0M0Qq3pJpnGOu5JaM/ydK7OGbqg==}
dependencies:
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
dev: true
@@ -7319,7 +7322,7 @@ packages:
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@babel/template': 7.22.15
- '@babel/types': 7.22.15
+ '@babel/types': 7.22.17
'@types/babel__core': 7.20.1
'@types/babel__traverse': 7.20.1
dev: true