-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c60b15
commit 542e5d3
Showing
6 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import useBoolean from './use-boolean'; | ||
import useLoading from './use-loading'; | ||
import useContext from './use-context'; | ||
import useSvgIconRender from './use-svg-icon-render'; | ||
|
||
export { useBoolean, useLoading, useContext }; | ||
export { useBoolean, useLoading, useContext, useSvgIconRender }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { h } from 'vue'; | ||
import type { Component } from 'vue'; | ||
|
||
/** | ||
* svg icon render hook | ||
* @param SvgIcon svg icon component | ||
*/ | ||
export default function useSvgIconRender(SvgIcon: Component) { | ||
interface IconConfig { | ||
/** | ||
* iconify icon name | ||
*/ | ||
icon?: string; | ||
/** | ||
* local icon name | ||
*/ | ||
localIcon?: string; | ||
/** | ||
* icon color | ||
*/ | ||
color?: string; | ||
/** | ||
* icon size | ||
*/ | ||
fontSize?: number; | ||
} | ||
|
||
type IconStyle = Partial<Pick<CSSStyleDeclaration, 'color' | 'fontSize'>>; | ||
|
||
/** | ||
* svg icon VNode | ||
* @param config | ||
*/ | ||
const SvgIconVNode = (config: IconConfig) => { | ||
const { color, fontSize, icon, localIcon } = config; | ||
|
||
const style: IconStyle = {}; | ||
|
||
if (color) { | ||
style.color = color; | ||
} | ||
if (fontSize) { | ||
style.fontSize = `${fontSize}px`; | ||
} | ||
|
||
if (!icon && !localIcon) { | ||
return undefined; | ||
} | ||
|
||
return () => h(SvgIcon, { icon, localIcon, style }); | ||
}; | ||
|
||
return { | ||
SvgIconVNode | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters