icons.mjs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
  2. // Icons
  3. import { aliases, mdi } from "../iconsets/mdi.mjs"; // Utilities
  4. import { computed, inject, unref } from 'vue';
  5. import { consoleWarn, defineComponent, genericComponent, mergeDeep, propsFactory } from "../util/index.mjs"; // Types
  6. export const IconValue = [String, Function, Object, Array];
  7. export const IconSymbol = Symbol.for('vuetify:icons');
  8. export const makeIconProps = propsFactory({
  9. icon: {
  10. type: IconValue
  11. },
  12. // Could not remove this and use makeTagProps, types complained because it is not required
  13. tag: {
  14. type: String,
  15. required: true
  16. }
  17. }, 'icon');
  18. export const VComponentIcon = genericComponent()({
  19. name: 'VComponentIcon',
  20. props: makeIconProps(),
  21. setup(props, _ref) {
  22. let {
  23. slots
  24. } = _ref;
  25. return () => {
  26. const Icon = props.icon;
  27. return _createVNode(props.tag, null, {
  28. default: () => [props.icon ? _createVNode(Icon, null, null) : slots.default?.()]
  29. });
  30. };
  31. }
  32. });
  33. export const VSvgIcon = defineComponent({
  34. name: 'VSvgIcon',
  35. inheritAttrs: false,
  36. props: makeIconProps(),
  37. setup(props, _ref2) {
  38. let {
  39. attrs
  40. } = _ref2;
  41. return () => {
  42. return _createVNode(props.tag, _mergeProps(attrs, {
  43. "style": null
  44. }), {
  45. default: () => [_createVNode("svg", {
  46. "class": "v-icon__svg",
  47. "xmlns": "http://www.w3.org/2000/svg",
  48. "viewBox": "0 0 24 24",
  49. "role": "img",
  50. "aria-hidden": "true"
  51. }, [Array.isArray(props.icon) ? props.icon.map(path => Array.isArray(path) ? _createVNode("path", {
  52. "d": path[0],
  53. "fill-opacity": path[1]
  54. }, null) : _createVNode("path", {
  55. "d": path
  56. }, null)) : _createVNode("path", {
  57. "d": props.icon
  58. }, null)])]
  59. });
  60. };
  61. }
  62. });
  63. export const VLigatureIcon = defineComponent({
  64. name: 'VLigatureIcon',
  65. props: makeIconProps(),
  66. setup(props) {
  67. return () => {
  68. return _createVNode(props.tag, null, {
  69. default: () => [props.icon]
  70. });
  71. };
  72. }
  73. });
  74. export const VClassIcon = defineComponent({
  75. name: 'VClassIcon',
  76. props: makeIconProps(),
  77. setup(props) {
  78. return () => {
  79. return _createVNode(props.tag, {
  80. "class": props.icon
  81. }, null);
  82. };
  83. }
  84. });
  85. function genDefaults() {
  86. return {
  87. svg: {
  88. component: VSvgIcon
  89. },
  90. class: {
  91. component: VClassIcon
  92. }
  93. };
  94. }
  95. // Composables
  96. export function createIcons(options) {
  97. const sets = genDefaults();
  98. const defaultSet = options?.defaultSet ?? 'mdi';
  99. if (defaultSet === 'mdi' && !sets.mdi) {
  100. sets.mdi = mdi;
  101. }
  102. return mergeDeep({
  103. defaultSet,
  104. sets,
  105. aliases: {
  106. ...aliases,
  107. /* eslint-disable max-len */
  108. vuetify: ['M8.2241 14.2009L12 21L22 3H14.4459L8.2241 14.2009Z', ['M7.26303 12.4733L7.00113 12L2 3H12.5261C12.5261 3 12.5261 3 12.5261 3L7.26303 12.4733Z', 0.6]],
  109. 'vuetify-outline': 'svg:M7.26 12.47 12.53 3H2L7.26 12.47ZM14.45 3 8.22 14.2 12 21 22 3H14.45ZM18.6 5 12 16.88 10.51 14.2 15.62 5ZM7.26 8.35 5.4 5H9.13L7.26 8.35Z',
  110. 'vuetify-play': ['m6.376 13.184-4.11-7.192C1.505 4.66 2.467 3 4.003 3h8.532l-.953 1.576-.006.01-.396.677c-.429.732-.214 1.507.194 2.015.404.503 1.092.878 1.869.806a3.72 3.72 0 0 1 1.005.022c.276.053.434.143.523.237.138.146.38.635-.25 2.09-.893 1.63-1.553 1.722-1.847 1.677-.213-.033-.468-.158-.756-.406a4.95 4.95 0 0 1-.8-.927c-.39-.564-1.04-.84-1.66-.846-.625-.006-1.316.27-1.693.921l-.478.826-.911 1.506Z', ['M9.093 11.552c.046-.079.144-.15.32-.148a.53.53 0 0 1 .43.207c.285.414.636.847 1.046 1.2.405.35.914.662 1.516.754 1.334.205 2.502-.698 3.48-2.495l.014-.028.013-.03c.687-1.574.774-2.852-.005-3.675-.37-.391-.861-.586-1.333-.676a5.243 5.243 0 0 0-1.447-.044c-.173.016-.393-.073-.54-.257-.145-.18-.127-.316-.082-.392l.393-.672L14.287 3h5.71c1.536 0 2.499 1.659 1.737 2.992l-7.997 13.996c-.768 1.344-2.706 1.344-3.473 0l-3.037-5.314 1.377-2.278.004-.006.004-.007.481-.831Z', 0.6]]
  111. /* eslint-enable max-len */
  112. }
  113. }, options);
  114. }
  115. export const useIcon = props => {
  116. const icons = inject(IconSymbol);
  117. if (!icons) throw new Error('Missing Vuetify Icons provide!');
  118. const iconData = computed(() => {
  119. const iconAlias = unref(props);
  120. if (!iconAlias) return {
  121. component: VComponentIcon
  122. };
  123. let icon = iconAlias;
  124. if (typeof icon === 'string') {
  125. icon = icon.trim();
  126. if (icon.startsWith('$')) {
  127. icon = icons.aliases?.[icon.slice(1)];
  128. }
  129. }
  130. if (!icon) consoleWarn(`Could not find aliased icon "${iconAlias}"`);
  131. if (Array.isArray(icon)) {
  132. return {
  133. component: VSvgIcon,
  134. icon
  135. };
  136. } else if (typeof icon !== 'string') {
  137. return {
  138. component: VComponentIcon,
  139. icon
  140. };
  141. }
  142. const iconSetName = Object.keys(icons.sets).find(setName => typeof icon === 'string' && icon.startsWith(`${setName}:`));
  143. const iconName = iconSetName ? icon.slice(iconSetName.length + 1) : icon;
  144. const iconSet = icons.sets[iconSetName ?? icons.defaultSet];
  145. return {
  146. component: iconSet.component,
  147. icon: iconName
  148. };
  149. });
  150. return {
  151. iconData
  152. };
  153. };
  154. //# sourceMappingURL=icons.mjs.map