vuetify
Version:
Vue Material Component Framework
193 lines (192 loc) • 7.81 kB
JavaScript
import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createElementVNode as _createElementVNode, createVNode as _createVNode } from "vue";
// Styles
import "./VProgressLinear.css";
// Composables
import { useBackgroundColor, useTextColor } from "../../composables/color.js";
import { makeComponentProps } from "../../composables/component.js";
import { useIntersectionObserver } from "../../composables/intersectionObserver.js";
import { useRtl } from "../../composables/locale.js";
import { makeLocationProps, useLocation } from "../../composables/location.js";
import { useProxiedModel } from "../../composables/proxiedModel.js";
import { makeRoundedProps, useRounded } from "../../composables/rounded.js";
import { makeTagProps } from "../../composables/tag.js";
import { makeThemeProps, provideTheme } from "../../composables/theme.js"; // Utilities
import { computed, Transition } from 'vue';
import { clamp, convertToUnit, genericComponent, IN_BROWSER, propsFactory, useRender } from "../../util/index.js";
export const makeVProgressLinearProps = propsFactory({
absolute: Boolean,
active: {
type: Boolean,
default: true
},
bgColor: String,
bgOpacity: [Number, String],
bufferValue: {
type: [Number, String],
default: 0
},
bufferColor: String,
bufferOpacity: [Number, String],
clickable: Boolean,
color: String,
height: {
type: [Number, String],
default: 4
},
indeterminate: Boolean,
max: {
type: [Number, String],
default: 100
},
modelValue: {
type: [Number, String],
default: 0
},
opacity: [Number, String],
reverse: Boolean,
stream: Boolean,
striped: Boolean,
roundedBar: Boolean,
...makeComponentProps(),
...makeLocationProps({
location: 'top'
}),
...makeRoundedProps(),
...makeTagProps(),
...makeThemeProps()
}, 'VProgressLinear');
export const VProgressLinear = genericComponent()({
name: 'VProgressLinear',
props: makeVProgressLinearProps(),
emits: {
'update:modelValue': value => true
},
setup(props, _ref) {
let {
slots
} = _ref;
const progress = useProxiedModel(props, 'modelValue');
const {
isRtl,
rtlClasses
} = useRtl();
const {
themeClasses
} = provideTheme(props);
const {
locationStyles
} = useLocation(props);
const {
textColorClasses,
textColorStyles
} = useTextColor(() => props.color);
const {
backgroundColorClasses,
backgroundColorStyles
} = useBackgroundColor(() => props.bgColor || props.color);
const {
backgroundColorClasses: bufferColorClasses,
backgroundColorStyles: bufferColorStyles
} = useBackgroundColor(() => props.bufferColor || props.bgColor || props.color);
const {
backgroundColorClasses: barColorClasses,
backgroundColorStyles: barColorStyles
} = useBackgroundColor(() => props.color);
const {
roundedClasses
} = useRounded(props);
const {
intersectionRef,
isIntersecting
} = useIntersectionObserver();
const max = computed(() => parseFloat(props.max));
const height = computed(() => parseFloat(props.height));
const normalizedBuffer = computed(() => clamp(parseFloat(props.bufferValue) / max.value * 100, 0, 100));
const normalizedValue = computed(() => clamp(parseFloat(progress.value) / max.value * 100, 0, 100));
const isReversed = computed(() => isRtl.value !== props.reverse);
const transition = computed(() => props.indeterminate ? 'fade-transition' : 'slide-x-transition');
const isForcedColorsModeActive = IN_BROWSER && window.matchMedia?.('(forced-colors: active)').matches;
function handleClick(e) {
if (!intersectionRef.value) return;
const {
left,
right,
width
} = intersectionRef.value.getBoundingClientRect();
const value = isReversed.value ? width - e.clientX + (right - width) : e.clientX - left;
progress.value = Math.round(value / width * max.value);
}
useRender(() => _createVNode(props.tag, {
"ref": intersectionRef,
"class": _normalizeClass(['v-progress-linear', {
'v-progress-linear--absolute': props.absolute,
'v-progress-linear--active': props.active && isIntersecting.value,
'v-progress-linear--reverse': isReversed.value,
'v-progress-linear--rounded': props.rounded,
'v-progress-linear--rounded-bar': props.roundedBar,
'v-progress-linear--striped': props.striped
}, roundedClasses.value, themeClasses.value, rtlClasses.value, props.class]),
"style": _normalizeStyle([{
bottom: props.location === 'bottom' ? 0 : undefined,
top: props.location === 'top' ? 0 : undefined,
height: props.active ? convertToUnit(height.value) : 0,
'--v-progress-linear-height': convertToUnit(height.value),
...(props.absolute ? locationStyles.value : {})
}, props.style]),
"role": "progressbar",
"aria-hidden": props.active ? 'false' : 'true',
"aria-valuemin": "0",
"aria-valuemax": props.max,
"aria-valuenow": props.indeterminate ? undefined : Math.min(parseFloat(progress.value), max.value),
"onClick": props.clickable && handleClick
}, {
default: () => [props.stream && _createElementVNode("div", {
"key": "stream",
"class": _normalizeClass(['v-progress-linear__stream', textColorClasses.value]),
"style": _normalizeStyle({
...textColorStyles.value,
[isReversed.value ? 'left' : 'right']: convertToUnit(-height.value),
borderTop: `${convertToUnit(height.value / 2)} dotted`,
opacity: parseFloat(props.bufferOpacity),
top: `calc(50% - ${convertToUnit(height.value / 4)})`,
width: convertToUnit(100 - normalizedBuffer.value, '%'),
'--v-progress-linear-stream-to': convertToUnit(height.value * (isReversed.value ? 1 : -1))
})
}, null), _createElementVNode("div", {
"class": _normalizeClass(['v-progress-linear__background', !isForcedColorsModeActive ? backgroundColorClasses.value : undefined]),
"style": _normalizeStyle([backgroundColorStyles.value, {
opacity: parseFloat(props.bgOpacity),
width: props.stream ? 0 : undefined
}])
}, null), _createElementVNode("div", {
"class": _normalizeClass(['v-progress-linear__buffer', !isForcedColorsModeActive ? bufferColorClasses.value : undefined]),
"style": _normalizeStyle([bufferColorStyles.value, {
opacity: parseFloat(props.bufferOpacity),
width: convertToUnit(normalizedBuffer.value, '%')
}])
}, null), _createVNode(Transition, {
"name": transition.value
}, {
default: () => [!props.indeterminate ? _createElementVNode("div", {
"class": _normalizeClass(['v-progress-linear__determinate', !isForcedColorsModeActive ? barColorClasses.value : undefined]),
"style": _normalizeStyle([barColorStyles.value, {
width: convertToUnit(normalizedValue.value, '%')
}])
}, null) : _createElementVNode("div", {
"class": "v-progress-linear__indeterminate"
}, [['long', 'short'].map(bar => _createElementVNode("div", {
"key": bar,
"class": _normalizeClass(['v-progress-linear__indeterminate', bar, !isForcedColorsModeActive ? barColorClasses.value : undefined]),
"style": _normalizeStyle(barColorStyles.value)
}, null))])]
}), slots.default && _createElementVNode("div", {
"class": "v-progress-linear__content"
}, [slots.default({
value: normalizedValue.value,
buffer: normalizedBuffer.value
})])]
}));
return {};
}
});
//# sourceMappingURL=VProgressLinear.js.map