Settings Container
<zn-settings-container>
ZnSettingsContainer
Settings containers let users choose which of their items are visible, using filters on item attributes.
By default, all elements inside a <zn-settings-container> are shown. You can add filters
to toggle visibility of specific elements based on their attributes.
<div style="width: 100%; height: 300px; border: 1px solid #ccc;"> <zn-settings-container store-key="example-filters"> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile original caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile original caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <div slot="filter" attribute="private" default="true">Toggle Private Messages</div> <div slot="filter" attribute="original" default="true">Toggle Original Messages</div> </zn-settings-container> </div>
Examples
Specific Elements Only
Give a filter an item-selector to limit it to the items matching that selector. Here one filter
toggles only the inline edits and the other only the tiles. Start the selector with > to
also search inside shadow roots.
<style> zn-tile, zn-inline-edit { position: relative; } [private]:after, [original]:after { position: absolute; top: 0; right: 0; font-size: 10px; padding: 2px 4px; border-radius: 0 0 0 4px; color: #000; font-weight: bold; } [private]:after { content: " (private)"; border: 1px solid #f00; background: #fee; } [original]:after { content: " (original)"; border: 1px solid #00f; background: #eef; } </style> <div style="width: 100%; height: 300px; border: 1px solid #ccc;"> <zn-settings-container> <zn-inline-edit private value="1" options="{"1": "Option 1","2": "Option 2"}"> </zn-inline-edit> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-inline-edit original value="1" options="{"1": "Option 1","2": "Option 2"}"> </zn-inline-edit> <zn-tile original caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <div slot="filter" attribute="private" default="true" item-selector="zn-inline-edit">Toggle Inline Edit Private Messages</div> <div slot="filter" attribute="original" default="true" item-selector="zn-tile">Toggle Tile Original Messages</div> </zn-settings-container> </div>
Pull Tab
Add the pull-tab attribute to replace the settings dropdown with a pull tab anchored to the top
right of the container. Clicking the tab slides down a panel containing the settings options. Optional
content can be placed in the tab slot to render alongside the chevron.
<div style="width: 100%; height: 300px; border: 1px solid #ccc;"> <zn-settings-container pull-tab store-key="example-pull-tab-filters"> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile private caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <zn-tile original caption="Leslie Alexander" description="Leslie.alexander@example.com" href="https://google.com"> <zn-icon slot="image" size="40" src="https://i.pravatar.cc/60?img=70" round></zn-icon> <div slot="actions"> <zn-button href="#">Action</zn-button> </div> </zn-tile> <div slot="filter" attribute="private" default="true">Toggle Private Messages</div> <div slot="filter" attribute="original" default="true">Toggle Original Messages</div> </zn-settings-container> </div>
Filtering From a Navbar
An isolated zn-navbar inside the container switches its filters. Selecting a tab
hides the items carrying the attribute named by the tab’s tab; a tab of "" shows
every item. Add no-settings to hide the container’s own settings toggle when the navbar is the
only control.
Unread message
Read message
Another unread message
<zn-settings-container no-settings no-scroll> <zn-navbar isolated pill size="small" flush navigation='[{"tab":"","title":"All","active":true},{"tab":"read","title":"Unread"}]'></zn-navbar> <div slot="filter" attribute="read" default="true">Read</div> <p>Unread message</p> <p read>Read message</p> <p>Another unread message</p> </zn-settings-container>
Events
With pull-tab, listen for zn-show and zn-hide to react when the panel
opens and closes. Check that the event’s target is the container, since popups inside it emit the same
events.
Unread message
Read message
Panel: closed
<div style="width: 100%; height: 200px; border: 1px solid #ccc;"> <zn-settings-container class="settings-container-events" pull-tab> <p>Unread message</p> <p read>Read message</p> <div slot="filter" attribute="read" default="true">Show read messages</div> </zn-settings-container> </div> <p>Panel: <code class="settings-container-events-out">closed</code></p> <script type="module"> const container = document.querySelector('.settings-container-events'); const out = document.querySelector('.settings-container-events-out'); container.addEventListener('zn-show', e => { if (e.target === container) out.textContent = 'open'; }); container.addEventListener('zn-hide', e => { if (e.target === container) out.textContent = 'closed'; }); </script>
Slots
| Name | Description |
|---|---|
| (default) | The default slot. |
filter
|
Filter definitions used to toggle visibility of content. |
dropdown-content
|
Custom content for the settings panel. |
tab
|
Extra content rendered inside the pull tab next to the chevron. An isolated
zn-navbar inside the container switches its filters: selecting a tab hides the items
carrying the attribute named by the tab’s tab, and a tab of "" shows every
item. An item fading out after a filter hides it carries data-leaving until it is
hidden, so styles that react to the visible items (e.g. an empty state) can count it as
gone while it leaves.
|
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
noSettings
no-settings
|
Hides the settings toggle, for a container whose filters an isolated
zn-navbar switches.
|
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
zn-show |
|
Emitted when the pull tab panel opens. | - |
zn-hide |
|
Emitted when the pull tab panel closes. | - |