feat: add info

This commit is contained in:
aibayanyu 2023-04-16 21:52:44 +08:00
parent 5d5653d3bd
commit e5896c093a
10 changed files with 319 additions and 36 deletions

View File

@ -12,6 +12,7 @@ export default defineConfig({
rewrites: getRewrites(),
mpa: true,
lang: 'en-US',
ignoreDeadLinks: true,
locales: {
'zh-CN': {
lang: 'zh-CN',

View File

@ -4,15 +4,45 @@ const componentsDir = `/components/`
export const getSidebar = (): DefaultTheme.Sidebar => {
return {
'/components/': [
[componentsDir]: [
{
text: 'General',
items: [
{
text: 'Button',
link: `${componentsDir}button/`
}
]
},
{
text: 'Layout',
items: []
},
{
text: 'Navigation',
items: []
},
{
text: 'Data Entry',
items: []
},
{
text: 'Data Display',
items: []
},
{
text: 'Feedback',
items: []
},
{
text: 'Other',
items: [
{
text: 'ConfigProvider',
link: `${componentsDir}config-provider/`
}
]
}
]
}
}

View File

@ -3,15 +3,45 @@ const componentsDir = `/zh-CN/components/`
export const getSidebar = (): DefaultTheme.Sidebar => {
return {
'/zh-CN/components/': [
[componentsDir]: [
{
text: '通用',
items: [
{
text: 'Button 按钮',
link: `${componentsDir}button/`
}
]
},
{
text: '布局',
items: []
},
{
text: '导航',
items: []
},
{
text: '数据入录',
items: []
},
{
text: '数据展示',
items: []
},
{
text: '反馈',
items: []
},
{
text: '其他',
items: [
{
text: 'ConfigProvider',
link: `${componentsDir}config-provider/`
}
]
}
]
}
}

View File

@ -0,0 +1,25 @@
<docs lang="zh-CN">
---
title: 按钮类型
---
按钮有五种类型主按钮次按钮虚线按钮文本按钮和链接按钮主按钮在同一个操作区域最多出现一次
</docs>
<docs lang="en-US">
---
title: Type
---
There are `primary` button, `default` button, `dashed` button, `text` button and `link` button in antd.
</docs>
<script setup lang="ts"></script>
<template>
<a-button type="primary">Primary Button</a-button>
<a-button>Default Button</a-button>
<a-button type="dashed">Dashed Button</a-button>
<a-button type="text">Text Button</a-button>
<a-button type="link">Link Button</a-button>
</template>

View File

@ -1,21 +0,0 @@
<docs lang="zh-CN">
---
title: 基本用法
---
这是基础按钮
</docs>
<docs lang="en-US">
---
title: Basic Button
---
Basic Usage Test
</docs>
<script setup lang="ts"></script>
<template>
<div>Test</div>
</template>

View File

@ -1,4 +1,67 @@
# Button
To trigger an operation.
<demo src="./demos/basic.vue"></demo>
## When To Use
A button means an operation (or a series of operations). Clicking a button will trigger corresponding business logic.
In Ant Design we provide 5 types of button.
- Primary button: indicate the main action, one primary button at most in one section.
- Default button: indicate a series of actions without priority.
- Dashed button: used for adding action commonly.
- Text button: used for the most secondary action.
- Link button: used for external links.
And 4 other properties additionally.
- `danger`: used for actions of risk, like deletion or authorization.
- `ghost`: used in situations with complex background, home pages usually.
- `disabled`: when actions are not available.
- `loading`: add loading spinner in button, avoiding multiple submits too.
## Examples
<demo src="./demo/basic.vue"></demo>
## API
Different button styles can be generated by setting Button properties. The recommended order is: `type` -> `shape` -> `size` -> `loading` -> `disabled`.
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| 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 | |
| ghost | Make background transparent and invert text and border colors | boolean | false | |
| href | Redirect url of link button | string | - | |
| 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` | |
| icon | Set the icon component of button | ReactNode | - | |
| loading | Set the loading status of button | boolean \| { delay: number } | false | |
| shape | Can be set button shape | `default` \| `circle` \| `round` | `default` | |
| size | Set the size of button | `large` \| `middle` \| `small` | `middle` | |
| target | Same as target attribute of a, works when href is specified | string | - | |
| type | Can be set to `primary` `ghost` `dashed` `link` `text` `default` | string | `default` | |
| onClick | Set the handler to handle `click` event | (event: MouseEvent) => void | - | |
It accepts all props which native buttons support.
## Design Token
<ComponentTokenTable component="Button"></ComponentTokenTable>
## FAQ
### How to remove space between 2 chinese characters?
Following the Ant Design specification, we will add one space between if Button (exclude Text button and Link button) contains two Chinese characters only. If you don't need that, you can use [ConfigProvider](/components/config-provider/#api) to set `autoInsertSpaceInButton` as `false`.
<img src="https://gw.alipayobjects.com/zos/antfincdn/MY%26THAPZrW/38f06cb9-293a-4b42-b183-9f443e79ffea.png" style="box-shadow: none; margin: 0; width: 100px" alt="Button with two Chinese characters" />
<style>
.site-button-ghost-wrapper {
padding: 16px;
background: rgb(190, 200, 200);
}
</style>

View File

@ -1,4 +1,76 @@
# 按钮
# Button 按钮
按钮用于开始一个即时操作。
## 何时使用
标记了一个(或封装一组)操作命令,响应用户点击行为,触发相应的业务逻辑。
在 Ant Design 中我们提供了五种按钮。
- 主按钮:用于主行动点,一个操作区域只能有一个主按钮。
- 默认按钮:用于没有主次之分的一组行动点。
- 虚线按钮:常用于添加操作。
- 文本按钮:用于最次级的行动点。
- 链接按钮:一般用于链接,即导航至某位置。
以及四种状态属性与上面配合使用。
- 危险:删除/移动/修改权限等危险操作,一般需要二次确认。
- 幽灵:用于背景色比较复杂的地方,常用在首页/产品页等展示场景。
- 禁用:行动点不可用的时候,一般需要文案解释。
- 加载中:用于异步操作等待反馈的时候,也可以避免多次提交。
[完整设计指南](https://ant.design/docs/spec/buttons-cn)
## 代码演示
<demo src="./demo/basic.vue"></demo>
<demo src="./demos/basic.vue"></demo>
## API
通过设置 Button 的属性来产生不同的按钮样式,推荐顺序为:`type` -> `shape` -> `size` -> `loading` -> `disabled`
按钮的属性说明如下:
| 属性 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| block | 将按钮宽度调整为其父宽度的选项 | boolean | false | |
| danger | 设置危险按钮 | boolean | false | |
| disabled | 设置按钮失效状态 | boolean | false | |
| ghost | 幽灵属性,使按钮背景透明 | boolean | false | |
| href | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 | string | - | |
| htmlType | 设置 `button` 原生的 `type` 值,可选值请参考 [HTML 标准](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type) | string | `button` | |
| icon | 设置按钮的图标组件 | ReactNode | - | |
| loading | 设置按钮载入状态 | boolean \| { delay: number } | false | |
| shape | 设置按钮形状 | `default` \| `circle` \| `round` | `default` | |
| size | 设置按钮大小 | `large` \| `middle` \| `small` | `middle` | |
| target | 相当于 a 链接的 target 属性href 存在时生效 | string | - | |
| type | 设置按钮类型 | `primary` \| `ghost` \| `dashed` \| `link` \| `text` \| `default` | `default` | |
| onClick | 点击按钮时的回调 | (event: MouseEvent) => void | - | |
支持原生 button 的其他所有属性。
## Design Token
<ComponentTokenTable component="Button"></ComponentTokenTable>
## FAQ
### 如何移除两个汉字之间的空格?
根据 Ant Design 设计规范要求,我们会在按钮内(文本按钮和链接按钮除外)只有两个汉字时自动添加空格,如果你不需要这个特性,可以设置 [ConfigProvider](/zh-CN/components/config-provider/#api) 的 `autoInsertSpaceInButton``false`
<img src="https://gw.alipayobjects.com/zos/antfincdn/MY%26THAPZrW/38f06cb9-293a-4b42-b183-9f443e79ffea.png" style="box-shadow: none; margin: 0; width: 100px" alt="移除两个汉字之间的空格" />
<style>
.site-button-ghost-wrapper {
padding: 16px;
background: rgb(190, 200, 200);
}
</style>
## 设计指引
- [我的按钮究竟该放哪儿!?| Ant Design 4.0 系列分享](https://zhuanlan.zhihu.com/p/109644406)

View File

@ -0,0 +1,29 @@
import type { FullToken, GenerateStyle } from '../../theme/internal'
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
// Component token here
}
interface SpaceToken extends FullToken<'Space'> {
// Custom token here
}
const genSpaceCompactStyle: GenerateStyle<SpaceToken> = (token) => {
const { componentCls } = token
return {
[componentCls]: {
display: 'inline-flex',
'&-block': {
display: 'flex',
width: '100%'
},
'&-vertical': {
flexDirection: 'column'
}
}
}
}
// ============================== Export ==============================
export default genSpaceCompactStyle

View File

@ -0,0 +1,54 @@
import type { FullToken, GenerateStyle } from '../../theme/internal'
import { genComponentStyleHook } from '../../theme/internal'
import genSpaceCompactStyle from './compact'
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
// Component token here
}
interface SpaceToken extends FullToken<'Space'> {
// Custom token here
}
const genSpaceStyle: GenerateStyle<SpaceToken> = (token) => {
const { componentCls } = token
return {
[componentCls]: {
display: 'inline-flex',
'&-rtl': {
direction: 'rtl'
},
'&-vertical': {
flexDirection: 'column'
},
'&-align': {
flexDirection: 'column',
'&-center': {
alignItems: 'center'
},
'&-start': {
alignItems: 'flex-start'
},
'&-end': {
alignItems: 'flex-end'
},
'&-baseline': {
alignItems: 'baseline'
}
},
[`${componentCls}-item`]: {
'&:empty': {
display: 'none'
}
}
}
}
}
// ============================== Export ==============================
export default genComponentStyleHook('Space', (token) => [
genSpaceStyle(token),
genSpaceCompactStyle(token)
])

View File

@ -34,7 +34,7 @@ import type { ComponentToken as ButtonComponentToken } from '../../button/style'
// import type { ComponentToken as SelectComponentToken } from '../../select/style'
// import type { ComponentToken as SkeletonComponentToken } from '../../skeleton/style'
// import type { ComponentToken as SliderComponentToken } from '../../slider/style'
// import type { ComponentToken as SpaceComponentToken } from '../../space/style'
import type { ComponentToken as SpaceComponentToken } from '../../space/style'
// import type { ComponentToken as SpinComponentToken } from '../../spin/style'
// import type { ComponentToken as StepsComponentToken } from '../../steps/style'
// import type { ComponentToken as TableComponentToken } from '../../table/style'
@ -108,7 +108,7 @@ export interface ComponentTokenMap {
// Upload?: UploadComponentToken
// Tooltip?: TooltipComponentToken
// Table?: TableComponentToken
// Space?: SpaceComponentToken
Space?: SpaceComponentToken
// Progress?: ProgressComponentToken
// Tour?: TourComponentToken
// QRCode?: QRCodeComponentToken