thegetty / quire

A multi-package repository for the Quire multiformat publishing framework
https://quire.getty.edu/
BSD 3-Clause "New" or "Revised" License
93 stars 12 forks source link

DEV-7190: Object Filters Feature #835

Closed anderspollack closed 11 months ago

anderspollack commented 1 year ago

Object filters

This branch includes work in progress on the Quire Object Filters feature. This adds new webc components, and a webc layout to packages/11ty.

See demo Netlify publication: https://quire-object-filters-demo.netlify.app/catalogue/alt/

New Components

This PR adds the following new webc components:

Instructions

Add another page to a catalogue directory:

# content/catalogue/gradoo.md
---
epub: false
title: Objects Catalogue
layout: objects-catalog.webc
order: 110
# why does 'classes' need to be set?
classes:
  - objects-catalogue
---

This is the content for the objects catalogue layout.

To Do

Questions

This is the objects catalogue


## WebC Notes

We have access to collections and navigations data when our component is used inside a layout
**`layout.webc`**
```html
<my-component gradoo="Gradoo" />

We have access to property data (like gradoo) inside a <script webc:type="js"> block. Note: with webc:type="js", the final line gets rendered to the DOM. my-component.webc

<script webc:type="js">
console.warn(gradoo) // > 'Gradoo' in build console
`<div class="my-component">${gradoo}</div>`
</script>

Properties can also be passed and accessed in markup

<!-- LAYOUT -->
<parent-component items="1,2,56" />

<!-- PARENT COMPONENT -->
<div class="parent-component">
  <child-component :items="items"></child-component>
</div>

Data handling

When we need to pass server-side data (11ty context) to the client, we do so by embedding it as JSON in a <script type="application/json"> tag:

component-data.webc

<script data-component webc:keep type="application/json" @raw="JSON.stringify(data)">
</script>

Then we can have access to it via querySelector:

my-component.webc

<template webc:nokeep>
  <component-data :data="data"></component-data>
  <button data-button>Show me the data</button>
</template>
<script webc:setup>
const data = {} // something from the 11ty context
</script>
<script webc:keep type="text/javascript">
// Use component data in client-side logic
window.customElements.define('my-component', class extends HTMLElement {
  connectedCallback() {
    const button = this.querySelector('[data-button]');
    button.addEventListener('click', () => {
      console.log('DATA', this.data);
    });
  }

  // get the data from the `<script type="application/json">` block
  get data() {
    const componentDataElement = this.querySelector('[data-component]');
    return JSON.parse(componentDataElement.textContent);
  }
});
</script>

UX Presentation

Responsive prototype for object filters UI on Quire catalog pages. To test, create a new publication with your local quire-11ty package: ``` quire new object-filters-demo --quire-path ~/full/path/to/local/quire/packages/11ty/ ``` **Default display** The default display mode of object filters will be visible on `/catalogue/`: ``` # /catalogue/index.md: # object-filter-display: default ``` ![localhost_8080_catalogue_ (12)](https://github.com/thegetty/quire/assets/7109269/7070e55a-df32-4b9d-a7c1-93e9cefbac25) **Collapsible display** When there are many (more than 8 or so) options, `collapsible` might be a better choice for `object-filter-display`: ``` # /catalogue/index.md: object-filter-display: collapsible ``` ![localhost_8080_catalogue_ (13)](https://github.com/thegetty/quire/assets/7109269/cd7e98b9-1e28-4c4e-a6b4-1ff113e45cbd) **Sticky display** When there are few (no more than 3 or 4) options, `sticky` might be a desirable option for `object-filter-display`: ``` # /catalogue/index.md: object-filter-display: sticky ``` ![localhost_8080_catalogue_ (14)](https://github.com/thegetty/quire/assets/7109269/48206f15-2077-452d-9994-a4f9eb753075)
mphstudios commented 1 year ago

Anders, your efforts sticking with the challenges of using WebC are producing some good patterns and this implementation is coming together. Writing the data as JSON to a script tag is likely a useful pattern for other client side data interaction.

mphstudios commented 11 months ago

Anders, packages/11ty/_includes/components/catalog-content.webc could be moved into either layouts/objects-catalog.webc or components/objects-catalog.webc