-
Notifications
You must be signed in to change notification settings - Fork 646
chore: use styled wrapper instead of Box #6962
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/styled-react": patch | ||
| --- | ||
|
|
||
| chore: use styled wrapper instead of Box for Label, Token and Spinner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <Box as={PrimerSpinner} {...props} /> | ||
| } | ||
| export const Spinner = styled(PrimerSpinner).withConfig({ | ||
| shouldForwardProp: prop => (prop as keyof SpinnerProps) !== 'sx', | ||
| })<SpinnerProps>` | ||
| ${sx} | ||
| ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<PrimerTokenProps> & SxProp | ||
|
|
||
| const Token: ForwardRefComponent<'a' | 'button' | 'span', TokenProps> = React.forwardRef<HTMLElement, TokenProps>( | ||
| ({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', | ||
| })<TokenProps>` | ||
| ${sx} | ||
| ` | ||
|
|
||
| // If no sx prop is provided, just return PrimerToken directly | ||
| if (!sxProp) { | ||
| return <PrimerToken {...rest} style={style} ref={ref} /> | ||
| } | ||
|
|
||
| // Convert sx to CSS styles using the theme context | ||
| const sxStyles = css(sxProp)(theme) | ||
| const mergedStyle = {...sxStyles, ...style} | ||
|
|
||
| return <PrimerToken {...rest} style={mergedStyle} ref={ref} /> | ||
| }, | ||
| ) as ForwardRefComponent<'a' | 'button' | 'span', TokenProps> | ||
| const Token = forwardRef<HTMLElement, TokenProps>(({as, ...props}, ref) => { | ||
| return <StyledToken {...props} {...(as ? {forwardedAs: as} : {})} ref={ref} /> | ||
francinelucca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) as ForwardRefComponent<'a' | 'button' | 'span', TokenProps> | ||
|
|
||
| export {Token, type TokenProps} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.