Skip to content

Commit 68fef3d

Browse files
authored
Revert "[Dialog] Replace deprecated Button for current one (#3084)" (#3527)
This reverts commit ded74d8.
1 parent 2df4d4e commit 68fef3d

File tree

8 files changed

+96
-263
lines changed

8 files changed

+96
-263
lines changed

.changeset/cool-schools-cheer.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Dialog/Dialog.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback, useEffect, useRef, useState} from 'react'
22
import styled from 'styled-components'
3-
import {Button, ButtonProps} from '../Button'
3+
import Button, {ButtonPrimary, ButtonDanger, ButtonProps} from '../deprecated/Button'
44
import Box from '../Box'
55
import {get} from '../constants'
66
import {useOnEscapePress, useProvidedRefOrCreate} from '../hooks'
@@ -20,11 +20,11 @@ const ANIMATION_DURATION = '200ms'
2020
* Props that characterize a button to be rendered into the footer of
2121
* a Dialog.
2222
*/
23-
export type DialogButtonProps = Omit<ButtonProps, 'children'> & {
23+
export type DialogButtonProps = ButtonProps & {
2424
/**
2525
* The type of Button element to use
2626
*/
27-
buttonType?: 'default' | 'primary' | 'danger' | 'normal'
27+
buttonType?: 'normal' | 'primary' | 'danger'
2828

2929
/**
3030
* The Button's inner text
@@ -366,6 +366,11 @@ const Footer = styled.div<SxProp>`
366366
${sx};
367367
`
368368

369+
const buttonTypes = {
370+
normal: Button,
371+
primary: ButtonPrimary,
372+
danger: ButtonDanger,
373+
}
369374
const Buttons: React.FC<React.PropsWithChildren<{buttons: DialogButtonProps[]}>> = ({buttons}) => {
370375
const autoFocusRef = useProvidedRefOrCreate<HTMLButtonElement>(buttons.find(button => button.autoFocus)?.ref)
371376
let autoFocusCount = 0
@@ -382,16 +387,17 @@ const Buttons: React.FC<React.PropsWithChildren<{buttons: DialogButtonProps[]}>>
382387
return (
383388
<>
384389
{buttons.map((dialogButtonProps, index) => {
385-
const {content, buttonType = 'default', autoFocus = false, ...buttonProps} = dialogButtonProps
390+
const {content, buttonType = 'normal', autoFocus = false, ...buttonProps} = dialogButtonProps
391+
const ButtonElement = buttonTypes[buttonType]
386392
return (
387-
<Button
393+
<ButtonElement
388394
key={index}
389395
{...buttonProps}
390-
variant={buttonType === 'normal' ? 'default' : buttonType}
396+
variant={buttonType}
391397
ref={autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null}
392398
>
393399
{content}
394-
</Button>
400+
</ButtonElement>
395401
)
396402
})}
397403
</>

src/SelectPanel/__snapshots__/SelectPanel.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ exports[`SelectPanel renders consistently 1`] = `
77
color: #1F2328;
88
}
99
10-
.c2 {
11-
margin-left: 4px;
12-
}
13-
1410
.c1 {
1511
position: relative;
1612
display: inline-block;
@@ -75,6 +71,10 @@ exports[`SelectPanel renders consistently 1`] = `
7571
border-color: rgba(31,35,40,0.15);
7672
}
7773
74+
.c2 {
75+
margin-left: 4px;
76+
}
77+
7878
<div
7979
className="c0"
8080
color="fg.default"

src/__tests__/ConfirmationDialog.test.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import {render as HTMLRender, fireEvent} from '@testing-library/react'
22
import {axe} from 'jest-axe'
33
import React, {useCallback, useRef, useState} from 'react'
44

5-
import {ActionMenu} from '../ActionMenu'
6-
import {ActionList} from '../ActionList'
5+
import {ActionMenu} from '../deprecated/ActionMenu'
76
import BaseStyles from '../BaseStyles'
87
import Box from '../Box'
9-
import {Button} from '../Button'
8+
import Button from '../deprecated/Button/Button'
109
import {ConfirmationDialog, useConfirm} from '../Dialog/ConfirmationDialog'
1110
import theme from '../theme'
1211
import {ThemeProvider} from '../ThemeProvider'
@@ -63,14 +62,10 @@ const ShorthandHookFromActionMenu = () => {
6362
<SSRProvider>
6463
<BaseStyles>
6564
<Box display="flex" flexDirection="column" alignItems="flex-start">
66-
<ActionMenu>
67-
<ActionMenu.Button>{text}</ActionMenu.Button>
68-
<ActionMenu.Overlay>
69-
<ActionList>
70-
<ActionList.Item onSelect={onButtonClick}>Show dialog</ActionList.Item>
71-
</ActionList>
72-
</ActionMenu.Overlay>
73-
</ActionMenu>
65+
<ActionMenu
66+
renderAnchor={props => <Button {...props}>{text}</Button>}
67+
items={[{text: 'Show dialog', onAction: onButtonClick}]}
68+
/>
7469
</Box>
7570
</BaseStyles>
7671
</SSRProvider>
@@ -100,36 +95,36 @@ describe('ConfirmationDialog', () => {
10095
})
10196

10297
it('focuses the primary action when opened and the confirmButtonType is not set', async () => {
103-
const {getByText, getByRole} = HTMLRender(<Basic />)
98+
const {getByText} = HTMLRender(<Basic />)
10499
fireEvent.click(getByText('Show dialog'))
105-
expect(getByRole('button', {name: 'Primary'})).toEqual(document.activeElement)
100+
expect(getByText('Primary')).toEqual(document.activeElement)
106101
expect(getByText('Secondary')).not.toEqual(document.activeElement)
107102
})
108103

109104
it('focuses the primary action when opened and the confirmButtonType is not danger', async () => {
110-
const {getByText, getByRole} = HTMLRender(<Basic confirmButtonType="primary" />)
105+
const {getByText} = HTMLRender(<Basic confirmButtonType="primary" />)
111106
fireEvent.click(getByText('Show dialog'))
112-
expect(getByRole('button', {name: 'Primary'})).toEqual(document.activeElement)
107+
expect(getByText('Primary')).toEqual(document.activeElement)
113108
expect(getByText('Secondary')).not.toEqual(document.activeElement)
114109
})
115110

116111
it('focuses the secondary action when opened and the confirmButtonType is danger', async () => {
117-
const {getByText, getByRole} = HTMLRender(<Basic confirmButtonType="danger" />)
112+
const {getByText} = HTMLRender(<Basic confirmButtonType="danger" />)
118113
fireEvent.click(getByText('Show dialog'))
119-
expect(getByRole('button', {name: 'Primary'})).not.toEqual(document.activeElement)
120-
expect(getByRole('button', {name: 'Secondary'})).toEqual(document.activeElement)
114+
expect(getByText('Primary')).not.toEqual(document.activeElement)
115+
expect(getByText('Secondary')).toEqual(document.activeElement)
121116
})
122117

123118
it('supports nested `focusTrap`s', async () => {
124119
const spy = jest.spyOn(console, 'error').mockImplementationOnce(() => {})
125120

126-
const {getByText, getByRole} = HTMLRender(<ShorthandHookFromActionMenu />)
121+
const {getByText} = HTMLRender(<ShorthandHookFromActionMenu />)
127122

128123
fireEvent.click(getByText('Show menu'))
129124
fireEvent.click(getByText('Show dialog'))
130125

131-
expect(getByRole('button', {name: 'Primary'})).toEqual(document.activeElement)
132-
expect(getByRole('button', {name: 'Secondary'})).not.toEqual(document.activeElement)
126+
expect(getByText('Primary')).toEqual(document.activeElement)
127+
expect(getByText('Secondary')).not.toEqual(document.activeElement)
133128

134129
// REACT_VERSION_LATEST should be treated as a constant for the test
135130
// environment

src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,6 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
100100
color: #1F2328;
101101
}
102102
103-
.c2 {
104-
background-color: #ffffff;
105-
box-shadow: 0 1px 3px rgba(31,35,40,0.12),0 8px 24px rgba(66,74,83,0.12);
106-
position: absolute;
107-
min-width: 192px;
108-
max-width: 640px;
109-
height: auto;
110-
width: auto;
111-
border-radius: 12px;
112-
overflow: hidden;
113-
-webkit-animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
114-
animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
115-
visibility: var(--styled-overlay-visibility);
116-
}
117-
118-
.c2:focus {
119-
outline: none;
120-
}
121-
122103
.c1 {
123104
position: relative;
124105
display: inline-block;
@@ -183,6 +164,25 @@ exports[`AnchoredOverlay should render consistently when open 1`] = `
183164
border-color: rgba(31,35,40,0.15);
184165
}
185166
167+
.c2 {
168+
background-color: #ffffff;
169+
box-shadow: 0 1px 3px rgba(31,35,40,0.12),0 8px 24px rgba(66,74,83,0.12);
170+
position: absolute;
171+
min-width: 192px;
172+
max-width: 640px;
173+
height: auto;
174+
width: auto;
175+
border-radius: 12px;
176+
overflow: hidden;
177+
-webkit-animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
178+
animation: overlay-appear 200ms cubic-bezier(0.33,1,0.68,1);
179+
visibility: var(--styled-overlay-visibility);
180+
}
181+
182+
.c2:focus {
183+
outline: none;
184+
}
185+
186186
@media (forced-colors:active) {
187187
.c2 {
188188
outline: solid 1px transparent;

0 commit comments

Comments
 (0)