feat(ConfigProvider): add icon-prefix prop (#8986)
This commit is contained in:
+15
-8
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user