Compare commits
10 Commits
9866bfba5c
...
205336cd6a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
205336cd6a | ||
|
|
230ed26763 | ||
|
|
b1283de219 | ||
|
|
4594c53f53 | ||
|
|
9bca25831b | ||
|
|
85f06fc373 | ||
|
|
37106d17a9 | ||
|
|
162ab6b14f | ||
|
|
d8a578d79c | ||
|
|
7f1c0e63d2 |
@@ -122,7 +122,6 @@ Vant 3/4 supports modern browsers and Chrome >= 51、iOS >= 10.0 (same as Vue 3)
|
||||
| Project | Description |
|
||||
| --- | --- |
|
||||
| [3lang3/react-vant](https://github.com/3lang3/react-vant) | React mobile UI Components based on Vant |
|
||||
| [vant-aliapp](https://github.com/ant-move/Vant-Aliapp) | Alipay MiniProgram UI |
|
||||
| [vant-theme](https://github.com/Aisen60/vant-theme) | Online theme preview built on Vant UI |
|
||||
| [@antmjs/vantui](https://github.com/antmjs/vantui) | Mobile UI Components based on Vant, supporting Taro and React |
|
||||
| [Taroify](https://github.com/mallfoundry/taroify) | Taroify is the Taro version of Vant |
|
||||
@@ -133,7 +132,6 @@ Vant 3/4 supports modern browsers and Chrome >= 51、iOS >= 10.0 (same as Vue 3)
|
||||
| [vscode-common-intellisense](https://github.com/Simon-He95/vscode-common-intellisense) | A VS Code extension that provides better intellisense to Vant developers |
|
||||
| [nuxt-vant-mobile](https://github.com/vue-zone/nuxt-vant-mobile) | Nuxt _⁴_ project template based on Vant, out of the box |
|
||||
| [mobvue](https://github.com/un-pany/mobvue) | A well-crafted mobile web app template |
|
||||
| [novlan1/press-ui](https://github.com/novlan1/press-ui) | Uni APP mobile UI Components based on Vant |
|
||||
|
||||
## Links
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
Vant 是一个**轻量、可定制的移动端组件库**,于 2017 年开源。
|
||||
|
||||
目前 Vant 官方提供了 [Vue 2 版本](https://vant-ui.github.io/vant/v2/)、[Vue 3 版本](https://vant-ui.github.io/vant/)和[微信小程序版本](https://vant-ui.github.io/vant-weapp/),并由社区团队维护 [React 版本](https://github.com/3lang3/react-vant)和[支付宝小程序版本](https://github.com/ant-move/Vant-Aliapp)。
|
||||
目前 Vant 官方提供了 [Vue 2 版本](https://vant-ui.github.io/vant/v2/)、[Vue 3 版本](https://vant-ui.github.io/vant/)和[微信小程序版本](https://vant-ui.github.io/vant-weapp/),并由社区团队维护 [React 版本](https://github.com/3lang3/react-vant)。
|
||||
|
||||
## 特性
|
||||
|
||||
@@ -128,7 +128,6 @@ Vant 3/4 支持现代浏览器以及 Chrome >= 51、iOS >= 10.0(与 Vue 3 一
|
||||
| 项目 | 描述 |
|
||||
| --- | --- |
|
||||
| [3lang3/react-vant](https://github.com/3lang3/react-vant) | 参照 Vant 打造的 React 框架移动端组件库 |
|
||||
| [vant-aliapp](https://github.com/ant-move/Vant-Aliapp) | Vant 支付宝小程序版 |
|
||||
| [vant-theme](https://github.com/Aisen60/vant-theme) | Vant 在线主题预览工具 |
|
||||
| [@antmjs/vantui](https://github.com/antmjs/vantui) | 基于 Vant Weapp 开发的多端组件库,同时支持 Taro 和 React |
|
||||
| [Taroify](https://github.com/mallfoundry/taroify) | Taroify 是 Vant 的 Taro 版本,两者基于相同的视觉规范,提供一致的 API 接口,助力开发者快速搭建小程序应用 |
|
||||
@@ -139,7 +138,6 @@ Vant 3/4 支持现代浏览器以及 Chrome >= 51、iOS >= 10.0(与 Vue 3 一
|
||||
| [vscode-common-intellisense](https://github.com/Simon-He95/vscode-common-intellisense) | VS Code 扩展,为 Vant 开发者提供更好的智能感知 |
|
||||
| [nuxt-vant-mobile](https://github.com/vue-zone/nuxt-vant-mobile) | 基于 Vant 的 Nuxt _⁴_ 项目模板,开箱即用 |
|
||||
| [mobvue](https://github.com/un-pany/mobvue) | 一个精心制作的移动端 H5 模板 |
|
||||
| [novlan1/press-ui](https://github.com/novlan1/press-ui) | 参照 Vant 打造的 uni-app 框架移动端组件库 |
|
||||
|
||||
## 链接
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
"*.{ts,tsx,js,vue}": "eslint --fix"
|
||||
},
|
||||
"engines": {
|
||||
"pnpm": ">= 10.28.0"
|
||||
"pnpm": ">= 10.30.0"
|
||||
},
|
||||
"packageManager": "pnpm@10.28.0",
|
||||
"packageManager": "pnpm@10.30.0",
|
||||
"devDependencies": {
|
||||
"@vant/cli": "workspace:*",
|
||||
"@vant/eslint-config": "workspace:*",
|
||||
"eslint": "^8.57.1",
|
||||
"husky": "^9.1.7",
|
||||
"nano-staged": "^0.9.0",
|
||||
"prettier": "^3.7.4"
|
||||
"prettier": "^3.8.1"
|
||||
},
|
||||
"overrides": {
|
||||
"esbuild": "^0.27.2"
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
"release": "rm -rf ./site/node_modules && vant-cli release"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.28.6",
|
||||
"@babel/core": "^7.29.0",
|
||||
"@babel/preset-typescript": "^7.28.5",
|
||||
"@rsbuild/core": "^1.7.2",
|
||||
"@rsbuild/plugin-babel": "^1.0.7",
|
||||
"@rsbuild/plugin-less": "^1.5.1",
|
||||
"@rsbuild/plugin-sass": "^1.4.1",
|
||||
"@rsbuild/plugin-babel": "^1.1.0",
|
||||
"@rsbuild/plugin-less": "^1.6.0",
|
||||
"@rsbuild/plugin-sass": "^1.5.0",
|
||||
"@rsbuild/plugin-vue": "^1.2.3",
|
||||
"@rsbuild/plugin-vue-jsx": "^1.1.2",
|
||||
"@vant/eslint-config": "workspace:^",
|
||||
@@ -55,17 +55,17 @@
|
||||
"highlight.js": "^11.11.1",
|
||||
"husky": "^9.1.7",
|
||||
"less": "^4.5.1",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash": "^4.17.23",
|
||||
"markdown-it": "^14.1.0",
|
||||
"markdown-it-anchor": "^9.2.0",
|
||||
"nano-staged": "^0.9.0",
|
||||
"picocolors": "^1.1.1",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss-load-config": "^6.0.1",
|
||||
"prettier": "^3.7.4",
|
||||
"prettier": "^3.8.1",
|
||||
"rslog": "^1.3.2",
|
||||
"rspack-plugin-virtual-module": "^1.0.1",
|
||||
"terser": "^5.44.1",
|
||||
"terser": "^5.46.0",
|
||||
"transliteration": "^2.6.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^5.4.20",
|
||||
|
||||
@@ -77,7 +77,6 @@ The current maintenance status of each version of Vant is as follows:
|
||||
| Project | Description |
|
||||
| --- | --- |
|
||||
| [3lang3/react-vant](https://github.com/3lang3/react-vant) | React mobile UI Components based on Vant |
|
||||
| [vant-aliapp](https://github.com/ant-move/Vant-Aliapp) | Alipay MiniProgram UI |
|
||||
| [vant-theme](https://github.com/Aisen60/vant-theme) | Online theme preview built on Vant UI |
|
||||
| [@antmjs/vantui](https://github.com/antmjs/vantui) | Mobile UI Components based on Vant, supporting Taro and React |
|
||||
| [vant-playground](https://github.com/LadyChatterleyLover/vant-playground) | Vant Playground |
|
||||
@@ -87,7 +86,6 @@ The current maintenance status of each version of Vant is as follows:
|
||||
| [raycast-vant-documentation](https://github.com/Aisen60/raycast-vant-documentation) | An Raycast extension, it can search Vant UI library documentation in Raycast |
|
||||
| [nuxt-vant-mobile](https://github.com/vue-zone/nuxt-vant-mobile) | Nuxt _⁴_ project template based on Vant, out of the box |
|
||||
| [mobvue](https://github.com/un-pany/mobvue) | A well-crafted mobile web app template |
|
||||
| [novlan1/press-ui](https://github.com/novlan1/press-ui) | Uni APP mobile UI Components based on Vant |
|
||||
|
||||
### Other Links
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
Vant 是一个**轻量、可定制的移动端组件库**,于 2017 年开源。
|
||||
|
||||
目前 Vant 官方提供了 [Vue 2 版本](/vant/v2/)、[Vue 3 版本](/vant/)和[微信小程序版本](/vant-weapp/),并由社区团队维护 [React 版本](https://github.com/3lang3/react-vant)和[支付宝小程序版本](https://github.com/ant-move/Vant-Aliapp)。
|
||||
目前 Vant 官方提供了 [Vue 2 版本](/vant/v2/)、[Vue 3 版本](/vant/)和[微信小程序版本](/vant-weapp/),并由社区团队维护 [React 版本](https://github.com/3lang3/react-vant)。
|
||||
|
||||
### 特性
|
||||
|
||||
@@ -91,7 +91,6 @@ Vant 3/4 支持现代浏览器以及 Chrome >= 51、iOS >= 10.0(与 Vue 3 一
|
||||
| 项目 | 描述 |
|
||||
| --- | --- |
|
||||
| [3lang3/react-vant](https://github.com/3lang3/react-vant) | 参照 Vant 打造的 React 移动端组件库 |
|
||||
| [vant-aliapp](https://github.com/ant-move/Vant-Aliapp) | Vant 支付宝小程序版 |
|
||||
| [vant-theme](https://github.com/Aisen60/vant-theme) | Vant 在线主题预览工具 |
|
||||
| [@antmjs/vantui](https://github.com/antmjs/vantui) | 基于 Vant Weapp 开发的多端组件库,同时支持 Taro 和 React |
|
||||
| [vant-playground](https://github.com/LadyChatterleyLover/vant-playground) | Vant Playground |
|
||||
@@ -101,7 +100,6 @@ Vant 3/4 支持现代浏览器以及 Chrome >= 51、iOS >= 10.0(与 Vue 3 一
|
||||
| [raycast-vant-documentation](https://github.com/Aisen60/raycast-vant-documentation) | 一个 Raycast 拓展,能在 Raycast 中搜索 Vant 组件库文档 |
|
||||
| [nuxt-vant-mobile](https://github.com/vue-zone/nuxt-vant-mobile) | 基于 Vant 的 Nuxt _⁴_ 项目模板,开箱即用 |
|
||||
| [mobvue](https://github.com/un-pany/mobvue) | 一个精心制作的移动端 H5 模板 |
|
||||
| [novlan1/press-ui](https://github.com/novlan1/press-ui) | 参照 Vant 打造的 uni-app 框架移动端组件库 |
|
||||
|
||||
### 其他链接
|
||||
|
||||
|
||||
@@ -66,26 +66,22 @@ export default defineComponent({
|
||||
);
|
||||
};
|
||||
|
||||
return () => {
|
||||
const { disabled } = props;
|
||||
|
||||
const handleClick = () => {
|
||||
if (!disabled) {
|
||||
route();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
class={bem({ disabled })}
|
||||
tabindex={disabled ? -1 : 0}
|
||||
onClick={handleClick}
|
||||
>
|
||||
{renderIcon()}
|
||||
{slots.default ? slots.default() : props.text}
|
||||
</div>
|
||||
);
|
||||
const onClick = () => {
|
||||
if (!props.disabled) {
|
||||
route();
|
||||
}
|
||||
};
|
||||
|
||||
return () => (
|
||||
<div
|
||||
role="button"
|
||||
class={bem({ disabled: props.disabled })}
|
||||
tabindex={props.disabled ? -1 : 0}
|
||||
onClick={onClick}
|
||||
>
|
||||
{renderIcon()}
|
||||
{slots.default ? slots.default() : props.text}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@ export const floatingPanelProps = {
|
||||
anchors: makeArrayProp<number>(),
|
||||
duration: makeNumericProp(0.3),
|
||||
magnetic: truthProp,
|
||||
draggable: truthProp,
|
||||
contentDraggable: truthProp,
|
||||
lockScroll: Boolean,
|
||||
safeAreaInsetBottom: truthProp,
|
||||
@@ -97,6 +98,8 @@ export default defineComponent({
|
||||
const touch = useTouch();
|
||||
|
||||
const onTouchstart = (e: TouchEvent) => {
|
||||
if (!props.draggable) return;
|
||||
|
||||
touch.start(e);
|
||||
dragging.value = true;
|
||||
startY = -height.value;
|
||||
@@ -104,6 +107,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const onTouchmove = (e: TouchEvent) => {
|
||||
if (!props.draggable) return;
|
||||
|
||||
touch.move(e);
|
||||
|
||||
const target = e.target as Element;
|
||||
@@ -130,8 +135,17 @@ export default defineComponent({
|
||||
|
||||
const onTouchend = () => {
|
||||
maxScroll = -1;
|
||||
|
||||
if (!dragging.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
dragging.value = false;
|
||||
|
||||
if (!props.draggable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.magnetic) {
|
||||
height.value = closest(anchors.value, height.value);
|
||||
} else {
|
||||
@@ -162,6 +176,10 @@ export default defineComponent({
|
||||
return slots.header();
|
||||
}
|
||||
|
||||
if (!props.draggable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={bem('header')}>
|
||||
<div class={bem('header-bar')} />
|
||||
|
||||
@@ -93,6 +93,18 @@ When `magnetic` is set to `false`, the panel will not automatically snap to anch
|
||||
</van-floating-panel>
|
||||
```
|
||||
|
||||
### Disable Dragging
|
||||
|
||||
You can disable the dragging functionality of the panel through the `draggable` attribute. When set to `false`, the panel will not be draggable, and the header drag bar will be hidden.
|
||||
|
||||
```html
|
||||
<van-floating-panel :draggable="false">
|
||||
<div style="text-align: center; padding: 15px">
|
||||
<p>This panel cannot be dragged</p>
|
||||
</div>
|
||||
</van-floating-panel>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
@@ -104,6 +116,7 @@ When `magnetic` is set to `false`, the panel will not automatically snap to anch
|
||||
| duration | Transition duration, unit second | _number \| string_ | `0.3` |
|
||||
| magnetic | Whether to enable magnetic adsorption to anchors. When disabled, panel can stop at any position within the anchor boundaries | _boolean_ | `true` |
|
||||
| content-draggable | Allow dragging content | _boolean_ | `true` |
|
||||
| draggable | Whether to allow dragging the panel. When disabled, the header drag bar will be hidden | _boolean_ | `true` |
|
||||
| lock-scroll `v4.6.4` | When not dragging, Whether to lock background scroll | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` |
|
||||
|
||||
|
||||
@@ -93,6 +93,18 @@ export default {
|
||||
</van-floating-panel>
|
||||
```
|
||||
|
||||
### 禁用拖拽
|
||||
|
||||
你可以通过 `draggable` 属性来禁用面板的拖拽功能。当设置为 `false` 时,面板将不可拖拽,同时头部拖拽栏也会被隐藏。
|
||||
|
||||
```html
|
||||
<van-floating-panel :draggable="false">
|
||||
<div style="text-align: center; padding: 15px">
|
||||
<p>该面板不可拖拽</p>
|
||||
</div>
|
||||
</van-floating-panel>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
@@ -104,6 +116,7 @@ export default {
|
||||
| duration | 动画时长,单位秒,设置为 0 可以禁用动画 | _number \| string_ | `0.3` |
|
||||
| magnetic | 是否启用磁力吸附到锚点。禁用后面板可在锚点边界范围内任意位置停留 | _boolean_ | `true` |
|
||||
| content-draggable | 允许拖拽内容容器 | _boolean_ | `true` |
|
||||
| draggable | 是否允许拖拽面板。禁用后头部拖拽栏会被隐藏 | _boolean_ | `true` |
|
||||
| lock-scroll `v4.6.4` | 当不拖拽时,是否锁定背景滚动 | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ const t = useTranslate({
|
||||
customAnchors: '自定义锚点',
|
||||
headDragOnly: '仅头部拖拽',
|
||||
disableMagnetic: '禁用吸附',
|
||||
disableDragging: '禁用拖拽',
|
||||
panelUnDrag: '该面板不可拖拽',
|
||||
panelShowHeight: '面板显示高度',
|
||||
contentUnDrag: '内容不可拖拽',
|
||||
magneticDisabled: '已禁用磁力吸附,可在边界内任意停留',
|
||||
@@ -23,6 +25,8 @@ const t = useTranslate({
|
||||
customAnchors: 'Custom Anchors',
|
||||
headDragOnly: 'Head Drag Only',
|
||||
disableMagnetic: 'Disable Magnetic',
|
||||
disableDragging: 'Disable Dragging',
|
||||
panelUnDrag: 'This panel cannot be dragged',
|
||||
panelShowHeight: 'Panel Show Height',
|
||||
contentUnDrag: 'Content cannot be dragged',
|
||||
magneticDisabled: 'Magnetic disabled, free positioning within boundaries',
|
||||
@@ -76,5 +80,13 @@ const height = ref(anchors[0]);
|
||||
</div>
|
||||
</van-floating-panel>
|
||||
</van-tab>
|
||||
|
||||
<van-tab :title="t('disableDragging')">
|
||||
<van-floating-panel :draggable="false">
|
||||
<div style="text-align: center; padding: 15px">
|
||||
<p>{{ t('panelUnDrag') }}</p>
|
||||
</div>
|
||||
</van-floating-panel>
|
||||
</van-tab>
|
||||
</van-tabs>
|
||||
</template>
|
||||
|
||||
@@ -56,6 +56,16 @@ exports[`should render demo and match snapshot 1`] = `
|
||||
style="display:none;"
|
||||
>
|
||||
</div>
|
||||
<div
|
||||
id="van-tab"
|
||||
role="tabpanel"
|
||||
class="van-tab__panel"
|
||||
tabindex="-1"
|
||||
aria-labelledby="van-tabs-4"
|
||||
data-allow-mismatch="attribute"
|
||||
style="display:none;"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -60,6 +60,19 @@ exports[`should render demo and match snapshot 1`] = `
|
||||
Disable Magnetic
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
id="van-tabs-4"
|
||||
role="tab"
|
||||
class="van-tab van-tab--line van-tab--grow"
|
||||
tabindex="-1"
|
||||
aria-selected="false"
|
||||
aria-controls="van-tab"
|
||||
data-allow-mismatch="attribute"
|
||||
>
|
||||
<span class="van-tab__text">
|
||||
Disable Dragging
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="van-tabs__line"
|
||||
style="transform: translateX(50px) translateX(-50%);"
|
||||
@@ -306,6 +319,16 @@ exports[`should render demo and match snapshot 1`] = `
|
||||
style="display: none;"
|
||||
>
|
||||
</div>
|
||||
<div
|
||||
id="van-tab"
|
||||
role="tabpanel"
|
||||
class="van-tab__panel"
|
||||
tabindex="-1"
|
||||
aria-labelledby="van-tabs-4"
|
||||
data-allow-mismatch="attribute"
|
||||
style="display: none;"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -189,3 +189,38 @@ test('should add padding bottom to content when panel is not fully expanded', as
|
||||
await wrapper.setProps({ height: 400 });
|
||||
expect(content.style.paddingBottom).toBe('0px');
|
||||
});
|
||||
|
||||
test('should not allow dragging when draggable is false', async () => {
|
||||
const wrapper = mount({
|
||||
render() {
|
||||
return (
|
||||
<FloatingPanel
|
||||
anchors={[100, 200, 400]}
|
||||
draggable={false}
|
||||
onHeightChange={(h) => this.$emit('change', h)}
|
||||
>
|
||||
Content
|
||||
</FloatingPanel>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.find('.van-floating-panel__header').exists()).toBe(false);
|
||||
|
||||
await triggerDrag(wrapper.find('.van-floating-panel__content'), 0, -199);
|
||||
await later();
|
||||
expect(wrapper.emitted('change')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should render header slot even when draggable is false', () => {
|
||||
const wrapper = mount(FloatingPanel, {
|
||||
props: {
|
||||
draggable: false,
|
||||
},
|
||||
slots: {
|
||||
header: () => 'Custom Header',
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.html()).toContain('Custom Header');
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ export default defineComponent({
|
||||
|
||||
props: progressProps,
|
||||
|
||||
setup(props) {
|
||||
setup(props, { slots }) {
|
||||
const background = computed(() =>
|
||||
props.inactive ? undefined : props.color,
|
||||
);
|
||||
@@ -42,9 +42,9 @@ export default defineComponent({
|
||||
const renderPivot = () => {
|
||||
const { textColor, pivotText, pivotColor, percentage } = props;
|
||||
const safePercentage = format(percentage);
|
||||
const text = pivotText ?? `${percentage}%`;
|
||||
const text = pivotText ?? `${safePercentage}%`;
|
||||
|
||||
if (props.showPivot && text) {
|
||||
if (props.showPivot && (slots.pivot || text)) {
|
||||
const style = {
|
||||
color: textColor,
|
||||
left: `${safePercentage}%`,
|
||||
@@ -57,7 +57,7 @@ export default defineComponent({
|
||||
style={style}
|
||||
class={bem('pivot', { inactive: props.inactive })}
|
||||
>
|
||||
{text}
|
||||
{slots.pivot ? slots.pivot({ percentage: safePercentage }) : text}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,19 @@ Use `pivot-text` to custom text, use `color` to custom bar color.
|
||||
/>
|
||||
```
|
||||
|
||||
### Custom Pivot Content
|
||||
|
||||
Use `pivot` slot to custom the pivot content.
|
||||
|
||||
```html
|
||||
<van-progress :percentage="50">
|
||||
<template #pivot="{ percentage }">
|
||||
<van-icon name="fire" />
|
||||
<span>{{ percentage }}%</span>
|
||||
</template>
|
||||
</van-progress>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
@@ -69,6 +82,12 @@ Use `pivot-text` to custom text, use `color` to custom bar color.
|
||||
| inactive | Whether to be gray | _boolean_ | `false` |
|
||||
| show-pivot | Whether to show text | _boolean_ | `true` |
|
||||
|
||||
### Slots
|
||||
|
||||
| Name | Description | SlotProps |
|
||||
| ----- | -------------------- | ------------------------ |
|
||||
| pivot | Custom pivot content | _{ percentage: number }_ |
|
||||
|
||||
### Types
|
||||
|
||||
The component exports the following type definitions:
|
||||
|
||||
@@ -57,6 +57,19 @@ app.use(Progress);
|
||||
/>
|
||||
```
|
||||
|
||||
### 自定义插槽内容
|
||||
|
||||
通过 `pivot` 插槽可以自定义进度文字的内容。
|
||||
|
||||
```html
|
||||
<van-progress :percentage="50">
|
||||
<template #pivot="{ percentage }">
|
||||
<van-icon name="fire" />
|
||||
<span>{{ percentage }}%</span>
|
||||
</template>
|
||||
</van-progress>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Props
|
||||
@@ -73,6 +86,12 @@ app.use(Progress);
|
||||
| inactive | 是否置灰 | _boolean_ | `false` |
|
||||
| show-pivot | 是否显示进度文字 | _boolean_ | `true` |
|
||||
|
||||
### Slots
|
||||
|
||||
| 名称 | 说明 | 参数 |
|
||||
| ----- | -------------- | ------------------------ |
|
||||
| pivot | 自定义进度文字 | _{ percentage: number }_ |
|
||||
|
||||
### 类型定义
|
||||
|
||||
组件导出以下类型定义:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import VanProgress from '..';
|
||||
import VanButton from '../../button';
|
||||
import VanIcon from '../../icon';
|
||||
import { ref } from 'vue';
|
||||
import { useTranslate } from '../../../docs/site';
|
||||
|
||||
@@ -8,12 +9,14 @@ const t = useTranslate({
|
||||
'zh-CN': {
|
||||
title2: '置灰',
|
||||
title3: '样式定制',
|
||||
title4: '进度插槽内容',
|
||||
strokeWidth: '线条粗细',
|
||||
transition: '过渡效果',
|
||||
},
|
||||
'en-US': {
|
||||
title2: 'Inactive',
|
||||
title3: 'Custom Style',
|
||||
title4: 'Pivot Slot',
|
||||
strokeWidth: 'Stroke Width',
|
||||
transition: 'Transition',
|
||||
},
|
||||
@@ -54,6 +57,17 @@ const reduce = () => {
|
||||
/>
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('title4')">
|
||||
<van-progress :percentage="percentage">
|
||||
<template #pivot="{ percentage: value }">
|
||||
<span style="display: inline-flex; align-items: center">
|
||||
<van-icon name="fire" />
|
||||
<span style="margin-left: 2px">{{ value }}%</span>
|
||||
</span>
|
||||
</template>
|
||||
</van-progress>
|
||||
</demo-block>
|
||||
|
||||
<demo-block :title="t('transition')">
|
||||
<van-progress :percentage="percentage" />
|
||||
<div style="margin-top: 15px">
|
||||
|
||||
@@ -110,6 +110,36 @@ exports[`should render demo and match snapshot 1`] = `
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<!--[-->
|
||||
<div
|
||||
class="van-progress"
|
||||
style
|
||||
>
|
||||
<span
|
||||
class="van-progress__portion"
|
||||
style="width:50%;"
|
||||
>
|
||||
</span>
|
||||
<span
|
||||
style="left:50%;transform:translate(-50%,-50%);"
|
||||
class="van-progress__pivot"
|
||||
>
|
||||
<!--[-->
|
||||
<span style="display:inline-flex;align-items:center;">
|
||||
<i
|
||||
class="van-badge__wrapper van-icon van-icon-fire"
|
||||
style
|
||||
>
|
||||
<!--[-->
|
||||
</i>
|
||||
<span style="margin-left:2px;">
|
||||
50%
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<!--[-->
|
||||
<div
|
||||
|
||||
@@ -90,6 +90,27 @@ exports[`should render demo and match snapshot 1`] = `
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-progress">
|
||||
<span
|
||||
class="van-progress__portion"
|
||||
style="width: 50%;"
|
||||
>
|
||||
</span>
|
||||
<span
|
||||
style="left: 50%; transform: translate(-50%,-50%);"
|
||||
class="van-progress__pivot"
|
||||
>
|
||||
<span style="display: inline-flex; align-items: center;">
|
||||
<i class="van-badge__wrapper van-icon van-icon-fire">
|
||||
</i>
|
||||
<span style="margin-left: 2px;">
|
||||
50%
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-progress">
|
||||
<span
|
||||
|
||||
@@ -27,3 +27,45 @@ test('should change track color when using track-color prop', () => {
|
||||
|
||||
expect(wrapper.style.background).toEqual('green');
|
||||
});
|
||||
|
||||
test('should render pivot slot with correct percentage', () => {
|
||||
const wrapper = mount(Progress, {
|
||||
props: {
|
||||
percentage: 75,
|
||||
},
|
||||
slots: {
|
||||
pivot: (props: { percentage: number }) =>
|
||||
`${props.percentage}% completed`,
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.find('.van-progress__pivot').text()).toEqual('75% completed');
|
||||
});
|
||||
|
||||
test('should render pivot slot instead of pivotText when both provided', () => {
|
||||
const wrapper = mount(Progress, {
|
||||
props: {
|
||||
percentage: 50,
|
||||
pivotText: 'prop text',
|
||||
},
|
||||
slots: {
|
||||
pivot: () => 'slot content',
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.find('.van-progress__pivot').text()).toEqual('slot content');
|
||||
});
|
||||
|
||||
test('should not render pivot slot when showPivot is false', () => {
|
||||
const wrapper = mount(Progress, {
|
||||
props: {
|
||||
percentage: 50,
|
||||
showPivot: false,
|
||||
},
|
||||
slots: {
|
||||
pivot: () => 'slot content',
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.find('.van-progress__pivot').exists()).toBeFalsy();
|
||||
});
|
||||
|
||||
753
pnpm-lock.yaml
generated
753
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user