Skip to content

Commit 7548779

Browse files
authored
fix: hcm progress circle (#8487)
* fix: hcm progress circle * remove border width 3 * fix progress strokewidth
1 parent 722c326 commit 7548779

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

packages/@react-spectrum/s2/src/ProgressCircle.tsx

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import {createContext, forwardRef} from 'react';
1515
import {DOMRef, DOMRefValue} from '@react-types/shared';
1616
import {getAllowedOverrides, staticColor, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'};
1717
import {keyframes} from '../style/style-macro' with {type: 'macro'};
18+
import {pxToRem} from './progress-utils' with {type: 'macro'};
1819
import {style} from '../style' with {type: 'macro'};
1920
import {useDOMRef} from '@react-spectrum/utils';
2021
import {useSpectrumContextProps} from './useSpectrumContextProps';
2122

23+
const pxToRemDynamic = (px: number): string => (px / 16) + 'rem';
2224
export interface ProgressCircleStyleProps {
2325
/**
2426
* The size of the ProgressCircle.
@@ -54,17 +56,52 @@ const track = style({
5456
default: 'gray-300',
5557
isStaticColor: 'transparent-overlay-300',
5658
forcedColors: 'Background'
59+
},
60+
strokeWidth: {
61+
default: `[${pxToRem(3)}]`,
62+
size: {
63+
S: `[${pxToRem(2)}]`,
64+
L: `[${pxToRem(4)}]`
65+
},
66+
forcedColors: {
67+
default: `[${pxToRem(2)}]`,
68+
size: {
69+
S: `[${pxToRem(1)}]`,
70+
L: `[${pxToRem(3)}]`
71+
}
72+
}
5773
}
5874
});
5975

6076
const fill = style({
6177
stroke: {
6278
default: 'blue-900',
6379
isStaticColor: 'transparent-overlay-900',
64-
forcedColors: 'Highlight'
80+
forcedColors: 'ButtonText'
6581
},
6682
rotate: -90,
67-
transformOrigin: 'center'
83+
transformOrigin: 'center',
84+
strokeWidth: {
85+
default: `[${pxToRem(3)}]`,
86+
size: {
87+
S: `[${pxToRem(2)}]`,
88+
L: `[${pxToRem(4)}]`
89+
}
90+
}
91+
});
92+
93+
const hcmStroke = style({
94+
stroke: {
95+
default: 'transparent',
96+
forcedColors: 'ButtonText'
97+
},
98+
strokeWidth: {
99+
default: `[${pxToRem(3)}]`,
100+
size: {
101+
S: `[${pxToRem(2)}]`,
102+
L: `[${pxToRem(4)}]`
103+
}
104+
}
68105
});
69106

70107
export interface ProgressCircleProps extends Omit<RACProgressBarProps, 'children' | 'style' | 'valueLabel' | 'formatOptions' | 'label' | 'className'>, ProgressCircleStyleProps, UnsafeStyles {
@@ -93,8 +130,6 @@ const dashoffsetAnimation = keyframes(`
93130
}
94131
`);
95132

96-
let pxToRem = px => (px / 16) + 'rem';
97-
98133
/**
99134
* ProgressCircles show the progression of a system operation such as downloading, uploading, or processing, in a visual way.
100135
* They can represent determinate or indeterminate progress.
@@ -117,7 +152,7 @@ export const ProgressCircle = /*#__PURE__*/ forwardRef(function ProgressCircle(p
117152
}
118153

119154
// SVG strokes are centered, so subtract half the stroke width from the radius to create an inner stroke.
120-
let radius = `calc(50% - ${pxToRem(strokeWidth / 2)})`;
155+
let radius = `calc(50% - ${pxToRemDynamic(strokeWidth / 2)})`;
121156
let isStaticColor = !!staticColor;
122157

123158
return (
@@ -139,14 +174,17 @@ export const ProgressCircle = /*#__PURE__*/ forwardRef(function ProgressCircle(p
139174
cx="50%"
140175
cy="50%"
141176
r={radius}
142-
strokeWidth={pxToRem(strokeWidth)}
143-
className={track({isStaticColor})} />
177+
className={hcmStroke({size})} />
178+
<circle
179+
cx="50%"
180+
cy="50%"
181+
r={radius}
182+
className={track({isStaticColor, size})} />
144183
<circle
145184
cx="50%"
146185
cy="50%"
147186
r={radius}
148-
strokeWidth={pxToRem(strokeWidth)}
149-
className={fill({isStaticColor})}
187+
className={fill({isStaticColor, size})}
150188
style={{
151189
// These cubic-bezier timing functions were derived from the previous animation keyframes
152190
// using a best fit algorithm, and then manually adjusted to approximate the original animation.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
export const pxToRem = (px: number): string => (px / 16) + 'rem';

0 commit comments

Comments
 (0)