VToolbar.mjs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  2. // Styles
  3. import "./VToolbar.css";
  4. // Components
  5. import { VToolbarTitle } from "./VToolbarTitle.mjs";
  6. import { VExpandTransition } from "../transitions/index.mjs";
  7. import { VDefaultsProvider } from "../VDefaultsProvider/index.mjs";
  8. import { VImg } from "../VImg/index.mjs"; // Composables
  9. import { makeBorderProps, useBorder } from "../../composables/border.mjs";
  10. import { useBackgroundColor } from "../../composables/color.mjs";
  11. import { makeComponentProps } from "../../composables/component.mjs";
  12. import { provideDefaults } from "../../composables/defaults.mjs";
  13. import { makeElevationProps, useElevation } from "../../composables/elevation.mjs";
  14. import { useRtl } from "../../composables/locale.mjs";
  15. import { makeRoundedProps, useRounded } from "../../composables/rounded.mjs";
  16. import { makeTagProps } from "../../composables/tag.mjs";
  17. import { makeThemeProps, provideTheme } from "../../composables/theme.mjs"; // Utilities
  18. import { computed, shallowRef, toRef } from 'vue';
  19. import { convertToUnit, genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types
  20. const allowedDensities = [null, 'prominent', 'default', 'comfortable', 'compact'];
  21. export const makeVToolbarProps = propsFactory({
  22. absolute: Boolean,
  23. collapse: Boolean,
  24. color: String,
  25. density: {
  26. type: String,
  27. default: 'default',
  28. validator: v => allowedDensities.includes(v)
  29. },
  30. extended: Boolean,
  31. extensionHeight: {
  32. type: [Number, String],
  33. default: 48
  34. },
  35. flat: Boolean,
  36. floating: Boolean,
  37. height: {
  38. type: [Number, String],
  39. default: 64
  40. },
  41. image: String,
  42. title: String,
  43. ...makeBorderProps(),
  44. ...makeComponentProps(),
  45. ...makeElevationProps(),
  46. ...makeRoundedProps(),
  47. ...makeTagProps({
  48. tag: 'header'
  49. }),
  50. ...makeThemeProps()
  51. }, 'VToolbar');
  52. export const VToolbar = genericComponent()({
  53. name: 'VToolbar',
  54. props: makeVToolbarProps(),
  55. setup(props, _ref) {
  56. let {
  57. slots
  58. } = _ref;
  59. const {
  60. backgroundColorClasses,
  61. backgroundColorStyles
  62. } = useBackgroundColor(toRef(props, 'color'));
  63. const {
  64. borderClasses
  65. } = useBorder(props);
  66. const {
  67. elevationClasses
  68. } = useElevation(props);
  69. const {
  70. roundedClasses
  71. } = useRounded(props);
  72. const {
  73. themeClasses
  74. } = provideTheme(props);
  75. const {
  76. rtlClasses
  77. } = useRtl();
  78. const isExtended = shallowRef(!!(props.extended || slots.extension?.()));
  79. const contentHeight = computed(() => parseInt(Number(props.height) + (props.density === 'prominent' ? Number(props.height) : 0) - (props.density === 'comfortable' ? 8 : 0) - (props.density === 'compact' ? 16 : 0), 10));
  80. const extensionHeight = computed(() => isExtended.value ? parseInt(Number(props.extensionHeight) + (props.density === 'prominent' ? Number(props.extensionHeight) : 0) - (props.density === 'comfortable' ? 4 : 0) - (props.density === 'compact' ? 8 : 0), 10) : 0);
  81. provideDefaults({
  82. VBtn: {
  83. variant: 'text'
  84. }
  85. });
  86. useRender(() => {
  87. const hasTitle = !!(props.title || slots.title);
  88. const hasImage = !!(slots.image || props.image);
  89. const extension = slots.extension?.();
  90. isExtended.value = !!(props.extended || extension);
  91. return _createVNode(props.tag, {
  92. "class": ['v-toolbar', {
  93. 'v-toolbar--absolute': props.absolute,
  94. 'v-toolbar--collapse': props.collapse,
  95. 'v-toolbar--flat': props.flat,
  96. 'v-toolbar--floating': props.floating,
  97. [`v-toolbar--density-${props.density}`]: true
  98. }, backgroundColorClasses.value, borderClasses.value, elevationClasses.value, roundedClasses.value, themeClasses.value, rtlClasses.value, props.class],
  99. "style": [backgroundColorStyles.value, props.style]
  100. }, {
  101. default: () => [hasImage && _createVNode("div", {
  102. "key": "image",
  103. "class": "v-toolbar__image"
  104. }, [!slots.image ? _createVNode(VImg, {
  105. "key": "image-img",
  106. "cover": true,
  107. "src": props.image
  108. }, null) : _createVNode(VDefaultsProvider, {
  109. "key": "image-defaults",
  110. "disabled": !props.image,
  111. "defaults": {
  112. VImg: {
  113. cover: true,
  114. src: props.image
  115. }
  116. }
  117. }, slots.image)]), _createVNode(VDefaultsProvider, {
  118. "defaults": {
  119. VTabs: {
  120. height: convertToUnit(contentHeight.value)
  121. }
  122. }
  123. }, {
  124. default: () => [_createVNode("div", {
  125. "class": "v-toolbar__content",
  126. "style": {
  127. height: convertToUnit(contentHeight.value)
  128. }
  129. }, [slots.prepend && _createVNode("div", {
  130. "class": "v-toolbar__prepend"
  131. }, [slots.prepend?.()]), hasTitle && _createVNode(VToolbarTitle, {
  132. "key": "title",
  133. "text": props.title
  134. }, {
  135. text: slots.title
  136. }), slots.default?.(), slots.append && _createVNode("div", {
  137. "class": "v-toolbar__append"
  138. }, [slots.append?.()])])]
  139. }), _createVNode(VDefaultsProvider, {
  140. "defaults": {
  141. VTabs: {
  142. height: convertToUnit(extensionHeight.value)
  143. }
  144. }
  145. }, {
  146. default: () => [_createVNode(VExpandTransition, null, {
  147. default: () => [isExtended.value && _createVNode("div", {
  148. "class": "v-toolbar__extension",
  149. "style": {
  150. height: convertToUnit(extensionHeight.value)
  151. }
  152. }, [extension])]
  153. })]
  154. })]
  155. });
  156. });
  157. return {
  158. contentHeight,
  159. extensionHeight
  160. };
  161. }
  162. });
  163. //# sourceMappingURL=VToolbar.mjs.map