Skip to content

Commit db60bab

Browse files
authored
feat: support label position side in meter (#7180)
1 parent a45e2a5 commit db60bab

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'react-aria-components';
1818
import {bar, track} from './bar-utils' with {type: 'macro'};
1919
import {createContext, forwardRef, ReactNode} from 'react';
20-
import {DOMRef, DOMRefValue} from '@react-types/shared';
20+
import {DOMRef, DOMRefValue, LabelPosition} from '@react-types/shared';
2121
import {FieldLabel} from './Field';
2222
import {fieldLabel, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
2323
import {size, style} from '../style' with {type: 'macro'};
@@ -37,8 +37,15 @@ interface MeterStyleProps {
3737
* @default 'M'
3838
*/
3939
size?: 'S' | 'M' | 'L' | 'XL',
40-
/** The static color style to apply. Useful when the button appears over a color background. */
41-
staticColor?: 'white' | 'black'
40+
/**
41+
* The static color style to apply. Useful when the button appears over a color background.
42+
*/
43+
staticColor?: 'white' | 'black',
44+
/**
45+
* The label's overall position relative to the element it is labeling.
46+
* @default 'top'
47+
*/
48+
labelPosition?: LabelPosition
4249
}
4350

4451
export interface MeterProps extends Omit<AriaMeterProps, 'children' | 'className' | 'style'>, MeterStyleProps, StyleProps {
@@ -106,6 +113,7 @@ function Meter(props: MeterProps, ref: DOMRef<HTMLDivElement>) {
106113
UNSAFE_className = '',
107114
UNSAFE_style,
108115
variant = 'informative',
116+
labelPosition = 'top',
109117
...groupProps
110118
} = props;
111119

@@ -118,11 +126,11 @@ function Meter(props: MeterProps, ref: DOMRef<HTMLDivElement>) {
118126
size,
119127
variant,
120128
staticColor,
121-
labelPosition: 'top'
129+
labelPosition
122130
}, styles)}>
123131
{({percentage, valueText}) => (
124132
<>
125-
{label && <FieldLabel size={size} labelAlign="start" labelPosition="top" staticColor={staticColor}>{label}</FieldLabel>}
133+
{label && <FieldLabel size={size} labelAlign="start" labelPosition={labelPosition} staticColor={staticColor}>{label}</FieldLabel>}
126134
{label && <Text styles={valueStyles({size, labelAlign: 'end', staticColor})}>{valueText}</Text>}
127135
<SkeletonWrapper>
128136
<div className={trackStyles({staticColor, size})}>

0 commit comments

Comments
 (0)