Skip to content

Commit 9d07f50

Browse files
feat: add icon.symbol to allow use of svg sprites
1 parent a80bbb1 commit 9d07f50

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

core/client/utils/utils.shapes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export function createShape (options) {
220220
// Render icon
221221
let iconTag = ''
222222
if (options.icon) {
223-
if (!_.isNil(options.icon.classes) || !_.isNil(options.icon.url)) {
223+
if (!_.isNil(options.icon.classes) || !_.isNil(options.icon.url) || !_.isNil(options.icon.symbol)) {
224224
if (!_.isEmpty(options.icon.classes) || !_.isEmpty(options.icon.url)) {
225225
let specificStyle = ''
226226
if (options.icon.url) {
@@ -242,6 +242,13 @@ export function createShape (options) {
242242
const rotation = options.icon.rotation || _.get(shape, 'icon.rotation', 0)
243243
iconTag += `style="position: absolute; top: 50%; left: 50%; transform: translate(${translation[0]},${translation[1]}) rotate(${rotation}deg); opacity: ${opacity}; ${specificStyle}"`
244244
iconTag += '/>'
245+
} else {
246+
let iconSize = options.icon.size ? getSize(options.icon.size) : size
247+
const color = getHtmlColor(options.icon.color, defaultColor)
248+
const opacity = options.icon.opacity || 1
249+
const translation = options.icon.translation || _.get(shape, 'icon.translation', ['-50%', '-50%'])
250+
const rotation = options.icon.rotation || _.get(shape, 'icon.rotation', 0)
251+
iconTag = `<svg width=${iconSize.width} height=${iconSize.height} style="position: absolute; top: 50%; left: 50%; transform: translate(${translation[0]},${translation[1]}) rotate(${rotation}deg); opacity: ${opacity}" fill="${color}"><use href="${options.icon.symbol}"></svg>`
245252
}
246253
} else {
247254
logger.warn(`[KDK] icon must contain either the 'classes' property or the 'url' property`)

0 commit comments

Comments
 (0)