Skip to content

Commit

Permalink
adds flash example
Browse files Browse the repository at this point in the history
  • Loading branch information
slagyr committed Jan 15, 2014
1 parent 8abfde4 commit 76613c2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 25 deletions.
96 changes: 80 additions & 16 deletions example/example.css
Expand Up @@ -56,18 +56,82 @@ label {
color: white; color: white;
} }


/* --------------------------------------
* Flash Styles
* -------------------------------------- */

.flash-container {
position: fixed;
top: 0;
margin: auto;
width: 100%;
text-align: center;
}

.flash-errors, .flash-notices, .flash-successes {
position: relative;
-moz-border-bottom-left-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
border-bottom-left-radius: 5px;
-moz-border-bottom-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
border-bottom-right-radius: 5px;
border: 1px solid;
border-top: 0;
font-size: 1em;
font-weight: normal;
margin: auto auto 5px;
padding: 1em;
text-align: center;
max-width: 50%;
}

.flash-errors {
background: #ff6555;
color: #a64237;
border-color: #a64237;
}

.flash-notices {
background-color: #ce9853;
color: #9c5c2b;
border-color: #9c5c2b;
}

.flash-successes {
background-color: #67f091;
color: #49a966;
border-color: #49a966;
}

.flash-close {
position: absolute;
right: 0;
top: 0;
margin: 5px;
}

a.flash-close:hover {
color: white;
cursor: pointer;
}

p.flash-error, p.flash-notice, p.flash-success {
margin: 0;
}

/* -------------------------------------- /* --------------------------------------
* Forms Styles * Forms Styles
* -------------------------------------- */ * -------------------------------------- */


p.field-errors { p.field-errors {
margin: 0; margin: 0;
padding: 0; padding: 0;
color: #E03725; color: #E03725;
} }


.field-error { .field-error {
border: 1px solid #E03725; border: 1px solid #E03725;
} }


/* -------------------------------------- /* --------------------------------------
Expand Down Expand Up @@ -113,18 +177,18 @@ p.field-errors {
} }


.modal-header button { .modal-header button {
float: right; float: right;
font-size: 1.2em; font-size: 1.2em;
font-weight: 600; font-weight: 600;
background: transparent; background: transparent;
padding: 0; padding: 0;
margin: 0; margin: 0;
-moz-appearance: none; -moz-appearance: none;
-webkit-appearance: none; -webkit-appearance: none;
appearance: none; appearance: none;
border: none; border: none;
cursor: pointer; cursor: pointer;
color: #333; color: #333;
} }


.modal-header h3 { .modal-header h3 {
Expand Down
2 changes: 1 addition & 1 deletion example/project.clj
Expand Up @@ -3,7 +3,7 @@
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"} :url "http://www.eclipse.org/legal/epl-v10.html"}


:dependencies [[com.8thlight/filament "1.1.4"] :dependencies [[com.8thlight/filament "1.2.0"]
[com.8thlight/hiccup "1.1.1"] [com.8thlight/hiccup "1.1.1"]
[org.clojure/clojure "1.5.1"]] [org.clojure/clojure "1.5.1"]]


Expand Down
2 changes: 2 additions & 0 deletions example/src/cljs/example/main.cljs
@@ -1,9 +1,11 @@
(ns example.main (ns example.main
(:require [example.autocomplete-demo :refer [demo-autocomplete]] (:require [example.autocomplete-demo :refer [demo-autocomplete]]
[example.flash-demo :refer [demo-flash]]
[example.forms-demo :refer [demo-forms]] [example.forms-demo :refer [demo-forms]]
[example.modal-demo :refer [demo-modal]])) [example.modal-demo :refer [demo-modal]]))


(defn ^:export init [] (defn ^:export init []
(demo-autocomplete) (demo-autocomplete)
(demo-flash)
(demo-forms) (demo-forms)
(demo-modal)) (demo-modal))
7 changes: 7 additions & 0 deletions spec/cljs/com/eighthlight/filament/flash_spec.cljs
Expand Up @@ -72,4 +72,11 @@
(should= nil (dom/by-id "flash-errors")) (should= nil (dom/by-id "flash-errors"))
(should= nil (dom/by-id "flash-notices")) (should= nil (dom/by-id "flash-notices"))
(should= nil (dom/by-id "flash-successes"))) (should= nil (dom/by-id "flash-successes")))


(it "css classes"
(should-contain "flash-container" (dom/classes (flash/flash-container-node)))
(should-contain "flash-errors" (dom/classes (flash/errors-node)))
(should-contain "flash-notices" (dom/classes (flash/notices-node)))
(should-contain "flash-successes" (dom/classes (flash/successes-node))))
) )
16 changes: 8 additions & 8 deletions src/cljs/com/eighthlight/filament/flash.cljs
Expand Up @@ -10,15 +10,15 @@
[] []
(or (or
(dom/by-id "flash-container") (dom/by-id "flash-container")
(let [container (dom/single-node (h/html [:div#flash-container]))] (let [container (dom/single-node (h/html [:div#flash-container.flash-container]))]
(dom/append! (.-body js/document) container) (dom/append! (.-body js/document) container)
container))) container)))


(defn- flash-section [section] (defn- flash-section [section]
(let [name (str "flash-" section)] (let [name (str "flash-" section)]
(or (or
(dom/by-id name) (dom/by-id name)
(let [section-node (dom/single-node (h/html [:div {:id name} [:a.flash-close "X"]]))] (let [section-node (dom/single-node (h/html [:div {:id name :class name} [:a.flash-close "X"]]))]
(util/override-click! (first (dom/children section-node)) #(dom/destroy! section-node)) (util/override-click! (first (dom/children section-node)) #(dom/destroy! section-node))
(dom/append! (flash-container-node) section-node) (dom/append! (flash-container-node) section-node)
section-node)))) section-node))))
Expand All @@ -39,8 +39,8 @@
"Adds an error flash to the DOM. "Adds an error flash to the DOM.
CSS: CSS:
#flash-container - a div added to the body element so consider using absolute/fixed positioning .flash-container - a div added to the body element so consider using absolute/fixed positioning
#flash-errors - a div inside the flash-container that will hold all the error flashes .flash-errors - a div inside the flash-container that will hold all the error flashes
a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section. a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section.
p.flash-error - one is added to the flash-errors div for each message" p.flash-error - one is added to the flash-errors div for each message"
[message] [message]
Expand All @@ -50,8 +50,8 @@
"Adds an notice flash to the DOM. "Adds an notice flash to the DOM.
CSS: CSS:
#flash-container - a div added to the body element so consider using absolute/fixed positioning .flash-container - a div added to the body element so consider using absolute/fixed positioning
#flash-notices - a div inside the flash-container that will hold all the notice flashes .flash-notices - a div inside the flash-container that will hold all the notice flashes
a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section. a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section.
p.flash-notice - one is added to the flash-notices div for each message" p.flash-notice - one is added to the flash-notices div for each message"
[message] [message]
Expand All @@ -61,8 +61,8 @@
"Adds an success flash to the DOM. "Adds an success flash to the DOM.
CSS: CSS:
#flash-container - a div added to the body element so consider using absolute/fixed positioning .flash-container - a div added to the body element so consider using absolute/fixed positioning
#flash-successes - a div inside the flash-container that will hold all the success flashes .flash-successes - a div inside the flash-container that will hold all the success flashes
a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section. a.flash-close - the first node in a flash section. Contains the text \"X\". Clicking it will close the section.
p.flash-success - one is added to the flash-successes div for each message" p.flash-success - one is added to the flash-successes div for each message"
[message] [message]
Expand Down

0 comments on commit 76613c2

Please sign in to comment.