Skip to content

Commit cc1480d

Browse files
committed
Overlay no longer accepts styled system props (#1567)
1 parent da81788 commit cc1480d

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

.changeset/lucky-zoos-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': major
3+
---
4+
5+
Overlay no longer accepts styled-system props. Please use the `sx` prop to extend Primer component styling instead. See also https://primer.style/react/overriding-styles for information about `sx` and https://primer.style/react/system-props for context on the removal.

docs/content/Overlay.mdx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ const Demo = () => {
6565
render(<Demo />)
6666
```
6767
68-
## System props
69-
70-
<Note variant="warning">
71-
72-
System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.
73-
74-
</Note>
75-
76-
`Overlay` gets `COMMON` system props. Read the [System Props](/system-props) doc page for a full list of available props.
77-
7868
## Component props
7969
8070
| Name | Type | Default | Description |
@@ -92,3 +82,4 @@ System props are deprecated in all components except [Box](/Box). Please use the
9282
| top | `number` | 0 | Vertical position of the overlay, relative to its closest positioned ancestor (often its `Portal`). |
9383
| left | `number` | 0 | Horizontal position of the overlay, relative to its closest positioned ancestor (often its `Portal`). |
9484
| portalContainerName | `string` | `undefined` | Optional. If defined, Overlays will be rendered in the named portal. See also `Portal`. |
85+
| sx | SystemStyleObject | {} | Style to be applied to the component |

src/Overlay.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import styled from 'styled-components'
22
import React, {ReactElement, useEffect, useRef} from 'react'
3-
import {get, COMMON, SystemPositionProps, SystemCommonProps} from './constants'
4-
import {ComponentProps} from './utils/types'
53
import useLayoutEffect from './utils/useIsomorphicLayoutEffect'
4+
import {get} from './constants'
5+
import {AriaRole, Merge} from './utils/types'
66
import {useOverlay, TouchOrMouseEvent} from './hooks'
77
import Portal from './Portal'
88
import sx, {SxProp} from './sx'
@@ -16,7 +16,7 @@ type StyledOverlayProps = {
1616
maxHeight?: keyof Omit<typeof heightMap, 'auto' | 'initial'>
1717
visibility?: 'visible' | 'hidden'
1818
anchorSide?: AnchorSide
19-
}
19+
} & SxProp
2020

2121
const heightMap = {
2222
xsmall: '192px',
@@ -52,7 +52,7 @@ function getSlideAnimationStartingVector(anchorSide?: AnchorSide): {x: number; y
5252
return {x: 0, y: 0}
5353
}
5454

55-
const StyledOverlay = styled.div<StyledOverlayProps & SystemCommonProps & SxProp>`
55+
const StyledOverlay = styled.div<StyledOverlayProps>`
5656
background-color: ${get('colors.canvas.overlay')};
5757
box-shadow: ${get('shadows.overlay.shadow')};
5858
position: absolute;
@@ -77,22 +77,25 @@ const StyledOverlay = styled.div<StyledOverlayProps & SystemCommonProps & SxProp
7777
:focus {
7878
outline: none;
7979
}
80-
${COMMON};
8180
${sx};
8281
`
83-
export type OverlayProps = {
82+
type BaseOverlayProps = {
8483
ignoreClickRefs?: React.RefObject<HTMLElement>[]
8584
initialFocusRef?: React.RefObject<HTMLElement>
8685
returnFocusRef: React.RefObject<HTMLElement>
8786
onClickOutside: (e: TouchOrMouseEvent) => void
8887
onEscape: (e: KeyboardEvent) => void
8988
visibility?: 'visible' | 'hidden'
90-
[additionalKey: string]: unknown
91-
top: number
92-
left: number
89+
'data-test-id'?: unknown
90+
top?: number
91+
left?: number
9392
portalContainerName?: string
9493
preventFocusOnOpen?: boolean
95-
} & Omit<ComponentProps<typeof StyledOverlay>, 'visibility' | keyof SystemPositionProps>
94+
role?: AriaRole
95+
children?: React.ReactNode
96+
}
97+
98+
export type OverlayProps = Merge<StyledOverlayProps, BaseOverlayProps>
9699

97100
/**
98101
* An `Overlay` is a flexible floating surface, used to display transient content such as menus,
@@ -180,7 +183,6 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>(
180183
{
181184
top: `${top || 0}px`,
182185
left: `${left || 0}px`,
183-
...rest.style,
184186
'--styled-overlay-visibility': visibility
185187
} as React.CSSProperties
186188
}

src/__tests__/Overlay.types.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
import Overlay from '../Overlay'
3+
4+
export function shouldAcceptCallWithNoProps(ref: React.RefObject<HTMLElement>) {
5+
return <Overlay returnFocusRef={ref} onClickOutside={() => null} onEscape={() => null} />
6+
}
7+
8+
export function shouldNotAcceptSystemProps(ref: React.RefObject<HTMLElement>) {
9+
return (
10+
<Overlay
11+
returnFocusRef={ref}
12+
onClickOutside={() => null}
13+
onEscape={() => null}
14+
// @ts-expect-error system props should not be accepted
15+
backgroundColor="olivedrab"
16+
/>
17+
)
18+
}

src/stories/ActionMenu.stories.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ export function SimpleListStory(): JSX.Element {
9898
onAction={onAction}
9999
anchorContent="Menu"
100100
overlayProps={{
101-
'data-test-id': 'some_test_id',
102-
onMouseDown: (e: React.MouseEvent) =>
103-
// eslint-disable-next-line no-console
104-
console.log('onMouseDown in the internal Overlay can be useful for controlling event interactions', e)
101+
'data-test-id': 'some_test_id'
105102
}}
106103
items={[
107104
{text: 'New file', trailingText: '⌘O', disabled: true, leadingVisual: ProjectIcon},

0 commit comments

Comments
 (0)