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

feat(check-tag): enable props shape and closable #2365

Merged
merged 2 commits into from
Mar 29, 2024
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
16 changes: 16 additions & 0 deletions src/check-tag/check-tag.less
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
@tag-extra-large-height: var(--td-tag-extra-large-height, 80rpx);

@tag-square-border-radius: var(--td-tag-square-border-radius, 8rpx);
@tag-round-border-radius: var(--td-tag-round-border-radius, 999px);
@tag-mark-border-radius: var(--td-tag-mark-border-radius, @tag-round-border-radius);

.genVariant(@variant) {
@themes: default, primary, success, warning, danger;
Expand Down Expand Up @@ -132,6 +134,20 @@
}
}

&.@{prefix}-tag {
&--square {
border-radius: @tag-square-border-radius;
}

&--round {
border-radius: @tag-round-border-radius;
}

&--mark {
border-radius: 0 @tag-mark-border-radius @tag-mark-border-radius 0;
}
}

&--dark {
.genVariant(dark);
&.@{prefix}-tag--default {
Expand Down
8 changes: 7 additions & 1 deletion src/check-tag/check-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class CheckTag extends SuperComponent {
methods = {
setClass() {
const { classPrefix } = this.data;
const { size, variant, disabled, checked } = this.properties;
const { size, variant, disabled, checked, shape } = this.properties;
const tagClass = [
classPrefix,
`${classPrefix}--checkable`,
Expand All @@ -58,6 +58,7 @@ export default class CheckTag extends SuperComponent {
`${classPrefix}--${checked ? 'primary' : 'default'}`,
`${classPrefix}--${size}`,
`${classPrefix}--${variant}`,
`${classPrefix}--${shape}`,
];
const className = classNames(tagClass);
this.setData({
Expand All @@ -72,5 +73,10 @@ export default class CheckTag extends SuperComponent {
this._trigger('click');
this._trigger('change', { checked: !checked });
},

onClose(e: WechatMiniprogram.BaseEvent) {
if (this.data.disabled) return;
this._trigger('close', e);
},
};
}
9 changes: 9 additions & 0 deletions src/check-tag/check-tag.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
<block wx:if="{{_.isArray(content) && content.length == 2}}">{{checked ? content[0] : content[1]}}</block>
<block wx:else>{{content}}</block>
</view>
<t-icon
wx:if="{{ closable }}"
class="{{classPrefix}}__icon-close"
t-class="{{prefix}}-icon"
catch:tap="onClose"
name="close"
aria-role="button"
aria-label="关闭"
/>
</view>
4 changes: 2 additions & 2 deletions src/check-tag/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const props: TdCheckTagProps = {
type: null,
value: undefined,
},
/** 已废弃。标签是否可关闭 */
/** 标签是否可关闭 */
closable: {
type: Boolean,
value: false,
Expand All @@ -43,7 +43,7 @@ const props: TdCheckTagProps = {
icon: {
type: null,
},
/** 已废弃。标签类型,有三种:方形、圆角方形、标记型 */
/** 标签类型,有三种:方形、圆角方形、标记型 */
shape: {
type: String,
value: 'square',
Expand Down
5 changes: 3 additions & 2 deletions src/tag/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ name | type | default | description | required
-- | -- | -- | -- | --
checked | Boolean | undefined | \- | N
default-checked | Boolean | undefined | uncontrolled property | N
closable | Boolean | false | `deprecated` | N
closable | Boolean | false | \- | N
content | String / Number / Array / Slot | - | Typescript:`string \| number \| string[]` | N
disabled | Boolean | false | \- | N
external-classes | Array | - | `['t-class']` | N
icon | String / Object / Slot | - | \- | N
shape | String | square | `deprecated`。options:square/round/mark | N
shape | String | square | options:square/round/mark | N
size | String | medium | options:small/medium/large。Typescript:`SizeEnum` | N
variant | String | dark | `0.26.0`。options:dark/light/outline/light-outline | N

Expand All @@ -43,6 +43,7 @@ name | params | description
-- | -- | --
change | `(checked: boolean)` | \-
click | - | \-
close | - | \-


### CSS Variables
Expand Down
5 changes: 3 additions & 2 deletions src/tag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ t-class | 根节点样式类
-- | -- | -- | -- | --
checked | Boolean | undefined | 标签选中的状态,默认风格(theme=default)才有选中态 | N
default-checked | Boolean | undefined | 标签选中的状态,默认风格(theme=default)才有选中态。非受控属性 | N
closable | Boolean | false | 已废弃。标签是否可关闭 | N
closable | Boolean | false | 标签是否可关闭 | N
content | String / Number / Array / Slot | - | 组件子元素;传入数组时:[选中内容,非选中内容]。TS 类型:`string \| number \| string[]` | N
disabled | Boolean | false | 标签禁用态,失效标签不能触发事件。默认风格(theme=default)才有禁用态 | N
icon | String / Object / Slot | - | 标签图标 | N
shape | String | square | 已废弃。标签类型,有三种:方形、圆角方形、标记型。可选项:square/round/mark | N
shape | String | square | 标签类型,有三种:方形、圆角方形、标记型。可选项:square/round/mark | N
size | String | medium | 标签尺寸。可选项:small/medium/large。TS 类型:`SizeEnum` | N
variant | String | dark | `0.26.0`。标签风格变体。可选项:dark/light/outline/light-outline | N

Expand All @@ -88,6 +88,7 @@ variant | String | dark | `0.26.0`。标签风格变体。可选项:dark/light
-- | -- | --
change | `(checked: boolean)` | 状态切换时触发
click | - | 点击标签时触发
close | - | 如果关闭按钮存在,点击关闭按钮时触发

### CheckTag 外部样式类
类名 | 说明
Expand Down
Loading