From a93c6bfa4556b39210e3735669ae689096a151f9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 20 Dec 2015 17:54:07 +0200 Subject: [PATCH] Add color conversion helpers. --- frontend/uxbox/ui/util.cljs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/frontend/uxbox/ui/util.cljs b/frontend/uxbox/ui/util.cljs index 96b9c23a2..9bc6a4293 100644 --- a/frontend/uxbox/ui/util.cljs +++ b/frontend/uxbox/ui/util.cljs @@ -4,6 +4,10 @@ (:refer-clojure :exclude [derive]) (:require [rum.core :as rum])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Rum Sugar +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defn component [spec] (let [name (or (:name spec) @@ -37,3 +41,23 @@ (def mount rum/mount) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Color Conversion +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn hex-to-rgb + [^string data] + (some->> (re-find #"^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$" data) + (rest) + (mapv #(js/parseInt % 16)))) + + +(defn rgb-to-hex + [[r g b]] + (letfn [(to-hex [c] + (let [hexdata (.toString c 16)] + (if (= (count hexdata) 1) + (str "0" hexdata) + hexdata)))] + (str "#" (to-hex r) (to-hex g) (to-hex b))))