Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(peer-deps): extend styled-components support to v6 #1978

Merged
merged 14 commits into from
Dec 5, 2024
Merged
126 changes: 64 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@types/prop-types": "15.7.13",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.1",
"@types/styled-components": "5.1.34",
"@zendeskgarden/css-bedrock": "10.0.0",
"@zendeskgarden/eslint-config": "44.0.1",
"@zendeskgarden/scripts": "2.4.3",
Expand Down Expand Up @@ -100,7 +99,7 @@
"rollup-plugin-delete": "2.1.0",
"rollup-plugin-typescript2": "0.36.0",
"storybook": "7.6.20",
"styled-components": "5.3.11",
"styled-components": "6.1.13",
"stylelint": "16.10.0",
"stylelint-order": "6.0.4",
"temp": "0.9.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import styled, { css, ThemeProps, DefaultTheme } from 'styled-components';
import styled, { css, ThemeProps, DefaultTheme, DataAttributes } from 'styled-components';
import { retrieveComponentStyles, StyledBaseIcon, getColor } from '@zendeskgarden/react-theming';

const COMPONENT_ID = 'accordions.rotate_icon';
Expand Down Expand Up @@ -38,7 +38,7 @@ const colorStyles = ({
`;
};

export const StyledRotateIcon = styled(StyledBaseIcon).attrs({
export const StyledRotateIcon = styled(StyledBaseIcon).attrs<DataAttributes>({
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})<IStyledRotateIcon>`
Expand Down
4 changes: 2 additions & 2 deletions packages/accordions/src/styled/timeline/StyledItemIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import styled, { DefaultTheme, ThemeProps, css } from 'styled-components';
import styled, { DataAttributes, DefaultTheme, ThemeProps, css } from 'styled-components';
import { math } from 'polished';
import { retrieveComponentStyles, StyledBaseIcon, getColor } from '@zendeskgarden/react-theming';

Expand Down Expand Up @@ -36,7 +36,7 @@ const colorStyles = ({ $surfaceColor, theme }: IStyledItemIcon & ThemeProps<Defa
/**
* 1. Odd sizing allows the timeline line to center respective of the circle icon.
*/
export const StyledItemIcon = styled(StyledBaseIcon).attrs({
export const StyledItemIcon = styled(StyledBaseIcon).attrs<DataAttributes>({
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})<IStyledItemIcon>`
Expand Down
4 changes: 2 additions & 2 deletions packages/avatars/src/elements/StatusIndicator.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe('StatusIndicator', () => {
it('renders in RTL mode', () => {
const { getByRole } = renderRtl(<StatusIndicator type="transfers">Caption</StatusIndicator>);

expect(getByRole('img')).toHaveStyleRule('transform', 'scale(-1,1)', {
modifier: "& > svg[data-icon-status='transfers']"
expect(getByRole('img')).toHaveStyleRule('transform', 'scale(-1, 1)', {
modifier: "&>svg[data-icon-status='transfers']"
});
});

Expand Down
16 changes: 8 additions & 8 deletions packages/avatars/src/styled/StyledAvatar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ describe('StyledAvatar', () => {
it('renders foreground color as expected', () => {
const { container } = render(<StyledAvatar $foregroundColor="red" />);

expect(container.firstChild).toHaveStyleRule('color', 'red', { modifier: '> svg' });
expect(container.firstChild).toHaveStyleRule('color', 'red', { modifier: '&>svg' });
});

it('renders foreground color variable as expected', () => {
const { container } = render(<StyledAvatar $foregroundColor="foreground.default" />);

expect(container.firstChild).toHaveStyleRule('color', PALETTE.grey[900], {
modifier: '> svg'
modifier: '&>svg'
});
});
});
Expand All @@ -99,37 +99,37 @@ describe('StyledAvatar', () => {
it('renders extraextrasmall', () => {
const { container } = render(<StyledAvatar $size="extraextrasmall" />);

expect(container.firstChild).toHaveStyleRule('width', '16px !important');
expect(container.firstChild).toHaveStyleRule('width', '16px!important');
});

it('renders extrasmall', () => {
const { container } = render(<StyledAvatar $size="extrasmall" />);

expect(container.firstChild).toHaveStyleRule('width', '24px !important');
expect(container.firstChild).toHaveStyleRule('width', '24px!important');
});

it('renders small', () => {
const { container } = render(<StyledAvatar $size="small" />);

expect(container.firstChild).toHaveStyleRule('width', '32px !important');
expect(container.firstChild).toHaveStyleRule('width', '32px!important');
});

it('renders medium', () => {
const { container } = render(<StyledAvatar $size="medium" />);

expect(container.firstChild).toHaveStyleRule('width', '40px !important');
expect(container.firstChild).toHaveStyleRule('width', '40px!important');
});

it('renders large', () => {
const { container } = render(<StyledAvatar $size="large" />);

expect(container.firstChild).toHaveStyleRule('width', '48px !important');
expect(container.firstChild).toHaveStyleRule('width', '48px!important');
});
});

describe('badge', () => {
const styleRuleOptions = {
modifier: `& > ${StyledStatusIndicator}`
modifier: `&>${StyledStatusIndicator}`
};

it('renders the status indicator correctly', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/breadcrumbs/src/elements/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { Children, cloneElement, forwardRef, HTMLAttributes } from 'react';
import ChevronRightStrokeIcon from '@zendeskgarden/svg-icons/src/12/chevron-right-stroke.svg';
import { useBreadcrumb } from '@zendeskgarden/container-breadcrumb';
import { useText } from '@zendeskgarden/react-theming';
import {
Expand Down Expand Up @@ -38,7 +39,9 @@ export const Breadcrumb = forwardRef<HTMLElement, HTMLAttributes<HTMLElement>>((
<>
<StyledBreadcrumbItem>{child}</StyledBreadcrumbItem>
<StyledCenteredBreadcrumbItem>
<StyledChevronIcon />
<StyledChevronIcon>
<ChevronRightStrokeIcon />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our SVGO config adds aria-hidden="true" to svgs.

</StyledChevronIcon>
</StyledCenteredBreadcrumbItem>
</>
);
Expand Down
15 changes: 2 additions & 13 deletions packages/breadcrumbs/src/styled/StyledChevronIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import React from 'react';
import styled from 'styled-components';
import { em } from 'polished';
import { getColor } from '@zendeskgarden/react-theming';
import ChevronRightStrokeIcon from '@zendeskgarden/svg-icons/src/12/chevron-right-stroke.svg';
import { getColor, StyledBaseIcon } from '@zendeskgarden/react-theming';

/**
* Accepts all `<svg>` props
*/
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export const StyledChevronIcon = styled(({ children, theme, ...props }) => (
<ChevronRightStrokeIcon {...props} />
)).attrs({
role: 'presentation',
'aria-hidden': 'true'
})`
export const StyledChevronIcon = styled(StyledBaseIcon)`
transform: ${p => p.theme.rtl && `rotate(180deg);`};
margin: 0 ${p => em(p.theme.space.base, p.theme.fontSizes.md)};
color: ${p => getColor({ variable: 'foreground.subtle', theme: p.theme })};
Expand Down
6 changes: 3 additions & 3 deletions packages/buttons/src/styled/StyledIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import styled, { css, ThemeProps, DefaultTheme } from 'styled-components';
import styled, { css, ThemeProps, DefaultTheme, DataAttributes } from 'styled-components';
import { StyledBaseIcon, retrieveComponentStyles } from '@zendeskgarden/react-theming';

const COMPONENT_ID = 'buttons.icon';

interface IStyledIconProps {
$isRotated: boolean;
$isRotated?: boolean;
$position?: 'start' | 'end';
}

Expand All @@ -32,7 +32,7 @@ const sizeStyles = (props: IStyledIconProps & ThemeProps<DefaultTheme>) => {
);
};

export const StyledIcon = styled(StyledBaseIcon).attrs({
export const StyledIcon = styled(StyledBaseIcon).attrs<DataAttributes>({
'data-garden-id': COMPONENT_ID,
'data-garden-version': PACKAGE_VERSION
})<IStyledIconProps>`
Expand Down
Loading
Loading