choo-taro-ui-vue3
Version:
Taro UI Rewritten in Vue 3.0
68 lines (60 loc) • 2.21 kB
JavaScript
import { defineComponent, computed, toRef, renderSlot, resolveComponent, openBlock, createBlock, createCommentVNode, toDisplayString, createTextVNode, withCtx, mergeProps } from 'vue';
const AtBadge = defineComponent({
name: "AtBadge",
props: {
dot: Boolean,
value: {
type: [String, Number],
default: ""
},
maxValue: {
type: Number,
default: 99
}
},
setup(props) {
const formatedValue = computed(() => formatValue(props.value, props.maxValue));
function formatValue(value, maxValue) {
if (!Boolean(value))
return "";
const numValue = +value;
if (Number.isNaN(numValue)) {
return value;
}
return numValue > maxValue ? `${maxValue}+` : numValue;
}
return {
dot: toRef(props, "dot"),
formatedValue
};
}
});
// Binding optimization for webpack code-split
const _renderSlot = renderSlot, _resolveComponent = resolveComponent, _openBlock = openBlock, _createBlock = createBlock, _createCommentVNode = createCommentVNode, _toDisplayString = toDisplayString, _createTextVNode = createTextVNode, _withCtx = withCtx, _mergeProps = mergeProps;
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_taro_view = process.env.TARO_ENV === "h5" ? _resolveComponent("taro-view") : "view";
return (_openBlock(), _createBlock(_component_taro_view, _mergeProps(_ctx.$attrs, { class: "at-badge" }), {
default: _withCtx(() => [
_renderSlot(_ctx.$slots, "default"),
(_ctx.dot)
? (_openBlock(), _createBlock(_component_taro_view, {
key: 0,
class: "at-badge__dot"
}))
: (_ctx.formatedValue !== '')
? (_openBlock(), _createBlock(_component_taro_view, {
key: 1,
class: "at-badge__num"
}, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(_ctx.formatedValue), 1 /* TEXT */)
]),
_: 1 /* STABLE */
}))
: _createCommentVNode("v-if", true)
]),
_: 3 /* FORWARDED */
}, 16 /* FULL_PROPS */))
}
AtBadge.render = _sfc_render;
export default AtBadge;