0.42.2 • Published 27 days ago

@spectrum-web-components/grid v0.42.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
27 days ago

Description

An <sp-grid> element displays a virtualized grid of elements built from its items, a normalized array of javascript objects, applied to a supplied renderItem, a TemplateResult returning method. sp-grid is a class extension of lit-virtualizer and as such surfaces all of its underlying methods and events.

Elements displayed in the grid can be focused via the roving tabindex that allows the grid to be entered via the Tab key and then subsequent elements to be focused via the arrow keys. To inform the <sp-grid> element what part of the DOM created by the renderItem method can be focused, supply a value to focusableSelector. Focus will always enter the element list at index 0 of ALL available elements, not just those currently realized to the page.

Elements rendered via renderItem can have their width and height customized by supplying a value for itemSize that accepts an object: { width: number, height: number }. You can customize the space between these elements via the gap property that accepts a value of 0 or ${number}px.

Usage

See it on NPM! How big is this package in your project?

yarn add @spectrum-web-components/grid

Import the side effectful registration of <sp-grid> via:

import '@spectrum-web-components/grid/sp-grid.js';

When looking to leverage the Grid base class as a type and/or for extension purposes, do so via:

import { Grid } from '@spectrum-web-components/grid';

Example

<sp-grid
    id="grid-demo"
    style="
        margin:
            calc(-1 * var(--spectrum-spacing-500))
            calc(-1 * var(--spectrum-spacing-600))
    "
></sp-grid>
<script type="module">
    const initItems = (count) => {
        const total = count;
        const items = [];
        while (count) {
            count--;
            items.push({
                name: String(total - count),
                date: count,
            });
        }
        return items;
    };
    const initGrid = () => {
        const grid = document.querySelector('#grid-demo');
        grid.items = initItems(100);
        grid.focusableSelector = 'sp-card';
        grid.gap = '10px';
        grid.itemSize = {
            width: 200,
            height: 300,
        };

        grid.renderItem = (
            item,
            index,
            selected
        ) => {
            const card = document.createElement('sp-card');
            const img = document.createElement('img');
            const description = document.createElement('div');
            const footer = document.createElement('div');
            card.toggles = true;
            card.variant = 'quiet';
            card.heading = `Card Heading ${index}`
            card.subheading = 'JPG Photo'
            card.style = 'contain: strict; padding: 1px;'
            card.value = `card-${index}`
            card.selected = selected;
            card.key = index;
            img.alt = '';
            img.slot = 'preview';
            img.src = `https://picsum.photos/id/${index}/200/300`;
            img.decoding = 'async';
            description.slot = 'description';
            description.textContent = '10/15/18';
            footer.slot = 'footer';
            footer.textContent = 'Footer';
            card.append(img, description, footer);
            return card;
        }
    };
    customElements.whenDefined('sp-grid').then(() => {
        initGrid();
    });
</script>
0.42.2

27 days ago

0.42.1

28 days ago

0.42.0

1 month ago

0.41.2

2 months ago

0.41.1

2 months ago

0.41.0

3 months ago

0.40.5

3 months ago

0.40.4

3 months ago

0.40.3

4 months ago

0.40.2

4 months ago

0.40.1

5 months ago

0.38.0

8 months ago

0.35.1-rc.34

9 months ago

0.36.0

9 months ago

0.34.0

10 months ago

0.35.1-rc.43

9 months ago

0.35.1-rc.41

9 months ago

0.40.0

6 months ago

0.39.1

7 months ago

0.39.0

7 months ago

0.35.1-rc.15

9 months ago

0.37.0

9 months ago

0.35.0

9 months ago

0.39.4

6 months ago

0.39.3

6 months ago

0.39.2

7 months ago

0.34.1-rc.0

10 months ago

0.35.1-rc.25

9 months ago

0.35.1-rc.26

9 months ago

0.35.1-rc.24

9 months ago

0.33.3-overlay.66

10 months ago

0.33.3-overlay.65

10 months ago

0.33.3-overlay.61

10 months ago

0.31.1-react.21

11 months ago

0.32.0

11 months ago

0.30.0

12 months ago

0.33.1-overlay.41

11 months ago

0.31.1-react.3

12 months ago

0.31.1-react.1

12 months ago

0.31.1-react.2

12 months ago

0.30.1-overlay.30

12 months ago

0.33.1-overlay.39

11 months ago

0.30.1-overlay.31

12 months ago

0.32.1-overlay.33

11 months ago

0.33.2

11 months ago

0.33.0

11 months ago

0.30.1-overlay.38

12 months ago

0.30.1-overlay.37

12 months ago

0.30.1-overlay.41

12 months ago

0.30.1-overlay.42

12 months ago

0.30.1-overlay.40

12 months ago

0.32.1-overlay.41

11 months ago

0.31.0

12 months ago

0.31.1-overlay.29

12 months ago

0.1.8

1 year ago

0.1.8-react.75

1 year ago

0.1.8-react.49

1 year ago

0.1.8-react.48

1 year ago

0.1.8-react.50

1 year ago

0.1.8-react.32

1 year ago

0.1.6-react.54

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.2

2 years ago

0.1.4

1 year ago

0.1.3

2 years ago

0.1.5

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.9-devmode.24

2 years ago

0.0.10-devmode.0

2 years ago

0.1.0-devmode.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.9-devmode.31

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.4-alpha.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago