mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
refactor: info component
This commit is contained in:
parent
79e7b4be65
commit
425ffb87eb
23
src-next/info/index.js
Normal file
23
src-next/info/index.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Utils
|
||||||
|
import { isDef } from '../../src/utils';
|
||||||
|
import { createNamespace } from '../utils/create';
|
||||||
|
|
||||||
|
const [createComponent, bem] = createNamespace('info');
|
||||||
|
|
||||||
|
export default createComponent({
|
||||||
|
props: {
|
||||||
|
dot: Boolean,
|
||||||
|
info: [Number, String],
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { dot, info } = this;
|
||||||
|
const showInfo = isDef(info) && info !== '';
|
||||||
|
|
||||||
|
if (!dot && !showInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div class={bem({ dot })}>{dot ? '' : info}</div>;
|
||||||
|
},
|
||||||
|
});
|
29
src-next/info/index.less
Normal file
29
src-next/info/index.less
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@import '../style/var';
|
||||||
|
|
||||||
|
.van-info {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
min-width: @info-size;
|
||||||
|
padding: @info-padding;
|
||||||
|
color: @info-color;
|
||||||
|
font-weight: @info-font-weight;
|
||||||
|
font-size: @info-font-size;
|
||||||
|
font-family: @info-font-family;
|
||||||
|
line-height: @info-size - @info-border-width * 2;
|
||||||
|
text-align: center;
|
||||||
|
background-color: @info-background-color;
|
||||||
|
border: @info-border-width solid @white;
|
||||||
|
border-radius: @info-size;
|
||||||
|
transform: translate(50%, -50%);
|
||||||
|
transform-origin: 100%;
|
||||||
|
|
||||||
|
&--dot {
|
||||||
|
width: @info-dot-size;
|
||||||
|
min-width: 0;
|
||||||
|
height: @info-dot-size;
|
||||||
|
background-color: @info-dot-color;
|
||||||
|
border-radius: 100%;
|
||||||
|
}
|
||||||
|
}
|
7
src-next/info/test/__snapshots__/index.spec.js.snap
Normal file
7
src-next/info/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`should not render when info is empty string 1`] = ``;
|
||||||
|
|
||||||
|
exports[`should not render when info is empty undefined 1`] = ``;
|
||||||
|
|
||||||
|
exports[`should render when info is zero 1`] = `<div class="van-info">0</div>`;
|
32
src-next/info/test/index.spec.js
Normal file
32
src-next/info/test/index.spec.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import Info from '..';
|
||||||
|
import { mount } from '../../../test';
|
||||||
|
|
||||||
|
test('should not render when info is empty string', () => {
|
||||||
|
const wrapper = mount(Info, {
|
||||||
|
propsData: {
|
||||||
|
info: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not render when info is empty undefined', () => {
|
||||||
|
const wrapper = mount(Info, {
|
||||||
|
propsData: {
|
||||||
|
info: undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render when info is zero', () => {
|
||||||
|
const wrapper = mount(Info, {
|
||||||
|
propsData: {
|
||||||
|
info: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user