Files
summercms/admin/src/components/form/FormTabs.vue
Jakub Zych 8f32416f4f feat(10-03): tabs, toggles, relation fields, form lifecycle and settings pages
- FormTabs groups fields by tab (untabbed fields in the default tab) as a
  segmented tablist; a tab holding invalid fields after a 422 shows a
  count badge and the form switches to the first invalid field
- switch, checkbox and relation join the renderer registry: toggle cards
  (role=switch, 20px checkbox) keep a numeric value numeric; relation
  fields are read-only labels from meta.labels, a searchable single
  select over fields/{field}/options with emptyOption first, or ordered
  removable chips with an appending search (300 ms debounce, 20 per
  page, more on scroll or the more action)
- FormView gets the back button, record title and update subtitle, a
  sticky footer (Usuń with deleteConfirm then DELETE, Anuluj, Zapisz i
  zamknij to the mapped redirectClose, Zapisz), and asks before leaving a
  dirty form on any route change plus a beforeunload guard
- Settings: the rail pins Ustawienia to the bottom when /settings is
  non-empty; /settings lists pages by category; /settings/:code renders
  the settings schema through FormGrid and the registry, PUTs the values
  and maps a 422 like the record form
- New backend::lang keys (form.more_options, tab_default, discard,
  settings.back); form and settings smoke tests; boardwalk/dist rebuilt
2026-09-27 17:00:18 +02:00

54 lines
2.1 KiB
Vue

<script setup lang="ts">
import { tc } from '../../app/i18n'
import { panelDomId, tabDomId, type TabItem } from './formState'
// Segmented tab control (design screen 4): track subtle with a border, 34px
// pills, the active one on surface with a shadow. A tab holding invalid
// fields after a 422 carries a count badge. Arrow keys move between tabs.
const props = defineProps<{ tabs: TabItem[]; modelValue: string; idPrefix: string }>()
const emit = defineEmits<{ 'update:modelValue': [key: string] }>()
function onKeydown(event: KeyboardEvent, index: number): void {
const step = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0
if (step === 0) {
return
}
event.preventDefault()
const nextIndex = (index + step + props.tabs.length) % props.tabs.length
const next = props.tabs[nextIndex]
if (next) {
emit('update:modelValue', next.key)
document.getElementById(tabDomId(props.idPrefix, nextIndex))?.focus()
}
}
</script>
<template>
<div role="tablist" class="inline-flex gap-1 rounded-inner border border-border bg-subtle p-1">
<button
v-for="(tab, index) in tabs"
:id="tabDomId(idPrefix, index)"
:key="tab.key"
type="button"
role="tab"
:data-tab="tab.key"
:aria-selected="tab.key === modelValue ? 'true' : 'false'"
:aria-controls="panelDomId(idPrefix, index)"
:tabindex="tab.key === modelValue ? 0 : -1"
:class="tab.key === modelValue ? 'bg-surface text-text shadow-tab' : 'text-muted hover:text-text'"
class="inline-flex h-[34px] items-center gap-2 rounded-tab px-4 font-semibold transition-colors duration-150 ease-out"
@click="emit('update:modelValue', tab.key)"
@keydown="onKeydown($event, index)"
>
{{ tab.label }}
<span
v-if="tab.errors > 0"
data-tab-errors
:aria-label="tc('backend::lang.form.tab_errors', tab.errors)"
class="inline-flex h-5 min-w-5 items-center justify-center rounded-pill bg-danger px-1.5 text-[11px] font-bold text-white"
>{{ tab.errors }}</span
>
</button>
</div>
</template>