All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.demos.TileDemo.md Maven / Gradle / Ivy

Go to download

This library provides a set of common React components for use with the PatternFly reference implementation.

The newest version!
---
id: Tile
section: components
---

## Demos

### Tiles with single selection

```ts
import React from 'react';
import { Tile } from '@patternfly/react-core';

const TileSingleSelect: React.FunctionComponent = () => {
  const [selectedId, setSelectedId] = React.useState('');

  const onSelect = (event: React.MouseEvent) => {
    setSelectedId(event.currentTarget.id);
  };

  const onKeyDown = (event: React.KeyboardEvent) => {
    if (event.key === ' ' || event.key === 'Enter') {
      event.preventDefault();
      setSelectedId(event.currentTarget.id);
    }
  };

  return (
    
); }; ``` ### Tiles with multiple selection ```ts import React from 'react'; import { Tile } from '@patternfly/react-core'; const TileMultiSelect: React.FunctionComponent = () => { const [selectedIds, setSelectedIds] = React.useState([]); const onSelect = (event: React.MouseEvent | React.KeyboardEvent) => { const targetId = event.currentTarget.id; setSelectedIds(prevSelectedIds => { const newSelectedIds = prevSelectedIds.includes(targetId) ? prevSelectedIds.filter(id => id !== targetId) : [...prevSelectedIds, targetId]; console.log('tile selections: ', newSelectedIds); return newSelectedIds; }); }; const onKeyDown = (event: React.KeyboardEvent) => { console.log(event.key); if (event.key === ' ' || event.key === 'Enter') { event.preventDefault(); onSelect(event); } }; return (
); }; ```




© 2015 - 2024 Weber Informatics LLC | Privacy Policy