UNPKG

hongluan-ui

Version:
219 lines (216 loc) 9.31 kB
import { defineComponent, reactive, computed, toRefs, provide, openBlock, createElementBlock, unref, normalizeClass, createElementVNode, normalizeStyle, createVNode, createBlock, createCommentVNode, Fragment, renderList, withModifiers } from 'vue'; import { useEventListener } from '@vueuse/core'; import '../../../hooks/index.mjs'; import '../../../tokens/index.mjs'; import { sliderProps, sliderEmits } from './slider2.mjs'; import _sfc_main$1 from './button2.mjs'; import SliderMarker from './marker.mjs'; import './composables/index.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; import { useLocale } from '../../../hooks/use-locale/index.mjs'; import { useSlide } from './composables/use-slide.mjs'; import { useStops } from './composables/use-stops.mjs'; import { useFormItemInputId } from '../../../hooks/use-form-item/index.mjs'; import { useMarks } from './composables/use-marks.mjs'; import { useWatch } from './composables/use-watch.mjs'; import { useLifecycle } from './composables/use-lifecycle.mjs'; import { sliderContextKey } from '../../../tokens/slider.mjs'; const __default__ = defineComponent({ name: "Slider" }); const _sfc_main = /* @__PURE__ */ defineComponent({ ...__default__, props: sliderProps, emits: sliderEmits, setup(__props, { expose, emit }) { const props = __props; const { namespace } = useNamespace("slider"); const { t } = useLocale(); const initData = reactive({ firstValue: 0, secondValue: 0, oldValue: 0, dragging: false, sliderSize: 1 }); const { formItem, slider, firstButton, secondButton, sliderDisabled, minValue, maxValue, runwayStyle, barStyle, resetSize, emitChange, onSliderWrapperPrevent, onSliderClick, onSliderDown, onSliderMarkerDown, setFirstValue, setSecondValue } = useSlide(props, initData, emit); const { stops, getStopStyle } = useStops(props, initData, minValue, maxValue); const { inputId, isLabeledByFormItem } = useFormItemInputId(props, { formItemContext: formItem }); const groupLabel = computed(() => { return props.label || props.ariaLabel || t("hl.slider.defaultLabel", { min: props.min, max: props.max }); }); const firstButtonLabel = computed(() => { if (props.range) { return props.rangeStartLabel || t("hl.slider.defaultRangeStartLabel"); } else { return groupLabel.value; } }); const firstValueText = computed(() => { return props.formatValueText ? props.formatValueText(firstValue.value) : `${firstValue.value}`; }); const secondButtonLabel = computed(() => { return props.rangeEndLabel || t("hl.slider.defaultRangeEndLabel"); }); const secondValueText = computed(() => { return props.formatValueText ? props.formatValueText(secondValue.value) : `${secondValue.value}`; }); const markList = useMarks(props); useWatch(props, initData, minValue, maxValue, emit, formItem); const precision = computed(() => { const precisions = [props.min, props.max, props.step].map((item) => { const decimal = `${item}`.split(".")[1]; return decimal ? decimal.length : 0; }); return Math.max.apply(null, precisions); }); const { sliderWrapper } = useLifecycle(props, initData, resetSize); const { firstValue, secondValue, sliderSize } = toRefs(initData); const updateDragging = (val) => { initData.dragging = val; }; useEventListener(sliderWrapper, "touchstart", onSliderWrapperPrevent, { passive: false }); useEventListener(sliderWrapper, "touchmove", onSliderWrapperPrevent, { passive: false }); provide(sliderContextKey, { ...toRefs(props), sliderSize, disabled: sliderDisabled, precision, emitChange, resetSize, updateDragging }); expose({ onSliderClick }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { id: _ctx.range ? unref(inputId) : void 0, ref_key: "sliderWrapper", ref: sliderWrapper, class: normalizeClass([ unref(namespace), _ctx.vertical ? "is-vertical" : "", _ctx.type ? _ctx.type : "", _ctx.showStops ? "show-stops" : "" ]), role: _ctx.range ? "group" : void 0, "aria-label": _ctx.range && !unref(isLabeledByFormItem) ? unref(groupLabel) : void 0, "aria-labelledby": _ctx.range && unref(isLabeledByFormItem) ? unref(formItem).labelId : void 0 }, [ createElementVNode("div", { ref_key: "slider", ref: slider, class: normalizeClass({ "slider-wrap": true, disabled: unref(sliderDisabled) }), style: normalizeStyle(unref(runwayStyle)), onMousedown: unref(onSliderDown), onTouchstartPassive: unref(onSliderDown) }, [ createElementVNode("div", { class: "slider-bar", style: normalizeStyle(unref(barStyle)) }, null, 4), createVNode(_sfc_main$1, { id: !_ctx.range ? unref(inputId) : void 0, ref_key: "firstButton", ref: firstButton, "model-value": unref(firstValue), vertical: _ctx.vertical, "tooltip-class": _ctx.tooltipClass, placement: _ctx.placement, role: "slider", "aria-label": _ctx.range || !unref(isLabeledByFormItem) ? unref(firstButtonLabel) : void 0, "aria-labelledby": !_ctx.range && unref(isLabeledByFormItem) ? unref(formItem).labelId : void 0, "aria-valuemin": _ctx.min, "aria-valuemax": _ctx.range ? unref(secondValue) : _ctx.max, "aria-valuenow": unref(firstValue), "aria-valuetext": unref(firstValueText), "aria-orientation": _ctx.vertical ? "vertical" : "horizontal", "aria-disabled": unref(sliderDisabled), "onUpdate:modelValue": unref(setFirstValue) }, null, 8, ["id", "model-value", "vertical", "tooltip-class", "placement", "aria-label", "aria-labelledby", "aria-valuemin", "aria-valuemax", "aria-valuenow", "aria-valuetext", "aria-orientation", "aria-disabled", "onUpdate:modelValue"]), _ctx.range ? (openBlock(), createBlock(_sfc_main$1, { key: 0, ref_key: "secondButton", ref: secondButton, "model-value": unref(secondValue), vertical: _ctx.vertical, "tooltip-class": _ctx.tooltipClass, placement: _ctx.placement, role: "slider", "aria-label": unref(secondButtonLabel), "aria-valuemin": unref(firstValue), "aria-valuemax": _ctx.max, "aria-valuenow": unref(secondValue), "aria-valuetext": unref(secondValueText), "aria-orientation": _ctx.vertical ? "vertical" : "horizontal", "aria-disabled": unref(sliderDisabled), "onUpdate:modelValue": unref(setSecondValue) }, null, 8, ["model-value", "vertical", "tooltip-class", "placement", "aria-label", "aria-valuemin", "aria-valuemax", "aria-valuenow", "aria-valuetext", "aria-orientation", "aria-disabled", "onUpdate:modelValue"])) : createCommentVNode("v-if", true), _ctx.showStops ? (openBlock(), createElementBlock("div", { key: 1 }, [ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(stops), (item, key) => { return openBlock(), createElementBlock("div", { key, class: "slider-stop", style: normalizeStyle(unref(getStopStyle)(item)) }, null, 4); }), 128)) ])) : createCommentVNode("v-if", true), unref(markList).length > 0 ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [ createElementVNode("div", null, [ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(markList), (item, key) => { return openBlock(), createElementBlock("div", { key, style: normalizeStyle(unref(getStopStyle)(item.position)), class: "slider-stop slider-marks-stop" }, null, 4); }), 128)) ]), createElementVNode("div", { class: "slider-marks" }, [ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(markList), (item, key) => { return openBlock(), createBlock(unref(SliderMarker), { key, mark: item.mark, style: normalizeStyle(unref(getStopStyle)(item.position)), onMousedown: withModifiers(($event) => unref(onSliderMarkerDown)(item.position), ["stop"]) }, null, 8, ["mark", "style", "onMousedown"]); }), 128)) ]) ], 64)) : createCommentVNode("v-if", true) ], 46, ["onMousedown", "onTouchstartPassive"]) ], 10, ["id", "role", "aria-label", "aria-labelledby"]); }; } }); export { _sfc_main as default }; //# sourceMappingURL=slider.mjs.map