From 32bfb504dda5536a1a43dd1fec47e3f926e06138 Mon Sep 17 00:00:00 2001 From: Joshua Pease Date: Fri, 3 Jan 2025 13:05:14 -0800 Subject: [PATCH] [#57] Adds tabs component --- templates/_components/tabs.twig | 75 +++++++++++++++++++++++++++ templates/parts-kit/tabs/default.twig | 21 ++++++++ 2 files changed, 96 insertions(+) create mode 100644 templates/_components/tabs.twig create mode 100644 templates/parts-kit/tabs/default.twig diff --git a/templates/_components/tabs.twig b/templates/_components/tabs.twig new file mode 100644 index 0000000..5c4770f --- /dev/null +++ b/templates/_components/tabs.twig @@ -0,0 +1,75 @@ +{# @var array{title: string, content: string}[] tabs #} +{% set tabs = tabs ?? [] %} + +{# @var int activeIndex #} +{% set activeIndex = activeIndex ?? 0 %} + +{# Computed attributes #} + +{% set id = 'tabs-' ~ random() %} + +
+ + + {% for tab in tabs %} +
+ {{ tab.content }} +
+ {% endfor %} + + {{ include('_components/button.twig', { + text: 'Back to tabs list', + size: 'sm', + variant: 'text', + class: 'sr-only focus:not-sr-only focus:mt-16 focus:z-max', + attrs: { + '@click': 'activeTab.focus()', + }, + }) }} +
+ diff --git a/templates/parts-kit/tabs/default.twig b/templates/parts-kit/tabs/default.twig new file mode 100644 index 0000000..e6d50fa --- /dev/null +++ b/templates/parts-kit/tabs/default.twig @@ -0,0 +1,21 @@ +{% extends "viget-parts-kit/layout.twig" %} + +{% block main %} +
+ {{ include('_components/tabs.twig', { + tabs: [ + { title: 'Tab 1', content: 'Content for Tab 1' }, + { title: 'Tab 2', content: 'Content for Tab 2' }, + ], + }) }} +
+ +
+ {{ include('_components/tabs.twig', { + tabs: [ + { title: 'Tab 1', content: 'Content for Tab 1' }, + { title: 'Tab 2', content: 'Content for Tab 2' }, + ], + }) }} +
+{% endblock %}