From 978e2f43c27de5cd9f47c26111f88d5f4bcbe1fc Mon Sep 17 00:00:00 2001 From: Marie Lucca Date: Tue, 7 Oct 2025 23:40:36 -0400 Subject: [PATCH 1/2] chore: use styled wrapper instead of Box --- .../styled-react/src/components/Label.tsx | 13 ++++--- .../styled-react/src/components/Spinner.tsx | 14 ++++--- .../styled-react/src/components/Token.tsx | 37 ++++++------------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/packages/styled-react/src/components/Label.tsx b/packages/styled-react/src/components/Label.tsx index f62ed44e99a..dd5121acc82 100644 --- a/packages/styled-react/src/components/Label.tsx +++ b/packages/styled-react/src/components/Label.tsx @@ -1,13 +1,16 @@ -import {type LabelProps as PrimerLabelProps, Label as PrimerLabel, Box} from '@primer/react' -import {type SxProp} from '../sx' +import {type LabelProps as PrimerLabelProps, Label as PrimerLabel} from '@primer/react' +import {sx, type SxProp} from '../sx' import {forwardRef} from 'react' import type {ForwardRefComponent} from '../polymorphic' +import styled from 'styled-components' type LabelProps = PrimerLabelProps & SxProp & {as?: React.ElementType} -const StyledLabel = forwardRef(function Label(props, ref) { - return -}) as ForwardRefComponent<'span', LabelProps> +const StyledLabel: ForwardRefComponent<'span', LabelProps> = styled(PrimerLabel).withConfig({ + shouldForwardProp: prop => (prop as keyof LabelProps) !== 'sx', +})` + ${sx} +` const Label = forwardRef(({as, ...props}, ref) => { return diff --git a/packages/styled-react/src/components/Spinner.tsx b/packages/styled-react/src/components/Spinner.tsx index e6c007c68f1..4349262f6c3 100644 --- a/packages/styled-react/src/components/Spinner.tsx +++ b/packages/styled-react/src/components/Spinner.tsx @@ -1,9 +1,11 @@ -import {Box, Spinner as PrimerSpinner, type SpinnerProps as PrimerSpinnerProps} from '@primer/react' -import React from 'react' -import type {SxProp} from '../sx' +import {Spinner as PrimerSpinner, type SpinnerProps as PrimerSpinnerProps} from '@primer/react' +import {sx, type SxProp} from '../sx' +import styled from 'styled-components' export type SpinnerProps = PrimerSpinnerProps & SxProp -export function Spinner(props: SpinnerProps) { - return -} +export const Spinner = styled(PrimerSpinner).withConfig({ + shouldForwardProp: prop => (prop as keyof SpinnerProps) !== 'sx', +})` + ${sx} +` diff --git a/packages/styled-react/src/components/Token.tsx b/packages/styled-react/src/components/Token.tsx index 1a0e2102744..36d6884af9e 100644 --- a/packages/styled-react/src/components/Token.tsx +++ b/packages/styled-react/src/components/Token.tsx @@ -1,33 +1,20 @@ -import React from 'react' -import { - type TokenProps as PrimerTokenProps, - type SxProp, - Token as PrimerToken, - useTheme, - theme as defaultTheme, -} from '@primer/react' -import css from '@styled-system/css' +import React, {forwardRef} from 'react' +import {type TokenProps as PrimerTokenProps, Token as PrimerToken} from '@primer/react' +import {sx, type SxProp} from '../sx' import type {ForwardRefComponent} from '../polymorphic' import type {PropsWithChildren} from 'react' +import styled from 'styled-components' type TokenProps = PropsWithChildren & SxProp -const Token: ForwardRefComponent<'a' | 'button' | 'span', TokenProps> = React.forwardRef( - ({sx: sxProp, style, ...rest}, ref) => { - const contextTheme = useTheme() - const theme = contextTheme.theme || defaultTheme +const StyledToken: ForwardRefComponent<'a' | 'button' | 'span', TokenProps> = styled(PrimerToken).withConfig({ + shouldForwardProp: prop => (prop as keyof TokenProps) !== 'sx', +})` + ${sx} +` - // If no sx prop is provided, just return PrimerToken directly - if (!sxProp) { - return - } - - // Convert sx to CSS styles using the theme context - const sxStyles = css(sxProp)(theme) - const mergedStyle = {...sxStyles, ...style} - - return - }, -) as ForwardRefComponent<'a' | 'button' | 'span', TokenProps> +const Token = forwardRef(({as, ...props}, ref) => { + return +}) as ForwardRefComponent<'a' | 'button' | 'span', TokenProps> export {Token, type TokenProps} From 6f2a45743e59cc43a6814c9612b1b6f073194486 Mon Sep 17 00:00:00 2001 From: Marie Lucca <40550942+francinelucca@users.noreply.github.com> Date: Tue, 7 Oct 2025 23:51:17 -0400 Subject: [PATCH 2/2] Refactor styled wrapper usage for Label, Token, Spinner --- .changeset/purple-waves-pay.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/purple-waves-pay.md diff --git a/.changeset/purple-waves-pay.md b/.changeset/purple-waves-pay.md new file mode 100644 index 00000000000..1d0da56050f --- /dev/null +++ b/.changeset/purple-waves-pay.md @@ -0,0 +1,5 @@ +--- +"@primer/styled-react": patch +--- + +chore: use styled wrapper instead of Box for Label, Token and Spinner