From 1a82efa5ca9ae85ad8d6f9802b89b460ed34dd38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Sat, 16 May 2020 14:43:29 +0800 Subject: [PATCH] Text support keyboard (#24195) --- components/typography/Base.tsx | 5 ++- .../__tests__/__snapshots__/demo.test.js.snap | 38 +++++++++++++++++++ components/typography/demo/basic.md | 8 ++++ components/typography/demo/text.md | 1 + components/typography/index.en-US.md | 1 + components/typography/index.zh-CN.md | 3 +- components/typography/style/index.less | 14 ++++++- 7 files changed, 66 insertions(+), 4 deletions(-) diff --git a/components/typography/Base.tsx b/components/typography/Base.tsx index e404af8983..255a5d32f6 100644 --- a/components/typography/Base.tsx +++ b/components/typography/Base.tsx @@ -56,10 +56,11 @@ export interface BlockProps extends TypographyProps { underline?: boolean; delete?: boolean; strong?: boolean; + keyboard?: boolean; } function wrapperDecorations( - { mark, code, underline, delete: del, strong }: BlockProps, + { mark, code, underline, delete: del, strong, keyboard }: BlockProps, content: React.ReactNode, ) { let currentContent = content; @@ -75,6 +76,7 @@ function wrapperDecorations( wrap(del, 'del'); wrap(code, 'code'); wrap(mark, 'mark'); + wrap(keyboard, 'kbd'); return currentContent; } @@ -433,6 +435,7 @@ class Base extends React.Component { 'delete', 'underline', 'strong', + 'keyboard', ...configConsumerProps, ]); const cssEllipsis = this.canUseCSSEllipsis(); diff --git a/components/typography/__tests__/__snapshots__/demo.test.js.snap b/components/typography/__tests__/__snapshots__/demo.test.js.snap index 70672a37fc..3fa96a6a82 100644 --- a/components/typography/__tests__/__snapshots__/demo.test.js.snap +++ b/components/typography/__tests__/__snapshots__/demo.test.js.snap @@ -80,6 +80,19 @@ exports[`renders ./components/typography/demo/basic.md correctly 1`] = ` +
+ Press + + + Esc + + + to exist... +
+
+ 按 + + + Esc + + + 键退出阅读…… +
`; @@ -707,6 +733,18 @@ exports[`renders ./components/typography/demo/text.md correctly 1`] = ` +
+ + + Ant Design + + +
+ + Press Esc to exist... + + 介绍 @@ -87,6 +91,10 @@ ReactDOM.render( + + + 按Esc键退出阅读…… + , mountNode, ); diff --git a/components/typography/demo/text.md b/components/typography/demo/text.md index 2b371fb40d..2a34918853 100644 --- a/components/typography/demo/text.md +++ b/components/typography/demo/text.md @@ -27,6 +27,7 @@ ReactDOM.render( Ant Design Ant Design Ant Design + Ant Design Ant Design Ant Design Ant Design diff --git a/components/typography/index.en-US.md b/components/typography/index.en-US.md index 56c4d687ea..8258349ec4 100644 --- a/components/typography/index.en-US.md +++ b/components/typography/index.en-US.md @@ -25,6 +25,7 @@ Basic text writing, including headings, body text, lists, and more. | editable | Editable. Can control edit state when is object | boolean \| { editing: boolean, onStart: Function, onChange: Function(string) } | false | | | ellipsis | Display ellipsis when text overflows | boolean | false | | | mark | Marked style | boolean | false | | +| keyboard | Keyboard style | boolean | false | 4.3.0 | | underline | Underlined style | boolean | false | | | onChange | Trigger when user edits the content | Function(string) | - | | | strong | Bold style | boolean | false | | diff --git a/components/typography/index.zh-CN.md b/components/typography/index.zh-CN.md index ac00e7c621..0dd187b929 100644 --- a/components/typography/index.zh-CN.md +++ b/components/typography/index.zh-CN.md @@ -19,13 +19,14 @@ cols: 1 | 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | +| code | 添加代码样式 | boolean | false | | | copyable | 是否可拷贝,为对象时可设置复制文本以回调函数 | boolean \| { text: string, onCopy: Function } | false | | | delete | 添加删除线样式 | boolean | false | | | disabled | 禁用文本 | boolean | false | | | editable | 是否可编辑,为对象时可对编辑进行控制 | boolean \| { editing: boolean, onStart: Function, onChange: Function(string) } | false | | | ellipsis | 设置自动溢出省略 | boolean | false | | | mark | 添加标记样式 | boolean | false | | -| code | 添加代码样式 | boolean | false | | +| keyboard | 添加键盘样式 | boolean | false | 4.3.0 | | underline | 添加下划线样式 | boolean | false | | | strong | 是否加粗 | boolean | false | | | type | 文本类型 | `secondary` \| `warning` \| `danger` | - | | diff --git a/components/typography/style/index.less b/components/typography/style/index.less index 9de63d6984..86b41a487a 100644 --- a/components/typography/style/index.less +++ b/components/typography/style/index.less @@ -98,8 +98,18 @@ margin: 0 0.2em; padding: 0.2em 0.4em 0.1em; font-size: 85%; - background: rgba(0, 0, 0, 0.06); - border: 1px solid rgba(0, 0, 0, 0.06); + background: rgba(150, 150, 150, 0.1); + border: 1px solid rgba(100, 100, 100, 0.2); + border-radius: 3px; + } + + kbd { + margin: 0 0.2em; + padding: 0.15em 0.4em 0.1em; + font-size: 90%; + background: rgba(150, 150, 150, 0.06); + border: 1px solid rgba(100, 100, 100, 0.2); + border-bottom-width: 2px; border-radius: 3px; }