Skip to content

Commit 8409541

Browse files
devongovettGitHub Enterprise
authored andcommitted
Fix output styles in ProgressBar and Meter (#188)
1 parent 2bf4761 commit 8409541

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {Group, GroupProps, Input as RACInput, InputProps as RACInputProps, Label, LabelProps, FieldErrorProps, FieldError, composeRenderProps, Text, Provider} from 'react-aria-components';
1414
import {baseColor, fontRelative, style} from '../style/spectrum-theme' with {type: 'macro'};
1515
import {ContextualHelpContext} from './ContextualHelp';
16-
import {StyleProps, UnsafeStyles, fieldInput, focusRing} from './style-utils' with {type: 'macro'};
16+
import {StyleProps, UnsafeStyles, fieldInput, fieldLabel, focusRing} from './style-utils' with {type: 'macro'};
1717
import AsteriskIcon from '../ui-icons/Asterisk';
1818
import AlertIcon from '../s2wf-icons/assets/svg/S2_Icon_AlertTriangle_20_N.svg';
1919
import {IconContext} from './Icon';
@@ -82,31 +82,7 @@ function FieldLabel(props: FieldLabelProps, ref: DOMRef<HTMLLabelElement>) {
8282
{...labelProps}
8383
ref={domRef}
8484
style={UNSAFE_style}
85-
className={UNSAFE_className + mergeStyles(
86-
style({
87-
fontFamily: 'sans',
88-
fontSize: 'control',
89-
lineHeight: 'ui',
90-
cursor: 'default',
91-
color: {
92-
default: 'neutral-subdued',
93-
isDisabled: 'disabled',
94-
staticColor: {
95-
white: {
96-
default: 'transparent-white-700'
97-
},
98-
black: {
99-
default: 'transparent-black-900'
100-
}
101-
},
102-
forcedColors: 'ButtonText'
103-
},
104-
contain: {
105-
labelPosition: {
106-
top: 'inline-size'
107-
}
108-
}
109-
})({labelPosition, isDisabled, size, staticColor}), props.styles)}>
85+
className={UNSAFE_className + mergeStyles(style(fieldLabel())({labelPosition, isDisabled, size, staticColor}), props.styles)}>
11086
{props.children}
11187
{(isRequired || necessityIndicator === 'label') && (
11288
<span className={style({whiteSpace: 'nowrap'})}>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {bar, track} from './bar-utils' with {type: 'macro'};
1414
import {DOMRef} from '@react-types/shared';
1515
import {FieldLabel} from './Field';
1616
import {forwardRef, ReactNode} from 'react';
17-
import {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
17+
import {fieldLabel, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
1818
import {
1919
Meter as AriaMeter,
2020
MeterProps as AriaMeterProps
@@ -53,6 +53,7 @@ const wrapper = style<MeterStyleProps>({
5353
}, getAllowedOverrides());
5454

5555
const valueStyles = style({
56+
...fieldLabel(),
5657
gridArea: 'value'
5758
});
5859

@@ -120,7 +121,7 @@ function Meter(props: MeterProps, ref: DOMRef<HTMLDivElement>) {
120121
{({percentage, valueText}) => (
121122
<>
122123
<FieldLabel size={size} labelAlign="start" labelPosition="top" staticColor={staticColor}>{label}</FieldLabel>
123-
<FieldLabel size={size} labelAlign="end" staticColor={staticColor} styles={valueStyles}>{valueText}</FieldLabel>
124+
<span className={valueStyles({size, labelAlign: 'end', staticColor})}>{valueText}</span>
124125
<div className={trackStyles({staticColor, size})}>
125126
<div className={fillStyles({staticColor, variant})} style={{width: percentage + '%'}} />
126127
</div>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from 'react-aria-components';
2121
import {FieldLabel} from './Field';
2222
import {ReactNode, forwardRef} from 'react';
23-
import {StyleProps, getAllowedOverrides} from './style-utils' with {type: 'macro'};
23+
import {StyleProps, fieldLabel, getAllowedOverrides} from './style-utils' with {type: 'macro'};
2424
import {DOMRef} from '@react-types/shared';
2525
import {useDOMRef} from '@react-spectrum/utils';
2626

@@ -65,6 +65,7 @@ const wrapper = style<ProgressBarStyleProps>({
6565
}, getAllowedOverrides());
6666

6767
const valueStyles = style({
68+
...fieldLabel(),
6869
gridArea: 'value'
6970
});
7071

@@ -122,8 +123,7 @@ function ProgressBar(props: ProgressBarProps, ref: DOMRef<HTMLDivElement>) {
122123
{({percentage, valueText}) => (
123124
<>
124125
<FieldLabel size={size} labelAlign="start" labelPosition="top" staticColor={staticColor}>{label}</FieldLabel>
125-
{/* TODO: this cannot be a label because they will both receive context */}
126-
<FieldLabel size={size} labelAlign="end" staticColor={staticColor} styles={valueStyles}>{valueText}</FieldLabel>
126+
<span className={valueStyles({size, labelAlign: 'end', staticColor})}>{valueText}</span>
127127
<div className={trackStyles({...props})}>
128128
<div
129129
className={mergeStyles(fill({...props, staticColor}), (isIndeterminate ? indeterminateAnimation : null))}

packages/@react-spectrum/s2/src/style-utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ export const field = () => ({
8383
disableTapHighlight: true
8484
} as const);
8585

86+
export const fieldLabel = () => ({
87+
fontFamily: 'sans',
88+
fontSize: 'control',
89+
lineHeight: 'ui',
90+
cursor: 'default',
91+
color: {
92+
default: 'neutral-subdued',
93+
isDisabled: 'disabled',
94+
staticColor: {
95+
white: {
96+
default: 'transparent-white-700'
97+
},
98+
black: {
99+
default: 'transparent-black-900'
100+
}
101+
},
102+
forcedColors: 'ButtonText'
103+
},
104+
contain: {
105+
labelPosition: {
106+
top: 'inline-size'
107+
}
108+
}
109+
} as const);
110+
86111
export const fieldInput = () => ({
87112
gridArea: 'input',
88113
minWidth: 'control',

0 commit comments

Comments
 (0)