From 409c0af1a12132a762a09d57350b50a01d80ec26 Mon Sep 17 00:00:00 2001 From: Dora <53067150+Dora-boots@users.noreply.github.com> Date: Fri, 10 Mar 2023 10:06:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20button-group-select=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=A7=92=E6=A0=87=20(#6309)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yanglu19 --- .../components/form/button-group-select.md | 46 ++++++++++++++++++- .../scss/components/_button-group.scss | 9 ++++ .../src/renderers/Form/ButtonGroupSelect.tsx | 1 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/zh-CN/components/form/button-group-select.md b/docs/zh-CN/components/form/button-group-select.md index f13a41da7..6c9e732b9 100755 --- a/docs/zh-CN/components/form/button-group-select.md +++ b/docs/zh-CN/components/form/button-group-select.md @@ -143,18 +143,60 @@ order: 6 } ``` +## 支持角标 + +按钮可支持角标,在 options 中配置 + +```schema: scope="body" +{ + "type": "form", + "api": "/api/mock2/form/saveForm", + "debug": true, + "body": [ + { + "type": "button-group-select", + "label": "选项", + "name": "type", + "options": [ + { + "label": "Option A", + "value": "a" + }, + { + "label": "Option B", + "value": "b", + "badge": { + "mode": "text", + "text": 15 + } + }, + { + "label": "Option C", + "value": "c", + "badge": { + "mode": "ribbon", + "text": "HOT" + } + } + ] + } + ] +} +``` + ## 属性表 当做选择器表单项使用时,除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置 -| 属性名 | 类型 | 默认值 | 说明 | -| -------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------- | +| 属性名 | 类型 | 默认值 | 说明 | 版本 | +| -------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------- | ------- | | type | `string` | `"button-group-select"` | 指定为 button-group-select 渲染器 | | vertical | `boolean` | `false` | 是否使用垂直模式 | | tiled | `boolean` | `false` | 是否使用平铺模式 | | btnLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 按钮样式 | | btnActiveLevel | `'link' \| 'primary' \| 'secondary' \| 'info'\|'success' \| 'warning' \| 'danger' \| 'light'\| 'dark' \| 'default'` | `"default"` | 选中按钮样式 | | options | `Array`或`Array` | | [选项组](./options#%E9%9D%99%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-options) | +| option.badge | `object` | | [角标](../badge#属性表) | `2.8.1` | | source | `string`或 [API](../../../docs/types/api) | | [动态选项组](./options#%E5%8A%A8%E6%80%81%E9%80%89%E9%A1%B9%E7%BB%84-source) | | multiple | `boolean` | `false` | [多选](./options#%E5%A4%9A%E9%80%89-multiple) | | labelField | `boolean` | `"label"` | [选项标签字段](./options#%E9%80%89%E9%A1%B9%E6%A0%87%E7%AD%BE%E5%AD%97%E6%AE%B5-labelfield) | diff --git a/packages/amis-ui/scss/components/_button-group.scss b/packages/amis-ui/scss/components/_button-group.scss index 8ab2fcb0d..faae89a73 100644 --- a/packages/amis-ui/scss/components/_button-group.scss +++ b/packages/amis-ui/scss/components/_button-group.scss @@ -25,6 +25,15 @@ } } + .#{$ns}Badge { + .#{$ns}Badge-text, + .#{$ns}Badge-dot, + .#{$ns}Badge-ribbon, + .#{$ns}Badge-dot { + z-index: 2; + } + } + .#{$ns}Button + .#{$ns}Button, .#{$ns}Button + .#{$ns}ButtonGroup, .#{$ns}ButtonGroup + .#{$ns}Button, diff --git a/packages/amis/src/renderers/Form/ButtonGroupSelect.tsx b/packages/amis/src/renderers/Form/ButtonGroupSelect.tsx index 2424d018a..004767220 100644 --- a/packages/amis/src/renderers/Form/ButtonGroupSelect.tsx +++ b/packages/amis/src/renderers/Form/ButtonGroupSelect.tsx @@ -109,6 +109,7 @@ export default class ButtonGroupControl extends React.Component< label: option[labelField || 'label'], icon: option.icon, size: option.size || size, + badge: option.badge, type: 'button', block: block },