Files
heroui-vue/packages/vue/src/components/slider/SliderOutput.vue
T

35 lines
1023 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import type { SlotsType, VNode as SlotVNode } from "vue";
import { defineComponent, h } from "vue";
import { useSlider } from "./context";
export default defineComponent({
name: "SliderOutput",
inheritAttrs: false,
slots: Object as SlotsType<{
default?: (state: {
values: number[];
getThumbValueLabel: (index: number) => string;
}) => SlotVNode[];
}>,
props: { as: { type: String, default: "output" } },
setup(props, { attrs, slots }) {
const slider = useSlider();
return () =>
h(
props.as,
{
...attrs,
class: [slider.styles.output(), attrs.class],
"data-slot": "slider-output",
"aria-live": attrs["aria-live"] ?? "off",
},
slots.default?.({
values: [...slider.values.value],
getThumbValueLabel: (index: number) =>
slider.format(slider.values.value[index]),
}) ?? slider.values.value.map(slider.format).join(" – "),
);
},
});
</script>