| 1 |
--- |
| 2 |
id: Tile |
| 3 |
section: components |
| 4 |
cssPrefix: pf-v6-c-tile |
| 5 |
propComponents: ['Tile'] |
| 6 |
deprecated: true |
| 7 |
--- |
| 8 |
|
| 9 |
import { useState } from 'react'; |
| 10 |
import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon'; |
| 11 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 12 |
import './Tile.css'; |
| 13 |
|
| 14 |
**Note:** Tile has been deprecated. Use the [card](/components/card#cards-as-tiles) component instead. |
| 15 |
|
| 16 |
## Examples |
| 17 |
|
| 18 |
### Basic tile |
| 19 |
|
| 20 |
Basic tiles can appear in one of three states: a default state, selected state, and a disabled state. To change the state of a tile, use the properties `isSelected` and `isDisabled`. |
| 21 |
|
| 22 |
```ts file="./TileBasic.tsx" |
| 23 |
|
| 24 |
``` |
| 25 |
|
| 26 |
### With subtext |
| 27 |
|
| 28 |
Tile subtext can provide users with additional context. To add subtext, pass a short description to the `<Tile>` component. |
| 29 |
|
| 30 |
```ts file="./TileWithSubtext.tsx" |
| 31 |
|
| 32 |
``` |
| 33 |
|
| 34 |
### With icon |
| 35 |
|
| 36 |
Icons can provide a visual cue that helps users understand what the tile is being used for. To add an icon, use the `icon` property. |
| 37 |
|
| 38 |
```ts file="./TileWithIcon.tsx" |
| 39 |
|
| 40 |
``` |
| 41 |
|
| 42 |
### With stacked icon |
| 43 |
|
| 44 |
You can further customize a tile’s appearance by placing an icon above the title. To stack your icon on top of a tile’s title, use the `isStacked` property. |
| 45 |
|
| 46 |
```ts file="./TileStacked.tsx" |
| 47 |
|
| 48 |
``` |
| 49 |
|
| 50 |
### With large icons |
| 51 |
|
| 52 |
You can make your icons larger to help catch a user’s attention. To increase the size of an icon, use the `isDisplayLarge` property. |
| 53 |
|
| 54 |
Be aware that `isDisplayLarge` can only be used when `isStacked` is also applied. |
| 55 |
|
| 56 |
```ts file="./TileStackedWithLargeIcons.tsx" |
| 57 |
|
| 58 |
``` |
| 59 |
|
| 60 |
### With long subtext |
| 61 |
|
| 62 |
To provide users with a large amount of context, subtext can be elongated to wrap around to the next line. To format a long subtext, you can pass the component `Flex` into `<Tile>`. |
| 63 |
|
| 64 |
You can also change the type of `Flex` you can use so that the line breaks in the subtext fits your needs. You can do this by changing the default flex. The standard is `default: “flex_1”`, and changing the number in the default will also change where the sentence breaks. |
| 65 |
|
| 66 |
```ts file="./TileWithExtraContent.tsx" |
| 67 |
|
| 68 |
``` |
| 69 |
|
| 70 |
## Demos |
| 71 |
|
| 72 |
### Tiles with single selection |
| 73 |
|
| 74 |
```ts |
| 75 |
import { useState } from 'react'; |
| 76 |
import { Tile } from '@patternfly/react-core/deprecated'; |
| 77 |
|
| 78 |
const TileSingleSelect: React.FunctionComponent = () => { |
| 79 |
const [selectedId, setSelectedId] = useState<string>(''); |
| 80 |
|
| 81 |
const onSelect = (event: React.MouseEvent) => { |
| 82 |
setSelectedId(event.currentTarget.id); |
| 83 |
}; |
| 84 |
|
| 85 |
const onKeyDown = (event: React.KeyboardEvent) => { |
| 86 |
if (event.key === ' ' || event.key === 'Enter') { |
| 87 |
event.preventDefault(); |
| 88 |
setSelectedId(event.currentTarget.id); |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
return ( |
| 93 |
<div role="listbox" aria-label="Single selection tiles"> |
| 94 |
<Tile title="Tile 1" id="single-select-tile-1" onClick={onSelect} onKeyDown={onKeyDown} isSelected={selectedId === 'single-select-tile-1'} /> |
| 95 |
<Tile title="Tile 2" id="single-select-tile-2" onClick={onSelect} onKeyDown={onKeyDown} isSelected={selectedId === 'single-select-tile-2'} /> |
| 96 |
<Tile title="Tile 3" id="single-select-tile-3" isDisabled isSelected={selectedId === 'single-select-tile-3'} /> |
| 97 |
<Tile title="Tile 4" id="single-select-tile-4" onClick={onSelect} onKeyDown={onKeyDown} isSelected={selectedId === 'single-select-tile-4'} /> |
| 98 |
</div> |
| 99 |
); |
| 100 |
}; |
| 101 |
``` |
| 102 |
|
| 103 |
### Tiles with multiple selection |
| 104 |
|
| 105 |
```ts |
| 106 |
import { useState } from 'react'; |
| 107 |
import { Tile } from '@patternfly/react-core/deprecated'; |
| 108 |
|
| 109 |
const TileMultiSelect: React.FunctionComponent = () => { |
| 110 |
const [selectedIds, setSelectedIds] = useState<string[]>([]); |
| 111 |
|
| 112 |
const onSelect = (event: React.MouseEvent | React.KeyboardEvent) => { |
| 113 |
const targetId = event.currentTarget.id; |
| 114 |
setSelectedIds(prevSelectedIds => { |
| 115 |
const newSelectedIds = prevSelectedIds.includes(targetId) |
| 116 |
? prevSelectedIds.filter(id => id !== targetId) |
| 117 |
: [...prevSelectedIds, targetId]; |
| 118 |
console.log('tile selections: ', newSelectedIds); |
| 119 |
return newSelectedIds; |
| 120 |
}); |
| 121 |
}; |
| 122 |
|
| 123 |
const onKeyDown = (event: React.KeyboardEvent) => { |
| 124 |
console.log(event.key); |
| 125 |
if (event.key === ' ' || event.key === 'Enter') { |
| 126 |
event.preventDefault(); |
| 127 |
onSelect(event); |
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
return ( |
| 132 |
<div role="listbox" aria-multiselectable={true} aria-label="Multiselectable tiles"> |
| 133 |
<Tile |
| 134 |
title="Tile 1" |
| 135 |
id="multiselect-tile-1" |
| 136 |
onClick={onSelect} |
| 137 |
onKeyDown={onKeyDown} |
| 138 |
isSelected={selectedIds.includes('multiselect-tile-1')} |
| 139 |
/> |
| 140 |
<Tile |
| 141 |
title="Tile 2" |
| 142 |
id="multiselect-tile-2" |
| 143 |
onClick={onSelect} |
| 144 |
onKeyDown={onKeyDown} |
| 145 |
isSelected={selectedIds.includes('multiselect-tile-2')} |
| 146 |
/> |
| 147 |
<Tile title="Tile 3" id="multiselect-tile-3" isDisabled /> |
| 148 |
<Tile |
| 149 |
title="Tile 4" |
| 150 |
id="multiselect-tile-4" |
| 151 |
onClick={onSelect} |
| 152 |
onKeyDown={onKeyDown} |
| 153 |
isSelected={selectedIds.includes('multiselect-tile-4')} |
| 154 |
/> |
| 155 |
</div> |
| 156 |
); |
| 157 |
}; |
| 158 |
``` |