Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 36c86e7

Browse files
hannakohxtswese44
authored andcommitted
fix(Spinner): Add min height to Spinner container (#505)
* fix(Spinner): Add min height to Spinner container Previously the spinner's parent container was not taking the height of its children because of the negative margins. A min height matching the text line height fixes this issue * Remove the now-unnecessary 1px push hack in PreviewCard * Fixing other vertical-align issues * fix(Spinner): update Spinner snapshots to match fixed margins * Update suggestionslist visual diffs
1 parent c8a6424 commit 36c86e7

13 files changed

+43
-17
lines changed
Loading
Loading
Loading
Loading
Loading
Loading

src/components/PreviewCard/PreviewCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class PreviewCard extends React.Component<PreviewCardProps & Customizable
113113

114114
if (isLoading && !this.hasProgress()) {
115115
return (
116-
<Block textColor={TextColor.METADATA} push={1}>
116+
<Block textColor={TextColor.METADATA}>
117117
<Spinner text={loadingText as string} size={SpinnerSize.XSMALL} color={SpinnerColor.METADATA} />
118118
</Block>
119119
);

src/components/PreviewCard/__snapshots__/PreviewCard.test.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ exports[`<PreviewCard /> when loading matches its snapshot 1`] = `
130130
}
131131
metadataContent={
132132
<CustomizedBlock
133-
push={1}
134133
textColor="metadata"
135134
>
136135
<CustomizedSpinner

src/components/Spinner/Spinner.styles.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@ import { memoizeFunction } from 'office-ui-fabric-react/lib/Utilities';
55
import { SpinnerColor, SpinnerSize } from './Spinner.types';
66
import { getGutterValue } from '../../util/styles/gutters';
77
import { ITheme } from '../Customizer';
8+
import { getFont } from '../../util/styles/fonts';
9+
import { TextSize } from '../Text';
810

911
export interface SpinnerClassNames {
1012
root: string;
1113
label: string;
1214
}
1315

1416
const labelMargins = {
15-
[SpinnerSize.XSMALL]: `-1px 0 0 ${getGutterValue(1.5, true)}`,
16-
[SpinnerSize.SMALL]: `-1px 0 0 ${getGutterValue(2, true)}`,
17-
[SpinnerSize.MEDIUM]: `-2px 0 0 ${getGutterValue(2, true)}`,
17+
[SpinnerSize.XSMALL]: `0 0 0 ${getGutterValue(1.5, true)}`,
18+
[SpinnerSize.SMALL]: `0 0 0 ${getGutterValue(2, true)}`,
19+
[SpinnerSize.MEDIUM]: `-1px 0 0 ${getGutterValue(2, true)}`,
1820
[SpinnerSize.LARGE]: `${getGutterValue(1, true)} 0 0`,
1921
};
2022
export interface SpinnerClassNameProps {
2123
size: SpinnerSize;
2224
isCentered: boolean;
25+
theme: ITheme;
26+
textSize: TextSize;
2327
}
2428

2529
export const getClassNames = memoizeFunction((classNameProps: SpinnerClassNameProps): SpinnerClassNames => {
26-
const { size, isCentered } = classNameProps;
30+
const { size, isCentered, theme, textSize } = classNameProps;
31+
const font = getFont(textSize, theme);
32+
2733
return mergeStyleSets({
2834
root: {
2935
display: 'flex',
3036
alignItems: 'center',
3137
flexDirection: size === SpinnerSize.LARGE ? 'column' : 'row',
38+
minHeight: font.lineHeight,
3239
justifyContent: isCentered ? 'center' : undefined,
3340
},
3441
label: {

src/components/Spinner/Spinner.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ const fabricSpinnerSizes = {
3939
*/
4040
export class Spinner extends React.Component<SpinnerProps & CustomizableComponentProps> {
4141
public render() {
42-
const { text, hideText, color = SpinnerColor.LIGHT, size = SpinnerSize.MEDIUM, isCentered = false } = this.props;
43-
const classNames = getClassNames({ size, isCentered });
42+
const {
43+
theme = defaultTheme,
44+
text,
45+
hideText,
46+
color = SpinnerColor.LIGHT,
47+
size = SpinnerSize.MEDIUM,
48+
isCentered = false,
49+
} = this.props;
50+
51+
const textSize = labelSizes[size];
52+
const classNames = getClassNames({ size, isCentered, theme, textSize });
4453

4554
const label = hideText ? (
4655
<ScreenreaderText>{text}</ScreenreaderText>
4756
) : (
48-
<Text className={classNames.label} color={labelColors[color]} size={labelSizes[size]}>
57+
<Text className={classNames.label} color={labelColors[color]} size={textSize}>
4958
{text}
5059
</Text>
5160
);

src/components/Spinner/__snapshots__/Spinner.test.tsx.snap

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports[`<Spinner /> when centered matches its snapshot 1`] = `
99
display: flex;
1010
flex-direction: row;
1111
justify-content: center;
12+
min-height: 2.0rem;
1213
}
1314
>
1415
<StyledCustomizedSpinner
@@ -28,7 +29,7 @@ exports[`<Spinner /> when centered matches its snapshot 1`] = `
2829
margin-bottom: 0;
2930
margin-left: 0.8rem;
3031
margin-right: 0;
31-
margin-top: -2px;
32+
margin-top: -1px;
3233
}
3334
color="primary"
3435
size="mediumSub"
@@ -46,6 +47,7 @@ exports[`<Spinner /> with additional className matches its snapshot 1`] = `
4647
align-items: center;
4748
display: flex;
4849
flex-direction: row;
50+
min-height: 2.0rem;
4951
}
5052
>
5153
<StyledCustomizedSpinner
@@ -65,7 +67,7 @@ exports[`<Spinner /> with additional className matches its snapshot 1`] = `
6567
margin-bottom: 0;
6668
margin-left: 0.8rem;
6769
margin-right: 0;
68-
margin-top: -2px;
70+
margin-top: -1px;
6971
}
7072
color="primary"
7173
size="mediumSub"
@@ -83,6 +85,7 @@ exports[`<Spinner /> with dark color matches its snapshot 1`] = `
8385
align-items: center;
8486
display: flex;
8587
flex-direction: row;
88+
min-height: 2.0rem;
8689
}
8790
>
8891
<StyledCustomizedSpinner
@@ -102,7 +105,7 @@ exports[`<Spinner /> with dark color matches its snapshot 1`] = `
102105
margin-bottom: 0;
103106
margin-left: 0.8rem;
104107
margin-right: 0;
105-
margin-top: -2px;
108+
margin-top: -1px;
106109
}
107110
color="white"
108111
size="mediumSub"
@@ -120,6 +123,7 @@ exports[`<Spinner /> with invisible text matches its snapshot 1`] = `
120123
align-items: center;
121124
display: flex;
122125
flex-direction: row;
126+
min-height: 2.0rem;
123127
}
124128
>
125129
<StyledCustomizedSpinner
@@ -146,6 +150,7 @@ exports[`<Spinner /> with large size matches its snapshot 1`] = `
146150
align-items: center;
147151
display: flex;
148152
flex-direction: column;
153+
min-height: 2.0rem;
149154
}
150155
>
151156
<StyledCustomizedSpinner
@@ -184,6 +189,7 @@ exports[`<Spinner /> with metadata color matches its snapshot 1`] = `
184189
align-items: center;
185190
display: flex;
186191
flex-direction: row;
192+
min-height: 2.0rem;
187193
}
188194
>
189195
<StyledCustomizedSpinner
@@ -203,7 +209,7 @@ exports[`<Spinner /> with metadata color matches its snapshot 1`] = `
203209
margin-bottom: 0;
204210
margin-left: 0.8rem;
205211
margin-right: 0;
206-
margin-top: -2px;
212+
margin-top: -1px;
207213
}
208214
color="metadata"
209215
size="mediumSub"
@@ -221,6 +227,7 @@ exports[`<Spinner /> with visible text matches its snapshot 1`] = `
221227
align-items: center;
222228
display: flex;
223229
flex-direction: row;
230+
min-height: 2.0rem;
224231
}
225232
>
226233
<StyledCustomizedSpinner
@@ -240,7 +247,7 @@ exports[`<Spinner /> with visible text matches its snapshot 1`] = `
240247
margin-bottom: 0;
241248
margin-left: 0.8rem;
242249
margin-right: 0;
243-
margin-top: -2px;
250+
margin-top: -1px;
244251
}
245252
color="primary"
246253
size="mediumSub"
@@ -258,6 +265,7 @@ exports[`<Spinner /> with xSmall size matches its snapshot 1`] = `
258265
align-items: center;
259266
display: flex;
260267
flex-direction: row;
268+
min-height: 1.6rem;
261269
}
262270
>
263271
<StyledCustomizedSpinner
@@ -278,7 +286,7 @@ exports[`<Spinner /> with xSmall size matches its snapshot 1`] = `
278286
margin-bottom: 0;
279287
margin-left: 0.6rem;
280288
margin-right: 0;
281-
margin-top: -1px;
289+
margin-top: 0;
282290
}
283291
color="primary"
284292
size="small"

src/components/Text/Text.styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { TextSize, TextColor } from './Text.types';
33
import { memoizeFunction } from 'office-ui-fabric-react/lib/Utilities';
44
import { mergeStyleSets, ITheme } from 'office-ui-fabric-react/lib/Styling';
5-
import { ellipsisStyle, fontWeights, textColors, verticalAligns } from '../../util/styles/fonts';
5+
import { ellipsisStyle, fontWeights, getFont, textColors, verticalAligns } from '../../util/styles/fonts';
66
import { PaletteColor } from '../../util/colors';
77

88
export interface TextClassNameProps {
@@ -16,7 +16,7 @@ export interface TextClassNameProps {
1616
}
1717
export const getClassNames = memoizeFunction((classNameProps: TextClassNameProps) => {
1818
const { size, maxWidth, bold, uppercase, color, backgroundColor, theme } = classNameProps;
19-
const font = size ? theme.fonts[size === TextSize.MEDIUM_SUB ? 'smallPlus' : size] : undefined;
19+
const font = size ? getFont(size, theme) : undefined;
2020

2121
return mergeStyleSets({
2222
root: {

src/util/styles/fonts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const verticalAligns: Record<TextSize, string> = {
1212
xxLarge: '-0.4rem',
1313
};
1414

15+
export const getFont = (size: TextSize, theme: ITheme): IRawStyle =>
16+
theme.fonts[size === TextSize.MEDIUM_SUB ? 'smallPlus' : size];
17+
1518
export const textColors = (theme: ITheme): Record<TextColor, string> => ({
1619
primary: theme.semanticColors.bodyText,
1720
secondary: theme.palette.neutralPrimaryAlt,

0 commit comments

Comments
 (0)