@nextcloud/vue
Version:
Nextcloud vue components
1 lines • 7.71 kB
Source Map (JSON)
{"version":3,"file":"NcIconSvgWrapper-BvLanNaW.mjs","sources":["../../src/components/NcIconSvgWrapper/NcIconSvgWrapper.vue"],"sourcesContent":["<!--\n - SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors\n - SPDX-License-Identifier: AGPL-3.0-or-later\n-->\n\n<docs>\n### Description\n\nRender raw SVG string icons.\n\n### Usage within `icon`-slot\n\n```vue\n<template>\n\t<div class=\"grid\">\n\t\t<NcButton aria-label=\"Close\">\n\t\t\t<template #icon>\n\t\t\t\t<NcIconSvgWrapper :svg=\"closeSvg\" name=\"Close\" />\n\t\t\t</template>\n\t\t</NcButton>\n\t\t<NcButton aria-label=\"Settings\">\n\t\t\t<template #icon>\n\t\t\t\t<NcIconSvgWrapper :svg=\"cogSvg\" name=\"Cog\" />\n\t\t\t</template>\n\t\t</NcButton>\n\t\t<NcButton aria-label=\"Add\">\n\t\t\t<template #icon>\n\t\t\t\t<NcIconSvgWrapper :svg=\"plusSvg\" name=\"Plus\" />\n\t\t\t</template>\n\t\t</NcButton>\n\t\t<NcButton aria-label=\"Send\">\n\t\t\t<template #icon>\n\t\t\t\t<NcIconSvgWrapper :path=\"mdiSendOutline\" name=\"Send\" />\n\t\t\t</template>\n\t\t</NcButton>\n\t\t<NcButton aria-label=\"Star\">\n\t\t\t<template #icon>\n\t\t\t\t<NcIconSvgWrapper :path=\"mdiStarOutline\" name=\"Star\" />\n\t\t\t</template>\n\t\t</NcButton>\n\t</div>\n</template>\n\n<script>\nimport closeSvg from '@mdi/svg/svg/close.svg?raw'\nimport cogSvg from '@mdi/svg/svg/cog-outline.svg?raw'\nimport plusSvg from '@mdi/svg/svg/plus.svg?raw'\nimport { mdiSendOutline } from '@mdi/js'\nimport { mdiStarOutline } from '@mdi/js'\n\nexport default {\n\tsetup() {\n\t\t// These icons are static data, so you do not need to put them into `data` which will make them reactive\n\t\treturn {\n\t\t\tcloseSvg,\n\t\t\tcogSvg,\n\t\t\tplusSvg,\n\t\t\tmdiSendOutline,\n\t\t\tmdiStarOutline,\n\t\t}\n\t},\n}\n</script>\n\n<style>\n.grid {\n\tdisplay: grid;\n\tgrid-template-columns: repeat(5, max-content);\n\tgap: 10px;\n}\n</style>\n```\n\n### Inline usage inside text\n\n```vue\n<template>\n\t<p>\n\t\tThis is my <NcIconSvgWrapper inline :path=\"mdiStarOutline\" /> Favorite\n\t</p>\n</template>\n<script>\nimport { mdiStarOutline } from '@mdi/js'\n\nexport default {\n\tsetup() {\n\t\treturn {\n\t\t\tmdiStarOutline,\n\t\t}\n\t},\n}\n</script>\n```\n\n### Directional usage\n\nThe `directional` property allows to enable a language direction aware icon.\nThis icon component can be used in places where an language direction aware icon should be used,\nfor example if an arrow pointing to the left it used it often points in the wrong direction for right-to-left languages.\nIn this cases this icon can be used which will always point into the logical \"start\" direction.\n\n```vue\n<template>\n\t<div class=\"wrapper\">\n\t\t<NcButton @click=\"isRtl = !isRtl\">Toggle RTL</NcButton>\n\t\t<div class=\"directional\" :dir=\"isRtl ? 'rtl' : 'ltr'\">\n\t\t\t<NcButton alignment=\"start\">\n\t\t\t\t<template #icon>\n\t\t\t\t\t<NcIconSvgWrapper directional :path=\"mdiChevronLeft\" />\n\t\t\t\t</template>\n\t\t\t\tPrevious\n\t\t\t</NcButton>\n\t\t\t<NcButton alignment=\"end-reverse\">\n\t\t\t\t<template #icon>\n\t\t\t\t\t<NcIconSvgWrapper directional :path=\"mdiChevronRight\" />\n\t\t\t\t</template>\n\t\t\t\tNext\n\t\t\t</NcButton>\n\t\t</div>\n\t</div>\n</template>\n\n<script>\nimport { mdiChevronLeft, mdiChevronRight } from '@mdi/js'\n\nexport default {\n\tsetup() {\n\t\treturn {\n\t\t\tmdiChevronLeft,\n\t\t\tmdiChevronRight,\n\t\t}\n\t},\n\tdata() {\n\t\treturn {\n\t\t\tisRtl: false\n\t\t}\n\t},\n}\n</script>\n<style scoped>\n.wrapper {\n\tdisplay: flex;\n\tflex-direction: column;\n\tgap: calc(2 * var(--default-grid-baseline));\n\tmax-width: 300px;\n}\n\n.directional {\n\tdisplay: flex;\n\tflex-direction: row;\n\tgap: calc(2 * var(--default-grid-baseline));\n}\n\n.directional * {\n\tflex: 1 50%;\n}\n</style>\n```\n</docs>\n\n<script setup lang=\"ts\">\nimport DOMPurify from 'dompurify'\nimport { computed, warn } from 'vue'\n\nconst props = withDefaults(defineProps<{\n\t/**\n\t * Make the icon directional, meaning it is langauge direction aware.\n\t * If the icon is placed in a right-to-left context it will be mirrored vertically.\n\t */\n\tdirectional?: boolean\n\n\t/**\n\t * Set if the icon should be used as inline content e.g. within text.\n\t * By default the icon is made a block element for use inside `icon`-slots.\n\t */\n\tinline?: boolean\n\n\t/**\n\t * Raw SVG string to render\n\t */\n\tsvg?: string\n\n\t/**\n\t * Label of the icon, used in aria-label\n\t */\n\tname?: string\n\n\t/**\n\t * Raw SVG path to render. Takes precedence over the SVG string in the `svg` prop.\n\t */\n\tpath?: string\n\n\t/**\n\t * Size of the icon to show. Only use if not using within an icon slot.\n\t * Defaults to 20px which is the Nextcloud icon size for all icon slots.\n\t */\n\tsize?: number | 'auto'\n}>(), {\n\tname: undefined,\n\tpath: '',\n\tsize: 20,\n\tsvg: '',\n})\n\n/**\n * Icon size used in CSS\n */\nconst iconSize = computed(() => typeof props.size === 'number' ? `${props.size}px` : props.size)\n\n/**\n * The sanitized SVG or undefined if path shall be used\n */\nconst cleanSvg = computed(() => {\n\tif (!props.svg || props.path) {\n\t\treturn\n\t}\n\n\tconst svg = DOMPurify.sanitize(props.svg)\n\n\tconst svgDocument = new DOMParser().parseFromString(svg, 'image/svg+xml')\n\n\tif (svgDocument.querySelector('parsererror')) {\n\t\twarn('SVG is not valid')\n\t\treturn ''\n\t}\n\n\tif (svgDocument.documentElement.id) {\n\t\tsvgDocument.documentElement.removeAttribute('id')\n\t}\n\n\treturn svgDocument.documentElement.outerHTML\n})\n</script>\n\n<template>\n\t<span\n\t\t:aria-hidden=\"name ? undefined : 'true'\"\n\t\t:aria-label=\"name || undefined\"\n\t\tclass=\"icon-vue\"\n\t\t:class=\"{\n\t\t\t'icon-vue--directional': directional,\n\t\t\t'icon-vue--inline': inline,\n\t\t}\"\n\t\trole=\"img\">\n\t\t<svg v-if=\"!cleanSvg\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t<path :d=\"path\" />\n\t\t</svg>\n\t\t<!-- eslint-disable-next-line vue/no-v-text-v-html-on-component,vue/no-v-html -->\n\t\t<span v-else v-html=\"cleanSvg\" />\n\t</span>\n</template>\n\n<style lang=\"scss\" scoped>\n.icon-vue {\n\tdisplay: flex;\n\tjustify-content: center;\n\talign-items: center;\n\tmin-width: var(--default-clickable-area);\n\tmin-height: var(--default-clickable-area);\n\topacity: 1;\n\n\t&#{&}--inline {\n\t\tdisplay: inline-flex !important;\n\t\tmin-width: fit-content;\n\t\tmin-height: fit-content;\n\t\tvertical-align: text-bottom;\n\t}\n\n\t// Icon svg wrapper\n\tspan {\n\t\tline-height: 0;\n\t}\n\n\t&:deep(svg) {\n\t\tfill: currentColor;\n\t\twidth: v-bind('iconSize');\n\t\theight: v-bind('iconSize');\n\t\tmax-width: v-bind('iconSize');\n\t\tmax-height: v-bind('iconSize');\n\t}\n\n\t&--directional:deep(svg:dir(rtl)) {\n\t\ttransform: scaleX(-1);\n\t}\n}\n</style>\n"],"names":["_createElementBlock","name","directional","inline","_openBlock","_createElementVNode","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoKA,UAAM,QAAQ;AA2Cd,UAAM,WAAW,SAAS,MAAM,OAAO,MAAM,SAAS,WAAW,GAAG,MAAM,IAAI,OAAO,MAAM,IAAI;AAK/F,UAAM,WAAW,SAAS,MAAM;AAC/B,UAAI,CAAC,MAAM,OAAO,MAAM,MAAM;AAC7B;AAAA,MACD;AAEA,YAAM,MAAM,UAAU,SAAS,MAAM,GAAG;AAExC,YAAM,cAAc,IAAI,UAAA,EAAY,gBAAgB,KAAK,eAAe;AAExE,UAAI,YAAY,cAAc,aAAa,GAAG;AAC7C,aAAK,kBAAkB;AACvB,eAAO;AAAA,MACR;AAEA,UAAI,YAAY,gBAAgB,IAAI;AACnC,oBAAY,gBAAgB,gBAAgB,IAAI;AAAA,MACjD;AAEA,aAAO,YAAY,gBAAgB;AAAA,IACpC,CAAC;;0BAIAA,mBAcO,QAAA;AAAA,QAbL,eAAaC,KAAAA,OAAO,SAAS;AAAA,QAC7B,cAAYA,KAAAA,QAAQ;AAAA,QACrB,uBAAM,YAAU;AAAA,mCACsBC,KAAAA;AAAAA,8BAAoCC,KAAAA;AAAAA,QAAAA;QAI1E,MAAK;AAAA,MAAA;SACO,SAAA,SAAZC,aAAAJ,mBAEM,OAFN,YAEM;AAAA,UADLK,mBAAkB,QAAA,EAAX,GAAGC,KAAAA,QAAI,MAAA,GAAA,UAAA;AAAA,QAAA,oBAGfN,mBAAiC,QAAA;AAAA;UAApB,WAAQ,SAAA;AAAA,QAAA;;;;;;"}