-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,163 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
stories | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
## 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`](https://www.npmjs.com/package/@lit-labs/virtualizer/v/0.7.0-pre.2) and as such surfaces all of its underlying methods and events. | ||
|
||
Elements displayed in the grid can be focused via the [roving tabindex](https://www.w3.org/TR/wai-aria-practices-1.2/#kbd_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!](https://img.shields.io/npm/v/@spectrum-web-components/grid?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/grid) | ||
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/grid?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/grid) | ||
|
||
``` | ||
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 | ||
|
||
```js | ||
const items = generateItems(1000); | ||
|
||
const renderItem = ( | ||
item: Item, | ||
index: number, | ||
selected: boolean | ||
): TemplateResult => { | ||
return html` | ||
<sp-card | ||
toggles | ||
variant="quiet" | ||
heading="Card Heading ${item.id}" | ||
subheading="JPG Photo" | ||
style="contain: strict; padding: 1px;" | ||
value="card-${item.id}" | ||
.selected=${selected} | ||
key=${index} | ||
> | ||
<img | ||
alt="" | ||
slot="preview" | ||
src="https://picsum.photos/id/${item.id}/200/300" | ||
decoding="async" | ||
/> | ||
<div slot="description">10/15/18</div> | ||
<div slot="footer">Footer</div> | ||
</sp-card> | ||
`; | ||
}; | ||
|
||
// ... | ||
|
||
<sp-grid | ||
.items=${items} | ||
.focusableSelector=${'sp-card'} | ||
.renderItem=${renderItem} | ||
.itemSize=${{ | ||
width: 200, | ||
height: 300, | ||
}} | ||
.gap=${'10px'} | ||
></sp-grid> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "@spectrum-web-components/grid", | ||
"version": "0.0.1", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Web component implementation of a Spectrum design Grid", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/adobe/spectrum-web-components.git", | ||
"directory": "packages/grid" | ||
}, | ||
"author": "", | ||
"homepage": "https://adobe.github.io/spectrum-web-components/components/grid", | ||
"bugs": { | ||
"url": "https://github.com/adobe/spectrum-web-components/issues" | ||
}, | ||
"main": "src/index.js", | ||
"module": "src/index.js", | ||
"type": "module", | ||
"exports": { | ||
".": "./src/index.js", | ||
"./src/*": "./src/*.js", | ||
"./package.json": "./package.json", | ||
"./sp-grid": "./sp-grid.js", | ||
"./sp-grid.js": "./sp-grid.js" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1" | ||
}, | ||
"files": [ | ||
"**/*.d.ts", | ||
"**/*.js", | ||
"**/*.js.map", | ||
"custom-elements.json", | ||
"!stories/", | ||
"!test/" | ||
], | ||
"keywords": [ | ||
"spectrum css", | ||
"web components", | ||
"lit-element", | ||
"lit-html" | ||
], | ||
"dependencies": { | ||
"@lit-labs/observers": "^1.0.1", | ||
"@lit-labs/virtualizer": "0.7.0-pre.2", | ||
"@spectrum-web-components/base": "^0.5.1", | ||
"@spectrum-web-components/reactive-controllers": "^0.2.0", | ||
"tslib": "^2.0.0" | ||
}, | ||
"types": "./src/index.d.ts", | ||
"customElements": "custom-elements.json", | ||
"sideEffects": [ | ||
"./sp-*.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2020 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { Grid } from './src/Grid.js'; | ||
|
||
customElements.define('sp-grid', Grid); | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'sp-grid': Grid; | ||
} | ||
} |
Oops, something went wrong.