diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 4a358ff..e79fbb0 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -12,6 +12,7 @@ export default defineConfig({ rewrites: getRewrites(), mpa: true, lang: 'en-US', + ignoreDeadLinks: true, locales: { 'zh-CN': { lang: 'zh-CN', diff --git a/.vitepress/config/en-US/sidebar.ts b/.vitepress/config/en-US/sidebar.ts index ed86c00..8258d93 100644 --- a/.vitepress/config/en-US/sidebar.ts +++ b/.vitepress/config/en-US/sidebar.ts @@ -4,14 +4,44 @@ const componentsDir = `/components/` export const getSidebar = (): DefaultTheme.Sidebar => { return { - '/components/': [ + [componentsDir]: [ { - text: 'Button', - link: `${componentsDir}button/` + text: 'General', + items: [ + { + text: 'Button', + link: `${componentsDir}button/` + } + ] }, { - text: 'ConfigProvider', - link: `${componentsDir}config-provider/` + 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/` + } + ] } ] } diff --git a/.vitepress/config/zh-CN/sidebar.ts b/.vitepress/config/zh-CN/sidebar.ts index ea4a18f..c78c294 100644 --- a/.vitepress/config/zh-CN/sidebar.ts +++ b/.vitepress/config/zh-CN/sidebar.ts @@ -3,14 +3,44 @@ const componentsDir = `/zh-CN/components/` export const getSidebar = (): DefaultTheme.Sidebar => { return { - '/zh-CN/components/': [ + [componentsDir]: [ { - text: 'Button 按钮', - link: `${componentsDir}button/` + text: '通用', + items: [ + { + text: 'Button 按钮', + link: `${componentsDir}button/` + } + ] }, { - text: 'ConfigProvider', - link: `${componentsDir}config-provider/` + text: '布局', + items: [] + }, + { + text: '导航', + items: [] + }, + { + text: '数据入录', + items: [] + }, + { + text: '数据展示', + items: [] + }, + { + text: '反馈', + items: [] + }, + { + text: '其他', + items: [ + { + text: 'ConfigProvider', + link: `${componentsDir}config-provider/` + } + ] } ] } diff --git a/components/button/demo/basic.vue b/components/button/demo/basic.vue new file mode 100644 index 0000000..91c124b --- /dev/null +++ b/components/button/demo/basic.vue @@ -0,0 +1,25 @@ + +--- +title: 按钮类型 +--- + +按钮有五种类型:主按钮、次按钮、虚线按钮、文本按钮和链接按钮。主按钮在同一个操作区域最多出现一次。 + + + +--- +title: Type +--- + +There are `primary` button, `default` button, `dashed` button, `text` button and `link` button in antd. + + + + + diff --git a/components/button/demos/basic.vue b/components/button/demos/basic.vue deleted file mode 100644 index 02a1cce..0000000 --- a/components/button/demos/basic.vue +++ /dev/null @@ -1,21 +0,0 @@ - ---- -title: 基本用法 ---- - -这是基础按钮 - - - ---- -title: Basic Button ---- - -Basic Usage Test - - - - - diff --git a/components/button/index.md b/components/button/index.md index 93d05a7..3bf78d8 100644 --- a/components/button/index.md +++ b/components/button/index.md @@ -1,4 +1,67 @@ # Button +To trigger an operation. - +## 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 + + + +## 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 + + + +## 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`. + +Button with two Chinese characters + + diff --git a/components/button/index.zh-CN.md b/components/button/index.zh-CN.md index a73de27..5491e62 100644 --- a/components/button/index.zh-CN.md +++ b/components/button/index.zh-CN.md @@ -1,4 +1,76 @@ -# 按钮 +# Button 按钮 + +按钮用于开始一个即时操作。 + +## 何时使用 + +标记了一个(或封装一组)操作命令,响应用户点击行为,触发相应的业务逻辑。 + +在 Ant Design 中我们提供了五种按钮。 + +- 主按钮:用于主行动点,一个操作区域只能有一个主按钮。 +- 默认按钮:用于没有主次之分的一组行动点。 +- 虚线按钮:常用于添加操作。 +- 文本按钮:用于最次级的行动点。 +- 链接按钮:一般用于链接,即导航至某位置。 + +以及四种状态属性与上面配合使用。 + +- 危险:删除/移动/修改权限等危险操作,一般需要二次确认。 +- 幽灵:用于背景色比较复杂的地方,常用在首页/产品页等展示场景。 +- 禁用:行动点不可用的时候,一般需要文案解释。 +- 加载中:用于异步操作等待反馈的时候,也可以避免多次提交。 + +[完整设计指南](https://ant.design/docs/spec/buttons-cn) + +## 代码演示 + + - +## 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 + + + +## FAQ + +### 如何移除两个汉字之间的空格? + +根据 Ant Design 设计规范要求,我们会在按钮内(文本按钮和链接按钮除外)只有两个汉字时自动添加空格,如果你不需要这个特性,可以设置 [ConfigProvider](/zh-CN/components/config-provider/#api) 的 `autoInsertSpaceInButton` 为 `false`。 + +移除两个汉字之间的空格 + + + +## 设计指引 + +- [我的按钮究竟该放哪儿!?| Ant Design 4.0 系列分享](https://zhuanlan.zhihu.com/p/109644406) diff --git a/components/space/style/compact.tsx b/components/space/style/compact.tsx new file mode 100644 index 0000000..48e50a2 --- /dev/null +++ b/components/space/style/compact.tsx @@ -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 = (token) => { + const { componentCls } = token + + return { + [componentCls]: { + display: 'inline-flex', + '&-block': { + display: 'flex', + width: '100%' + }, + '&-vertical': { + flexDirection: 'column' + } + } + } +} + +// ============================== Export ============================== +export default genSpaceCompactStyle diff --git a/components/space/style/index.tsx b/components/space/style/index.tsx new file mode 100644 index 0000000..2540840 --- /dev/null +++ b/components/space/style/index.tsx @@ -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 = (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) +]) diff --git a/components/theme/interface/components.ts b/components/theme/interface/components.ts index a2ccfe9..afdb22f 100644 --- a/components/theme/interface/components.ts +++ b/components/theme/interface/components.ts @@ -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