-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(icons-vue): add vue 3 support (#7545)
* fix: carbon icons vue for vue 3 * fix(icon-build-helpers): add vue as external * chore(ci): update build concurrency to 1 * chore(ci): increase heap size for Node.js * chore(project): revert ci heap space change * feat(icon-build-helpers): update rollup to latest versions * chore(ci): update heap space for Node.js * chore(project): debug icons-vue build * chore(icons): add rimraf devDependency * chore(icons): update to include workspace dependencies * fix: smal refactor * fix: big refactor * fix: correct handling of children * chore(project): revert changes to circleci Co-authored-by: Lee Chase <lee.chase@uk.ibm.com> Co-authored-by: Josh Black <josh@josh.black> Co-authored-by: Dave Clark <dave.clark@uk.ibm.com> Co-authored-by: Andrea N. Cardona <andreancardona@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7133b68
commit aebf79e
Showing
14 changed files
with
136 additions
and
119 deletions.
There are no files selected for viewing
Binary file added
BIN
+9.38 KB
.yarn/cache/@rollup-plugin-replace-npm-2.3.4-2b255f0126-97ae11600a.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-4.29 KB
.yarn/cache/rollup-plugin-strip-banner-npm-0.2.0-0aa46b3887-ba6dab339b.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright IBM Corp. 2018, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { getAttributes } from '@carbon/icon-helpers'; | ||
import { h } from 'vue'; | ||
|
||
const getSvgAttrs = (title, svgAttrs, componentAttrs) => { | ||
return getAttributes({ | ||
...svgAttrs, | ||
preserveAspectRatio: 'xMidYMid meet', | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
// Special case here, we need to coordinate that we are using title, | ||
// potentially, to get the right focus attributes | ||
title, | ||
...componentAttrs, | ||
}); | ||
}; | ||
|
||
const getVue2SvgAttrs = (title, svgAttrs, data, listeners) => { | ||
const result = { | ||
attrs: getSvgAttrs(title, svgAttrs, data.attrs), | ||
on: listeners, | ||
style: { ...data.staticStyle, ...data.style }, | ||
}; | ||
|
||
// remove style set by getAttributes | ||
delete result.attrs.style; | ||
|
||
if (data.staticClass || data.class) { | ||
result.class = {}; | ||
|
||
if (data.staticClass) { | ||
result.class[data.staticClass] = true; | ||
} | ||
|
||
if (data.class) { | ||
result.class[data.class] = true; | ||
} | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
const createSVGComponent = (name, svgAttrs, svgContent) => ({ | ||
// We use title as a prop name for the component | ||
// as it is not a valid attribute for an SVG HTML element | ||
props: { title: String }, | ||
name: name, | ||
...(h | ||
? { | ||
// Vue 3 component | ||
setup({ title }, { attrs: componentAttrs, slots }) { | ||
return () => | ||
h('svg', getSvgAttrs(title, svgAttrs, componentAttrs), [ | ||
...(title ? [h('title', title)] : []), | ||
...svgContent.map(({ elem, attrs }) => h(elem, attrs)), | ||
...(slots.default ? slots.default() : []), | ||
]); | ||
}, | ||
} | ||
: { | ||
// Vue 2 component | ||
functional: true, | ||
render(createElement, { props: { title }, children, data, listeners }) { | ||
return createElement( | ||
'svg', | ||
getVue2SvgAttrs(title, svgAttrs, data, listeners), | ||
[ | ||
...(title ? [createElement('title', null, title)] : []), | ||
...svgContent.map(({ elem, attrs }) => | ||
createElement(elem, { attrs: attrs }) | ||
), | ||
...(children || []), | ||
] | ||
); | ||
}, | ||
}), | ||
}); | ||
|
||
export default createSVGComponent; |
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
Oops, something went wrong.