VStepperItem.mjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  2. // Styles
  3. import "./VStepperItem.css";
  4. // Components
  5. import { VAvatar } from "../VAvatar/VAvatar.mjs";
  6. import { VIcon } from "../VIcon/VIcon.mjs"; // Composables
  7. import { makeGroupItemProps, useGroupItem } from "../../composables/group.mjs";
  8. import { IconValue } from "../../composables/icons.mjs";
  9. import { genOverlays } from "../../composables/variant.mjs"; // Directives
  10. import { Ripple } from "../../directives/ripple/index.mjs"; // Utilities
  11. import { computed } from 'vue';
  12. import { VStepperSymbol } from "./shared.mjs";
  13. import { genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types
  14. export const makeStepperItemProps = propsFactory({
  15. color: String,
  16. title: String,
  17. subtitle: String,
  18. complete: Boolean,
  19. completeIcon: {
  20. type: IconValue,
  21. default: '$complete'
  22. },
  23. editable: Boolean,
  24. editIcon: {
  25. type: IconValue,
  26. default: '$edit'
  27. },
  28. error: Boolean,
  29. errorIcon: {
  30. type: IconValue,
  31. default: '$error'
  32. },
  33. icon: IconValue,
  34. ripple: {
  35. type: [Boolean, Object],
  36. default: true
  37. },
  38. rules: {
  39. type: Array,
  40. default: () => []
  41. }
  42. }, 'StepperItem');
  43. export const makeVStepperItemProps = propsFactory({
  44. ...makeStepperItemProps(),
  45. ...makeGroupItemProps()
  46. }, 'VStepperItem');
  47. export const VStepperItem = genericComponent()({
  48. name: 'VStepperItem',
  49. directives: {
  50. Ripple
  51. },
  52. props: makeVStepperItemProps(),
  53. emits: {
  54. 'group:selected': val => true
  55. },
  56. setup(props, _ref) {
  57. let {
  58. slots
  59. } = _ref;
  60. const group = useGroupItem(props, VStepperSymbol, true);
  61. const step = computed(() => group?.value.value ?? props.value);
  62. const isValid = computed(() => props.rules.every(handler => handler() === true));
  63. const isClickable = computed(() => !props.disabled && props.editable);
  64. const canEdit = computed(() => !props.disabled && props.editable);
  65. const hasError = computed(() => props.error || !isValid.value);
  66. const hasCompleted = computed(() => props.complete || props.rules.length > 0 && isValid.value);
  67. const icon = computed(() => {
  68. if (hasError.value) return props.errorIcon;
  69. if (hasCompleted.value) return props.completeIcon;
  70. if (group.isSelected.value && props.editable) return props.editIcon;
  71. return props.icon;
  72. });
  73. const slotProps = computed(() => ({
  74. canEdit: canEdit.value,
  75. hasError: hasError.value,
  76. hasCompleted: hasCompleted.value,
  77. title: props.title,
  78. subtitle: props.subtitle,
  79. step: step.value,
  80. value: props.value
  81. }));
  82. useRender(() => {
  83. const hasColor = (!group || group.isSelected.value || hasCompleted.value || canEdit.value) && !hasError.value && !props.disabled;
  84. const hasTitle = !!(props.title != null || slots.title);
  85. const hasSubtitle = !!(props.subtitle != null || slots.subtitle);
  86. function onClick() {
  87. group?.toggle();
  88. }
  89. return _withDirectives(_createVNode("button", {
  90. "class": ['v-stepper-item', {
  91. 'v-stepper-item--complete': hasCompleted.value,
  92. 'v-stepper-item--disabled': props.disabled,
  93. 'v-stepper-item--error': hasError.value
  94. }, group?.selectedClass.value],
  95. "disabled": !props.editable,
  96. "onClick": onClick
  97. }, [isClickable.value && genOverlays(true, 'v-stepper-item'), _createVNode(VAvatar, {
  98. "key": "stepper-avatar",
  99. "class": "v-stepper-item__avatar",
  100. "color": hasColor ? props.color : undefined,
  101. "size": 24
  102. }, {
  103. default: () => [slots.icon?.(slotProps.value) ?? (icon.value ? _createVNode(VIcon, {
  104. "icon": icon.value
  105. }, null) : step.value)]
  106. }), _createVNode("div", {
  107. "class": "v-stepper-item__content"
  108. }, [hasTitle && _createVNode("div", {
  109. "key": "title",
  110. "class": "v-stepper-item__title"
  111. }, [slots.title?.(slotProps.value) ?? props.title]), hasSubtitle && _createVNode("div", {
  112. "key": "subtitle",
  113. "class": "v-stepper-item__subtitle"
  114. }, [slots.subtitle?.(slotProps.value) ?? props.subtitle]), slots.default?.(slotProps.value)])]), [[_resolveDirective("ripple"), props.ripple && props.editable, null]]);
  115. });
  116. return {};
  117. }
  118. });
  119. //# sourceMappingURL=VStepperItem.mjs.map