Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6ebac45
Adapt Button to styled-react and remove sx
pksjce Sep 24, 2025
3355375
Remove sx property from Button
pksjce Sep 24, 2025
951d29c
fix(ActionMenu): remove unused ActionMenuButtonProps export
pksjce Sep 24, 2025
84ee2d9
refactor(ActionMenu): streamline ActionMenuOverlay and improve prop t…
pksjce Sep 24, 2025
1803ebc
Remove sx from Button components
pksjce Sep 24, 2025
ee422b9
Move button styles in UnderlineNav
pksjce Sep 25, 2025
4ccf3d0
Add css file
pksjce Sep 25, 2025
4f51aee
fix(UnderlineNav): update MoreButton styles for consistency and clarity
pksjce Sep 25, 2025
a4d9360
Update snapshots
pksjce Sep 25, 2025
60ee02d
This test needs to be fixed. lets see if it shows up in integration t…
pksjce Sep 25, 2025
3dfc37d
Add an adapter for TextInput
pksjce Sep 25, 2025
258e001
Add an adapter for TextInput
pksjce Sep 25, 2025
e2db1af
Remove from docs
pksjce Sep 25, 2025
562b7d9
fix lint css
pksjce Sep 25, 2025
3e16f1e
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca Sep 30, 2025
0fb5103
fix imports
francinelucca Sep 30, 2025
2c336a0
remove unnecessary story
francinelucca Sep 30, 2025
86e24cb
remove unused file
francinelucca Sep 30, 2025
38064ab
revert test changes
francinelucca Sep 30, 2025
0071478
Apply suggestion from @Copilot
francinelucca Sep 30, 2025
60d2f6f
use forwardedAs
francinelucca Sep 30, 2025
fae295d
Merge branch 'pk/remove-button-sx-prop' of github.com:primer/react in…
francinelucca Sep 30, 2025
95cba9d
use forwardedAs in ActionMenuButton
francinelucca Sep 30, 2025
bf812bb
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca Sep 30, 2025
5a6b920
revert some changes
francinelucca Sep 30, 2025
bc5c7b9
lint fixes
francinelucca Sep 30, 2025
5c005fb
index fix
francinelucca Sep 30, 2025
607b3b6
remove sx from test
francinelucca Sep 30, 2025
622b98e
revert change
francinelucca Sep 30, 2025
a119ec1
type fixes
francinelucca Sep 30, 2025
8d6da5a
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca Sep 30, 2025
79b26bb
type fixes
francinelucca Sep 30, 2025
4fad9ab
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca Sep 30, 2025
421b9db
remove sx from stories
francinelucca Sep 30, 2025
a0fa59e
format
francinelucca Sep 30, 2025
4b624f0
type fix
francinelucca Sep 30, 2025
906ff31
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca Sep 30, 2025
bb61840
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca Oct 1, 2025
67b3980
remove sx prop snapshots
francinelucca Oct 1, 2025
5065339
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca Oct 1, 2025
891b3b7
update snapshot
francinelucca Oct 1, 2025
4d1f4bc
test
francinelucca Oct 1, 2025
2f3c2c9
remove unused imports
francinelucca Oct 1, 2025
da668f9
add displayName to deprecated tooltip
francinelucca Oct 1, 2025
3cefec2
fix
francinelucca Oct 1, 2025
62f1d55
Revert "fix"
francinelucca Oct 1, 2025
27c7606
Revert "add displayName to deprecated tooltip"
francinelucca Oct 1, 2025
4518692
Revert "remove unused imports"
francinelucca Oct 1, 2025
0396ead
Revert "test"
francinelucca Oct 1, 2025
bc1543e
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca Oct 1, 2025
c1ba2b8
remove custom ActionMenu
francinelucca Oct 1, 2025
bd84452
Merge branch 'pk/remove-button-sx-prop' of github.com:primer/react in…
francinelucca Oct 1, 2025
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
6 changes: 6 additions & 0 deletions .changeset/tasty-suns-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

---
"@primer/react": major
"@primer/styled-react": patch
---
Remove sx property from Button
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions e2e/components/Button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ const stories = [
title: 'Dev Invisible Variants',
id: 'components-button-dev--invisible-variants',
},
{
title: 'Dev Sx Prop',
id: 'components-button-dev--test-sx-prop',
},
{
title: 'Aria Expanded Buttons',
id: 'components-button-features--expanded-button',
Expand Down
66 changes: 1 addition & 65 deletions packages/react/src/Button/Button.dev.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {SearchIcon, TriangleDownIcon, EyeIcon, IssueClosedIcon, HeartFillIcon} from '@primer/octicons-react'
import {SearchIcon, TriangleDownIcon, EyeIcon, HeartFillIcon} from '@primer/octicons-react'
import {Button, IconButton} from '.'
import {default as Text} from '../Text'
import {Stack} from '../Stack'

export default {
Expand Down Expand Up @@ -32,69 +31,6 @@ export const InvisibleVariants = () => {
)
}

export const TestSxProp = () => {
const count = 4
return (
<div style={{display: 'flex', flexDirection: 'row', gap: '1rem'}}>
<Button
size="medium"
sx={{
color: 'firebrick',
backgroundColor: '#F6F8FA',
}}
>
Medium Red
</Button>
<Button
size="small"
sx={{
':hover': {
color: 'deepskyblue',
},
[`@media screen and (max-width: 768px)`]: {
color: 'maroon',
backgroundColor: '#F6F8FA',
},
'@media (min-width: 1440)': {
color: 'firebrick',
backgroundColor: '#F6F8FA',
},
}}
>
Red
</Button>
<Button variant="invisible" sx={{color: 'firebrick', backgroundColor: '#F6F8FA'}}>
Invariant color overridden
</Button>
<Button leadingVisual={IssueClosedIcon} sx={{color: 'done.fg'}}>
<Text sx={{color: 'fg.default'}}>Close issue</Text>
</Button>
<Button
size="small"
variant="invisible"
sx={{
width: 32,
height: 32,
'&:focus': {
outline: 0,
'& > span': {
boxShadow: `inset 0 0 0 2px deeppink`,
},
},
}}
>
Custom size
</Button>
<Button size="small" block variant="invisible" sx={{width: 320}}>
Overridden Block
</Button>
<Button sx={{fontSize: 32}} count={count}>
Watch
</Button>
</div>
)
}

export const DisabledButtonVariants = () => {
return (
<Stack direction="horizontal">
Expand Down
5 changes: 0 additions & 5 deletions packages/react/src/Button/Button.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@
"type": "'small'\n| 'medium'\n| 'large'",
"defaultValue": "'medium'"
},
{
"name": "sx",
"type": "SystemStyleObject",
"deprecated": true
},
{
"name": "trailingIcon",
"type": "React.ComponentType<OcticonProps>",
Expand Down
83 changes: 3 additions & 80 deletions packages/react/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,15 @@ import {forwardRef} from 'react'
import type {ButtonProps} from './types'
import {ButtonBase} from './ButtonBase'
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import {defaultSxProp} from '../utils/defaultSxProp'
import type {BetterSystemStyleObject, CSSCustomProperties} from '../sx'

const ButtonComponent = forwardRef(({children, sx: sxProp = defaultSxProp, ...props}, forwardedRef): JSX.Element => {
const {block, size = 'medium', leadingVisual, trailingVisual, trailingAction} = props
let sxStyles = sxProp
const style: CSSCustomProperties = {}

if (sxProp !== null && Object.keys(sxProp).length > 0) {
sxStyles = generateCustomSxProp({block, size, leadingVisual, trailingVisual, trailingAction}, sxProp)

// @ts-ignore sxProp can have color attribute
const {color} = sxProp
if (color) style['--button-color'] = color
}

const ButtonComponent = forwardRef(({children, ...props}, forwardedRef): JSX.Element => {
return (
<ButtonBase ref={forwardedRef} as="button" sx={sxStyles} style={style} type="button" {...props}>
<ButtonBase ref={forwardedRef} as="button" type="button" {...props}>
{children}
</ButtonBase>
)
}) as PolymorphicForwardRefComponent<'button', ButtonProps>

// This function is used to generate a custom cssSelector for the sxProp

// The usual sx prop can like this:
// sx={{
// [`@media (max-width: 768px)`]: {
// '& > ul': {
// backgroundColor: 'deeppink',
// },
// '&:hover': {
// backgroundColor: 'yellow',
// },
// },
// '&:hover': {
// backgroundColor: 'yellow',
// },
// '&': {
// width : 320px
// }
// }}
//*
/* What we want for Button styles is this:
sx={{
// [`@media (max-width: 768px)`]: {
// '&[data-attribute="something"] > ul': {
// backgroundColor: 'deeppink',
// },
// '&[data-attribute="something"]:hover': {
// backgroundColor: 'yellow',
// },
// },
// '&[data-attribute="something"]:hover': {
// backgroundColor: 'yellow',
// },
// '&[data-attribute="something"]': {
// width : 320px
// }
// }}

// We need to make sure we append the customCSSSelector to the original class selector. i.e & - > &[data-attribute="Icon"][data-size="small"]
*/
export function generateCustomSxProp(
props: Partial<Pick<ButtonProps, 'size' | 'block' | 'leadingVisual' | 'trailingVisual' | 'trailingAction'>>,
providedSx: BetterSystemStyleObject,
) {
// Possible data attributes: data-size, data-block, data-no-visuals
const size = `[data-size="${props.size}"]`
const block = props.block ? `[data-block="block"]` : ''
const noVisuals = props.leadingVisual || props.trailingVisual || props.trailingAction ? '' : '[data-no-visuals]'

// this is a custom selector. We need to make sure we add the data attributes to the base css class (& -> &[data-attributename="value"]])
const cssSelector = `&${size}${block}${noVisuals}` // &[data-size="small"][data-block="block"][data-no-visuals]

const customSxProp: {
[key: string]: BetterSystemStyleObject
} = {}

if (!providedSx) return customSxProp
else {
customSxProp[cssSelector] = providedSx
return customSxProp
}
}

ButtonComponent.displayName = 'Button'

export {ButtonComponent}
export {ButtonComponent, type ButtonProps}
Loading
Loading