@patternfly/react-table 4.110.6 → 4.110.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.110.6",
3
+ "version": "4.110.8",
4
4
  "description": "This library provides a set of React table components for use with the PatternFly 4",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,7 +31,7 @@
31
31
  "clean": "rimraf dist"
32
32
  },
33
33
  "dependencies": {
34
- "@patternfly/react-core": "^4.242.1",
34
+ "@patternfly/react-core": "^4.242.3",
35
35
  "@patternfly/react-icons": "^4.92.3",
36
36
  "@patternfly/react-styles": "^4.91.3",
37
37
  "@patternfly/react-tokens": "^4.93.3",
@@ -46,5 +46,5 @@
46
46
  "react": "^16.8 || ^17 || ^18",
47
47
  "react-dom": "^16.8 || ^17 || ^18"
48
48
  },
49
- "gitHead": "348ba42ca2bc97042feb569b1427f38e5b4afbb1"
49
+ "gitHead": "5538c2f9925a8ac29505f1a4ec6003add9e14fa0"
50
50
  }
@@ -2107,411 +2107,7 @@ class FilterTableDemo extends React.Component {
2107
2107
 
2108
2108
  ### Sortable - responsive
2109
2109
 
2110
- ```js isFullscreen
2111
- import React from 'react';
2112
- import {
2113
- Button,
2114
- Card,
2115
- Flex,
2116
- FlexItem,
2117
- InputGroup,
2118
- Toolbar,
2119
- ToolbarContent,
2120
- ToolbarGroup,
2121
- ToolbarItem,
2122
- ToolbarToggleGroup,
2123
- OptionsMenu,
2124
- OptionsMenuToggle,
2125
- Pagination,
2126
- Text,
2127
- TextContent,
2128
- Select,
2129
- SelectVariant,
2130
- SelectOption,
2131
- Nav,
2132
- NavList,
2133
- NavItem,
2134
- Dropdown,
2135
- DropdownItem,
2136
- DropdownGroup,
2137
- DropdownToggle,
2138
- Divider,
2139
- KebabToggle,
2140
- Avatar,
2141
- OptionsMenuItem,
2142
- OptionsMenuSeparator,
2143
- OptionsMenuItemGroup,
2144
- OverflowMenu,
2145
- OverflowMenuContent,
2146
- OverflowMenuControl,
2147
- OverflowMenuDropdownItem,
2148
- OverflowMenuGroup,
2149
- OverflowMenuItem,
2150
- PageSection
2151
- } from '@patternfly/react-core';
2152
- import { ActionsColumn, TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
2153
-
2154
- import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon';
2155
- import SortAmountDownIcon from '@patternfly/react-icons/dist/esm/icons/sort-amount-down-icon';
2156
- import CloneIcon from '@patternfly/react-icons/dist/esm/icons/clone-icon';
2157
- import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
2158
- import EditIcon from '@patternfly/react-icons/dist/esm/icons/edit-icon';
2159
- import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
2160
- import SyncIcon from '@patternfly/react-icons/dist/esm/icons/sync-icon';
2161
- import QuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/question-circle-icon';
2162
- import AttentionBellIcon from '@patternfly/react-icons/dist/esm/icons/attention-bell-icon';
2163
- import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
2164
- import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon';
2165
- import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
2166
- import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper';
2167
-
2168
- ComposableTableSortable = () => {
2169
- const [navActiveItem, setNavActiveItem] = React.useState(0);
2170
- const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
2171
- const [isKebabDropdownOpen, setIsKebabDropdownOpen] = React.useState(false);
2172
- const [isSelectOpen, setIsSelectOpen] = React.useState(false);
2173
- const [isFullKebabDropdownOpen, setIsFullKebabDropdownOpen] = React.useState(false);
2174
-
2175
- const columns = ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit'];
2176
-
2177
- const [rows, setRows] = React.useState([
2178
- ['Node 1', 10, 25, 5, 2],
2179
- ['Node 2', 8, 30, 2, 2],
2180
- ['Node 3', 12, 48, 13, 30],
2181
- ['Node 4', 10, 25, 5, 8],
2182
- ['Node 5', 34, 21, 26, 2]
2183
- ]);
2184
-
2185
- // index of the currently active column
2186
- const [activeSortIndex, setActiveSortIndex] = React.useState(0);
2187
- // sort direction of the currently active column
2188
- const [activeSortDirection, setActiveSortDirection] = React.useState('asc');
2189
- // sort dropdown expansion
2190
- const [isSortDropdownOpen, setIsSortDropdownOpen] = React.useState(false);
2191
-
2192
- const [selectedNodeNames, setSelectedNodeNames] = React.useState([]);
2193
- const setNodeSelected = (node, isSelecting = true) => {
2194
- if (!selectedNodeNames.includes(node)) {
2195
- setSelectedNodeNames([...selectedNodeNames, node]);
2196
- } else {
2197
- setSelectedNodeNames(selectedNodeNames.filter(n => n !== node));
2198
- }
2199
- };
2200
-
2201
- const selectAllNodes = (isSelecting = true) => setSelectedNodeNames(isSelecting ? rows.map(r => r[0]) : []);
2202
- const areAllReposSelected = selectedNodeNames.length === rows.length;
2203
- const isNodeSelected = node => selectedNodeNames.includes(node[0]);
2204
-
2205
- // To allow shift+click to select/deselect multiple rows
2206
- const [recentSelectedRowIndex, setRecentSelectedRowIndex] = React.useState(null);
2207
- const [shifting, setShifting] = React.useState(false);
2208
-
2209
- const onSelectNode = (node, rowIndex, isSelecting) => {
2210
- // If the user is shift + selecting the checkboxes, then all intermediate checkboxes should be selected
2211
- if (shifting && recentSelectedRowIndex !== null) {
2212
- const numberSelected = rowIndex - recentSelectedRowIndex;
2213
- const intermediateIndexes =
2214
- numberSelected > 0
2215
- ? Array.from(new Array(numberSelected + 1), (_x, i) => i + recentSelectedRowIndex)
2216
- : Array.from(new Array(Math.abs(numberSelected) + 1), (_x, i) => i + rowIndex);
2217
- intermediateIndexes.forEach(index => setNodeSelected(rows[index], isSelecting));
2218
- } else {
2219
- setNodeSelected(node[0], isSelecting);
2220
- }
2221
- setRecentSelectedRowIndex(rowIndex);
2222
- };
2223
-
2224
- const onSort = (event, index, direction) => {
2225
- setActiveSortIndex(index);
2226
- setActiveSortDirection(direction);
2227
- // sorts the rows
2228
- const updatedRows = rows.sort((a, b) => {
2229
- if (typeof a[index] === 'number') {
2230
- // numeric sort
2231
- if (direction === 'asc') {
2232
- return a[index] - b[index];
2233
- }
2234
- return b[index] - a[index];
2235
- } else {
2236
- // string sort
2237
- if (direction === 'asc') {
2238
- return a[index].localeCompare(b[index]);
2239
- }
2240
- return b[index].localeCompare(a[index]);
2241
- }
2242
- });
2243
- setRows(updatedRows);
2244
- };
2245
-
2246
- const PageNav = (
2247
- <Nav onSelect={result => setNavActiveItem(result.itemId)} aria-label="Nav">
2248
- <NavList>
2249
- <NavItem itemId={0} isActive={navActiveItem === 0} to="#system-panel">
2250
- System Panel
2251
- </NavItem>
2252
- <NavItem itemId={1} isActive={navActiveItem === 1} to="#policy">
2253
- Policy
2254
- </NavItem>
2255
- <NavItem itemId={2} isActive={navActiveItem === 2} to="#auth">
2256
- Authentication
2257
- </NavItem>
2258
- <NavItem itemId={3} isActive={navActiveItem === 3} to="#network">
2259
- Network Services
2260
- </NavItem>
2261
- <NavItem itemId={4} isActive={navActiveItem === 4} to="#server">
2262
- Server
2263
- </NavItem>
2264
- </NavList>
2265
- </Nav>
2266
- );
2267
-
2268
- const kebabDropdownItems = [<OverflowMenuDropdownItem key="kebab-1">Some action</OverflowMenuDropdownItem>];
2269
-
2270
- const defaultActions = () => [
2271
- {
2272
- title: 'Settings',
2273
- onClick: () => console.log(`clicked on Settings`)
2274
- },
2275
- {
2276
- title: 'Help',
2277
- onClick: () => console.log(`clicked on Help`)
2278
- }
2279
- ];
2280
-
2281
- const renderPagination = (variant, isCompact) => (
2282
- <Pagination
2283
- isCompact={isCompact}
2284
- itemCount={36}
2285
- page={1}
2286
- perPage={10}
2287
- variant={variant}
2288
- titles={{
2289
- paginationTitle: `${variant} pagination`
2290
- }}
2291
- />
2292
- );
2293
-
2294
- const userDropdownItems = [
2295
- <DropdownGroup key="group 2">
2296
- <DropdownItem key="group 2 profile">My profile</DropdownItem>
2297
- <DropdownItem key="group 2 user" component="button">
2298
- User management
2299
- </DropdownItem>
2300
- <DropdownItem key="group 2 logout">Logout</DropdownItem>
2301
- </DropdownGroup>
2302
- ];
2303
-
2304
- const fullKebabItems = [
2305
- <DropdownGroup key="group 2">
2306
- <DropdownItem key="group 2 profile">My profile</DropdownItem>
2307
- <DropdownItem key="group 2 user" component="button">
2308
- User management
2309
- </DropdownItem>
2310
- <DropdownItem key="group 2 logout">Logout</DropdownItem>
2311
- </DropdownGroup>,
2312
- <Divider key="divider" />,
2313
- <DropdownItem key="kebab-1">
2314
- <CogIcon /> Settings
2315
- </DropdownItem>,
2316
- <DropdownItem key="kebab-2">
2317
- <HelpIcon /> Help
2318
- </DropdownItem>
2319
- ];
2320
-
2321
- const tableToolbar = (
2322
- <Toolbar id="sortable-toolbar">
2323
- <ToolbarContent>
2324
- <ToolbarItem visibility={{ md: 'hidden' }}>
2325
- <OptionsMenu
2326
- id="options-menu-multiple-options-example"
2327
- menuItems={[
2328
- <OptionsMenuItemGroup key="first group" aria-label="Sort column">
2329
- {columns.map((column, columnIndex) => (
2330
- <OptionsMenuItem
2331
- key={column}
2332
- isSelected={activeSortIndex === columnIndex}
2333
- onSelect={evt =>
2334
- onSort(evt, columnIndex, activeSortDirection !== 'none' ? activeSortDirection : 'asc')
2335
- }
2336
- >
2337
- {column}
2338
- </OptionsMenuItem>
2339
- ))}
2340
- </OptionsMenuItemGroup>,
2341
- <OptionsMenuSeparator key="separator" />,
2342
- <OptionsMenuItemGroup key="second group" aria-label="Sort direction">
2343
- <OptionsMenuItem
2344
- onSelect={evt => onSort(evt, activeSortIndex, 'asc')}
2345
- isSelected={activeSortDirection === 'asc'}
2346
- id="ascending"
2347
- key="ascending"
2348
- >
2349
- Ascending
2350
- </OptionsMenuItem>
2351
- <OptionsMenuItem
2352
- onSelect={evt => onSort(evt, activeSortIndex, 'desc')}
2353
- isSelected={activeSortDirection === 'desc'}
2354
- id="descending"
2355
- key="descending"
2356
- >
2357
- Descending
2358
- </OptionsMenuItem>
2359
- </OptionsMenuItemGroup>
2360
- ]}
2361
- isOpen={isSortDropdownOpen}
2362
- toggle={
2363
- <OptionsMenuToggle
2364
- hideCaret
2365
- onToggle={() => setIsSortDropdownOpen(!isSortDropdownOpen)}
2366
- toggleTemplate={<SortAmountDownIcon />}
2367
- />
2368
- }
2369
- isPlain
2370
- isGrouped
2371
- menuAppendTo="parent"
2372
- isFlipEnabled
2373
- />
2374
- </ToolbarItem>
2375
- <OverflowMenu breakpoint="lg">
2376
- <OverflowMenuContent isPersistent>
2377
- <OverflowMenuGroup isPersistent groupType="button">
2378
- <OverflowMenuItem>
2379
- <Button variant="primary">Create instance</Button>
2380
- </OverflowMenuItem>
2381
- <OverflowMenuItem>
2382
- <Button variant="secondary">Action</Button>
2383
- </OverflowMenuItem>
2384
- </OverflowMenuGroup>
2385
- </OverflowMenuContent>
2386
- <OverflowMenuControl hasAdditionalOptions>
2387
- <Dropdown
2388
- isPlain
2389
- onSelect={() => setIsKebabDropdownOpen(!isKebabDropdownOpen)}
2390
- toggle={<KebabToggle onToggle={() => setIsKebabDropdownOpen(!isKebabDropdownOpen)} />}
2391
- isOpen={isKebabDropdownOpen}
2392
- dropdownItems={kebabDropdownItems}
2393
- isFlipEnabled
2394
- menuAppendTo="parent"
2395
- />
2396
- </OverflowMenuControl>
2397
- </OverflowMenu>
2398
- <ToolbarGroup variant="icon-button-group">
2399
- <ToolbarItem>
2400
- <Button aria-label="Edit" variant="plain" icon={<EditIcon />} />
2401
- </ToolbarItem>
2402
- <ToolbarItem>
2403
- <Button aria-label="Clone" variant="plain" icon={<CloneIcon />} />
2404
- </ToolbarItem>
2405
- <ToolbarItem>
2406
- <Button aria-label="Sync" variant="plain" icon={<SyncIcon />} />
2407
- </ToolbarItem>
2408
- </ToolbarGroup>
2409
- <ToolbarItem variant="pagination">{renderPagination('top', true)}</ToolbarItem>
2410
- </ToolbarContent>
2411
- </Toolbar>
2412
- );
2413
-
2414
- return (
2415
- <React.Fragment>
2416
- <DashboardWrapper>
2417
- <PageSection isWidthLimited variant={PageSectionVariants.light}>
2418
- <TextContent>
2419
- <Text component="h1">Table demos</Text>
2420
- <Text component="p">
2421
- Below is an example of a responsive sortable table. When the screen size shrinks the table into a compact
2422
- form, the toolbar will display a dropdown menu containing sorting options.
2423
- </Text>
2424
- </TextContent>
2425
- </PageSection>
2426
- <PageSection
2427
- padding={{
2428
- default: 'noPadding',
2429
- xl: 'padding'
2430
- }}
2431
- >
2432
- <Card component="div">
2433
- {tableToolbar}
2434
- <TableComposable aria-label="Sortable Table">
2435
- <Thead>
2436
- <Tr>
2437
- <Th />
2438
- {columns.map((column, columnIndex) => {
2439
- const sortParams = {
2440
- sort: {
2441
- sortBy: {
2442
- index: activeSortIndex,
2443
- direction: activeSortDirection
2444
- },
2445
- onSort,
2446
- columnIndex
2447
- }
2448
- };
2449
- return (
2450
- <Th key={columnIndex} {...sortParams}>
2451
- {column}
2452
- </Th>
2453
- );
2454
- })}
2455
- </Tr>
2456
- </Thead>
2457
- <Tbody>
2458
- {rows.map((row, rowIndex) => (
2459
- <Tr key={rowIndex}>
2460
- <>
2461
- <Td
2462
- select={{
2463
- rowIndex,
2464
- onSelect: (_event, isSelecting) => onSelectNode(row, rowIndex, isSelecting),
2465
- isSelected: isNodeSelected(row)
2466
- }}
2467
- />
2468
- <Td dataLabel={columns[0]}>
2469
- <div>{row[0]}</div>
2470
- <a href="#">siemur/test-space</a>
2471
- </Td>
2472
- <Td dataLabel={columns[1]}>
2473
- <Flex spaceItems={{ default: 'spaceItemsSm' }}>
2474
- <FlexItem>
2475
- <CodeBranchIcon key="icon" />
2476
- </FlexItem>
2477
- <FlexItem>{row[1]}</FlexItem>
2478
- </Flex>
2479
- </Td>
2480
- <Td dataLabel={columns[2]}>
2481
- <Flex spaceItems={{ default: 'spaceItemsSm' }}>
2482
- <FlexItem>
2483
- <CodeIcon key="icon" />
2484
- </FlexItem>
2485
- <FlexItem>{row[2]}</FlexItem>
2486
- </Flex>
2487
- </Td>
2488
- <Td dataLabel={columns[3]}>
2489
- <Flex spaceItems={{ default: 'spaceItemsSm' }}>
2490
- <FlexItem>
2491
- <CubeIcon key="icon" />
2492
- </FlexItem>
2493
- <FlexItem>{row[3]}</FlexItem>
2494
- </Flex>
2495
- </Td>
2496
- <Td dataLabel={columns[4]}>{row[4]} days ago</Td>
2497
- <Td dataLabel={'Action'}>
2498
- <a href="#">Action link</a>
2499
- </Td>
2500
- <Td isActionCell>
2501
- <ActionsColumn items={defaultActions()} />
2502
- </Td>
2503
- </>
2504
- </Tr>
2505
- ))}
2506
- </Tbody>
2507
- </TableComposable>
2508
- {renderPagination('bottom', false)}
2509
- </Card>
2510
- </PageSection>
2511
- </DashboardWrapper>
2512
- </React.Fragment>
2513
- );
2514
- };
2110
+ ```js isFullscreen file="./table-demos/SortableResponsive.jsx"
2515
2111
  ```
2516
2112
 
2517
2113
  ### Automatic pagination