Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
1.6 KB
Raw Blame
'use client'

import React from 'react'
import Link from 'next/link'
import { cn } from '@lib/cn'
import type { TabBarProps } from './types'

export function TabBar<T extends string>({
  activeValue,
  ariaLabel,
  className,
  onChange,
  options,
}: TabBarProps<T>) {
  return (
    <nav className={cn('cu-tabs', className)} aria-label={ariaLabel} role="tablist">
      {options.map(option => {
        const isActive = activeValue === option.value
        if (option.href && !option.disabled) {
          return (
            <Link
              key={option.value}
              href={option.href}
              className="cu-tab"
              role="tab"
              data-active={isActive ? 'true' : 'false'}
              aria-selected={isActive}
              aria-current={isActive ? 'page' : undefined}
              onClick={event => {
                if (
                  event.button === 0 &&
                  !event.altKey &&
                  !event.ctrlKey &&
                  !event.metaKey &&
                  !event.shiftKey
                ) {
                  option.onLinkActivate?.()
                }
              }}
            >
              {option.label}
            </Link>
          )
        }
        return (
          <button
            key={option.value}
            type="button"
            className="cu-tab"
            role="tab"
            data-active={isActive ? 'true' : 'false'}
            aria-selected={isActive}
            disabled={option.disabled}
            onClick={() => onChange?.(option.value)}
          >
            {option.label}
          </button>
        )
      })}
    </nav>
  )
}