summaryrefslogtreecommitdiff
path: root/src/view-components.lisp
blob: ee88628b2c6e26708c2196d8181da464dfd80e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;;; 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
    (:ul :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 item-name)
  (with-html
    (when data
      (:div :class (or class (format nil "checkboxes ~a" (class-name (class-of (first data)))))
            :id (or id (format nil "checkboxes-~a" (class-name (class-of (first data)))))
            (dolist (item data)
              (render :checkbox item :name item-name)
              (: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" "🍺"))))))