Skip to content

Commit d305f1a

Browse files
committed
feat(tag): add new feature check-tag
- Add new component `check-tag`
1 parent 3faec50 commit d305f1a

File tree

12 files changed

+340
-1
lines changed

12 files changed

+340
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { mount } from '@vue/test-utils'
2+
import CheckTag from '../src/index.vue'
3+
4+
const AXIOM = 'Rem is the best girl'
5+
6+
describe('CheckTag.vue', () => {
7+
test('render test', async () => {
8+
const wrapper = mount(CheckTag, {
9+
slots: {
10+
default: AXIOM,
11+
},
12+
})
13+
expect(wrapper.text()).toEqual(AXIOM)
14+
15+
expect(wrapper.classes()).toContain('el-check-tag')
16+
})
17+
18+
19+
test('functionality', async () => {
20+
const wrapper = mount({
21+
template: `<el-check-tag @change="checked = !checked" :checked="checked">
22+
${AXIOM}
23+
</el-check-tag>`,
24+
components: {
25+
'el-check-tag': CheckTag,
26+
},
27+
data() {
28+
return {
29+
checked: false,
30+
}
31+
},
32+
}, {
33+
slots: {
34+
default: AXIOM,
35+
},
36+
})
37+
expect(wrapper.text()).toEqual(AXIOM)
38+
39+
await wrapper.find('.el-check-tag').trigger('click')
40+
41+
expect(wrapper.vm.checked).toBe(true)
42+
43+
await wrapper.find('.el-check-tag').trigger('click')
44+
45+
expect(wrapper.vm.checked).toBe(false)
46+
47+
})
48+
49+
50+
})

packages/check-tag/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { App } from 'vue'
2+
import CheckTag from './src/index.vue'
3+
import type { SFCWithInstall } from '@element-plus/utils/types'
4+
5+
CheckTag.install = (app: App): void => {
6+
app.component(CheckTag.name, CheckTag)
7+
}
8+
9+
const _CheckTag: SFCWithInstall<typeof CheckTag> = CheckTag
10+
11+
export default _CheckTag

packages/check-tag/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@element-plus/check-tag",
3+
"version": "0.0.0",
4+
"main": "dist/index.js",
5+
"license": "MIT",
6+
"peerDependencies": {
7+
"vue": "^3.0.7"
8+
},
9+
"devDependencies": {
10+
"@vue/test-utils": "^2.0.0-beta.3"
11+
}
12+
}

packages/check-tag/src/index.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<span
3+
:class="{
4+
'el-check-tag': true,
5+
'is-checked': checked,
6+
}"
7+
@click="onChange"
8+
>
9+
<slot></slot>
10+
</span>
11+
</template>
12+
<script lang='ts'>
13+
import { defineComponent } from 'vue'
14+
export default defineComponent({
15+
name: 'ElCheckTag',
16+
props: {
17+
checked: Boolean,
18+
},
19+
emits: ['change'],
20+
setup(props, { emit }) {
21+
22+
const onChange = () => {
23+
emit('change', !props.checked)
24+
}
25+
26+
return {
27+
onChange,
28+
}
29+
},
30+
})
31+
</script>
32+
<style scoped>
33+
</style>

packages/element-plus/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ import ElVirtualList from '@element-plus/virtual-list'
8989
import ElSpace from '@element-plus/space'
9090
import ElSkeleton from '@element-plus/skeleton'
9191
import ElSkeletonItem from '@element-plus/skeleton-item'
92+
import ElCheckTag from '@element-plus/check-tag'
93+
9294
import { use, i18n } from '@element-plus/locale'
9395
// if you encountered problems alike "Can't resolve './version'"
9496
// please run `yarn bootstrap` first
@@ -141,6 +143,7 @@ const components = [
141143
ElCheckbox,
142144
ElCheckboxButton,
143145
ElCheckboxGroup,
146+
ElCheckTag,
144147
ElCol,
145148
ElCollapse,
146149
ElCollapseItem,
@@ -255,6 +258,7 @@ export {
255258
ElCheckbox,
256259
ElCheckboxButton,
257260
ElCheckboxGroup,
261+
ElCheckTag,
258262
ElCol,
259263
ElCollapse,
260264
ElCollapseItem,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@import "mixins/mixins";
2+
@import "common/var";
3+
4+
@include b(check-tag) {
5+
background-color: $--background-color-base;
6+
border-radius: $--border-radius-base;
7+
color: $--color-info;
8+
cursor: pointer;
9+
display: inline-block;
10+
font-size: $--font-size-base;
11+
line-height: $--font-size-base;
12+
padding: 7px 15px;
13+
transition: $--all-transition;
14+
font-weight: bold;
15+
&:hover {
16+
background-color: rgb(220, 223, 230);
17+
}
18+
19+
@include when(checked) {
20+
background-color: #DEEDFC;
21+
color: $--color-primary-light-1;
22+
&:hover {
23+
background-color: $--color-primary-light-7;
24+
}
25+
}
26+
}

packages/theme-chalk/src/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@
8686
@import "./skeleton-item.scss";
8787
@import "./empty.scss";
8888
@import "./affix.scss";
89+
@import "./check-tag.scss";

website/docs/en-US/tag.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ Tag provide three different themes: `dark`、`light` and `plain`
185185
```
186186
:::
187187

188+
### Checkable tag
189+
190+
Sometimes because of the business needs, we might need checkbox like tag, but **button like checkbox** cannot meet our needs, here comes `check-tag`
191+
192+
:::demo basic check-tag usage, the API is rather simple.
193+
```html
194+
195+
<div>
196+
<el-check-tag checked style="margin-right: 8px;">Checked</el-check-tag>
197+
<el-check-tag @change="onChange" :checked="checked">Toggle me</el-check-tag>
198+
</div>
199+
200+
<script>
201+
export default {
202+
data() {
203+
return {
204+
checked: false,
205+
}
206+
},
207+
methods: {
208+
onChange(checked) {
209+
this.checked = checked;
210+
}
211+
}
212+
}
213+
</script>
214+
215+
```
216+
:::
217+
188218
### Attributes
189219
| Attribute | Description | Type | Accepted Values | Default |
190220
|---------- |-------------- |---------- |-------------------------------- |-------- |
@@ -202,3 +232,13 @@ Tag provide three different themes: `dark`、`light` and `plain`
202232
|---------- |-------- |---------- |
203233
| click | triggers when Tag is clicked ||
204234
| close | triggers when Tag is removed ||
235+
236+
### CheckTag Attributes
237+
| Attribute | Description | Type | Accepted | Default |
238+
|---------- |-------------- |---------- |-------------------------------- |-------- |
239+
| checked | is checked | boolean | true/false ||
240+
241+
### CheckTag Events
242+
| Event Name | Description | Parameters |
243+
|---------- |-------- |---------- |
244+
| change | triggers when Check Tag is clicked | checked |

website/docs/es/tag.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Se utiliza para marcar y seleccionar.
1717

1818
### Etiqueta removible
1919

20-
:::demo el atributo `closable` puede usarse para definir una etiqueta removible. Acepta un `Boolean`. De forma predeterminada, la eliminación de la etiqueta tiene una animación que se desvanece. Si no quiere usarlo, puede configurar el atributo `disable-transitions` , que acepta `Boolean`, como `true`. Se dispara el evento `close` cuando la etiqueta es removida.
20+
:::demo el atributo `closable` puede usarse para definir una etiqueta removible. Acepta un `Boolean`. De forma predeterminada, la eliminación de la etiqueta tiene una animación que se desvanece. Si no quiere usarlo, puede configurar el atributo `disable-transitions` , que acepta `Boolean`, como `true`. Se dispara el evento `close` cuando la etiqueta es removida.
2121

2222
```html
2323
<el-tag
@@ -184,6 +184,36 @@ Tag provide three different themes: `dark`、`light` and `plain`
184184
```
185185
:::
186186

187+
### Checkable tag
188+
189+
Sometimes because of the business needs, we might need checkbox like tag, but **button like checkbox** cannot meet our needs, here comes `check-tag`
190+
191+
:::demo basic check-tag usage, the API is rather simple.
192+
```html
193+
194+
<div>
195+
<el-check-tag checked style="margin-right: 8px;">Checked</el-check-tag>
196+
<el-check-tag @change="onChange" :checked="checked">Toggle me</el-check-tag>
197+
</div>
198+
199+
<script>
200+
export default {
201+
data() {
202+
return {
203+
checked: false,
204+
}
205+
},
206+
methods: {
207+
onChange(checked) {
208+
this.checked = checked;
209+
}
210+
}
211+
}
212+
</script>
213+
214+
```
215+
:::
216+
187217
### Atributos
188218
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
189219
| ------------------- | ----------------------------------- | ------- | --------------------------- | ----------- |
@@ -201,3 +231,13 @@ Tag provide three different themes: `dark`、`light` and `plain`
201231
| ------ | ------------------------------------ | ---------- |
202232
| click | se dispara cuando el Tag es clic ||
203233
| close | se dispara cuando el Tag es removido ||
234+
235+
### CheckTag Atributos
236+
| Attribute | Description | Type | Accepted | Default |
237+
|---------- |-------------- |---------- |-------------------------------- |-------- |
238+
| checked | is checked | boolean | true/false ||
239+
240+
### CheckTag Eventos
241+
| Event Name | Description | Parameters |
242+
|---------- |-------- |---------- |
243+
| change | triggers when Check Tag is clicked | checked |

website/docs/fr-FR/tag.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,37 @@ Les balises utilisent trois thèmes différents: `dark`, `light` et `plain`
184184
```
185185
:::
186186

187+
### Checkable tag
188+
189+
Sometimes because of the business needs, we might need checkbox like tag, but **button like checkbox** cannot meet our needs, here comes `check-tag`
190+
191+
:::demo basic check-tag usage, the API is rather simple.
192+
```html
193+
194+
<div>
195+
<el-check-tag checked style="margin-right: 8px;">Checked</el-check-tag>
196+
<el-check-tag @change="onChange" :checked="checked">Toggle me</el-check-tag>
197+
</div>
198+
199+
<script>
200+
export default {
201+
data() {
202+
return {
203+
checked: false,
204+
}
205+
},
206+
methods: {
207+
onChange(checked) {
208+
this.checked = checked;
209+
}
210+
}
211+
}
212+
</script>
213+
214+
```
215+
:::
216+
217+
187218
### Attributs
188219

189220
| Attribut | Description | Type | Valeurs acceptées | Défaut |
@@ -202,3 +233,13 @@ Les balises utilisent trois thèmes différents: `dark`, `light` et `plain`
202233
|---------- |-------- |---------- |
203234
| click | Se déclenche quand le tag est cliqué. ||
204235
| close | Se déclenche quand le tag est supprimé. ||
236+
237+
### CheckTag Attributs
238+
| Attribute | Description | Type | Accepted | Default |
239+
|---------- |-------------- |---------- |-------------------------------- |-------- |
240+
| checked | is checked | boolean | true/false ||
241+
242+
### CheckTag Évènements
243+
| Event Name | Description | Parameters |
244+
|---------- |-------- |---------- |
245+
| change | triggers when Check Tag is clicked | checked |

0 commit comments

Comments
 (0)