Skip to content

Commit 2e9a321

Browse files
author
Luke Bowerman
authored
Drawer implementation (#1500)
* Initial Drawer implementation * Refinements and test coverage * Use new scroll-lock implementation * 0.9.16 CHANGELOG
1 parent 7436717 commit 2e9a321

File tree

18 files changed

+778
-17
lines changed

18 files changed

+778
-17
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"cSpell.words": [
1919
"JIRA",
2020
"camelcase",
21+
"chuse",
2122
"combobox",
2223
"csstype",
2324
"describedby",

CHANGELOG.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [UNRELEASED]
8+
## [0.9.16] - 2020-10-02
99

10+
### Added
11+
12+
- `Drawer` component
13+
- Note: This is a new implementation of the previously deprecated `Drawer` and features a more modern API. `DrawerManager` behaviors are now baked in to `Drawer`
14+
- Includes `useDrawer` hook
1015
- `TabList` now supports `PaddingProps` and `fontSize`
1116
- `TabList` w/ `distribute` now uses default "small" `fontSize`
1217

13-
* Preview: `InputFilters` component and tests (this component is not yet ready for general-use)
14-
* Preview: `ActionListControls` component (this component is not yet ready for general-use)
15-
* Experimental: `@looker/components-theme-editor` package
16-
* Experimental: "Semantic" Layout components - `Layout`, `Header`, `Footer`, `Aside`
17-
18-
- Implemented image snapshot support and added coverage for `Button*`, `IconButton` & `Tree` components
19-
- Preliminary infrastructure for Storybook composition
20-
- Added support for Storybook extract behavior to improve published-Storybook performance
18+
- Image snapshots tests
19+
- Infrastructure to run image snapshot tests leveraging Storybook `storyshots` + `jest-image-snapshots`
20+
- Image snapshot coverage for `Button*`, `IconButton` & `Tree` components
21+
- Storybook: Preliminary infrastructure for composition
22+
- Storybook: Added support for extract behavior to improve published-Storybook performance
2123

2224
### Changed
2325

@@ -32,6 +34,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3234

3335
- Page "jumps" when opening a `Popover` due to the scrollbar disappearing
3436

37+
### Preview / Experimental
38+
39+
- Experimental: `@looker/components-theme-editor` package
40+
- Preview: `InputFilters` component and tests (this component is not yet ready for general-use)
41+
- Preview: `ActionListControls` component (this component is not yet ready for general-use)
42+
- Preview: "Semantic" Layout components - `Layout`, `Header`, `Footer`, `Aside`
43+
3544
## [0.9.15] - 2020-09-21
3645

3746
### Changed
1.89 KB
Loading
1.89 KB
Loading

packages/components/src/Dialog/Surface.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
import { useGlobalHotkeys } from '../utils'
4646
import { DialogContext } from './DialogContext'
4747

48-
interface SurfaceProps
48+
export interface SurfaceProps
4949
extends CompatibleHTMLProps<HTMLDivElement>,
5050
BorderProps,
5151
BoxShadowProps,
@@ -85,12 +85,12 @@ const SurfaceLayout: FC<SurfaceProps> = ({
8585
)
8686
}
8787

88-
const surfaceTransition = () => css`
89-
${(props) =>
90-
`${props.theme.transitions.durationModerate} ${props.theme.easings.ease}`}
88+
export const surfaceTransition = () => css`
89+
${({ theme }) =>
90+
`${theme.transitions.durationModerate} ${theme.easings.ease}`}
9191
`
9292

93-
export const Surface = styled(SurfaceLayout)`
93+
export const SurfaceBase = styled(SurfaceLayout)`
9494
${reset}
9595
${boxShadow}
9696
${border}
@@ -100,12 +100,20 @@ export const Surface = styled(SurfaceLayout)`
100100
101101
display: flex;
102102
flex-direction: column;
103-
position: relative;
104-
transition: transform ${surfaceTransition}, opacity ${surfaceTransition};
105103
106104
&:focus {
107105
outline: none;
108106
}
107+
`
108+
109+
SurfaceBase.defaultProps = {
110+
backgroundColor: 'background',
111+
color: 'text5',
112+
}
113+
114+
export const Surface = styled(SurfaceBase)`
115+
position: relative;
116+
transition: transform ${surfaceTransition}, opacity ${surfaceTransition};
109117
110118
&.entering,
111119
&.exiting {
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import 'jest-styled-components'
28+
import React, { useContext } from 'react'
29+
import { renderWithTheme } from '@looker/components-test-utils'
30+
import {
31+
screen,
32+
fireEvent,
33+
waitForElementToBeRemoved,
34+
} from '@testing-library/react'
35+
import { DialogContext } from '../Dialog/DialogContext'
36+
import { Drawer } from './Drawer'
37+
import { UseDrawerHook, RenderProps } from './stories/Drawer.story'
38+
39+
const SimpleContent = () => {
40+
const { closeModal } = useContext(DialogContext)
41+
42+
return (
43+
<>
44+
Drawer content
45+
<button onClick={closeModal}>Done</button>
46+
</>
47+
)
48+
}
49+
50+
describe('Drawer', () => {
51+
test('Verify initial state', () => {
52+
renderWithTheme(<Drawer content={<SimpleContent />} />)
53+
expect(screen.queryByText('Drawer content')).not.toBeInTheDocument()
54+
})
55+
56+
test('defaultOpen prop', async () => {
57+
renderWithTheme(<Drawer defaultOpen content={<SimpleContent />} />)
58+
expect(screen.queryByText('Drawer content')).toBeInTheDocument()
59+
const doneButton = screen.getByText('Done')
60+
fireEvent.click(doneButton)
61+
await waitForElementToBeRemoved(() => screen.getByText('Drawer content'))
62+
})
63+
64+
test('Drawer can be opened & closed', async () => {
65+
renderWithTheme(
66+
<Drawer content={<SimpleContent />}>
67+
<a>Open Drawer</a>
68+
</Drawer>
69+
)
70+
71+
// Dialog closed
72+
expect(screen.queryByText('Drawer content')).not.toBeInTheDocument()
73+
74+
// Open Drawer
75+
const link = screen.getByText('Open Drawer')
76+
expect(link).toBeInTheDocument()
77+
fireEvent.click(link)
78+
expect(screen.queryByText('Drawer content')).toBeInTheDocument()
79+
80+
// Close the Drawer
81+
const doneButton = screen.getByText('Done')
82+
fireEvent.click(doneButton)
83+
await waitForElementToBeRemoved(() => screen.getByText('Drawer content'))
84+
})
85+
86+
test('useDrawer hook', async () => {
87+
renderWithTheme(<UseDrawerHook />)
88+
89+
// Dialog closed
90+
expect(
91+
screen.queryByText('The Constitution of the United States')
92+
).not.toBeInTheDocument()
93+
94+
// Open Drawer
95+
const link = screen.getByText('Open Drawer')
96+
fireEvent.click(link)
97+
expect(
98+
screen.queryByText('The Constitution of the United States')
99+
).toBeInTheDocument()
100+
101+
// Close the Drawer
102+
const doneButton = screen.getByText('Done Reading')
103+
fireEvent.click(doneButton)
104+
await waitForElementToBeRemoved(() =>
105+
screen.getByText('The Constitution of the United States')
106+
)
107+
})
108+
109+
test('renderProps form', async () => {
110+
renderWithTheme(<RenderProps />)
111+
112+
// Dialog closed
113+
expect(
114+
screen.queryByText('The Constitution of the United States')
115+
).not.toBeInTheDocument()
116+
117+
// Open Drawer
118+
const link = screen.getByText('Open Drawer')
119+
fireEvent.click(link)
120+
expect(
121+
screen.queryByText('The Constitution of the United States')
122+
).toBeInTheDocument()
123+
124+
// Close the Drawer
125+
const doneButton = screen.getByText('Done Reading')
126+
fireEvent.click(doneButton)
127+
await waitForElementToBeRemoved(() =>
128+
screen.getByText('The Constitution of the United States')
129+
)
130+
})
131+
132+
xtest('Backdrop can be clicked to close', () => true)
133+
xtest('Composition form: controlled', () => true)
134+
xtest('canClose callback', () => true)
135+
xtest('onClose callback', () => true)
136+
})

0 commit comments

Comments
 (0)