-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.clj
More file actions
124 lines (96 loc) · 3.16 KB
/
dev.clj
File metadata and controls
124 lines (96 loc) · 3.16 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(ns dev
(:require [clojure.pprint :refer [pprint]]
[dev.onionpancakes.chassis.core :as c]
[html.yeah :as yeah :refer [defelem children]]
[html.yeah.attrs :as attrs]
[malli.generator :as mg]
[malli.dev :as dev]))
;;; Class constants for Tailwind JIT
(def colors
{:neutral "btn-neutral"
:primary "btn-primary"
:secondary "btn-secondary"
:accent "btn-accent"
:info "btn-info"
:success "btn-success"
:warning "btn-warning"
:error "btn-error"})
(def Color (into [:enum] (keys colors)))
(def styles
{:outline "btn-outline"
:dash "btn-dash"
:soft "btn-soft"
:ghost "btn-ghost"
:link "btn-link"})
(def Style (into [:enum] (keys styles)))
(def behaviors
{:active "btn-active"
:disabled "btn-disabled"})
(def Behavior (into [:enum] (keys behaviors)))
(def sizes
{:xs "btn-xs"
:sm "btn-sm"
:md "btn-md"
:lg "btn-lg"
:xl "btn-xl"})
(def Size (into [:enum] (keys sizes)))
(def modifiers
{:wide "btn-wide"
:block "btn-block"
:square "btn-square"
:circle "btn-circle"})
(def Modifier (into [:enum] (keys modifiers)))
;;; Add support for :doc+ which appends a pretty printed
;;; schema to an element's inline documentation.
(defmethod yeah/property :doc+
[_ schema doc]
(let [formatted (with-out-str (pprint schema))]
(assoc-in schema [1 :doc]
(-> "Description:\n"
(str "================\n")
(str doc)
(str "\nAttributes:\n")
(str "================\n")
(str formatted)))))
(defelem daisy-button
[:maybe {:doc+ "A robust and correct DaisyUI button"
:keys [color style behavior size modifier]
:or {color :primary}}
[:map
[:color {:optional true} Color]
[:style {:optional true} Style]
[:behavior {:optional true} Behavior]
[:size {:optional true} Size]
[:modifier {:optional true} Modifier]]]
[:button {:class [(colors color)
(styles style)
(behaviors behavior)
(sizes size)
(modifiers modifier)]}
(children)])
(defn generate
"We can make custom fun with the fact that a schema is attached to the element"
[tag & children]
(when-some [{:keys [attributes]} (yeah/element tag)]
[tag (mg/generate attributes) children]))
(comment
;;; Get full element metadata
(yeah/element :dev/daisy-button)
;;; Get the attribute schema for an element
(:attributes (yeah/element :dev/daisy-button))
;;; List all element tags
(yeah/element-tags)
;;; List elements in this namespace
(yeah/elements {:ns 'dev})
;;; Search elements by doc
(yeah/search-elements "button")
;;; Generate a sample element
(c/html
(generate :dev/daisy-button "Click Me"))
;;; Render this invalid button and check the error output in the REPL
(c/html
[:dev/daisy-button {:color :mauve} "Click Me"])
(do "not make me create a new line just to evaluate my comments"))
;;; Try rendering an invalid daisy-button with malli.dev running
(dev/stop!)
(dev/start! {:ns *ns*}) ;;; Normally won't qualify namespace, but I don't want tests getting pulled in