feat(ConfigProvider): add icon-prefix prop (#8986)

This commit is contained in:
neverland
2021-07-06 17:24:22 +08:00
committed by GitHub
parent b5ea1cd3ad
commit 2a74d88c91
9 changed files with 89 additions and 41 deletions
+15 -8
View File
@@ -1,11 +1,12 @@
import { PropType, defineComponent } from 'vue';
import { PropType, defineComponent, inject, computed } from 'vue';
import { addUnit, createNamespace } from '../utils';
import { Badge } from '../badge';
import { CONFIG_PROVIDER_KEY } from '../config-provider/ConfigProvider';
const [name, bem] = createNamespace('icon');
function isImage(name?: string) {
return name ? name.includes('/') : false;
return name?.includes('/');
}
export default defineComponent({
@@ -17,19 +18,22 @@ export default defineComponent({
size: [Number, String],
badge: [Number, String],
color: String,
classPrefix: String,
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'i',
},
classPrefix: {
type: String,
default: bem(),
},
},
setup(props, { slots }) {
const config = inject(CONFIG_PROVIDER_KEY, null);
const classPrefix = computed(
() => props.classPrefix || config?.iconPrefix || bem()
);
return () => {
const { tag, dot, name, size, badge, color, classPrefix } = props;
const { tag, dot, name, size, badge, color } = props;
const isImageIcon = isImage(name);
return (
@@ -37,7 +41,10 @@ export default defineComponent({
dot={dot}
tag={tag}
content={badge}
class={[classPrefix, isImageIcon ? '' : `${classPrefix}-${name}`]}
class={[
classPrefix.value,
isImageIcon ? '' : `${classPrefix.value}-${name}`,
]}
style={{
color,
fontSize: addUnit(size),