@@ -63,24 +63,25 @@ function createGradientStop (stop, index) {
6363 * @param {Object } props The user-defined props.
6464 * @param {Object } attrs The user-defined native HTML attributes.
6565 * @param {Object } [gradientFill] Optional gradient fill config.
66+ * @param {boolean } [stripFills] Whether to strip fill from descendant path elements.
6667 * @returns {VNode }
6768 */
68- export default function convert ( abstractElement , props = { } , attrs = { } , gradientFill = null ) {
69+ export default function convert ( abstractElement , props = { } , attrs = { } , gradientFill = null , stripFills = false ) {
6970 // If the abstract element is a string, we'll just return a string render function
7071 if ( typeof abstractElement === 'string' ) {
7172 return abstractElement
7273 }
7374
7475 // Converting abstract element children into Vue VNodes
75- // If a gradientFill (or fill attr) is provided, strip fill from child path elements
76+ // If a gradientFill (or fill attr) is provided, strip fill from all descendant path elements
7677 // so the gradient/fill takes precedence over the icon's built-in fill
77- const hasFillOverride = gradientFill || ( 'fill' in attrs )
78+ const shouldStripFills = stripFills || ! ! gradientFill || ( 'fill' in attrs )
7879 const children = ( abstractElement . children || [ ] )
7980 . map ( child => {
80- if ( hasFillOverride && child . tag === 'path' && child . attributes && 'fill' in child . attributes ) {
81- return convert ( { ...child , attributes : { ...child . attributes , fill : undefined } } )
81+ if ( shouldStripFills && child . tag === 'path' && child . attributes && 'fill' in child . attributes ) {
82+ return convert ( { ...child , attributes : { ...child . attributes , fill : undefined } } , { } , { } , null , true )
8283 }
83- return convert ( child )
84+ return convert ( child , { } , { } , null , shouldStripFills )
8485 } )
8586
8687 // Converting abstract element attributes into valid Vue format
@@ -112,8 +113,8 @@ export default function convert (abstractElement, props = {}, attrs = {}, gradie
112113 // Now, we'll return the VNode
113114 const { class : _aClass = { } , style : aStyle = { } , ...otherAttrs } = attrs
114115
115- // If a gradientFill is provided, inject the gradient element and set fill to reference it
116- if ( gradientFill ) {
116+ // If a valid gradientFill is provided, inject the gradient element and set fill to reference it
117+ if ( gradientFill && gradientFill . id && ( gradientFill . type === 'linear' || gradientFill . type === 'radial' ) ) {
117118 const { type : gradientType , stops = [ ] , id, ...gradientProps } = gradientFill
118119 const gradientTag = gradientType === 'linear' ? 'linearGradient' : 'radialGradient'
119120 const gradientVNode = h ( gradientTag , { ...gradientProps , id } , stops . map ( createGradientStop ) )
0 commit comments