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..cc2ffe89 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..ea6fd054 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,15 +25,13 @@ 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..c8df1f85 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..fcc65940 --- /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..ed06428f 100644 --- a/src/tag/_example/index.jsx +++ b/src/tag/_example/index.jsx @@ -1,32 +1,64 @@ 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 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 ( <> - - - - - + + +
+ +
+
+ +
+
+ +
+ +
+
+ +
+ +
- +
+ +
+
+ +
+ +
- +
+ +
- +
+ +
+ +
+ 点击标签30 + 点击标签24 +
); diff --git a/src/tag/_example/shape.jsx b/src/tag/_example/shape.jsx index 303d8804..cfbe243d 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..164cc8fb 100644 --- a/src/tag/_example/size.jsx +++ b/src/tag/_example/size.jsx @@ -1,25 +1,18 @@ import React from 'react'; import { Tag } from 'tdesign-mobile-react'; -import { TagCheck } from 'tdesign-mobile-react'; -const Size =() => ( -
-
- - 展示标签大号 - - - 展示标签中号 - - - 展示标签小号 - -
-
- 点击标签大号 - 点击标签中号 -
-
+const SizeDemo = () => ( + <> + + 展示标签30 + + + 展示标签24 + + + 展示标签20 + + ); -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..441db18a 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..1731138a 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;