From 7f8fe66324a391fea719bd5d9d726ce2b61a5921 Mon Sep 17 00:00:00 2001 From: anlyyao Date: Mon, 11 Jul 2022 15:31:07 +0800 Subject: [PATCH 1/2] fix(tag): update style --- src/tag/CheckTag.tsx | 12 +++++--- src/tag/Tag.tsx | 20 ++++++------- src/tag/_example/checkable.jsx | 47 ++++++++++++++++++++----------- src/tag/_example/closable.jsx | 20 +++++++------ src/tag/_example/ellipsis.jsx | 18 +++--------- src/tag/_example/icon.jsx | 13 +++++++++ src/tag/_example/index.jsx | 34 ++++++++++++++-------- src/tag/_example/shape.jsx | 10 +++---- src/tag/_example/size.jsx | 25 ++++++++-------- src/tag/_example/style/index.less | 44 +++++++++++++++++------------ src/tag/_example/theme.jsx | 14 ++++----- src/tag/_example/variant.jsx | 17 ++++++----- 12 files changed, 159 insertions(+), 115 deletions(-) create mode 100644 src/tag/_example/icon.jsx diff --git a/src/tag/CheckTag.tsx b/src/tag/CheckTag.tsx index b79c7bd2..2127a57e 100644 --- a/src/tag/CheckTag.tsx +++ b/src/tag/CheckTag.tsx @@ -39,7 +39,7 @@ const TagCheck: React.FC = React.memo( const checkTagClass = classNames( `${baseClass}`, `${baseClass}--checkable`, - `${baseClass}--${shape}`, + `${baseClass}--shape-${shape}`, `${baseClass}--size-${size}`, { [`${classPrefix}-is-closable ${baseClass}--closable`]: closable, @@ -70,11 +70,15 @@ const TagCheck: React.FC = React.memo( }; return ( - + {closable ? ( + + + + ) : null} + ); }), ); diff --git a/src/tag/Tag.tsx b/src/tag/Tag.tsx index 1d11375c..fef07567 100644 --- a/src/tag/Tag.tsx +++ b/src/tag/Tag.tsx @@ -18,7 +18,7 @@ const Tag = forwardRef((props, ref) => { content = null, disabled = false, icon = undefined, - maxWidth = '', + maxWidth, children = '', shape = 'square', size = 'medium', @@ -30,19 +30,15 @@ const Tag = forwardRef((props, ref) => { } = props; const { classPrefix } = useConfig(); - const baseClass = `${classPrefix}-tag`; const tagClassNames = classNames( `${baseClass}`, - `${baseClass}-${theme}`, - `${baseClass}--${shape}`, - `${baseClass}-${variant}`, + `${baseClass}--theme-${theme}`, + `${baseClass}--shape-${shape}`, + `${baseClass}--variant-${variant}`, `${baseClass}--size-${size}`, { - [`${classPrefix}-is-error`]: theme === 'danger', - [`${classPrefix}-is-success`]: theme === 'success', - [`${classPrefix}-is-warning`]: theme === 'warning', [`${classPrefix}-is-closable ${baseClass}--closable`]: closable, [`${classPrefix}-is-disabled ${baseClass}--disabled`]: disabled, }, @@ -51,7 +47,7 @@ const Tag = forwardRef((props, ref) => { const tagStyle = { ...style, - maxWidth, + maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth, }; const getRenderContent = useCallback(() => { @@ -85,7 +81,11 @@ const Tag = forwardRef((props, ref) => { {icon} {getRenderContent() || children} - {closable ? : null} + {closable ? ( + + + + ) : null} ); }); diff --git a/src/tag/_example/checkable.jsx b/src/tag/_example/checkable.jsx index 29f6f641..381392af 100644 --- a/src/tag/_example/checkable.jsx +++ b/src/tag/_example/checkable.jsx @@ -1,27 +1,40 @@ import React, { useState } from 'react'; import { TagCheck } from 'tdesign-mobile-react'; -const ClickableUse = () => { - const [checked, setChecked] = useState(false); +const TagChecksOptions = [ + { + name: '选中', + checked: true, + }, + { + name: '未选中', + checked: false, + }, + { + name: '不可选', + checked: false, + disabled: true, + }, +]; - const handleOnChange = (v) => { - console.log('on checked', v); - }; - const handleChange = (v) => { - console.log('to checked', v); - setChecked(v); +const CheckeableDemo = () => { + const [tagChecks, setTagChecks] = useState(TagChecksOptions); + + const onClick = (tagCheckIndex) => { + const shallowClone = [...tagChecks]; + shallowClone[tagCheckIndex].checked = !shallowClone[tagCheckIndex].checked; + setTagChecks([...shallowClone]); }; + return ( -
- - 已点击 - - - 未点击 - - 不可点击 +
+ {tagChecks.map((item, index) => ( + onClick(index)}> + {item.name} + + ))}
); }; -export default ClickableUse; +export default CheckeableDemo; diff --git a/src/tag/_example/closable.jsx b/src/tag/_example/closable.jsx index f1d1cbde..516f2d5e 100644 --- a/src/tag/_example/closable.jsx +++ b/src/tag/_example/closable.jsx @@ -1,11 +1,17 @@ import React, { useState } from 'react'; import { Tag } from 'tdesign-mobile-react'; +import { Icon } from 'tdesign-icons-react'; const TagOptions = [ { size: 'medium', name: '标签', }, + { + name: '标签', + size: 'medium', + icon: , + }, ]; const ClosableDemo = () => { const [tags, setTags] = useState(TagOptions); @@ -19,14 +25,12 @@ const ClosableDemo = () => { }; return ( -
- {tags.map((opt, dex) => { - return ( - onClose(dex)}> - 标签 - - ); - })} +
+ {tags.map((item, index) => ( + onClose(index)}> + 标签 + + ))}
); }; diff --git a/src/tag/_example/ellipsis.jsx b/src/tag/_example/ellipsis.jsx index 7af87e32..7c4e152b 100644 --- a/src/tag/_example/ellipsis.jsx +++ b/src/tag/_example/ellipsis.jsx @@ -1,20 +1,10 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; -const Ellipsis = () => ( -
-
- - 标签标签标签标签标签标签标签标签标签标签标签 - - - 标签标签标签标签标签标签标签标签标签标签 - - - 标签标签标签标签标签标签标签标签标签 - -
+const EllipsisDemo = () => ( +
+ 听说超长可以省略听说超长
); -export default Ellipsis; +export default EllipsisDemo; diff --git a/src/tag/_example/icon.jsx b/src/tag/_example/icon.jsx new file mode 100644 index 00000000..2880755f --- /dev/null +++ b/src/tag/_example/icon.jsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { Tag } from 'tdesign-mobile-react'; +import { Icon } from 'tdesign-icons-react'; + +const IconDemo = () => ( +
+ }> + 标签 + +
+); + +export default IconDemo; diff --git a/src/tag/_example/index.jsx b/src/tag/_example/index.jsx index 82eff2fa..73ec8e77 100644 --- a/src/tag/_example/index.jsx +++ b/src/tag/_example/index.jsx @@ -1,32 +1,42 @@ import React from 'react'; import TDemoBlock from '../../../site/mobile/components/DemoBlock'; import TDemoHeader from '../../../site/mobile/components/DemoHeader'; -import ClickableUse from './checkable'; -import Shape from './shape'; +import CheckeableDemo from './checkable'; +import ShapeDemo from './shape'; import ClosableDemo from './closable'; -import Theme from './theme'; -import Variant from './variant'; -import Size from './size'; +import ThemeDemo from './theme'; +import VariantDemo from './variant'; +import SizeDemo from './size'; +import EllipsisDemo from './ellipsis'; import './style/index.less'; +import IconDemo from './icon'; export default function Base() { return ( <> - - - - - + + + + + + + + + + + + + - + - + ); diff --git a/src/tag/_example/shape.jsx b/src/tag/_example/shape.jsx index 303d8804..e4e5e436 100644 --- a/src/tag/_example/shape.jsx +++ b/src/tag/_example/shape.jsx @@ -1,15 +1,15 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; -const Shape = () => ( -
+const ShapeDemo = () => ( +
- 圆角标签 + 圆弧 - 半圆角标签 + 半圆弧
); -export default Shape; +export default ShapeDemo; diff --git a/src/tag/_example/size.jsx b/src/tag/_example/size.jsx index dcbcf3b6..c16c5f53 100644 --- a/src/tag/_example/size.jsx +++ b/src/tag/_example/size.jsx @@ -1,25 +1,24 @@ import React from 'react'; -import { Tag } from 'tdesign-mobile-react'; -import { TagCheck } from 'tdesign-mobile-react'; +import { Tag, TagCheck } from 'tdesign-mobile-react'; -const Size =() => ( -
-
+const SizeDemo = () => ( +
+
- 展示标签大号 + 展示标签30 - - 展示标签中号 + + 展示标签24 - 展示标签小号 + 展示标签20
-
- 点击标签大号 - 点击标签中号 +
+ 点击标签30 + 点击标签24
); -export default Size; +export default SizeDemo; diff --git a/src/tag/_example/style/index.less b/src/tag/_example/style/index.less index 35afd69f..3aa8c663 100644 --- a/src/tag/_example/style/index.less +++ b/src/tag/_example/style/index.less @@ -1,25 +1,33 @@ -.t-tag__demo { - &-block { - background-color: rgba(255, 255, 255, 1); - padding: 16px; - display: flex; - &:not(:last-child) { - margin-bottom: 16px; - } - } - &-theme > span { - margin-right: 8px; +.tag-demo { + background-color: #fff; + padding: 16px; + display: flex; + + .t-tag + .t-tag { + margin-left: 16px; } +} + +.tag-demo + .tag-demo { + margin-top: 16px; +} - &-size > span, - &-size > button { - flex-direction: row; +.group { + padding: 16px; + background-color: #fff; + display: flex; + align-items: center; - margin-right: 48px; - margin-bottom: 18px; + &.d-flex { + display: flex; + align-items: flex-start; } - &-common > button, - &-common > span { + + &.padding-bottom { + padding: 16px 16px 0; + } + + .t-tag { margin-right: 16px; } } diff --git a/src/tag/_example/theme.jsx b/src/tag/_example/theme.jsx index bfd3f6bf..0acda07e 100644 --- a/src/tag/_example/theme.jsx +++ b/src/tag/_example/theme.jsx @@ -1,14 +1,14 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; -const Theme = () => ( -
+const ThemeDemo = () => ( +
标签 - 成功 - 警告 - 危险 - 信息 + 标签 + 标签 + 标签 + 标签
); -export default Theme; +export default ThemeDemo; diff --git a/src/tag/_example/variant.jsx b/src/tag/_example/variant.jsx index ddf763a0..b2706fa1 100644 --- a/src/tag/_example/variant.jsx +++ b/src/tag/_example/variant.jsx @@ -1,18 +1,21 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; -const Variant = () => ( -
- - 镂空标签 +const VariantDemo = () => ( +
+ + 深色 - 浅底标签 + 浅色 + + + 描边 - 标签 + 浅色描边
); -export default Variant; +export default VariantDemo; From 22929486705e34080fda32d5f09c3d1ffcb64e8e Mon Sep 17 00:00:00 2001 From: anlyyao Date: Tue, 12 Jul 2022 13:48:07 +0800 Subject: [PATCH 2/2] style(tag): adjust demo --- src/tag/_example/checkable.jsx | 4 ++-- src/tag/_example/closable.jsx | 4 ++-- src/tag/_example/ellipsis.jsx | 4 ++-- src/tag/_example/icon.jsx | 4 ++-- src/tag/_example/index.jsx | 38 +++++++++++++++++++++++++++------- src/tag/_example/shape.jsx | 4 ++-- src/tag/_example/size.jsx | 30 +++++++++++---------------- src/tag/_example/theme.jsx | 4 ++-- src/tag/_example/variant.jsx | 4 ++-- 9 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/tag/_example/checkable.jsx b/src/tag/_example/checkable.jsx index 381392af..cc2ffe89 100644 --- a/src/tag/_example/checkable.jsx +++ b/src/tag/_example/checkable.jsx @@ -27,13 +27,13 @@ const CheckeableDemo = () => { }; return ( -
+ <> {tagChecks.map((item, index) => ( onClick(index)}> {item.name} ))} -
+ ); }; diff --git a/src/tag/_example/closable.jsx b/src/tag/_example/closable.jsx index 516f2d5e..ea6fd054 100644 --- a/src/tag/_example/closable.jsx +++ b/src/tag/_example/closable.jsx @@ -25,13 +25,13 @@ const ClosableDemo = () => { }; return ( -
+ <> {tags.map((item, index) => ( onClose(index)}> 标签 ))} -
+ ); }; diff --git a/src/tag/_example/ellipsis.jsx b/src/tag/_example/ellipsis.jsx index 7c4e152b..c8df1f85 100644 --- a/src/tag/_example/ellipsis.jsx +++ b/src/tag/_example/ellipsis.jsx @@ -2,9 +2,9 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; const EllipsisDemo = () => ( -
+ <> 听说超长可以省略听说超长 -
+ ); export default EllipsisDemo; diff --git a/src/tag/_example/icon.jsx b/src/tag/_example/icon.jsx index 2880755f..fcc65940 100644 --- a/src/tag/_example/icon.jsx +++ b/src/tag/_example/icon.jsx @@ -3,11 +3,11 @@ import { Tag } from 'tdesign-mobile-react'; import { Icon } from 'tdesign-icons-react'; const IconDemo = () => ( -
+ <> }> 标签 -
+ ); export default IconDemo; diff --git a/src/tag/_example/index.jsx b/src/tag/_example/index.jsx index 73ec8e77..ed06428f 100644 --- a/src/tag/_example/index.jsx +++ b/src/tag/_example/index.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import { TagCheck } from 'tdesign-mobile-react'; import TDemoBlock from '../../../site/mobile/components/DemoBlock'; import TDemoHeader from '../../../site/mobile/components/DemoHeader'; import CheckeableDemo from './checkable'; @@ -17,26 +18,47 @@ export default function Base() { <> - - +
+ +
+
+ +
- +
+ +
- +
+ +
- +
+ +
- +
+ +
- +
+ +
- +
+ +
+ +
+ 点击标签30 + 点击标签24 +
); diff --git a/src/tag/_example/shape.jsx b/src/tag/_example/shape.jsx index e4e5e436..cfbe243d 100644 --- a/src/tag/_example/shape.jsx +++ b/src/tag/_example/shape.jsx @@ -2,14 +2,14 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; const ShapeDemo = () => ( -
+ <> 圆弧 半圆弧 -
+ ); export default ShapeDemo; diff --git a/src/tag/_example/size.jsx b/src/tag/_example/size.jsx index c16c5f53..164cc8fb 100644 --- a/src/tag/_example/size.jsx +++ b/src/tag/_example/size.jsx @@ -1,24 +1,18 @@ import React from 'react'; -import { Tag, TagCheck } from 'tdesign-mobile-react'; +import { Tag } from 'tdesign-mobile-react'; const SizeDemo = () => ( -
-
- - 展示标签30 - - - 展示标签24 - - - 展示标签20 - -
-
- 点击标签30 - 点击标签24 -
-
+ <> + + 展示标签30 + + + 展示标签24 + + + 展示标签20 + + ); export default SizeDemo; diff --git a/src/tag/_example/theme.jsx b/src/tag/_example/theme.jsx index 0acda07e..441db18a 100644 --- a/src/tag/_example/theme.jsx +++ b/src/tag/_example/theme.jsx @@ -2,13 +2,13 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; const ThemeDemo = () => ( -
+ <> 标签 标签 标签 标签 标签 -
+ ); export default ThemeDemo; diff --git a/src/tag/_example/variant.jsx b/src/tag/_example/variant.jsx index b2706fa1..1731138a 100644 --- a/src/tag/_example/variant.jsx +++ b/src/tag/_example/variant.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; const VariantDemo = () => ( -
+ <> 深色 @@ -15,7 +15,7 @@ const VariantDemo = () => ( 浅色描边 -
+ ); export default VariantDemo;