useStretchStyle.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { computed, ref } from 'vue';
  2. export default (function (stretch) {
  3. var targetSize = ref({
  4. width: 0,
  5. height: 0
  6. });
  7. function measureStretch(element) {
  8. targetSize.value = {
  9. width: element.offsetWidth,
  10. height: element.offsetHeight
  11. };
  12. }
  13. // Merge stretch style
  14. var style = computed(function () {
  15. var sizeStyle = {};
  16. if (stretch.value) {
  17. var _targetSize$value = targetSize.value,
  18. width = _targetSize$value.width,
  19. height = _targetSize$value.height;
  20. // Stretch with target
  21. if (stretch.value.indexOf('height') !== -1 && height) {
  22. sizeStyle.height = "".concat(height, "px");
  23. } else if (stretch.value.indexOf('minHeight') !== -1 && height) {
  24. sizeStyle.minHeight = "".concat(height, "px");
  25. }
  26. if (stretch.value.indexOf('width') !== -1 && width) {
  27. sizeStyle.width = "".concat(width, "px");
  28. } else if (stretch.value.indexOf('minWidth') !== -1 && width) {
  29. sizeStyle.minWidth = "".concat(width, "px");
  30. }
  31. }
  32. return sizeStyle;
  33. });
  34. return [style, measureStretch];
  35. });