hongluan-ui
Version:
Hongluan Component Library for Vue 3
55 lines (52 loc) • 1.76 kB
JavaScript
import { defineComponent, ref, computed, watch, openBlock, createElementBlock, normalizeClass, createElementVNode, createCommentVNode } from 'vue';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
const _sfc_main = defineComponent({
name: "SimpleTableSortableIcon",
props: {
sortable: [Boolean, String]
},
emits: ["sort-change"],
setup(props, { emit }) {
const active = ref(getActive());
const shouldShow = computed(() => {
return typeof props.sortable === "boolean" ? props.sortable : !!props.sortable;
});
const sort = (which) => {
if (active.value !== which) {
active.value = which;
} else {
active.value = "";
}
emit("sort-change", active.value);
};
function getActive() {
return typeof props.sortable !== "boolean" && props.sortable ? props.sortable : "";
}
watch(() => props.sortable, () => {
active.value = getActive();
});
return {
active,
shouldShow,
sort
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return _ctx.shouldShow ? (openBlock(), createElementBlock("span", {
key: 0,
class: normalizeClass(["caret-wrapper", _ctx.active])
}, [
createElementVNode("i", {
class: "sort-caret ascending",
onClick: ($event) => _ctx.sort("ascending")
}, null, 8, ["onClick"]),
createElementVNode("i", {
class: "sort-caret descending",
onClick: ($event) => _ctx.sort("descending")
}, null, 8, ["onClick"])
], 2)) : createCommentVNode("v-if", true);
}
var SortableIcon = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { SortableIcon as default };
//# sourceMappingURL=sortable.mjs.map