Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Button): Button组件对齐 mobile-vue #469

Merged
merged 21 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ab6345f
feat(Button): 同步Button组件特性
tobytovi Aug 16, 2024
7559d0d
chore: 解决开发环境无prettier导致提交校验prettier运行报错
tobytovi Aug 16, 2024
dba0a01
feat(Button): 升级Button组件样式表到v2
tobytovi Aug 16, 2024
95152f9
feat(Demo): 更新Buttons示例样式
tobytovi Aug 16, 2024
9bd1522
chore: common仓库同步
tobytovi Aug 16, 2024
b65a41b
feat(Demo): 更新Buttons示例背景颜色
tobytovi Aug 16, 2024
a4d1549
chore: 同步新的类型规范
tobytovi Aug 16, 2024
6250e0b
docs(Button): 更新Buttons的API样式
tobytovi Aug 16, 2024
553066e
fix(Button-type): 更正Button组件的ref类型
tobytovi Aug 16, 2024
ee83930
chore: 更新测试snap
tobytovi Aug 20, 2024
0bcf7fd
Merge remote-tracking branch 'upstream/develop' into feat/button-v2-u…
tobytovi Aug 20, 2024
3fa369c
chore: 更新测试snap
tobytovi Aug 20, 2024
3676b72
chore: 更新测试snap
tobytovi Aug 20, 2024
f84683e
feat(Button): 使用parseTNode包裹TNode
tobytovi Aug 20, 2024
877e709
Merge remote-tracking branch 'upstream/develop' into feat/button-v2-u…
tobytovi Aug 20, 2024
c575b29
chore(Button): 更新测试snap
tobytovi Aug 20, 2024
9673537
fix(Button): 去掉children类型继承
tobytovi Aug 20, 2024
63583fd
fix(Demo): 恢复演示背景默认颜色
tobytovi Aug 21, 2024
4fd8db7
fix(Button): button演示背景改为白色
tobytovi Aug 21, 2024
d749da4
Merge remote-tracking branch 'upstream/develop' into feat/button-v2-u…
tobytovi Aug 21, 2024
b350507
chore: snap-update
tobytovi Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/mobile/mobile.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
{
title: 'Button 按钮',
name: 'button',
component: () => import('tdesign-mobile-react/button/_example/index.jsx'),
component: () => import('tdesign-mobile-react/button/_example/index.tsx'),
},
{
title: 'Divider 分割符',
Expand Down
2 changes: 1 addition & 1 deletion site/style/mobile/demo.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.tdesign-mobile-demo {
background-color: #f6f6f6;
background-color: #ffffff;
font-family: 'PingFang SC';
padding-bottom: 28px;
box-sizing: border-box;
Expand Down
28 changes: 17 additions & 11 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { buttonDefaultProps } from './defaultProps';

export interface ButtonProps extends TdButtonProps, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'content'> {}
HaixingOoO marked this conversation as resolved.
Show resolved Hide resolved

const Button = forwardRef((props: ButtonProps, ref: React.Ref<HTMLButtonElement>) => {
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
const {
className = '',
style,
Expand All @@ -18,13 +18,15 @@ const Button = forwardRef((props: ButtonProps, ref: React.Ref<HTMLButtonElement>
disabled,
ghost,
icon = null,
suffix = null,
loading,
shape,
size,
theme,
type,
variant,
onClick = noop,
loadingProps = {},
tobytovi marked this conversation as resolved.
Show resolved Hide resolved
} = props;
const { classPrefix } = useConfig();

Expand All @@ -33,24 +35,28 @@ const Button = forwardRef((props: ButtonProps, ref: React.Ref<HTMLButtonElement>
ref={ref}
type={type}
className={classnames(
[`${classPrefix}-button`, `${classPrefix}-button--${variant}`, `${classPrefix}-button--${theme}`, className],
[
`${classPrefix}-button`,
`${classPrefix}-button--size-${size}`,
`${classPrefix}-button--${variant}`,
`${classPrefix}-button--${theme}`,
`${classPrefix}-button--${shape}`,
className,
],
{
[`${classPrefix}-button--ghost`]: ghost,
[`${classPrefix}-size-s`]: size === 'small',
[`${classPrefix}-size-default`]: size === 'medium',
[`${classPrefix}-size-l`]: size === 'large',
[`${classPrefix}-is-loading`]: loading,
[`${classPrefix}-is-disabled`]: disabled,
[`${classPrefix}-is-block`]: block,
[`${classPrefix}-button--loading`]: loading,
[`${classPrefix}-button--disabled`]: disabled,
[`${classPrefix}-button--block`]: block,
},
[`${classPrefix}-button--shape-${shape}`],
)}
style={style}
onClick={!loading && !disabled ? onClick : undefined}
disabled={disabled || loading}
>
{loading ? <LoadingIcon /> : icon}
{content || children ? <span className={`${classPrefix}-button__text`}> {content || children}</span> : ''}
{loading ? <LoadingIcon {...loadingProps} /> : icon}
{content || children ? <span className={`${classPrefix}-button__content`}> {content || children}</span> : ''}
{suffix}
</button>
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/button/__tests__/__snapshots__/button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Button 组件测试 > content 1`] = `
<span
class="t-button__text"
class="t-button__content"
>
按钮组件
Expand Down
78 changes: 0 additions & 78 deletions src/button/_example/base.jsx

This file was deleted.

29 changes: 29 additions & 0 deletions src/button/_example/base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';

export default function () {
return (
<>
<div className="row">
<Button size="large" theme="primary">
填充按钮
</Button>
<Button size="large" theme="light">
填充按钮
</Button>
<Button size="large">填充按钮</Button>
</div>
<div className="row">
<Button size="large" theme="primary" variant="outline">
描边按钮
</Button>
<Button size="large" theme="primary" variant="dashed">
虚框按钮
</Button>
<Button size="large" theme="primary" variant="text">
文字按钮
</Button>
</div>
</>
);
}
12 changes: 12 additions & 0 deletions src/button/_example/block.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';

export default function () {
return (
<div className="row">
<Button size="large" theme="primary" block>
填充按钮
</Button>
</div>
);
}
18 changes: 18 additions & 0 deletions src/button/_example/ghost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';

export default function () {
return (
<div className="row section-ghost">
<Button size="large" ghost theme="primary">
幽灵按钮
</Button>
<Button size="large" ghost theme="danger">
幽灵按钮
</Button>
<Button size="large" ghost>
幽灵按钮
</Button>
</div>
);
}
15 changes: 15 additions & 0 deletions src/button/_example/group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';

export default function () {
return (
<div className="row section-group">
<Button size="large" theme="light">
组合按钮
</Button>
<Button size="large" theme="primary">
组合按钮
</Button>
</div>
);
}
17 changes: 17 additions & 0 deletions src/button/_example/icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';
import { Icon } from 'tdesign-icons-react';

export default function () {
return (
<div className="row">
<Button theme="primary" size="large" icon={<Icon name="app" />}>
填充按钮
</Button>
<Button theme="primary" size="large" loading>
加载中
</Button>
<Button theme="primary" size="large" shape="square" icon={<Icon name="search" />} />
</div>
);
}
28 changes: 0 additions & 28 deletions src/button/_example/index.jsx

This file was deleted.

52 changes: 52 additions & 0 deletions src/button/_example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import TDemoBlock from '../../../site/mobile/components/DemoBlock';
import TDemoHeader from '../../../site/mobile/components/DemoHeader';
import './style/index.less';
import BaseDemo from './base';
import IconDemo from './icon';
import GhostDemo from './ghost';
import GroupDemo from './group';
import BlockDemo from './block';
import SizeDemo from './size';
import StatusDemo from './status';
import ShapeDemo from './shape';
import ThemeDemo from './theme';

export default function Base() {
return (
<div className="tdesign-mobile-demo">
<TDemoHeader title="Button 按钮" summary="按钮用于开启一个闭环的操作任务,如“删除”对象、“购买”商品等。" />
<TDemoBlock title="01 组件类型" summary="基础按钮">
<BaseDemo />
</TDemoBlock>
<TDemoBlock summary="图标按钮">
<IconDemo />
</TDemoBlock>
<TDemoBlock summary="幽灵按钮">
<GhostDemo />
</TDemoBlock>
<TDemoBlock summary="组合按钮">
<GroupDemo />
</TDemoBlock>
<TDemoBlock summary="通栏按钮">
<BlockDemo />
</TDemoBlock>

<TDemoBlock title="02 组件状态" summary="按钮禁用态">
<StatusDemo />
</TDemoBlock>

<TDemoBlock title="03 组件样式" summary="按钮尺寸">
<SizeDemo />
</TDemoBlock>

<TDemoBlock summary="按钮形状">
<ShapeDemo />
</TDemoBlock>

<TDemoBlock summary="按钮主题">
<ThemeDemo />
</TDemoBlock>
</div>
);
}
23 changes: 23 additions & 0 deletions src/button/_example/shape.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { Button } from 'tdesign-mobile-react';
import { Icon } from 'tdesign-icons-react';

export default function () {
return (
<>
<div className="row section-shape">
<Button theme="primary" size="large">
填充按钮
</Button>
<Button theme="primary" size="large" shape="square" aria-label="搜索" icon={<Icon name="search" />}></Button>
<Button theme="primary" size="large" shape="round">
填充按钮
</Button>
<Button theme="primary" size="large" shape="circle" aria-label="搜索" icon={<Icon name="search" />}></Button>
</div>
<Button theme="primary" size="large" block className="rectangle-button">
填充按钮
</Button>
</>
);
}
Loading
Loading