VFab.mjs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { withDirectives as _withDirectives, createVNode as _createVNode, mergeProps as _mergeProps, resolveDirective as _resolveDirective, vShow as _vShow } from "vue";
  2. // Styles
  3. import "./VFab.css";
  4. // Components
  5. import { makeVBtnProps, VBtn } from "../VBtn/VBtn.mjs"; // Composables
  6. import { makeLayoutItemProps, useLayoutItem } from "../../composables/layout.mjs";
  7. import { makeLocationProps } from "../../composables/location.mjs";
  8. import { useProxiedModel } from "../../composables/proxiedModel.mjs";
  9. import { useResizeObserver } from "../../composables/resizeObserver.mjs";
  10. import { useToggleScope } from "../../composables/toggleScope.mjs";
  11. import { makeTransitionProps, MaybeTransition } from "../../composables/transition.mjs"; // Utilities
  12. import { computed, ref, shallowRef, toRef, watchEffect } from 'vue';
  13. import { genericComponent, omit, propsFactory, useRender } from "../../util/index.mjs"; // Types
  14. export const makeVFabProps = propsFactory({
  15. app: Boolean,
  16. appear: Boolean,
  17. extended: Boolean,
  18. layout: Boolean,
  19. offset: Boolean,
  20. modelValue: {
  21. type: Boolean,
  22. default: true
  23. },
  24. ...omit(makeVBtnProps({
  25. active: true
  26. }), ['location']),
  27. ...makeLayoutItemProps(),
  28. ...makeLocationProps(),
  29. ...makeTransitionProps({
  30. transition: 'fab-transition'
  31. })
  32. }, 'VFab');
  33. export const VFab = genericComponent()({
  34. name: 'VFab',
  35. props: makeVFabProps(),
  36. emits: {
  37. 'update:modelValue': value => true
  38. },
  39. setup(props, _ref) {
  40. let {
  41. slots
  42. } = _ref;
  43. const model = useProxiedModel(props, 'modelValue');
  44. const height = shallowRef(56);
  45. const layoutItemStyles = ref();
  46. const {
  47. resizeRef
  48. } = useResizeObserver(entries => {
  49. if (!entries.length) return;
  50. height.value = entries[0].target.clientHeight;
  51. });
  52. const hasPosition = computed(() => props.app || props.absolute);
  53. const position = computed(() => {
  54. if (!hasPosition.value) return false;
  55. return props.location?.split(' ').shift() ?? 'bottom';
  56. });
  57. const orientation = computed(() => {
  58. if (!hasPosition.value) return false;
  59. return props.location?.split(' ')[1] ?? 'end';
  60. });
  61. useToggleScope(() => props.app, () => {
  62. const layout = useLayoutItem({
  63. id: props.name,
  64. order: computed(() => parseInt(props.order, 10)),
  65. position,
  66. layoutSize: computed(() => props.layout ? height.value + 24 : 0),
  67. elementSize: computed(() => height.value + 24),
  68. active: computed(() => props.app && model.value),
  69. absolute: toRef(props, 'absolute')
  70. });
  71. watchEffect(() => {
  72. layoutItemStyles.value = layout.layoutItemStyles.value;
  73. });
  74. });
  75. const vFabRef = ref();
  76. useRender(() => {
  77. const btnProps = VBtn.filterProps(props);
  78. return _createVNode("div", {
  79. "ref": vFabRef,
  80. "class": ['v-fab', {
  81. 'v-fab--absolute': props.absolute,
  82. 'v-fab--app': !!props.app,
  83. 'v-fab--extended': props.extended,
  84. 'v-fab--offset': props.offset,
  85. [`v-fab--${position.value}`]: hasPosition.value,
  86. [`v-fab--${orientation.value}`]: hasPosition.value
  87. }, props.class],
  88. "style": [props.app ? {
  89. ...layoutItemStyles.value
  90. } : {
  91. height: 'inherit',
  92. width: undefined
  93. }, props.style]
  94. }, [_createVNode("div", {
  95. "class": "v-fab__container"
  96. }, [_createVNode(MaybeTransition, {
  97. "appear": props.appear,
  98. "transition": props.transition
  99. }, {
  100. default: () => [_withDirectives(_createVNode(VBtn, _mergeProps({
  101. "ref": resizeRef
  102. }, btnProps, {
  103. "active": undefined,
  104. "location": undefined
  105. }), slots), [[_vShow, props.active]])]
  106. })])]);
  107. });
  108. return {};
  109. }
  110. });
  111. //# sourceMappingURL=VFab.mjs.map