From f24c521d26c38c99afc871dd4d36678214e0d419 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 22 Aug 2021 16:19:37 +0800 Subject: [PATCH] feat(Circle): add startPosition prop (#9305) * feat(Circle): add startPosition prop * docs(Circle): add start-position demo --- src/circle/Circle.tsx | 27 ++++++++- src/circle/README.md | 24 ++++++++ src/circle/README.zh-CN.md | 26 ++++++++ src/circle/demo/index.vue | 29 +++++++++ src/circle/index.ts | 1 + .../test/__snapshots__/demo.spec.ts.snap | 59 +++++++++++++++++++ src/circle/test/index.spec.ts | 19 ++++++ 7 files changed, 184 insertions(+), 1 deletion(-) diff --git a/src/circle/Circle.tsx b/src/circle/Circle.tsx index 93c9475db..20d3747f9 100644 --- a/src/circle/Circle.tsx +++ b/src/circle/Circle.tsx @@ -17,6 +17,8 @@ function getPath(clockwise: boolean, viewBoxSize: number) { } m 0, -500 a 500, 500 0 1, ${sweepFlag} 0, 1000 a 500, 500 0 1, ${sweepFlag} 0, -1000`; } +export type CircleStartPosition = 'top' | 'right' | 'bottom' | 'left'; + export default defineComponent({ name, @@ -47,6 +49,10 @@ export default defineComponent({ type: [Number, String], default: 40, }, + startPosition: { + type: String as PropType, + default: 'top', + }, }, emits: ['update:currentRate'], @@ -58,6 +64,22 @@ export default defineComponent({ const path = computed(() => getPath(props.clockwise, viewBoxSize.value)); + const svgStyle = computed(() => { + const ROTATE_ANGLE_MAP: Record = { + top: 0, + right: 90, + bottom: 180, + left: 270, + }; + + const angleValue = ROTATE_ANGLE_MAP[props.startPosition]; + if (angleValue) { + return { + transform: `rotate(${angleValue}deg)`, + }; + } + }); + watch( () => props.rate, (rate) => { @@ -160,7 +182,10 @@ export default defineComponent({ return () => (
- + {renderGradient()} {renderLayer()} {renderHover()} diff --git a/src/circle/README.md b/src/circle/README.md index f90f6667e..efef5c2c2 100644 --- a/src/circle/README.md +++ b/src/circle/README.md @@ -119,6 +119,29 @@ export default { /> ``` +### Start Position + +```html + + + +``` + ## API ### Props @@ -136,6 +159,7 @@ export default { | stroke-width | Stroke width | _number \| string_ | `40` | | stroke-linecap | Stroke linecap,can be set to `square` `butt` | _string_ | `round` | | clockwise | Whether to be clockwise | _boolean_ | `true` | +| start-position `v3.2.1` | Progress start position,can be set to `left`、`right`、`bottom` | _CircleStartPosition_ | `top` | ### Slots diff --git a/src/circle/README.zh-CN.md b/src/circle/README.zh-CN.md index 6326f2ca1..146da496a 100644 --- a/src/circle/README.zh-CN.md +++ b/src/circle/README.zh-CN.md @@ -131,6 +131,31 @@ export default { /> ``` +### 起始位置 + +进度条默认从顶部开始,可以通过 `start-position` 属性设置起始位置。 + +```html + + + +``` + ## API ### Props @@ -148,6 +173,7 @@ export default { | stroke-width | 进度条宽度 | _number \| string_ | `40` | | stroke-linecap | 进度条端点的形状,可选值为 `square` `butt` | _string_ | `round` | | clockwise | 是否顺时针增加 | _boolean_ | `true` | +| start-position `v3.2.1` | 进度起始位置,可选值为 `left`、`right`、`bottom` | _CircleStartPosition_ | `top` | ### Slots diff --git a/src/circle/demo/index.vue b/src/circle/demo/index.vue index 4a23b2159..79a6b74f7 100644 --- a/src/circle/demo/index.vue +++ b/src/circle/demo/index.vue @@ -6,19 +6,27 @@ const format = (rate: number) => Math.min(Math.max(rate, 0), 100); const i18n = { 'zh-CN': { + left: '左侧', + right: '右侧', + bottom: '底部', gradient: '渐变色', customSize: '大小定制', customStyle: '样式定制', customColor: '颜色定制', customWidth: '宽度定制', + startPosition: '起始位置', counterClockwise: '逆时针', }, 'en-US': { + left: 'Left', + right: 'Right', + bottom: 'Bottom', gradient: 'Gradient', customSize: 'Custom Size', customStyle: 'Custom Style', customColor: 'Custom Color', customWidth: 'Custom Width', + startPosition: 'Start Position', counterClockwise: 'Counter Clockwise', }, }; @@ -111,6 +119,27 @@ const reduce = () => { @click="reduce" />
+ + + + + +