Skip to content

Commit b3b1657

Browse files
authored
RI-6998: flex components
* replace EuiFlexGrid * remove all usages of EuiFlexItem and EuiFlexGroup * add FocusTrap.tsx, replace EuiFocusTrap * add ShowFor, HideFor components * add WindowEvent.tsx and tests for it, replaced EuiWindowEvent * add useWindowEvent hook * RI-7008: replace eui spacer
1 parent 07e2fb0 commit b3b1657

File tree

202 files changed

+3508
-2825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+3508
-2825
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ redisinsight/api/content
5858
redisinsight/ui/dist-stats.html
5959
report
6060
reports
61-
dist
6261
distWeb
6362
dll
6463
main.js
@@ -85,3 +84,6 @@ redisinsight/ui/src/packages/common/index*
8584
.temp_cache
8685

8786
static/
87+
88+
.env*
89+
.npmrc

redisinsight/ui/src/components/base/layout/flex.module.scss

Whitespace-only changes.
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
import React from 'react'
2+
import { render } from 'uiSrc/utils/test-utils'
3+
import { theme } from 'uiSrc/components/base/theme'
4+
import { alignValues, dirValues, gapSizes, justifyValues } from './flex.styles'
5+
import { Col, FlexGroup as Flex, FlexItem, Grid, Row } from './flex'
6+
7+
const gapStyles = {
8+
none: '',
9+
xs: theme.semantic.core.space.xs,
10+
s: theme.semantic.core.space.s,
11+
m: theme.semantic.core.space.m,
12+
l: theme.semantic.core.space.l,
13+
xl: theme.semantic.core.space.xl,
14+
}
15+
describe('Flex Components', () => {
16+
it('should render', () => {
17+
expect(render(<FlexItem />)).toBeTruthy()
18+
expect(
19+
render(
20+
<Flex>
21+
<span>Child</span>
22+
</Flex>,
23+
),
24+
).toBeTruthy()
25+
expect(
26+
render(
27+
<Row>
28+
<span>Child</span>
29+
</Row>,
30+
),
31+
).toBeTruthy()
32+
expect(
33+
render(
34+
<Col>
35+
<span>Child</span>
36+
</Col>,
37+
),
38+
).toBeTruthy()
39+
expect(
40+
render(
41+
<Grid>
42+
<span>Child</span>
43+
</Grid>,
44+
),
45+
).toBeTruthy()
46+
})
47+
48+
describe('Flex', () => {
49+
it('should render with default classes', () => {
50+
const { container } = render(
51+
<Row>
52+
<span>Child</span>
53+
</Row>,
54+
)
55+
expect(container).toBeTruthy()
56+
expect(container.firstChild).toHaveClass('RI-flex-row', 'RI-flex-group')
57+
expect(container.firstChild).toHaveStyle('flex-direction: row')
58+
})
59+
60+
describe('Col', () => {
61+
it('should render', () => {
62+
const { container } = render(
63+
<Col>
64+
<span>Child</span>
65+
</Col>,
66+
)
67+
expect(container.firstChild).toHaveClass('RI-flex-col', 'RI-flex-group')
68+
expect(container.firstChild).toHaveStyle('flex-direction: column')
69+
})
70+
})
71+
72+
describe('Props', () => {
73+
describe('gap', () => {
74+
gapSizes.forEach((value) => {
75+
it(`should render gap ${value}`, () => {
76+
const { container } = render(
77+
<Flex gap={value}>
78+
<span>Child</span>
79+
</Flex>,
80+
)
81+
expect(container.firstChild).toHaveClass('RI-flex-group')
82+
if (value !== 'none') {
83+
expect(container.firstChild).toHaveStyle(
84+
`gap: ${gapStyles[value]}`,
85+
)
86+
} else {
87+
expect(container.firstChild).not.toHaveStyle('')
88+
}
89+
})
90+
})
91+
})
92+
describe('align', () => {
93+
alignValues.forEach((value) => {
94+
it(`should render ${value} align`, () => {
95+
const { container } = render(
96+
<Flex align={value}>
97+
<span>Child</span>
98+
</Flex>,
99+
)
100+
expect(container.firstChild).toHaveClass(
101+
'RI-flex-group',
102+
// flex[`align-${value}`],
103+
)
104+
})
105+
})
106+
})
107+
108+
describe('justify', () => {
109+
justifyValues.forEach((value) => {
110+
it(`should render ${value} justify`, () => {
111+
const { container } = render(
112+
<Flex justify={value}>
113+
<span>Child</span>
114+
</Flex>,
115+
)
116+
expect(container.firstChild).toHaveClass(
117+
'RI-flex-group',
118+
// flex[`justify-${value}`],
119+
)
120+
})
121+
})
122+
})
123+
124+
describe('dir', () => {
125+
dirValues.forEach((value) => {
126+
it(`should render ${value} dir`, () => {
127+
const { container } = render(
128+
<Flex direction={value}>
129+
<span>Child</span>
130+
</Flex>,
131+
)
132+
133+
expect(container.firstChild).toHaveClass(
134+
'RI-flex-group',
135+
// flex[`flex-${value}`],
136+
)
137+
})
138+
})
139+
})
140+
141+
describe('wrap', () => {
142+
;[true, false].forEach((value) => {
143+
test(`${value} is rendered`, () => {
144+
const { container } = render(
145+
<Flex wrap={value}>
146+
<span>Child</span>
147+
</Flex>,
148+
)
149+
150+
expect(container.firstChild).toHaveClass(
151+
'RI-flex-group',
152+
// value ? flex['flex-wrap'] : '',
153+
)
154+
})
155+
})
156+
})
157+
describe('responsive', () => {
158+
;[true, false].forEach((value) => {
159+
it(`should render ${value} responsive`, () => {
160+
const { container } = render(
161+
<Flex responsive={value}>
162+
<span>Child</span>
163+
</Flex>,
164+
)
165+
166+
expect(container.firstChild).toHaveClass(
167+
'RI-flex-group',
168+
// value ? flex['flex-responsive'] : '',
169+
)
170+
})
171+
})
172+
})
173+
})
174+
})
175+
176+
describe('FlexItem', () => {
177+
describe('inline', () => {
178+
it('should render div as default', () => {
179+
const { getByText, container } = render(
180+
<FlexItem>
181+
<span>Child</span>
182+
</FlexItem>,
183+
)
184+
expect(container.firstChild?.nodeName).toEqual('DIV')
185+
186+
expect(getByText('Child')).toBeInTheDocument()
187+
})
188+
})
189+
190+
describe('grow', () => {
191+
describe('falsy values', () => {
192+
const VALUES = [0, false, null] as const
193+
194+
VALUES.forEach((value) => {
195+
it(`${value} should generate a flex-grow of 0`, () => {
196+
const { container } = render(<FlexItem grow={value} />)
197+
expect(container.firstChild).toHaveClass(
198+
'RI-flex-item',
199+
// value ? flex['flex-responsive'] : '',
200+
)
201+
// assertClassName(flex['flexItem-grow-0'])
202+
})
203+
})
204+
})
205+
206+
describe('default values', () => {
207+
const VALUES = [true, undefined] as const
208+
209+
VALUES.forEach((value) => {
210+
test(`${value} generates a flex-grow of 1`, () => {
211+
const { container } = render(<FlexItem grow={value} />)
212+
expect(container.firstChild).toHaveClass(
213+
'RI-flex-item',
214+
// value ? flex['flex-responsive'] : '',
215+
)
216+
// assertClassName(flex['flexItem-grow-0'])
217+
})
218+
})
219+
})
220+
221+
describe('numeric values', () => {
222+
const VALUES = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const
223+
224+
VALUES.forEach((value) => {
225+
test(`${value} generates a flex-grow of ${value}`, () => {
226+
const { container } = render(<FlexItem grow={value} />)
227+
expect(container.firstChild).toHaveClass(
228+
'RI-flex-item',
229+
// value ? flex['flex-responsive'] : '',
230+
)
231+
// assertClassName(flex[`flexItem-grow-${value}`])
232+
})
233+
})
234+
})
235+
})
236+
})
237+
238+
describe('Grid', () => {
239+
it('should render', () => {
240+
expect(
241+
render(
242+
<Grid>
243+
<h2>My Child</h2>
244+
</Grid>,
245+
),
246+
).toBeTruthy()
247+
})
248+
describe('props', () => {
249+
describe('gap', () => {
250+
gapSizes.forEach((value) => {
251+
it(`should render ${value} gap`, () => {
252+
const { getByText, container } = render(
253+
<Grid gap={value}>
254+
<h2>My Child</h2>
255+
</Grid>,
256+
)
257+
const grid = container.firstChild
258+
expect(grid).toHaveClass('RI-flex-grid')
259+
if (value !== 'none') {
260+
expect(grid).toHaveStyle(`gap: ${gapStyles[value]}`)
261+
} else {
262+
expect(grid).not.toHaveStyle('')
263+
}
264+
expect(getByText('My Child')).toBeInTheDocument()
265+
})
266+
})
267+
})
268+
269+
describe('columns', () => {
270+
;([1, 2, 3, 4] as const).forEach((value) => {
271+
it(`should render ${value} columns`, () => {
272+
const { container } = render(
273+
<Grid columns={value}>
274+
<h2>My Child</h2>
275+
</Grid>,
276+
)
277+
expect(container.firstChild).toHaveClass(
278+
'RI-flex-grid',
279+
// flex[`grid-columns-${value}`],
280+
)
281+
})
282+
})
283+
})
284+
285+
describe('responsive', () => {
286+
it('should render when responsive is false', () => {
287+
const { container } = render(
288+
<Grid responsive={false}>
289+
<h2>My Child</h2>
290+
</Grid>,
291+
)
292+
expect(container.firstChild).toHaveClass('RI-flex-grid')
293+
// expect(container.firstChild).not.toHaveClass(flex.gridResponsive)
294+
})
295+
it('should have class grid-responsive when responsive is true', () => {
296+
const { container } = render(
297+
<Grid responsive>
298+
<h2>My Child</h2>
299+
</Grid>,
300+
)
301+
expect(container.firstChild).toHaveClass(
302+
'RI-flex-grid',
303+
// flex['grid-responsive'],
304+
)
305+
})
306+
})
307+
308+
describe('centered', () => {
309+
it('should render when centered is false', () => {
310+
const { container } = render(
311+
<Grid centered={false}>
312+
<h2>My Child</h2>
313+
</Grid>,
314+
)
315+
expect(container.firstChild).toHaveClass('RI-flex-grid')
316+
// expect(container.firstChild).not.toHaveClass(flex.gridCentered)
317+
})
318+
it('should have class grid-centered when responsive is true', () => {
319+
const { container } = render(
320+
<Grid centered>
321+
<h2>My Child</h2>
322+
</Grid>,
323+
)
324+
expect(container.firstChild).toHaveClass(
325+
'RI-flex-grid',
326+
// flex['grid-centered'],
327+
)
328+
})
329+
})
330+
})
331+
})
332+
})

0 commit comments

Comments
 (0)