Skip to content

Commit 61795c9

Browse files
authored
fix(chrome,loaders): ferry props to view component transient props (#2007)
ensures the following are properly ferried to the underlying view components: - `<Header.ItemWrapper isRound={...} maxX={...} maxY={...}>` - `<Dots size={...}>` - `<Spinner size={...}>`
1 parent 2992c12 commit 61795c9

File tree

8 files changed

+65
-22
lines changed

8 files changed

+65
-22
lines changed

.storybook/preview.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const DARK = getColor({ theme: DARK_THEME, variable: 'background.default' });
1515
const LIGHT = getColor({ theme: DEFAULT_THEME, variable: 'background.default' });
1616

1717
export const args = {
18-
'colors.dark': DEFAULT_THEME.colors.variables.dark,
19-
'colors.light': DEFAULT_THEME.colors.variables.light
18+
'$colors.dark': DEFAULT_THEME.colors.variables.dark,
19+
'$colors.light': DEFAULT_THEME.colors.variables.light
2020
};
2121

2222
export const argTypes = {
23-
'colors.dark': { table: { category: 'Variables' } },
24-
'colors.light': { table: { category: 'Variables' } }
23+
'$colors.dark': { name: 'colors.dark', table: { category: 'Variables' } },
24+
'$colors.light': { name: 'colors.light', table: { category: 'Variables' } }
2525
};
2626

2727
export const parameters = {
@@ -76,8 +76,8 @@ const withThemeProvider = (story, context) => {
7676
primaryHue: context.globals.primaryHue,
7777
variables: {
7878
...DEFAULT_THEME.colors.variables,
79-
dark: context.args['colors.dark'],
80-
light: context.args['colors.light']
79+
dark: context.args['$colors.dark'],
80+
light: context.args['$colors.light']
8181
}
8282
};
8383

packages/chrome/src/elements/header/HeaderItemWrapper.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import { StyledHeaderItemWrapper } from '../../styled';
1515
* @extends HTMLAttributes<HTMLDivElement>
1616
*/
1717
export const HeaderItemWrapper = React.forwardRef<HTMLDivElement, IHeaderItemWrapperProps>(
18-
(props, ref) => <StyledHeaderItemWrapper ref={ref} {...props} />
18+
({ isRound, maxX, maxY, ...other }, ref) => (
19+
<StyledHeaderItemWrapper ref={ref} $isRound={isRound} $maxX={maxX} $maxY={maxY} {...other} />
20+
)
1921
);
2022

2123
HeaderItemWrapper.displayName = 'Header.ItemWrapper';

packages/chrome/src/styled/header/StyledHeaderItemWrapper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import styled from 'styled-components';
99
import { componentStyles } from '@zendeskgarden/react-theming';
10-
import { StyledBaseHeaderItem } from './StyledBaseHeaderItem';
10+
import { IStyledBaseHeaderItemProps, StyledBaseHeaderItem } from './StyledBaseHeaderItem';
1111

1212
const COMPONENT_ID = 'chrome.header_item_wrapper';
1313

1414
export const StyledHeaderItemWrapper = styled(StyledBaseHeaderItem as 'div').attrs({
1515
'data-garden-id': COMPONENT_ID,
1616
'data-garden-version': PACKAGE_VERSION,
1717
as: 'div'
18-
})`
18+
})<IStyledBaseHeaderItemProps>`
1919
${componentStyles};
2020
`;

packages/loaders/demo/dots.stories.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import README from '../README.md';
1313
<Canvas>
1414
<Story
1515
name="Dots"
16-
argTypes={{ color: { control: 'color' }, size: { control: 'number' } }}
16+
argTypes={{ color: { control: 'color' }, size: { control: 'text' } }}
1717
parameters={{
1818
design: {
1919
allowFullscreen: true,

packages/loaders/src/elements/Dots.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const Dots = forwardRef<SVGSVGElement, IDotsProps>(
5656
});
5757

5858
if (!delayComplete && delayMS !== 0) {
59-
return <StyledLoadingPlaceholder fontSize={size!}>&nbsp;</StyledLoadingPlaceholder>;
59+
return <StyledLoadingPlaceholder $fontSize={size!}>&nbsp;</StyledLoadingPlaceholder>;
6060
}
6161

6262
return (

packages/loaders/src/elements/Spinner.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const Spinner = forwardRef<SVGSVGElement, ISpinnerProps>(
6666

6767
if (!delayComplete && delayMS !== 0) {
6868
return (
69-
<StyledLoadingPlaceholder width="1em" height="1em" fontSize={size!}>
69+
<StyledLoadingPlaceholder $width="1em" $height="1em" $fontSize={size!}>
7070
&nbsp;
7171
</StyledLoadingPlaceholder>
7272
);

packages/loaders/src/styled/StyledLoadingPlaceholder.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,47 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import styled from 'styled-components';
8+
import styled, { css } from 'styled-components';
9+
import { getValueAndUnit } from 'polished';
910
import { componentStyles } from '@zendeskgarden/react-theming';
1011

1112
const COMPONENT_ID = 'loaders.loading_placeholder';
1213

1314
interface IStyledLoadingPlaceholderProps {
14-
fontSize: string | number;
15-
width?: string;
16-
height?: string;
15+
$fontSize: string | number;
16+
$width?: string;
17+
$height?: string;
1718
}
1819

20+
const sizeStyles = ({
21+
$width = '1em',
22+
$height = '0.9em',
23+
$fontSize
24+
}: IStyledLoadingPlaceholderProps) => {
25+
const [value, unit] = getValueAndUnit($fontSize);
26+
let fontSize;
27+
28+
if (unit === undefined) {
29+
fontSize = $fontSize;
30+
} else {
31+
fontSize = `${value}${unit === '' ? 'px' : unit}`;
32+
}
33+
34+
return css`
35+
width: ${$width};
36+
height: ${$height};
37+
font-size: ${fontSize};
38+
`;
39+
};
40+
1941
export const StyledLoadingPlaceholder = styled.div.attrs({
2042
'data-garden-id': COMPONENT_ID,
2143
'data-garden-version': PACKAGE_VERSION,
2244
role: 'progressbar'
2345
})<IStyledLoadingPlaceholderProps>`
2446
display: inline-block;
25-
width: ${props => props.width || '1em'};
26-
height: ${props => props.height || '0.9em'};
27-
font-size: ${props => props.fontSize};
47+
48+
${sizeStyles};
2849
2950
${componentStyles}
3051
`;

packages/loaders/src/styled/StyledSVG.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import styled, { css, DefaultTheme, ThemeProps } from 'styled-components';
9+
import { getValueAndUnit } from 'polished';
910
import { getColor, componentStyles } from '@zendeskgarden/react-theming';
1011

1112
interface IStyledSVGProps {
@@ -26,16 +27,35 @@ const colorStyles = ({ theme, $color = 'inherit' }: IStyledSVGProps & ThemeProps
2627
`;
2728
};
2829

30+
const sizeStyles = ({
31+
$containerWidth = '1em',
32+
$containerHeight = '0.9em',
33+
$fontSize = 'inherit'
34+
}: IStyledSVGProps) => {
35+
const [value, unit] = getValueAndUnit($fontSize);
36+
let fontSize;
37+
38+
if (unit === undefined) {
39+
fontSize = $fontSize;
40+
} else {
41+
fontSize = `${value}${unit === '' ? 'px' : unit}`;
42+
}
43+
44+
return css`
45+
width: ${$containerWidth};
46+
height: ${$containerHeight};
47+
font-size: ${fontSize};
48+
`;
49+
};
50+
2951
export const StyledSVG = styled.svg.attrs<IStyledSVGProps>(props => ({
3052
'data-garden-version': PACKAGE_VERSION,
3153
xmlns: 'http://www.w3.org/2000/svg',
3254
focusable: 'false',
3355
viewBox: `0 0 ${props.$width} ${props.$height}`,
3456
role: 'img'
3557
}))<IStyledSVGProps>`
36-
width: ${props => props.$containerWidth || '1em'};
37-
height: ${props => props.$containerHeight || '0.9em'};
38-
font-size: ${props => props.$fontSize || 'inherit'};
58+
${sizeStyles};
3959
4060
${colorStyles};
4161

0 commit comments

Comments
 (0)