diff --git a/.changeset/lazy-gifts-join.md b/.changeset/lazy-gifts-join.md new file mode 100644 index 00000000000..ad6f3278c95 --- /dev/null +++ b/.changeset/lazy-gifts-join.md @@ -0,0 +1,6 @@ +--- +"@primer/react": major +"@primer/styled-react": patch +--- + +chore: remove sx from Overlay diff --git a/e2e/components/Overlay.test.ts b/e2e/components/Overlay.test.ts index b9f36ba62ed..556db3c4a10 100644 --- a/e2e/components/Overlay.test.ts +++ b/e2e/components/Overlay.test.ts @@ -39,10 +39,6 @@ const stories = [ title: 'Positioned Overlays', id: 'private-components-overlay-features--positioned-overlays', }, - { - title: 'SX Props', - id: 'private-components-overlay-dev--sx-props', - }, ] as const test.describe('Overlay ', () => { diff --git a/packages/react/src/Overlay/Overlay.dev.stories.tsx b/packages/react/src/Overlay/Overlay.dev.stories.tsx index 624f920320f..55736b4e2b5 100644 --- a/packages/react/src/Overlay/Overlay.dev.stories.tsx +++ b/packages/react/src/Overlay/Overlay.dev.stories.tsx @@ -3,7 +3,6 @@ import type {Args, Meta} from '@storybook/react-vite' import Text from '../Text' import {Button, IconButton} from '../Button' import Overlay from './Overlay' -import {useFocusTrap} from '../hooks/useFocusTrap' import {XIcon} from '@primer/octicons-react' import classes from './Overlay.dev.stories.module.css' @@ -21,62 +20,6 @@ export default { }, } as Meta -export const SxProps = (args: Args) => { - const [isOpen, setIsOpen] = useState(false) - const buttonRef = useRef(null) - const confirmButtonRef = useRef(null) - const anchorRef = useRef(null) - const closeOverlay = () => setIsOpen(false) - const containerRef = useRef(null) - useFocusTrap({ - containerRef, - disabled: !isOpen, - }) - return ( -
- - {isOpen || args.open ? ( - -
- - Look! an overlay -
-
- ) : null} -
- ) -} - export const PreventFocusOnOpen = (args: Args) => { const [isOpen, setIsOpen] = useState(false) const openButtonRef = useRef(null) diff --git a/packages/react/src/Overlay/Overlay.docs.json b/packages/react/src/Overlay/Overlay.docs.json index 18e76af6ba0..3c262d79be2 100644 --- a/packages/react/src/Overlay/Overlay.docs.json +++ b/packages/react/src/Overlay/Overlay.docs.json @@ -146,11 +146,6 @@ "description": "", "defaultValue": "" }, - { - "name": "sx", - "type": "SystemStyleObject", - "deprecated": true - }, { "name": "responsiveVariant", "type": "'fullscreen'", diff --git a/packages/react/src/Overlay/Overlay.features.stories.tsx b/packages/react/src/Overlay/Overlay.features.stories.tsx index 925d6659e57..a8860d992c9 100644 --- a/packages/react/src/Overlay/Overlay.features.stories.tsx +++ b/packages/react/src/Overlay/Overlay.features.stories.tsx @@ -186,7 +186,7 @@ export const OverlayOnTopOfOverlay = ({anchorSide, role, open}: Args) => { onEscape={closeSecondaryOverlay} onClickOutside={closeSecondaryOverlay} width="small" - sx={{top: '40px'}} + style={{top: '40px'}} anchorSide={anchorSide} role={role} aria-modal={role === 'dialog' ? 'true' : undefined} diff --git a/packages/react/src/Overlay/Overlay.tsx b/packages/react/src/Overlay/Overlay.tsx index aa9cfc1e374..ca84e09c668 100644 --- a/packages/react/src/Overlay/Overlay.tsx +++ b/packages/react/src/Overlay/Overlay.tsx @@ -6,7 +6,6 @@ import type {AriaRole, Merge} from '../utils/types' import type {TouchOrMouseEvent} from '../hooks' import {useOverlay} from '../hooks' import Portal from '../Portal' -import type {SxProp} from '../sx' import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef' import type {AnchorSide} from '@primer/behaviors' import {useTheme} from '../ThemeProvider' @@ -14,7 +13,6 @@ import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../uti import {useFeatureFlag} from '../FeatureFlags' import classes from './Overlay.module.css' import {clsx} from 'clsx' -import {BoxWithFallback} from '../internal/components/BoxWithFallback' type StyledOverlayProps = { width?: keyof typeof widthMap @@ -24,7 +22,7 @@ type StyledOverlayProps = { visibility?: 'visible' | 'hidden' overflow?: 'auto' | 'hidden' | 'scroll' | 'visible' style?: React.CSSProperties -} & SxProp +} export const heightMap = { xsmall: '192px', @@ -91,7 +89,7 @@ type OwnOverlayProps = Merge * @param bottom Optional. Vertical bottom position of the overlay, relative to its closest positioned ancestor (often its `Portal`). * @param position Optional. Sets how an element is positioned in a document. Defaults to `absolute` positioning. */ -export const BaseOverlay = React.forwardRef( +export const BaseOverlay = React.forwardRef( ( { visibility, @@ -106,13 +104,13 @@ export const BaseOverlay = React.forwardRef( className, maxHeight, maxWidth, + as: Component = 'div', ...rest }, forwardedRef, ): ReactElement => { return ( - & SxProp + +const ActionMenuOverlay: React.ComponentType = styled(PrimerActionMenu.Overlay).withConfig({ + shouldForwardProp: prop => (prop as keyof ActionMenuOverlayProps) !== 'sx', +})` + ${sx} +` + +export const ActionMenu: typeof PrimerActionMenu & { + Button: typeof PrimerActionMenu.Button + Anchor: typeof PrimerActionMenu.Anchor + Overlay: typeof ActionMenuOverlay + Divider: typeof PrimerActionMenu.Divider +} = Object.assign(PrimerActionMenu, { + Button: PrimerActionMenu.Button, + Anchor: PrimerActionMenu.Anchor, + Overlay: ActionMenuOverlay, + Divider: PrimerActionMenu.Divider, +}) diff --git a/packages/styled-react/src/components/Autocomplete.tsx b/packages/styled-react/src/components/Autocomplete.tsx new file mode 100644 index 00000000000..2028c65d111 --- /dev/null +++ b/packages/styled-react/src/components/Autocomplete.tsx @@ -0,0 +1,34 @@ +import { + Autocomplete as PrimerAutocomplete, + type AutocompleteOverlayProps as PrimerAutocompleteOverlayProps, +} from '@primer/react' +import {sx, type SxProp} from '../sx' +import styled from 'styled-components' +import type {ComponentProps} from 'react' + +export type AutocompleteOverlayProps = PrimerAutocompleteOverlayProps & SxProp + +const AutocompleteOverlay: React.ComponentType = styled( + PrimerAutocomplete.Overlay, +).withConfig({ + shouldForwardProp: prop => (prop as keyof AutocompleteOverlayProps) !== 'sx', +})` + ${sx} +` + +interface AutocompleteExport { + (props: ComponentProps): React.ReactNode + Context: typeof PrimerAutocomplete.Context + Input: typeof PrimerAutocomplete.Input + Menu: typeof PrimerAutocomplete.Menu + Overlay: typeof AutocompleteOverlay +} + +const Autocomplete: AutocompleteExport = Object.assign(PrimerAutocomplete, { + Context: PrimerAutocomplete.Context, + Input: PrimerAutocomplete.Input, + Menu: PrimerAutocomplete.Menu, + Overlay: AutocompleteOverlay, +}) + +export {Autocomplete} diff --git a/packages/styled-react/src/components/Overlay.tsx b/packages/styled-react/src/components/Overlay.tsx new file mode 100644 index 00000000000..37b2103f466 --- /dev/null +++ b/packages/styled-react/src/components/Overlay.tsx @@ -0,0 +1,14 @@ +import {Overlay as PrimerOverlay, type OverlayProps as PrimerOverlayProps, sx, type SxProp} from '@primer/react' +import styled from 'styled-components' +import {type ForwardRefComponent} from '../polymorphic' + +type OverlayProps = PrimerOverlayProps & SxProp + +const Overlay: ForwardRefComponent<'div', OverlayProps> = styled(PrimerOverlay).withConfig({ + shouldForwardProp: prop => (prop as keyof OverlayProps) !== 'sx', +})` + ${sx} +` + +export {Overlay} +export type {OverlayProps} diff --git a/packages/styled-react/src/index.tsx b/packages/styled-react/src/index.tsx index f0b680cd843..2842a1eb15e 100644 --- a/packages/styled-react/src/index.tsx +++ b/packages/styled-react/src/index.tsx @@ -1,6 +1,4 @@ export {ActionList} from '@primer/react' -export {ActionMenu} from '@primer/react' -export {Autocomplete} from '@primer/react' export {Avatar} from '@primer/react' export {Breadcrumbs} from '@primer/react' export {Box, type BoxProps} from './components/Box' @@ -10,7 +8,6 @@ export {Details} from '@primer/react' export {Heading} from '@primer/react' export {IconButton} from '@primer/react' export {Label} from '@primer/react' -export {Overlay} from '@primer/react' export {ProgressBar} from '@primer/react' export {Select} from '@primer/react' export {Text} from '@primer/react' @@ -29,6 +26,8 @@ export {themeGet} from '@primer/react' export {useColorSchemeVar} from '@primer/react' export {useTheme} from '@primer/react' +export {ActionMenu} from './components/ActionMenu' +export {Autocomplete, type AutocompleteOverlayProps} from './components/Autocomplete' export {Checkbox, type CheckboxProps} from './components/Checkbox' export {CircleBadge} from './components/CircleBadge' export {CounterLabel, type CounterLabelProps} from './components/CounterLabel' @@ -39,6 +38,7 @@ export {Header, type HeaderProps} from './components/Header' export {Link, type LinkProps} from './components/Link' export {LinkButton, type LinkButtonProps} from './components/LinkButton' export {NavList, type NavListProps} from './components/NavList' +export {Overlay} from './components/Overlay' export {PageLayout, type PageLayoutProps} from './components/PageLayout' export { PageHeader,