-
Notifications
You must be signed in to change notification settings - Fork 673
Adapt Button to styled-react and remove sx #6904
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 1 commit
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
6ebac45
Adapt Button to styled-react and remove sx
pksjce 3355375
Remove sx property from Button
pksjce 951d29c
fix(ActionMenu): remove unused ActionMenuButtonProps export
pksjce 84ee2d9
refactor(ActionMenu): streamline ActionMenuOverlay and improve prop t…
pksjce 1803ebc
Remove sx from Button components
pksjce ee422b9
Move button styles in UnderlineNav
pksjce 4ccf3d0
Add css file
pksjce 4f51aee
fix(UnderlineNav): update MoreButton styles for consistency and clarity
pksjce a4d9360
Update snapshots
pksjce 60ee02d
This test needs to be fixed. lets see if it shows up in integration t…
pksjce 3dfc37d
Add an adapter for TextInput
pksjce 258e001
Add an adapter for TextInput
pksjce e2db1af
Remove from docs
pksjce 562b7d9
fix lint css
pksjce 3e16f1e
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 0fb5103
fix imports
francinelucca 2c336a0
remove unnecessary story
francinelucca 86e24cb
remove unused file
francinelucca 38064ab
revert test changes
francinelucca 0071478
Apply suggestion from @Copilot
francinelucca 60d2f6f
use forwardedAs
francinelucca fae295d
Merge branch 'pk/remove-button-sx-prop' of github.com:primer/react in…
francinelucca 95cba9d
use forwardedAs in ActionMenuButton
francinelucca bf812bb
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 5a6b920
revert some changes
francinelucca bc5c7b9
lint fixes
francinelucca 5c005fb
index fix
francinelucca 607b3b6
remove sx from test
francinelucca 622b98e
revert change
francinelucca a119ec1
type fixes
francinelucca 8d6da5a
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 79b26bb
type fixes
francinelucca 4fad9ab
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 421b9db
remove sx from stories
francinelucca a0fa59e
format
francinelucca 4b624f0
type fix
francinelucca 906ff31
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca bb61840
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 67b3980
remove sx prop snapshots
francinelucca 5065339
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 891b3b7
update snapshot
francinelucca 4d1f4bc
test
francinelucca 2f3c2c9
remove unused imports
francinelucca da668f9
add displayName to deprecated tooltip
francinelucca 3cefec2
fix
francinelucca 62f1d55
Revert "fix"
francinelucca 27c7606
Revert "add displayName to deprecated tooltip"
francinelucca 4518692
Revert "remove unused imports"
francinelucca 0396ead
Revert "test"
francinelucca bc1543e
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca c1ba2b8
remove custom ActionMenu
francinelucca bd84452
Merge branch 'pk/remove-button-sx-prop' of github.com:primer/react in…
francinelucca fdd3115
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 3830a4a
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 7805ee9
remove unused classes
francinelucca 22729d6
test
francinelucca c70e32c
add type export
francinelucca ec5bc80
remove sx from TextInput.Action
francinelucca de9f833
update snapshot
francinelucca 300ffc9
port over TextInput changes
francinelucca aefc40d
forwardRef in IconButton
francinelucca ddb1cc1
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 8982832
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca c41fde3
minimize changes
francinelucca 26819cd
export type
francinelucca a21155f
test export fix
francinelucca 85b34b8
re-add changes
francinelucca 86b71ac
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 9abc1d8
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 35ab677
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 9fae808
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca 88c1906
cleanup type
francinelucca 1fdd993
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca bd06715
Merge branch 'main' into pk/remove-button-sx-prop
francinelucca e776422
use styled wrapper instead of Box
francinelucca 6a68ab0
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 4dc9012
sx -> style
francinelucca 0326fa5
lint
francinelucca 6a07119
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 140c421
Merge branch 'main' of github.com:primer/react into pk/remove-button-…
francinelucca 4c84f03
add missing slots
francinelucca e4ea9fe
remove unnecessary files
francinelucca 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
Some comments aren't visible on the classic Files Changed page.
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,33 @@ | ||
| import {ActionMenu as PrimerActionMenu} from '@primer/react' | ||
| import type {ComponentProps} from 'react' | ||
| import {forwardRef} from 'react' | ||
| import {Box} from './Box' | ||
| import type {SxProp} from '../sx' | ||
|
|
||
| // Derive prop types from the underlying Primer components and augment with SxProp | ||
| export type ActionMenuProps = ComponentProps<typeof PrimerActionMenu> & SxProp | ||
| export type ActionMenuButtonProps = ComponentProps<typeof PrimerActionMenu.Button> & SxProp | ||
|
|
||
| const ActionMenuButton = forwardRef<HTMLButtonElement, ActionMenuButtonProps>(function ActionMenuButton(props, ref) { | ||
| return <Box as={PrimerActionMenu.Button} ref={ref} {...props} /> | ||
| }) | ||
|
|
||
| const ActionMenuImpl = (props: ActionMenuProps) => { | ||
| return <Box as={PrimerActionMenu} {...props} /> | ||
| } | ||
|
|
||
| type ActionMenuComposite = ((props: ActionMenuProps) => JSX.Element) & { | ||
| Button: typeof ActionMenuButton | ||
| Anchor: typeof PrimerActionMenu.Anchor | ||
| Overlay: typeof PrimerActionMenu.Overlay | ||
| Divider: typeof PrimerActionMenu.Divider | ||
| } | ||
|
|
||
| export const ActionMenu: ActionMenuComposite = Object.assign(ActionMenuImpl, { | ||
| Button: ActionMenuButton, | ||
| Anchor: PrimerActionMenu.Anchor, | ||
| Overlay: PrimerActionMenu.Overlay, | ||
| Divider: PrimerActionMenu.Divider, | ||
| }) | ||
|
|
||
| export {ActionMenuButton} |
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,92 @@ | ||
| import {Button as PrimerButton, type ButtonProps as PrimerButtonProps} from '@primer/react' | ||
| import type {SxProp, CSSCustomProperties} from '../sx' | ||
| import type {BetterSystemStyleObject} from '../styled-props' | ||
| import {Box} from './Box' | ||
|
|
||
| type ButtonComponentProps = PrimerButtonProps & SxProp | ||
| const ButtonComponent = ({sx, ...rest}: ButtonComponentProps) => { | ||
| const {block, size = 'medium', leadingVisual, trailingVisual, trailingAction} = rest | ||
| let sxStyles: {[key: string]: BetterSystemStyleObject} = {} | ||
| const style: CSSCustomProperties = {} | ||
|
|
||
| if (sx !== null && Object.keys(sx || {}).length > 0) { | ||
| sxStyles = generateCustomSxProp( | ||
| {block, size, leadingVisual, trailingVisual, trailingAction}, | ||
| sx as BetterSystemStyleObject, | ||
| ) | ||
|
|
||
| // @ts-ignore sx can have color attribute | ||
| const {color} = sx | ||
|
francinelucca marked this conversation as resolved.
Outdated
|
||
| if (color) style['--button-color'] = color | ||
| } | ||
|
|
||
| // @ts-expect-error type mismatch between Box usage here and PrimerButton | ||
| return <Box {...rest} as={PrimerButton} style={style} sx={sxStyles} /> | ||
|
francinelucca marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // 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 | ||
| // } | ||
|
francinelucca marked this conversation as resolved.
|
||
| // }} | ||
| //* | ||
| /* 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<PrimerButtonProps, '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, type ButtonComponentProps} | ||
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,19 @@ | ||
| import { | ||
| IconButton as PrimerIconButton, | ||
| type IconButtonProps as PrimerIconButtonProps, | ||
| sx, | ||
| type SxProp, | ||
| } from '@primer/react' | ||
| import styled from 'styled-components' | ||
| import {type ForwardRefComponent} from '../polymorphic' | ||
|
|
||
| type IconButtonProps = PrimerIconButtonProps & SxProp | ||
|
|
||
| const IconButton: ForwardRefComponent<'a' | 'button', IconButtonProps> = styled(PrimerIconButton).withConfig({ | ||
| shouldForwardProp: prop => (prop as keyof IconButtonProps) !== 'sx', | ||
| })<IconButtonProps>` | ||
| ${sx} | ||
| ` | ||
|
|
||
| export {IconButton} | ||
| export type {IconButtonProps} |
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
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 +1,4 @@ | ||
| export {sx, type SxProp} from '@primer/react' | ||
| export type CSSCustomProperties = { | ||
| [key: `--${string}`]: string | number | ||
| } |
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.