Skip to content

Commit 8887d21

Browse files
Add icon sprite resolver
Resolves icon sprite references from iconsPublicPath if the the source path starts from the '#'.
1 parent cc47435 commit 8887d21

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/elements/icon/icon.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33

44
import iconClassNames from './icon.css'
5+
import config from '../../config'
56

67
import { classNames } from 'utils'
78

9+
const resolve = (url) =>
10+
config.iconsPublicPath != null && url && url.toString().charAt() === '#'
11+
? `${config.iconsPublicPath}${url}`
12+
: url
13+
814
/**
915
* The component creates an inline SVG image based on
1016
* `src` and `alt` attributes.
@@ -16,7 +22,7 @@ const Icon = ({ src, alt, className, ...restProps }) => (
1622
{...restProps}
1723
>
1824
<title>{alt}</title>
19-
<use href={src} />
25+
<use href={resolve(src)} />
2026
</svg>
2127
)
2228

0 commit comments

Comments
 (0)