choo-taro-ui-vue3
Version:
Taro UI Rewritten in Vue 3.0
108 lines (100 loc) • 4.57 kB
JavaScript
import { defineComponent, computed, toRef, renderList, Fragment, openBlock, createElementBlock, createCommentVNode, toDisplayString, createTextVNode, resolveComponent, withCtx, createVNode, normalizeClass, createBlock, mergeProps } from 'vue';
import { useModelValue } from '../composables';
const AtRadio = defineComponent({
name: "AtRadio",
emits: ["update:modelValue"],
props: {
modelValue: {
type: String,
default: ""
},
options: {
type: Array,
default: []
}
},
setup(props, { emit }) {
const radioModelValue = useModelValue(props, emit);
const genOptionClasses = computed(() => (option) => ({
"at-radio__option": true,
"at-radio__option--disabled": option.disabled
}));
const genIconClasses = computed(() => (option) => ({
"at-radio__icon": true,
"at-radio__icon--checked": props.modelValue === option.value
}));
function handleClick(option) {
if (option.disabled)
return;
radioModelValue.value = option.value;
}
return {
options: toRef(props, "options"),
genOptionClasses,
genIconClasses,
handleClick
};
}
});
// Binding optimization for webpack code-split
const _renderList = renderList, _Fragment = Fragment, _openBlock = openBlock, _createElementBlock = createElementBlock, _createCommentVNode = createCommentVNode, _toDisplayString = toDisplayString, _createTextVNode = createTextVNode, _resolveComponent = resolveComponent, _withCtx = withCtx, _createVNode = createVNode, _normalizeClass = normalizeClass, _createBlock = createBlock, _mergeProps = mergeProps;
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_taro_view = process.env.TARO_ENV === "h5" ? _resolveComponent("taro-view") : "view";
const _component_taro_text = process.env.TARO_ENV === "h5" ? _resolveComponent("taro-text") : "text";
return (_openBlock(), _createBlock(_component_taro_view, _mergeProps(_ctx.$attrs, { class: "at-radio" }), {
default: _withCtx(() => [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.options, (option, index) => {
return (_openBlock(), _createBlock(_component_taro_view, {
key: index,
class: _normalizeClass(_ctx.genOptionClasses(option)),
onTap: $event => (_ctx.handleClick(option))
}, {
default: _withCtx(() => [
_createVNode(_component_taro_view, { class: "at-radio__option-wrap" }, {
default: _withCtx(() => [
_createVNode(_component_taro_view, { class: "at-radio__option-container" }, {
default: _withCtx(() => [
_createCommentVNode(" title "),
_createVNode(_component_taro_view, { class: "at-radio__title" }, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(option.label), 1 /* TEXT */)
]),
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */),
_createCommentVNode(" icon "),
_createVNode(_component_taro_view, {
class: _normalizeClass(_ctx.genIconClasses(option))
}, {
default: _withCtx(() => [
_createVNode(_component_taro_text, { class: "at-icon at-icon-check" })
]),
_: 2 /* DYNAMIC */
}, 1032 /* PROPS, DYNAMIC_SLOTS */, ["class"])
]),
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */),
_createCommentVNode(" description "),
(option.desc)
? (_openBlock(), _createBlock(_component_taro_view, {
key: 0,
class: "at-radio__desc"
}, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(option.desc), 1 /* TEXT */)
]),
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */))
: _createCommentVNode("v-if", true)
]),
_: 2 /* DYNAMIC */
}, 1024 /* DYNAMIC_SLOTS */)
]),
_: 2 /* DYNAMIC */
}, 1032 /* PROPS, DYNAMIC_SLOTS */, ["class", "onTap"]))
}), 128 /* KEYED_FRAGMENT */))
]),
_: 1 /* STABLE */
}, 16 /* FULL_PROPS */))
}
AtRadio.render = _sfc_render;
export default AtRadio;