mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
breaking change: remove SwitchCell component
This commit is contained in:
parent
1349301f01
commit
966fb5f46a
@ -1,78 +0,0 @@
|
||||
# SwitchCell
|
||||
|
||||
### Deprecate Tip
|
||||
|
||||
The SwitchCell component will be deprecated in version 3.0. Please use the Cell and Switch components instead.
|
||||
|
||||
### Install
|
||||
|
||||
```js
|
||||
import Vue from 'vue';
|
||||
import { SwitchCell } from 'vant';
|
||||
|
||||
Vue.use(SwitchCell);
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" title="Title" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
checked: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### Disabled
|
||||
|
||||
use `disabled` property to disable the component
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" disabled title="Title" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
### Loading
|
||||
|
||||
use `loading` property to keep component in loading state
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" loading title="Title" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
|
||||
| Attribute | Description | Type | Default |
|
||||
| --- | --- | --- | --- |
|
||||
| v-model | on-off state of the switch | _any_ | `false` |
|
||||
| title | the left side title | _string_ | `''` |
|
||||
| border | whether to show cell border | _boolean_ | `true` |
|
||||
| cell-size | Cell size,can be set to `large` | _string_ | - |
|
||||
| loading | whether switch is loading | _boolean_ | `false` |
|
||||
| disabled | whether to disable switch | _boolean_ | `false` |
|
||||
| size | Size of switch | _number \| string_ | `24px` |
|
||||
| active-color | Background of switch color when active | _string_ | `#1989fa` |
|
||||
| inactive-color | Background of switch color when inactive | _string_ | `white` |
|
||||
| active-value | Value when active | _any_ | `true` |
|
||||
| inactive-value | Value when inactive | _any_ | `false` |
|
||||
|
||||
### Events
|
||||
|
||||
| Event | Description | Arguments |
|
||||
| --- | --- | --- |
|
||||
| change | triggered when the on-off state is changed | checked: switch is on or not |
|
@ -1,86 +0,0 @@
|
||||
# SwitchCell 开关单元格
|
||||
|
||||
### 废弃提示
|
||||
|
||||
<b>SwitchCell 组件将在 3.0 版本中废弃</b>,请直接使用 Cell 和 Switch 组件代替,替换写法如下:
|
||||
|
||||
```html
|
||||
<van-cell center title="标题">
|
||||
<template #right-icon>
|
||||
<van-switch v-model="checked" size="24" />
|
||||
</template>
|
||||
</van-cell>
|
||||
```
|
||||
|
||||
### 引入
|
||||
|
||||
```js
|
||||
import Vue from 'vue';
|
||||
import { SwitchCell } from 'vant';
|
||||
|
||||
Vue.use(SwitchCell);
|
||||
```
|
||||
|
||||
## 代码演示
|
||||
|
||||
### 基础用法
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" title="标题" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
```js
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
checked: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### 禁用状态
|
||||
|
||||
通过`disabled`属性可以将组件设置为禁用状态
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" disabled title="标题" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
### 加载状态
|
||||
|
||||
通过`loading`属性可以将组件设置为加载状态
|
||||
|
||||
```html
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" loading title="标题" />
|
||||
</van-cell-group>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| --- | --- | --- | --- |
|
||||
| v-model | 开关状态 | _any_ | `false` |
|
||||
| title | 左侧标题 | _string_ | `''` |
|
||||
| border | 是否展示单元格内边框 | _boolean_ | `true` |
|
||||
| cell-size | 单元格大小,可选值为 `large` | _string_ | - |
|
||||
| loading | 是否为加载状态 | _boolean_ | `false` |
|
||||
| disabled | 是否为禁用状态 | _boolean_ | `false` |
|
||||
| size | 开关尺寸 | _number \| string_ | `24px` |
|
||||
| active-color | 开关时的背景色 | _string_ | `#1989fa` |
|
||||
| inactive-color | 开关时的背景色 | _string_ | `white` |
|
||||
| active-value | 打开时的值 | _any_ | `true` |
|
||||
| inactive-value | 关闭时的值 | _any_ | `false` |
|
||||
|
||||
### Events
|
||||
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
| ------ | ---------------- | --------------------- |
|
||||
| change | 开关状态切换回调 | checked: 是否选中开关 |
|
@ -1,31 +0,0 @@
|
||||
<template>
|
||||
<demo-section>
|
||||
<demo-block :title="t('basicUsage')">
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" :title="t('title')" />
|
||||
</van-cell-group>
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('disabled')">
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" disabled :title="t('title')" />
|
||||
</van-cell-group>
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('loadingStatus')">
|
||||
<van-cell-group>
|
||||
<van-switch-cell v-model="checked" loading :title="t('title')" />
|
||||
</van-cell-group>
|
||||
</demo-block>
|
||||
</demo-section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
checked: true,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
@ -1,15 +0,0 @@
|
||||
@import '../style/var';
|
||||
|
||||
.van-switch-cell {
|
||||
padding-top: @switch-cell-padding-top;
|
||||
padding-bottom: @switch-cell-padding-bottom;
|
||||
|
||||
&--large {
|
||||
padding-top: @switch-cell-large-padding-top;
|
||||
padding-bottom: @switch-cell-large-padding-bottom;
|
||||
}
|
||||
|
||||
.van-switch {
|
||||
float: right;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
// Utils
|
||||
import { createNamespace } from '../utils';
|
||||
import { inherit } from '../utils/functional';
|
||||
|
||||
// Components
|
||||
import Cell from '../cell';
|
||||
import Switch from '../switch';
|
||||
import { switchProps, SharedSwitchProps } from '../switch/shared';
|
||||
|
||||
// Types
|
||||
import { CreateElement, RenderContext } from 'vue/types';
|
||||
import { DefaultSlots } from '../utils/types';
|
||||
|
||||
export type SwitchCellProps = SharedSwitchProps & {
|
||||
size: string;
|
||||
title?: string;
|
||||
border?: boolean;
|
||||
cellSize?: string;
|
||||
};
|
||||
|
||||
export type SwitchCellEvents = {
|
||||
onChange?(checked: boolean): void;
|
||||
};
|
||||
|
||||
const [createComponent, bem] = createNamespace('switch-cell');
|
||||
|
||||
function SwitchCell(
|
||||
h: CreateElement,
|
||||
props: SwitchCellProps,
|
||||
slots: DefaultSlots,
|
||||
ctx: RenderContext<SwitchCellProps>
|
||||
) {
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
size={props.cellSize}
|
||||
title={props.title}
|
||||
border={props.border}
|
||||
class={bem([props.cellSize])}
|
||||
{...inherit(ctx)}
|
||||
>
|
||||
<Switch {...{ props, on: ctx.listeners }} />
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
|
||||
SwitchCell.props = {
|
||||
...switchProps,
|
||||
title: String,
|
||||
cellSize: String,
|
||||
border: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
size: {
|
||||
type: String,
|
||||
default: '24px',
|
||||
},
|
||||
};
|
||||
|
||||
export default createComponent<SwitchCellProps, SwitchCellEvents>(SwitchCell);
|
@ -1,44 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renders demo correctly 1`] = `
|
||||
<div>
|
||||
<div>
|
||||
<div class="van-cell-group van-hairline--top-bottom">
|
||||
<div class="van-cell van-cell--center van-switch-cell">
|
||||
<div class="van-cell__title"><span>标题</span></div>
|
||||
<div class="van-cell__value">
|
||||
<div role="switch" aria-checked="true" class="van-switch van-switch--on" style="font-size: 24px;">
|
||||
<div class="van-switch__node"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-cell-group van-hairline--top-bottom">
|
||||
<div class="van-cell van-cell--center van-switch-cell">
|
||||
<div class="van-cell__title"><span>标题</span></div>
|
||||
<div class="van-cell__value">
|
||||
<div role="switch" aria-checked="true" class="van-switch van-switch--on van-switch--disabled" style="font-size: 24px;">
|
||||
<div class="van-switch__node"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-cell-group van-hairline--top-bottom">
|
||||
<div class="van-cell van-cell--center van-switch-cell">
|
||||
<div class="van-cell__title"><span>标题</span></div>
|
||||
<div class="van-cell__value">
|
||||
<div role="switch" aria-checked="true" class="van-switch van-switch--on van-switch--loading" style="font-size: 24px;">
|
||||
<div class="van-switch__node">
|
||||
<div class="van-loading van-loading--circular van-switch__loading"><span class="van-loading__spinner van-loading__spinner--circular"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
@ -1,21 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`border prop 1`] = `
|
||||
<div class="van-cell van-cell--center van-cell--borderless van-switch-cell">
|
||||
<div class="van-cell__value van-cell__value--alone">
|
||||
<div role="switch" aria-checked="false" class="van-switch" style="font-size: 24px;">
|
||||
<div class="van-switch__node"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`cell-size prop 1`] = `
|
||||
<div class="van-cell van-cell--center van-cell--large van-switch-cell van-switch-cell--large">
|
||||
<div class="van-cell__value van-cell__value--alone">
|
||||
<div role="switch" aria-checked="false" class="van-switch" style="font-size: 24px;">
|
||||
<div class="van-switch__node"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
@ -1,4 +0,0 @@
|
||||
import Demo from '../demo';
|
||||
import { snapshotDemo } from '../../../test/demo';
|
||||
|
||||
snapshotDemo(Demo);
|
@ -1,37 +0,0 @@
|
||||
import SwitchCell from '..';
|
||||
import { mount } from '../../../test';
|
||||
|
||||
test('change event', () => {
|
||||
const onChange = jest.fn();
|
||||
const wrapper = mount(SwitchCell, {
|
||||
context: {
|
||||
on: {
|
||||
change: onChange,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.find('.van-switch').trigger('click');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
test('border prop', () => {
|
||||
const wrapper = mount(SwitchCell, {
|
||||
propsData: {
|
||||
border: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('cell-size prop', () => {
|
||||
const wrapper = mount(SwitchCell, {
|
||||
propsData: {
|
||||
cellSize: 'large',
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user