Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (9.5 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
value
property only
{ name, email, notifications, theme }{"name":"","email":"","notifications":{},"theme":"system"}
notifications
property only
{ id, label, description }[][]
headingstring"Settings"
busybooleanfalse
statusstring""
Events
EventWhen
valuechangeA field changed; detail is the new value.
saveThe form was saved; detail is the value.
deleteThe 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour