Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tag): update style #270

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/tag/CheckTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const TagCheck: React.FC<TagCheckProps> = React.memo(
const checkTagClass = classNames(
`${baseClass}`,
`${baseClass}--checkable`,
`${baseClass}--${shape}`,
`${baseClass}--shape-${shape}`,
`${baseClass}--size-${size}`,
{
[`${classPrefix}-is-closable ${baseClass}--closable`]: closable,
Expand Down Expand Up @@ -70,11 +70,15 @@ const TagCheck: React.FC<TagCheckProps> = React.memo(
};

return (
<button className={checkTagClass} style={tagStyle} onClick={handleClick} ref={ref} disabled={disabled} {...other}>
<span className={checkTagClass} style={tagStyle} onClick={handleClick} ref={ref} {...other}>
<span className={`${baseClass}__icon`}>{icon}</span>
<span className={`${baseClass}__text`}>{content || children}</span>
{closable ? <Icon name="close" className={`${baseClass}__close`} onClick={handleClose} /> : null}
</button>
{closable ? (
<span className={`${baseClass}__icon-close`} onClick={handleClose}>
<Icon name="close" />
</span>
) : null}
</span>
);
}),
);
Expand Down
20 changes: 10 additions & 10 deletions src/tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Tag = forwardRef<HTMLDivElement, TagProps>((props, ref) => {
content = null,
disabled = false,
icon = undefined,
maxWidth = '',
maxWidth,
children = '',
shape = 'square',
size = 'medium',
Expand All @@ -30,19 +30,15 @@ const Tag = forwardRef<HTMLDivElement, TagProps>((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,
},
Expand All @@ -51,7 +47,7 @@ const Tag = forwardRef<HTMLDivElement, TagProps>((props, ref) => {

const tagStyle = {
...style,
maxWidth,
maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
};

const getRenderContent = useCallback(() => {
Expand Down Expand Up @@ -85,7 +81,11 @@ const Tag = forwardRef<HTMLDivElement, TagProps>((props, ref) => {
<span className={tagClassNames} style={tagStyle} onClick={handleClick} ref={ref} {...other}>
<span className={`${baseClass}__icon`}>{icon}</span>
<span className={`${baseClass}__text`}>{getRenderContent() || children}</span>
{closable ? <Icon name="close" className={`${baseClass}__close`} onClick={onClickClose} /> : null}
{closable ? (
<span className={`${baseClass}__icon-close`} onClick={onClickClose}>
<Icon name="close" />
</span>
) : null}
</span>
);
});
Expand Down
49 changes: 31 additions & 18 deletions src/tag/_example/checkable.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="t-tag__demo-block t-tag__demo-common">
<TagCheck defaultChecked onChange={handleOnChange}>
已点击
</TagCheck>
<TagCheck onChange={handleChange} checked={checked}>
未点击
</TagCheck>
<TagCheck disabled> 不可点击</TagCheck>
</div>
<>
{tagChecks.map((item, index) => (
<TagCheck key={index} checked={item.checked} disabled={item.disabled} onClick={() => onClick(index)}>
{item.name}
</TagCheck>
))}
</>
);
};

export default ClickableUse;
export default CheckeableDemo;
22 changes: 13 additions & 9 deletions src/tag/_example/closable.jsx
Original file line number Diff line number Diff line change
@@ -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: <Icon name="app" />,
},
];
const ClosableDemo = () => {
const [tags, setTags] = useState(TagOptions);
Expand All @@ -19,15 +25,13 @@ const ClosableDemo = () => {
};

return (
<div className="t-tag__demo-block">
{tags.map((opt, dex) => {
return (
<Tag key={dex} theme="primary" closable size={opt.size} onClose={() => onClose(dex)}>
标签
</Tag>
);
})}
</div>
<>
{tags.map((item, index) => (
<Tag key={index} theme="primary" closable size={item.size} icon={item.icon} onClose={() => onClose(index)}>
标签
</Tag>
))}
</>
);
};

Expand Down
20 changes: 5 additions & 15 deletions src/tag/_example/ellipsis.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React from 'react';
import { Tag } from 'tdesign-mobile-react';

const Ellipsis = () => (
<div className="t-tag__demo-common">
<div className="t-tag__demo-block">
<Tag theme="primary" maxWidth="80px">
标签标签标签标签标签标签标签标签标签标签标签
</Tag>
<Tag theme="primary" size="middle" maxWidth="80px">
标签标签标签标签标签标签标签标签标签标签
</Tag>
<Tag theme="primary" size="small" maxWidth="80px">
标签标签标签标签标签标签标签标签标签
</Tag>
</div>
</div>
const EllipsisDemo = () => (
<>
<Tag maxWidth={130}>听说超长可以省略听说超长</Tag>
</>
);

export default Ellipsis;
export default EllipsisDemo;
13 changes: 13 additions & 0 deletions src/tag/_example/icon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { Tag } from 'tdesign-mobile-react';
import { Icon } from 'tdesign-icons-react';

const IconDemo = () => (
<>
<Tag theme="primary" shape="round" icon={<Icon name="app" />}>
标签
</Tag>
</>
);

export default IconDemo;
58 changes: 45 additions & 13 deletions src/tag/_example/index.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<TDemoHeader title="Tag标签" summary="用于标记表示主体属性、类型、状态等,由底部图形和标签文字组成" />
<TDemoBlock title="01类型" summary="展示型标签">
<Theme />
<Variant />
<Shape />
<TDemoHeader title="Tag 标签" summary="用于标记表示主体属性、类型、状态等,由底部图形和标签文字组成" />
<TDemoBlock title="01类型" summary="基础标签">
<div className="tag-demo">
<ThemeDemo />
</div>
<div className="tag-demo">
<VariantDemo />
</div>
</TDemoBlock>
<TDemoBlock summary="带图标标签">
<div className="tag-demo">
<IconDemo />
</div>
</TDemoBlock>
<TDemoBlock summary="圆角标签">
<div className="tag-demo">
<ShapeDemo />
</div>
</TDemoBlock>
<TDemoBlock summary="可关闭标签">
<ClosableDemo />
<div className="tag-demo">
<ClosableDemo />
</div>
</TDemoBlock>
<TDemoBlock summary="超长省略标签">
<div className="tag-demo">
<EllipsisDemo />
</div>
</TDemoBlock>
<TDemoBlock title="02 状态" summary="标签状态">
<ClickableUse />
<div className="tag-demo">
<CheckeableDemo />
</div>
</TDemoBlock>
<TDemoBlock title="03 规格" summary="标签规格">
<Size />
<div className="group padding-bottom d-flex">
<SizeDemo />
</div>

<div className="group d-flex">
<TagCheck size="large">点击标签30</TagCheck>
<TagCheck size="medium">点击标签24</TagCheck>
</div>
</TDemoBlock>
</>
);
Expand Down
12 changes: 6 additions & 6 deletions src/tag/_example/shape.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import { Tag } from 'tdesign-mobile-react';

const Shape = () => (
<div className="t-tag__demo-block t-tag__demo-common">
const ShapeDemo = () => (
<>
<Tag theme="primary" shape="round">
圆角标签
圆弧
</Tag>
<Tag theme="primary" shape="mark">
半圆角标签
半圆弧
</Tag>
</div>
</>
);

export default Shape;
export default ShapeDemo;
33 changes: 13 additions & 20 deletions src/tag/_example/size.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import React from 'react';
import { Tag } from 'tdesign-mobile-react';
import { TagCheck } from 'tdesign-mobile-react';

const Size =() => (
<div className="t-tag__demo-block">
<div className="t-tag__demo-size">
<Tag theme="primary" size="large">
展示标签大号
</Tag>
<Tag theme="primary" size="middle">
展示标签中号
</Tag>
<Tag theme="primary" size="small">
展示标签小号
</Tag>
</div>
<div className="t-tag__demo-size ">
<TagCheck size="large">点击标签大号</TagCheck>
<TagCheck size="middle">点击标签中号</TagCheck>
</div>
</div>
const SizeDemo = () => (
<>
<Tag theme="primary" size="large">
展示标签30
</Tag>
<Tag theme="primary" size="medium">
展示标签24
</Tag>
<Tag theme="primary" size="small">
展示标签20
</Tag>
</>
);

export default Size;
export default SizeDemo;
Loading