settings-block
An account settings page: profile, notification switches, light or dark appearance, and a delete that asks first. value holds it all and is two-way; Save fires save.
Try it: events appear here (valuechange, save, delete).
Source: settings-block.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/settings-block.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/settings-block.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/settings-block.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/settings-block.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/settings-block.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/settings-block.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/settings-block.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/settings-block.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/settings-block.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/settings-block.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/settings-block.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/settings-block.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/settings-block.js"></script>The compiled install writes src/components/zubra/settings-block.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed , with the plain elements of the components it's made of; it's smaller on a page with one to three components, the shared runtime with more.
Usage
<settings-block></settings-block>
<script type="module">
import './components/zubra/settings-block.js';
const element = document.querySelector('settings-block');
element.value = {
name: 'Maya Chen',
email: 'maya@example.com',
notifications: { replies: true, digest: false },
theme: 'system',
};
element.notifications = [
{
id: 'replies',
label: 'Replies to me',
description: 'When someone answers your message.',
},
{
id: 'digest',
label: 'Weekly summary',
description: 'One email on Mondays.',
},
];
element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
element.addEventListener('save', (event) => console.log('save', event.detail));
element.addEventListener('delete', (event) => console.log('delete', event.detail));
</script>import './components/zubra/settings-block.js';
const value = {
name: 'Maya Chen',
email: 'maya@example.com',
notifications: { replies: true, digest: false },
theme: 'system',
};
const notifications = [
{
id: 'replies',
label: 'Replies to me',
description: 'When someone answers your message.',
},
{
id: 'digest',
label: 'Weekly summary',
description: 'One email on Mondays.',
},
];
export function SettingsBlockExample() {
return (
<settings-block
value={value}
notifications={notifications}
onvaluechange={(event) => console.log('valuechange', event.detail)}
onsave={(event) => console.log('save', event.detail)}
ondelete={(event) => console.log('delete', event.detail)}
></settings-block>
);
}<script setup>
import './components/zubra/settings-block.js';
const value = {
name: 'Maya Chen',
email: 'maya@example.com',
notifications: { replies: true, digest: false },
theme: 'system',
};
const notifications = [
{
id: 'replies',
label: 'Replies to me',
description: 'When someone answers your message.',
},
{
id: 'digest',
label: 'Weekly summary',
description: 'One email on Mondays.',
},
];
const onValuechange = (event) => console.log('valuechange', event.detail);
const onSave = (event) => console.log('save', event.detail);
const onDelete = (event) => console.log('delete', event.detail);
</script>
<template>
<settings-block
:value.prop="value"
:notifications.prop="notifications"
@valuechange="onValuechange"
@save="onSave"
@delete="onDelete"
></settings-block>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/settings-block.js';
const value = {
name: 'Maya Chen',
email: 'maya@example.com',
notifications: { replies: true, digest: false },
theme: 'system',
};
const notifications = [
{
id: 'replies',
label: 'Replies to me',
description: 'When someone answers your message.',
},
{
id: 'digest',
label: 'Weekly summary',
description: 'One email on Mondays.',
},
];
</script>
<settings-block
{value}
{notifications}
onvaluechange={(event) => console.log('valuechange', event.detail)}
onsave={(event) => console.log('save', event.detail)}
ondelete={(event) => console.log('delete', event.detail)}
></settings-block>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/settings-block.js';
@Component({
selector: 'app-settings-block-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<settings-block
[value]="value"
[notifications]="notifications"
(valuechange)="onValuechange($event)"
(save)="onSave($event)"
(delete)="onDelete($event)"
></settings-block>
`,
})
export class SettingsBlockExample {
value = {
name: 'Maya Chen',
email: 'maya@example.com',
notifications: { replies: true, digest: false },
theme: 'system',
};
notifications = [
{
id: 'replies',
label: 'Replies to me',
description: 'When someone answers your message.',
},
{
id: 'digest',
label: 'Weekly summary',
description: 'One email on Mondays.',
},
];
onValuechange(event: Event) {
console.log('valuechange', (event as CustomEvent).detail);
}
onSave(event: Event) {
console.log('save', (event as CustomEvent).detail);
}
onDelete(event: Event) {
console.log('delete', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
valueproperty only | { name, email, notifications, theme } | {"name":"","email":"","notifications":{},"theme":"system"} |
notificationsproperty only | { id, label, description }[] | [] |
heading | string | "Settings" |
busy | boolean | false |
status | string | "" |
| Event | When |
|---|---|
valuechange | A field changed; detail is the new value. |
save | The form was saved; detail is the value. |
delete | The delete was confirmed. |
Size
2.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 20.8 KB.