src/views/components/tab.lisp
(defpackage murja.views.components.tab
(:import-from :lisp-fixup :partial)
(:export :tabs)
(:use :cl :murja.newui))
(in-package :murja.views.components.tab)
(defun tabs (firstly-selected-title tab-hash ;; &key onleave ;; how did I plan to call js callbacks here again?
)
"Takes in a Title -> (Component | State mapping, returns a component that's supposed to look like the tab component used by the old Elm app"
(let ((titles))
(maphash (lambda (k v)
(declare (ignore v))
(push k titles))
tab-hash)
(sort titles #'string-lessp)
(with-state ((selected-title firstly-selected-title)) ()
(c :div (:id "topbar" :class "tabs")
(component :ul (:class "tab-headers")
(map 'list
(lambda (title)
(c :li (:class (format nil "tab-header ~a" (when (string= title selected-title) "tab-selected"))
:onclick (e (lambda ()
(setf selected-title title))))
title))
titles))
(gethash selected-title tab-hash)))))