diff options
author | colin <colin@cicadas.surf> | 2023-04-01 09:48:08 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-04-01 09:48:08 -0700 |
commit | cc3f850c514967ae2f9effef7e68e1d4965c6865 (patch) | |
tree | 6d0b52c3a65d53f247f4c8272667aca5a4e05bac /src/view-components.lisp | |
parent | 56a584ab1b13ff9510dd5145a778000169901a76 (diff) |
Refactor to make cooperative hacking nicer
Diffstat (limited to 'src/view-components.lisp')
-rw-r--r-- | src/view-components.lisp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/view-components.lisp b/src/view-components.lisp new file mode 100644 index 0000000..0711dda --- /dev/null +++ b/src/view-components.lisp @@ -0,0 +1,51 @@ +;;;; views-components.lisp -- reusable components + +(in-package :dnd) + +;;; LIST DATA + +(defrender :list ((data list) (class "listview") (item-class "listitem")) + "A catch all for rendering lists of renderable data items as unordered +lists. CLASS is the lass string for the containing list. ITEM-CLASS is +the class string for the contained list items." + (with-html + (:ol :class class + (dolist (item data) + (:li :class item-class (render :list-item item)))))) + +(defrender :horiz-list ((data list) (class "hlistview") (item-class "listitem")) + (with-html + (:ol :class class + (dolist (item data) + (:li :class item-class (render :list-item item)))))) + +(defrender :select ((data list) name class) + (with-html + (when data + (:select :name (or name (format nil "select-~a" (class-of (first data)))) + :class (or class (format nil "select ~a" (class-of (first data)))) + (dolist (item data) + (render :option item)))))) + +(defrender :checkboxes ((data list) id class) + (with-html + (when data + (:div :class (or class (format nil "checkboxes ~a" (class-of (first data)))) + :id (or id (format nil "checkboxes-~a" (class-of (first data)))) + (dolist (item data) + (render :checkbox item) + (:br)))))) + + +;;;; PAGE ELEMENTS + +(defun navbar () + (with-html + (:nav :class "navbar" :aria-label "Navigation" + (:div :class "logo" :aria-label "DND logo" "DND") + (:ul :class "nav-links" :aria-label "Nav links" + (:li (:a :href "/hero" :aria-label "Hero profile" "🧝")) + (:li (:a :href "/inventory" :aria-label "Inventory" "🎒")) + (:li (:a :href "/quests" :aria-label "Quests" "📜")) + (:li (:a :href "/tavern" :aria-label "Tavern" "🍺")))))) + |