VIcon.mjs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { createVNode as _createVNode } from "vue";
  2. // Styles
  3. import "./VIcon.css";
  4. // Composables
  5. import { useTextColor } from "../../composables/color.mjs";
  6. import { makeComponentProps } from "../../composables/component.mjs";
  7. import { IconValue, useIcon } from "../../composables/icons.mjs";
  8. import { makeSizeProps, useSize } from "../../composables/size.mjs";
  9. import { makeTagProps } from "../../composables/tag.mjs";
  10. import { makeThemeProps, provideTheme } from "../../composables/theme.mjs"; // Utilities
  11. import { computed, ref, Text, toRef } from 'vue';
  12. import { convertToUnit, flattenFragments, genericComponent, propsFactory, useRender } from "../../util/index.mjs";
  13. export const makeVIconProps = propsFactory({
  14. color: String,
  15. disabled: Boolean,
  16. start: Boolean,
  17. end: Boolean,
  18. icon: IconValue,
  19. ...makeComponentProps(),
  20. ...makeSizeProps(),
  21. ...makeTagProps({
  22. tag: 'i'
  23. }),
  24. ...makeThemeProps()
  25. }, 'VIcon');
  26. export const VIcon = genericComponent()({
  27. name: 'VIcon',
  28. props: makeVIconProps(),
  29. setup(props, _ref) {
  30. let {
  31. attrs,
  32. slots
  33. } = _ref;
  34. const slotIcon = ref();
  35. const {
  36. themeClasses
  37. } = provideTheme(props);
  38. const {
  39. iconData
  40. } = useIcon(computed(() => slotIcon.value || props.icon));
  41. const {
  42. sizeClasses
  43. } = useSize(props);
  44. const {
  45. textColorClasses,
  46. textColorStyles
  47. } = useTextColor(toRef(props, 'color'));
  48. useRender(() => {
  49. const slotValue = slots.default?.();
  50. if (slotValue) {
  51. slotIcon.value = flattenFragments(slotValue).filter(node => node.type === Text && node.children && typeof node.children === 'string')[0]?.children;
  52. }
  53. const hasClick = !!(attrs.onClick || attrs.onClickOnce);
  54. return _createVNode(iconData.value.component, {
  55. "tag": props.tag,
  56. "icon": iconData.value.icon,
  57. "class": ['v-icon', 'notranslate', themeClasses.value, sizeClasses.value, textColorClasses.value, {
  58. 'v-icon--clickable': hasClick,
  59. 'v-icon--disabled': props.disabled,
  60. 'v-icon--start': props.start,
  61. 'v-icon--end': props.end
  62. }, props.class],
  63. "style": [!sizeClasses.value ? {
  64. fontSize: convertToUnit(props.size),
  65. height: convertToUnit(props.size),
  66. width: convertToUnit(props.size)
  67. } : undefined, textColorStyles.value, props.style],
  68. "role": hasClick ? 'button' : undefined,
  69. "aria-hidden": !hasClick,
  70. "tabindex": hasClick ? props.disabled ? -1 : 0 : undefined
  71. }, {
  72. default: () => [slotValue]
  73. });
  74. });
  75. return {};
  76. }
  77. });
  78. //# sourceMappingURL=VIcon.mjs.map