mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
93 lines
2.0 KiB
TypeScript
93 lines
2.0 KiB
TypeScript
import { computed, CSSProperties, defineComponent } from 'vue';
|
|
import { createNamespace, isDef, truthProp } from '../utils';
|
|
import { Badge } from '../badge';
|
|
|
|
const [name, bem] = createNamespace('tab');
|
|
|
|
export default defineComponent({
|
|
name,
|
|
|
|
props: {
|
|
dot: Boolean,
|
|
type: String,
|
|
color: String,
|
|
title: String,
|
|
badge: [Number, String],
|
|
isActive: Boolean,
|
|
disabled: Boolean,
|
|
scrollable: Boolean,
|
|
activeColor: String,
|
|
renderTitle: Function,
|
|
inactiveColor: String,
|
|
showZeroBadge: truthProp,
|
|
},
|
|
|
|
setup(props) {
|
|
const style = computed(() => {
|
|
const style: CSSProperties = {};
|
|
const { type, color, disabled, isActive, activeColor, inactiveColor } =
|
|
props;
|
|
|
|
const isCard = type === 'card';
|
|
|
|
// card theme color
|
|
if (color && isCard) {
|
|
style.borderColor = color;
|
|
|
|
if (!disabled) {
|
|
if (isActive) {
|
|
style.backgroundColor = color;
|
|
} else {
|
|
style.color = color;
|
|
}
|
|
}
|
|
}
|
|
|
|
const titleColor = isActive ? activeColor : inactiveColor;
|
|
if (titleColor) {
|
|
style.color = titleColor;
|
|
}
|
|
|
|
return style;
|
|
});
|
|
|
|
const renderText = () => {
|
|
const Text = (
|
|
<span class={bem('text', { ellipsis: !props.scrollable })}>
|
|
{props.renderTitle ? props.renderTitle() : props.title}
|
|
</span>
|
|
);
|
|
|
|
if (props.dot || (isDef(props.badge) && props.badge !== '')) {
|
|
return (
|
|
<Badge
|
|
dot={props.dot}
|
|
content={props.badge}
|
|
showZero={props.showZeroBadge}
|
|
>
|
|
{Text}
|
|
</Badge>
|
|
);
|
|
}
|
|
|
|
return Text;
|
|
};
|
|
|
|
return () => (
|
|
<div
|
|
role="tab"
|
|
class={[
|
|
bem({
|
|
active: props.isActive,
|
|
disabled: props.disabled,
|
|
}),
|
|
]}
|
|
style={style.value}
|
|
aria-selected={props.isActive}
|
|
>
|
|
{renderText()}
|
|
</div>
|
|
);
|
|
},
|
|
});
|