Skip to content

Update Styled Components to V6 #1695

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

Merged
merged 9 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-trainers-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': major
---

chore!: default color for Typography is currentColor
5 changes: 5 additions & 0 deletions .changeset/tasty-suits-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': major
---

chore: Box/Flex/Grid & Typography are now all react components, they are no longer styled-components.
6 changes: 6 additions & 0 deletions .changeset/tidy-eggs-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@strapi/design-system': major
'@strapi/icons': major
---

chore: update to use styled-components@6
5 changes: 5 additions & 0 deletions .changeset/tidy-rats-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': major
---

chore: disallow use of as and instead use tag prop instead
5 changes: 3 additions & 2 deletions docs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parse } from 'qs';
import { DesignSystemProvider, Box, darkTheme, lightTheme, type BoxProps } from '@strapi/design-system';

import { DocsContainer, Unstyled } from '@storybook/blocks';
import styled, { DefaultTheme } from 'styled-components';
import { styled, DefaultTheme } from 'styled-components';
import { MARKDOWN_OVERRIDES, Markdown } from '../components/Markdown';

const createCustomTheme = (theme: DefaultTheme, base: 'light' | 'dark' = 'light') => {
Expand Down Expand Up @@ -57,7 +57,7 @@ const Theme = ({ children, ...props }: BoxProps) => {

return (
<DesignSystemProvider locale="en" theme={isDark ? darkTheme : lightTheme}>
<Main as="main" background="neutral0" padding="4rem" paddingBottom="8rem" height="100%">
<Main tag="main" background="neutral0" padding="4rem" paddingBottom="8rem" height="100%">
<Box maxWidth="84rem" margin="auto" height="100%" {...props}>
{children}
</Box>
Expand Down Expand Up @@ -136,6 +136,7 @@ const preview: Preview = {
'Primitives',
['Overview', '*'],
'Inputs',
'Components',
'Design System',
['Technical Components', 'Components'],
'Utilities',
Expand Down
20 changes: 10 additions & 10 deletions docs/components/ColorCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const ColorCards = () => {
const { compare } = useCollator(locale);

return (
<Flex as="article" alignItems="stretch" direction="column">
<Flex tag="article" alignItems="stretch" direction="column">
{COLOR_CARD_NAMES.map((colorName) => {
const colorKeys = Object.keys(allColors).filter((colorKey) => colorKey.startsWith(colorName.toLowerCase()));

return (
<Box key={colorName} as="section">
<Box key={colorName} tag="section">
<H2>{`${colorName} colors`}</H2>
<Grid as="ol" gap={6} gridCols={3}>
<Grid tag="ol" gap={6} gridCols={3}>
{colorKeys
.toSorted((a, b) => compare(a, b))
.map((key) => (
Expand Down Expand Up @@ -73,9 +73,9 @@ const Card = ({ colorKey, colorName, colorShade }: CardProps) => {
const colorRGB = `${colorRef.toRgb().r}, ${colorRef.toRgb().g}, ${colorRef.toRgb().b}`;

return (
<Box as="article" background="neutral100" borderRadius="8px">
<Box tag="article" background="neutral100" borderRadius="8px">
<Flex
as="dl"
tag="dl"
alignItems="end"
direction="row"
background={colorKey}
Expand All @@ -91,7 +91,7 @@ const Card = ({ colorKey, colorName, colorShade }: CardProps) => {
<ContrastInfo backgroundColor={colorHex} isLighter isSmall />
</Flex>
<Grid
as="dl"
tag="dl"
aria-label={`Table properties for ${colorName} ${colorShade}`}
gap={2}
gridCols={2}
Expand All @@ -117,10 +117,10 @@ const Card = ({ colorKey, colorName, colorShade }: CardProps) => {
},
].map((props) => (
<Box key={props.label}>
<Typography as="dt" variant="sigma">
<Typography tag="dt" variant="sigma">
{props.label}
</Typography>
<Typography as="dd" variant="pi">
<Typography tag="dd" variant="pi">
{props.content}
</Typography>
</Box>
Expand All @@ -142,15 +142,15 @@ const ContrastInfo = ({ backgroundColor = '', isLighter = false, isSmall = false
return (
<Flex alignItems="stretch" direction="column" flex={1} textAlign="center">
<Box
as="dt"
tag="dt"
aria-label={`${isSmall ? 'Small' : 'Large'} font and ${isLighter ? 'lighter' : 'darker'} text.`}
paddingBottom={2}
style={{ color: textColor, fontSize: isSmall ? '12px' : '16px' }}
>
A
</Box>
<Box
as="dd"
tag="dd"
background="neutral1000"
borderRadius="4px"
color="neutral0"
Expand Down
2 changes: 1 addition & 1 deletion docs/components/DeprecationNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface DeprecationNoticeProps {

const DeprecationNotice = ({ children, href }: DeprecationNoticeProps) => (
<Flex padding={5} background="danger500" justifyContent="center" marginTop={4} marginBottom={4} hasRadius>
<Typography fontSize={4} fontWeight="bold" as="p">
<Typography fontSize={4} fontWeight="bold" tag="p">
⛔️
<strong>
{' This component has been deprecated. Please use '}
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentPropsWithoutRef } from 'react';

import styled from 'styled-components';
import { styled } from 'styled-components';

interface ImageProps extends ComponentPropsWithoutRef<'img'> {}

Expand Down
2 changes: 1 addition & 1 deletion docs/components/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Markdown as MarkdownImpl } from '@storybook/blocks';
import { BaseLink } from '@strapi/design-system';
import styled, { css } from 'styled-components';
import { styled, css } from 'styled-components';

import { DeprecationNotice } from './DeprecationNotice';
import { Image } from './Image';
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Typescale.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Typography } from '@strapi/design-system';
import styled from 'styled-components';
import { styled } from 'styled-components';

const TEXT_VARIANTS = ['alpha', 'beta', 'delta', 'epsilon', 'omega', 'pi', 'sigma'] as const;

Expand Down
32 changes: 21 additions & 11 deletions docs/components/Typography.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import { Typography, TypographyProps } from '@strapi/design-system';
import styled, { css } from 'styled-components';
import { Typography, TypographyComponent, TypographyProps } from '@strapi/design-system';
import { styled, css } from 'styled-components';

const H1 = (props: TypographyProps) => (
<Typography as="h1" variant="alpha" textColor="neutral800" marginBottom="0.5em" {...props} />
<Typography {...props} tag="h1" variant="alpha" textColor="neutral800" marginBottom="0.5em" />
);

const H2 = (props: TypographyProps) => (
<Typography as="h2" variant="beta" textColor="neutral800" marginBottom="1em" marginTop="2em" {...props} />
<Typography {...props} tag="h2" variant="beta" textColor="neutral800" marginBottom="1em" marginTop="2em" />
);

const H3 = (props: TypographyProps) => (
<Typography as="h3" variant="delta" textColor="neutral800" marginBottom="1em" marginTop="1.4em" {...props} />
<Typography
{...props}
tag="h3"
variant="delta"
textColor="neutral800"
marginBottom="1em"
marginTop="1.4em"
fontSize={4}
/>
);

const H4 = (props: TypographyProps) => (
<Typography
as="h4"
{...props}
tag="h4"
variant="epsilon"
textColor="neutral800"
marginBottom="1em"
marginTop="1.4em"
fontWeight="bold"
{...props}
fontWeight="semiBold"
/>
);

const P = (props: TypographyProps) => <Paragraph as="p" variant="epsilon" textColor="neutral700" {...props} />;
const P = (props: TypographyProps) => (
<Paragraph {...props} tag="p" variant="epsilon" textColor="neutral700" fontSize={2} />
);

const codeStyles = css`
color: ${({ theme }) => theme.colors.neutral700};
Expand All @@ -34,7 +44,7 @@ const codeStyles = css`
padding: 0.6rem;
`;

const Paragraph = styled(Typography)`
const Paragraph = styled<TypographyComponent<'p'>>(Typography)`
& code {
${codeStyles}
}
Expand All @@ -44,7 +54,7 @@ const Paragraph = styled(Typography)`
}
`;

const Li = (props: TypographyProps) => <ListItem as="li" variant="epsilon" textColor="neutral700" {...props} />;
const Li = (props: TypographyProps) => <ListItem tag="li" variant="epsilon" textColor="neutral700" {...props} />;

const ListItem = styled(Typography)`
& code {
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"storybook-dark-mode": "^3.0.3",
"styled-components": "^5.3.11"
"styled-components": "6.1.8"
},
"devDependencies": {
"@storybook/blocks": "^7.6.17",
Expand Down
Binary file added docs/public/stories/strapi-img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 0 additions & 13 deletions docs/stories/Accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ import { Accordion, AccordionToggle, AccordionContent, AccordionGroup } from '@s

<Canvas of={AccordionStories.Group} />

## Accordion keyboard navigable

The accordion component has two main states: collapsed and expanded. By default it has a collapsed state. If
Call-to-actions are required, use them on the right side and use chevron icon on the left one.

<Canvas of={AccordionStories.Keyboard} />

## Accordion expanded

The Accordion component can also be open by default using the parameter `expanded={true}`.

<Canvas of={AccordionStories.Expanded} />

## Accordion props

<ArgTypes of={Accordion} />
Expand Down
Loading