UNPKG

@carbon/icons-vue

Version:

Vue components for icons in digital and software products using the Carbon Design System

134 lines (126 loc) 3.57 kB
/** * Copyright IBM Corp. 2019, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. * * Code generated by @carbon/icon-build-helpers. DO NOT EDIT. */ 'use strict'; var iconHelpers = require('@carbon/icon-helpers'); var Vue = require('vue'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var Vue__namespace = /*#__PURE__*/_interopNamespace(Vue); /** * Copyright IBM Corp. 2018, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ // Note: we dynamically access keys on the Vue namespace so that rollup does not // automatically rewrite the binding into `import { h } from 'vue'` as this is // currently causing issues in Vue 2 environments function getVueExport(key) { return Vue__namespace[key]; } const h = getVueExport('h'); const createApp = getVueExport('createApp'); const getSvgAttrs = (title, svgAttrs, componentAttrs) => { return iconHelpers.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, ...(createApp ? { // Vue 3 component setup(_ref, _ref2) { let { title } = _ref; let { attrs: componentAttrs, slots } = _ref2; return () => h('svg', getSvgAttrs(title, svgAttrs, componentAttrs), [...(title ? [h('title', title)] : []), ...svgContent.map(_ref3 => { let { elem, attrs } = _ref3; return h(elem, attrs); }), ...(slots.default ? slots.default() : [])]); } } : { // Vue 2 component functional: true, render(createElement, _ref4) { let { props: { title }, children, data, listeners } = _ref4; return createElement('svg', getVue2SvgAttrs(title, svgAttrs, data, listeners), [...(title ? [createElement('title', null, title)] : []), ...svgContent.map(_ref5 => { let { elem, attrs } = _ref5; return createElement(elem, { attrs: attrs }); }), ...(children || [])]); } }) }); exports.createSVGComponent = createSVGComponent;