Skip to content

Commit

Permalink
feat: support label position side in meter (#7180)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuiliao authored Oct 11, 2024
1 parent a45e2a5 commit db60bab
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/@react-spectrum/s2/src/Meter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'react-aria-components';
import {bar, track} from './bar-utils' with {type: 'macro'};
import {createContext, forwardRef, ReactNode} from 'react';
import {DOMRef, DOMRefValue} from '@react-types/shared';
import {DOMRef, DOMRefValue, LabelPosition} from '@react-types/shared';
import {FieldLabel} from './Field';
import {fieldLabel, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {size, style} from '../style' with {type: 'macro'};
Expand All @@ -37,8 +37,15 @@ interface MeterStyleProps {
* @default 'M'
*/
size?: 'S' | 'M' | 'L' | 'XL',
/** The static color style to apply. Useful when the button appears over a color background. */
staticColor?: 'white' | 'black'
/**
* The static color style to apply. Useful when the button appears over a color background.
*/
staticColor?: 'white' | 'black',
/**
* The label's overall position relative to the element it is labeling.
* @default 'top'
*/
labelPosition?: LabelPosition
}

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

Expand All @@ -118,11 +126,11 @@ function Meter(props: MeterProps, ref: DOMRef<HTMLDivElement>) {
size,
variant,
staticColor,
labelPosition: 'top'
labelPosition
}, styles)}>
{({percentage, valueText}) => (
<>
{label && <FieldLabel size={size} labelAlign="start" labelPosition="top" staticColor={staticColor}>{label}</FieldLabel>}
{label && <FieldLabel size={size} labelAlign="start" labelPosition={labelPosition} staticColor={staticColor}>{label}</FieldLabel>}
{label && <Text styles={valueStyles({size, labelAlign: 'end', staticColor})}>{valueText}</Text>}
<SkeletonWrapper>
<div className={trackStyles({staticColor, size})}>
Expand Down

1 comment on commit db60bab

@rspbot
Copy link

@rspbot rspbot commented on db60bab Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.