VStepperItem.mjs 3.9 KB

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