mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 06:59:15 +08:00
docs(Icon): support copy icon name (#4409)
This commit is contained in:
parent
3fd40d7929
commit
cb92d0a6a2
@ -1,36 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<demo-section>
|
<demo-section>
|
||||||
<van-tabs
|
<van-tabs v-model="tab" sticky :color="BLUE">
|
||||||
v-model="tab"
|
|
||||||
sticky
|
|
||||||
:color="BLUE"
|
|
||||||
>
|
|
||||||
<van-tab title="基础图标">
|
<van-tab title="基础图标">
|
||||||
<van-col
|
<van-col v-for="icon in icons.basic" :key="icon" span="6" @click="copy(icon)">
|
||||||
v-for="icon in icons.basic"
|
|
||||||
:key="icon"
|
|
||||||
span="6"
|
|
||||||
>
|
|
||||||
<van-icon :name="icon" />
|
<van-icon :name="icon" />
|
||||||
<span>{{ icon }}</span>
|
<span>{{ icon }}</span>
|
||||||
</van-col>
|
</van-col>
|
||||||
</van-tab>
|
</van-tab>
|
||||||
<van-tab title="线框风格">
|
<van-tab title="线框风格">
|
||||||
<van-col
|
<van-col v-for="icon in icons.outline" :key="icon" span="6" @click="copy(icon)">
|
||||||
v-for="icon in icons.outline"
|
|
||||||
:key="icon"
|
|
||||||
span="6"
|
|
||||||
>
|
|
||||||
<van-icon :name="icon" />
|
<van-icon :name="icon" />
|
||||||
<span>{{ icon }}</span>
|
<span>{{ icon }}</span>
|
||||||
</van-col>
|
</van-col>
|
||||||
</van-tab>
|
</van-tab>
|
||||||
<van-tab title="实底风格">
|
<van-tab title="实底风格">
|
||||||
<van-col
|
<van-col v-for="icon in icons.filled" :key="icon" span="6" @click="copy(icon)">
|
||||||
v-for="icon in icons.filled"
|
|
||||||
:key="icon"
|
|
||||||
span="6"
|
|
||||||
>
|
|
||||||
<van-icon :name="icon" />
|
<van-icon :name="icon" />
|
||||||
<span>{{ icon }}</span>
|
<span>{{ icon }}</span>
|
||||||
</van-col>
|
</van-col>
|
||||||
@ -43,17 +27,43 @@
|
|||||||
import icons from '@vant/icons';
|
import icons from '@vant/icons';
|
||||||
import { BLUE } from '../../utils/constant';
|
import { BLUE } from '../../utils/constant';
|
||||||
|
|
||||||
|
// from https://30secondsofcode.org
|
||||||
|
function copyToClipboard(str) {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
|
||||||
|
const selected =
|
||||||
|
document.getSelection().rangeCount > 0
|
||||||
|
? document.getSelection().getRangeAt(0)
|
||||||
|
: false;
|
||||||
|
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
i18n: {
|
i18n: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
title: '图标列表',
|
title: '图标列表',
|
||||||
info: '显示徽标',
|
info: '显示徽标',
|
||||||
basic: '基础图标'
|
basic: '基础图标',
|
||||||
|
copied: '复制成功'
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
title: 'Icon List',
|
title: 'Icon List',
|
||||||
info: 'Show Info',
|
info: 'Show Info',
|
||||||
basic: 'Basic Icon'
|
basic: 'Basic Icon',
|
||||||
|
copied: 'Copied'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -63,6 +73,20 @@ export default {
|
|||||||
return {
|
return {
|
||||||
tab: 0
|
tab: 0
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
copy(icon) {
|
||||||
|
const tag = `<van-icon name="${icon}" />`;
|
||||||
|
copyToClipboard(tag);
|
||||||
|
|
||||||
|
this.$notify({
|
||||||
|
type: 'success',
|
||||||
|
duration: 1500,
|
||||||
|
className: 'demo-icon-notify',
|
||||||
|
message: `${this.$t('copied')}:${tag}`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -79,6 +103,10 @@ export default {
|
|||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-notify {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
.van-col {
|
.van-col {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
float: none;
|
float: none;
|
||||||
@ -93,6 +121,10 @@ export default {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: @active-color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.van-icon {
|
.van-icon {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user