Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ulysses-front/src/cljs/ulysses/components/basic.cljs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (57 sloc)
1.76 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ulysses.components.basic | |
(:require [reagent.core :as reagent] | |
[ulysses.utils :refer [d-p]] | |
[re-frame.core :refer [dispatch]] | |
[clojure.string :as string])) | |
;; links ----------------------------------- | |
(defn link | |
"regular link" | |
[href attr & body] | |
(into [:a (assoc attr :href href)] body)) | |
(defn hink | |
"handled link (prevents default and calls handler on click)" | |
[handler attr & body] | |
(into [:a (assoc attr :href "" :on-click (d-p handler))] body)) | |
(defn rink | |
"router link (sets :active-page)" | |
[page attr & body] | |
(apply | |
(partial hink | |
#(dispatch [:set-active-page page]) | |
attr) | |
body)) | |
;; bootstrap helpers ----------------------- | |
(defn label | |
"bootstrap label" | |
[contextual & rest] | |
(let [classes ["label" (str "label-" (name contextual))] | |
cname (string/join "." (into ["span"] classes))] | |
(into [(keyword cname)] rest))) | |
(defn nav-item | |
"bootstrap nav item" | |
[href & rest] | |
[:li.nav-item | |
(into [link href {}] rest)]) | |
;; css transition group -------------------- | |
; adapt CSSTransitionGroup to reagent | |
(def ^:private css-transition-group-native | |
(reagent/adapt-react-class js/React.addons.CSSTransitionGroup)) | |
(defn css-transition-group | |
"transition group" | |
[attr items] | |
(into [css-transition-group-native attr] items)) | |
(defn css-transition-group-standard | |
"transition group using tran- prefix, appear, and 300ms time" | |
[items] | |
(css-transition-group | |
{:component :div | |
:transition-name "tran" | |
:transition-appear true | |
:transition-appear-timeout 300 | |
:transition-enter-timeout 300 | |
:transition-leave-timeout 300} | |
items)) | |
;; misc -------------------------------------- | |
(defn no-results [] | |
[:div.no-results | |
"Sorry, your search didn't return any results."]) |