forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolbarSticky.tsx
More file actions
48 lines (46 loc) · 1.73 KB
/
ToolbarSticky.tsx
File metadata and controls
48 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Fragment, useState } from 'react';
import { Toolbar, ToolbarItem, ToolbarContent, SearchInput, Checkbox } from '@patternfly/react-core';
export const ToolbarSticky = () => {
const [isSticky, setIsSticky] = useState(true);
const [showEvenOnly, setShowEvenOnly] = useState(true);
const [searchValue, setSearchValue] = useState('');
const array = Array.from(Array(30), (_, x) => x); // create array of numbers from 1-30 for demo purposes
const numbers = showEvenOnly ? array.filter((number) => number % 2 === 0) : array;
return (
<Fragment>
<div style={{ overflowY: 'scroll', height: '200px' }}>
<Toolbar id="toolbar-sticky" inset={{ default: 'insetNone' }} isSticky={isSticky}>
<ToolbarContent>
<ToolbarItem>
<SearchInput
aria-label="Sticky example search input"
value={searchValue}
onChange={(_event, value) => setSearchValue(value)}
onClear={() => setSearchValue('')}
/>
</ToolbarItem>
<ToolbarItem alignSelf="center">
<Checkbox
label="Show only even number items"
isChecked={showEvenOnly}
onChange={(_event, checked) => setShowEvenOnly(checked)}
id="showOnlyEvenCheckbox"
/>
</ToolbarItem>
</ToolbarContent>
</Toolbar>
<ul>
{numbers.map((number) => (
<li key={number}>{`item ${number}`}</li>
))}
</ul>
</div>
<Checkbox
label="Is toolbar sticky"
isChecked={isSticky}
onChange={(_event, checked) => setIsSticky(checked)}
id="isStickyCheckbox"
/>
</Fragment>
);
};