Skip to content

Commit

Permalink
Merge pull request #880 from thundersdata-frontend/rn-issue
Browse files Browse the repository at this point in the history
feat: 进度条组件支持非百分比模式
  • Loading branch information
chj-damon authored Jul 10, 2024
2 parents d13a1ef + 91b431a commit ffef805
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-phones-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@td-design/lego': patch
---

feat: 进度条组件支持非百分比模式
1 change: 1 addition & 0 deletions packages/lego/example/ProgressDemo/demo2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default () => {
{ name: '上海', value: 78 },
{ name: '成都', value: 38 },
]}
mode="normal"
inModal
/>
</Modal>
Expand Down
17 changes: 14 additions & 3 deletions packages/lego/src/progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,25 @@ export interface ProgressProps {
onEvents?: Record<string, (params?: any) => void>;
/** 图表渲染器 */
renderer?: 'canvas' | 'svg';
/** 显示模式: percentage百分比; normal数字 */
mode: 'percentage' | 'normal';
}

/**
* 进度条图,对应Figma其他图6
*/
export default forwardRef<ReactEcharts, ProgressProps>(
(
{ name, data, style = { width: 300, height: 300 }, config, inModal = false, onEvents, renderer = 'canvas' },
{
name,
data,
style = { width: 300, height: 300 },
config,
inModal = false,
mode = 'percentage',
onEvents,
renderer = 'canvas',
},
ref
) => {
const theme = useTheme();
Expand Down Expand Up @@ -111,8 +122,8 @@ export default forwardRef<ReactEcharts, ProgressProps>(
z: 2,
silent: true,
data: data.map(item => ({
name: item.value + '%',
value: 100,
name: item.value + (mode === 'percentage' ? '%' : ''),
value: mode === 'percentage' ? 100 : Math.max(...data.map(item => +item.value)) * 2.5,
})),
label: {
...baseBarConfig.label,
Expand Down

0 comments on commit ffef805

Please sign in to comment.