View Switcher
ViewSwitcher lets users switch between available content views such as table, grid, list, and kanban. The free version supports local view switching, active state management, optional panel sync, hidden input sync, and change events.
Overview
The View Switcher component is a core building block of the Byteion design system, providing a robust, accessibility-compliant interface for its specific UI capabilities.
Why this exists
This component provides a reusable, accessible primitive for view-switcher use cases within the Byteion design system.
Mental model
Think of this component as a building block. Compose it with other Byteion primitives to build complex interfaces.
When to use
When not to use
Basic example
The following example demonstrates standard usage, fully compliant with Byteion's token-first approach.
Content views
| Project | Owner | Status |
|---|---|---|
| Revenue dashboard | Ava | On track |
| Billing cleanup | Noah | Review |
| Customer import | Mia | Active |
Revenue dashboard
8 tasks open
Billing cleanup
3 approvals
Customer import
12k rows
Revenue dashboard
Ava updated the forecast widget.
Billing cleanup
Noah requested a second review.
Customer import
Mia mapped the remaining fields.
Todo
Doing
Done
Compact with disabled view
Orders
128 open
Revenue
$42k tracked
Orders: 128 open this week
Revenue: $42k tracked
import { useState } from 'react';
import { ViewSwitcher, type ViewSwitcherItem } from '@byteion/react';
const views: ViewSwitcherItem[] = [
{ value: 'table', label: 'Table' },
{ value: 'cards', label: 'Cards' },
{ value: 'kanban', label: 'Kanban' },
];
export default function ViewSwitcherDemo() {
const [view, setView] = useState('table');
return (
<div className="space-y-3 p-6">
<ViewSwitcher
items={views}
value={view}
name="ordersView"
ariaLabel="Choose orders view"
onValueChange={setView}
/>
<p className="text-sm text-muted-foreground">Current view: {view}</p>
</div>
);
}
<script setup lang="ts">
import { ref } from 'vue';
import { ViewSwitcher, type ViewSwitcherItem } from '@byteion/vue';
const view = ref('table');
const views: ViewSwitcherItem[] = [
{ value: 'table', label: 'Table' },
{ value: 'cards', label: 'Cards' },
{ value: 'kanban', label: 'Kanban' },
];
</script>
<template>
<div class="space-y-3 p-6">
<ViewSwitcher
v-model="view"
:items="views"
name="ordersView"
aria-label="Choose orders view"
/>
<p class="text-sm text-muted-foreground">Current view: {{ view }}</p>
</div>
</template>
Variants
Each variant communicates a different meaning. Choose based on priority, not aesthetics.
Single default variant.
Sizes
Size should match the importance and context of the component.
- md — md size.
States
This component reacts seamlessly to the following interaction and data states:
- default — Resting appearance before interaction.
- active — Currently selected or in use.
- disabled — Non-interactive — grayed out, cursor not-allowed.
Anatomy
Usage guidelines
- Follow the design system tokens.
- Maintain consistent spacing.
Do and Don't
Do
- Follow accessibility guidelines.
- Maintain visual hierarchy.
Don't
- Do not hardcode colors.
- Do not nest interactive elements.
Accessibility
This component follows standard ARIA patterns for its role. Keyboard interaction matches the native HTML element behavior.
Role:group
ARIA Attributes
aria-labelaria-pressed
Keyboard Navigation
- Tab
- Enter
- Space
- ArrowLeft
- ArrowRight
- ArrowUp
- ArrowDown
- Home
- End
Customization
Override visual appearance by modifying variables.css or Tailwind utility classes.
Compose with React cva()
Use the exportedcva() +cn() utilities to compose your own variant on top of the Byteion tokens.
import { cva, cn, type VariantProps } from '@byteion/react';
const myViewSwitcher = cva('base classes…', {
variants: {
accent: { soft:'border-primary-200', loud:'border-primary-500' },
},
defaultVariants: { accent:'soft' },
});
type Props = React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof myViewSwitcher>;
Compose with Vue cva()
Use the exportedcva() +cn() utilities inside standard Vue setup blocks.
<script setup lang="ts">
import { computed, useAttrs } from 'vue';
import { cva, type VariantProps } from '@byteion/vue';
interface Props { accent?:'soft' |'loud' }
const props = withDefaults(defineProps<Props>(), { accent:'soft' });
const attrs = useAttrs();
const myViewSwitcher = cva('base classes…', {
variants: { accent: { soft:'border-primary-200', loud:'border-primary-500' } },
});
const cls = computed(() => myViewSwitcher({ accent: props.accent, class: attrs.class as string | undefined }));
</script>
Runtime events
Byteion keeps framework APIs idiomatic: HTML uses DOM custom events, React uses callback props, and Vue uses emitted events / v-model updates.
HTML / JS events
bi:view-switcher:changebyteion:view-switcher-change
React callbacks
onValueChange(value: string, item: ViewSwitcherItem) => void
Vue emits
update:modelValue[value: string]change[value: string, item: ViewSwitcherItem]
Remote / AJAX
This component does not implement Byteion JS remote loading. Use normal HTML form submission, framework state, or your application data layer around it.
API Reference
No custom data attributes required. Uses standard HTML attributes.
HTML Data Attributes
No custom data attributes required.
React Props · ViewSwitcherProps
Extracted directly fromreact/src/components/ViewSwitcher.tsx.
export interface ViewSwitcherProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
items?: ViewSwitcherItem[];
value?: string;
defaultValue?: string;
onValueChange?: (value: string, item: ViewSwitcherItem) => void;
name?: string;
ariaLabel?: string;
disabled?: boolean;
label?: string;
}
Vue Props · ViewSwitcherProps
Extracted directly fromvue/src/components/ViewSwitcher.vue.
export interface ViewSwitcherProps {
items?: ViewSwitcherItem[];
modelValue?: string;
defaultValue?: string;
name?: string;
ariaLabel?: string;
disabled?: boolean;
label?: string;
}
Developer tips
Common mistakes
Production usage tips
data-bi-* attributes instead of styling hooks.
Premium examples
Advanced patterns available in Byteion Pro:
Related components
Unlock Premium Patterns
Get access to copy-paste ready Pro blocks, SaaS templates, and advanced data-tables built with this component.
Explore Pro Components