mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: improve Collapse、ContactCard jsx segment
This commit is contained in:
parent
9c6ae2c28b
commit
1dd0d42b5f
@ -25,7 +25,7 @@ function CellGroup(
|
|||||||
) {
|
) {
|
||||||
const Group = (
|
const Group = (
|
||||||
<div class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]} {...inherit(ctx, true)}>
|
<div class={[bem(), { [BORDER_TOP_BOTTOM]: props.border }]} {...inherit(ctx, true)}>
|
||||||
{slots.default && slots.default()}
|
{slots.default?.()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ export default createComponent({
|
|||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const progress = Math.min((now - this.startTime) / this.duration, 1);
|
const progress = Math.min((now - this.startTime) / this.duration, 1);
|
||||||
const rate = progress * (this.endRate - this.startRate) + this.startRate;
|
const rate = progress * (this.endRate - this.startRate) + this.startRate;
|
||||||
|
|
||||||
this.$emit('input', format(parseFloat(rate.toFixed(1))));
|
this.$emit('input', format(parseFloat(rate.toFixed(1))));
|
||||||
|
|
||||||
if (this.increase ? rate < this.endRate : rate > this.endRate) {
|
if (this.increase ? rate < this.endRate : rate > this.endRate) {
|
||||||
|
@ -6,6 +6,7 @@ import { cellProps } from '../cell/shared';
|
|||||||
import { ChildrenMixin } from '../mixins/relation';
|
import { ChildrenMixin } from '../mixins/relation';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('collapse-item');
|
const [createComponent, bem] = createNamespace('collapse-item');
|
||||||
|
|
||||||
const CELL_SLOTS = ['title', 'icon', 'right-icon'];
|
const CELL_SLOTS = ['title', 'icon', 'right-icon'];
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
@ -40,7 +41,11 @@ export default createComponent({
|
|||||||
|
|
||||||
const { value, accordion } = this.parent;
|
const { value, accordion } = this.parent;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production' && !accordion && !Array.isArray(value)) {
|
if (
|
||||||
|
process.env.NODE_ENV !== 'production' &&
|
||||||
|
!accordion &&
|
||||||
|
!Array.isArray(value)
|
||||||
|
) {
|
||||||
console.error('[Vant] Collapse: type of prop "value" should be Array');
|
console.error('[Vant] Collapse: type of prop "value" should be Array');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -73,6 +78,7 @@ export default createComponent({
|
|||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
const { content, wrapper } = this.$refs;
|
const { content, wrapper } = this.$refs;
|
||||||
|
|
||||||
if (!content || !wrapper) {
|
if (!content || !wrapper) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,9 +105,9 @@ export default createComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { parent } = this;
|
const { parent, currentName } = this;
|
||||||
const name =
|
const name = parent.accordion && currentName === parent.value ? '' : currentName;
|
||||||
parent.accordion && this.currentName === parent.value ? '' : this.currentName;
|
|
||||||
this.parent.switch(name, !this.expanded);
|
this.parent.switch(name, !this.expanded);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -111,52 +117,59 @@ export default createComponent({
|
|||||||
} else {
|
} else {
|
||||||
this.$refs.wrapper.style.height = '';
|
this.$refs.wrapper.style.height = '';
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
genTitle() {
|
||||||
|
const { disabled, expanded } = this;
|
||||||
|
|
||||||
|
const titleSlots = CELL_SLOTS.reduce((slots, name) => {
|
||||||
|
if (this.slots(name)) {
|
||||||
|
slots[name] = () => this.slots(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return slots;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
if (this.slots('value')) {
|
||||||
|
titleSlots.default = () => this.slots('value');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Cell
|
||||||
|
role="button"
|
||||||
|
class={bem('title', { disabled, expanded })}
|
||||||
|
onClick={this.onClick}
|
||||||
|
scopedSlots={titleSlots}
|
||||||
|
tabindex={disabled ? -1 : 0}
|
||||||
|
aria-expanded={String(expanded)}
|
||||||
|
{...{ props: this.$props }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
genContent() {
|
||||||
|
if (this.inited) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
vShow={this.show}
|
||||||
|
ref="wrapper"
|
||||||
|
class={bem('wrapper')}
|
||||||
|
onTransitionend={this.onTransitionEnd}
|
||||||
|
>
|
||||||
|
<div ref="content" class={bem('content')}>
|
||||||
|
{this.slots()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { disabled, expanded } = this;
|
|
||||||
|
|
||||||
const titleSlots = CELL_SLOTS.reduce((slots, name) => {
|
|
||||||
if (this.slots(name)) {
|
|
||||||
slots[name] = () => this.slots(name);
|
|
||||||
}
|
|
||||||
return slots;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
if (this.slots('value')) {
|
|
||||||
titleSlots.default = () => this.slots('value');
|
|
||||||
}
|
|
||||||
|
|
||||||
const Title = (
|
|
||||||
<Cell
|
|
||||||
role="button"
|
|
||||||
class={bem('title', { disabled, expanded })}
|
|
||||||
onClick={this.onClick}
|
|
||||||
scopedSlots={titleSlots}
|
|
||||||
tabindex={disabled ? -1 : 0}
|
|
||||||
aria-expanded={String(expanded)}
|
|
||||||
{...{ props: this.$props }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const Content = this.inited && (
|
|
||||||
<div
|
|
||||||
vShow={this.show}
|
|
||||||
ref="wrapper"
|
|
||||||
class={bem('wrapper')}
|
|
||||||
onTransitionend={this.onTransitionEnd}
|
|
||||||
>
|
|
||||||
<div ref="content" class={bem('content')}>
|
|
||||||
{this.slots()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={[bem(), { [BORDER_TOP]: this.index }]}>
|
<div class={[bem(), { [BORDER_TOP]: this.index }]}>
|
||||||
{Title}
|
{this.genTitle()}
|
||||||
{Content}
|
{this.genContent()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,17 @@ function ContactCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Content() {
|
||||||
|
if (type === 'add') {
|
||||||
|
return props.addText || t('addText');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
<div>{`${t('name')}:${props.name}`}</div>,
|
||||||
|
<div>{`${t('tel')}:${props.tel}`}</div>
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Cell
|
<Cell
|
||||||
center
|
center
|
||||||
@ -41,12 +52,7 @@ function ContactCard(
|
|||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
{...inherit(ctx)}
|
{...inherit(ctx)}
|
||||||
>
|
>
|
||||||
{type === 'add'
|
{Content()}
|
||||||
? props.addText || t('addText')
|
|
||||||
: [
|
|
||||||
<div>{`${t('name')}:${props.name}`}</div>,
|
|
||||||
<div>{`${t('tel')}:${props.tel}`}</div>
|
|
||||||
]}
|
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user