Changes to the colorpicker to support gradients

This commit is contained in:
alonso.torres 2020-10-08 16:08:00 +02:00
parent a7335533bb
commit 381aef77ee
10 changed files with 368 additions and 174 deletions

View file

@ -77,3 +77,16 @@
(defn hsv->hsl
[hsv]
(hex->hsl (hsv->hex hsv)))
(defn gradient->css [{:keys [type stops]}]
(let [parse-stop
(fn [{:keys [offset color opacity]}]
(let [[r g b] (hex->rgb color)]
(str/fmt "rgba(%s, %s, %s, %s) %s" r g b opacity (str (* offset 100) "%"))))
stops-css (str/join "," (map parse-stop stops))]
(if (= type :linear)
(str/fmt "linear-gradient(to bottom, %s)" stops-css)
(str/fmt "radial-gradient(circle, %s" stops-css))))