Skip to content

Commit cfb52a0

Browse files
committed
Weekly calendar component, version bumped to 0.3.26
1 parent fa4ac23 commit cfb52a0

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

‎project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject org.clojars.intception/om-widgets "0.3.25"
1+
(defproject org.clojars.intception/om-widgets "0.3.26"
22
:description "Widgets for OM/React"
33
:url "https://github.com/orgs/intception/"
44
:license {:name "Eclipse Public License"

‎src/om_widgets/calendar.cljs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[cljs.reader :as reader]
77
[cljs-time.core :as time]
88
[cljs-time.coerce :as timec])
9-
(:use [om-widgets.datepicker :only [weeks-component day-header days-short]]))
9+
(:use [om-widgets.datepicker :only [weeks-component day-header days-short week-component]]))
1010

1111
(defn calendar
1212
"Calendar does not support date selection nor shows a specific date either"
@@ -41,3 +41,39 @@
4141
(map #(om/build day-header %) days-short))]
4242
(om/build weeks-component app
4343
{:state {:path path :date date}})]]])))))
44+
45+
46+
47+
(defn week-calendar
48+
"Calendar with only one week shown"
49+
[app owner]
50+
(reify
51+
om/IInitState
52+
(init-state [_]
53+
{:date (time/now)})
54+
55+
om/IRenderState
56+
(render-state [_ {:keys [date path id on-week-changed] :as state}]
57+
(letfn [(change-date [d]
58+
(om/set-state! owner :date d)
59+
(when on-week-changed
60+
(on-week-changed (timec/to-date
61+
(time/date-time (time/year d)
62+
(time/month d)
63+
(time/day d))))))]
64+
(html
65+
[:div {:id id}
66+
[:div {:class "box-header"}
67+
[:a {:onClick #(change-date (time/minus date (time/weeks 1)))}
68+
[:span {:class "icn-big-left-arrow"}]]
69+
[:h2
70+
(str (utils/get-hr-month date) " " (time/year date))]
71+
[:a {:onClick #(change-date (time/plus date (time/weeks 1)))}
72+
[:span {:class "icn-big-right-arrow"}]]]
73+
[:div {:class "calendar-content"}
74+
[:table
75+
[:thead
76+
(utils/make-childs [:tr]
77+
(map #(om/build day-header %) days-short))]
78+
(om/build week-component app
79+
{:state {:path path :date date}})]]])))))

‎src/om_widgets/datepicker.cljs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,41 @@
127127
(when onChange (onChange date-updated)))}
128128
(day-renderer app owner {:day day})))))
129129

130+
(defn days-of-week
131+
[date]
132+
(let [start-day (time/minus date
133+
(time/days (time/day-of-week date)))]
134+
(map #(time/plus start-day
135+
(time/days %))
136+
(range 1 8))))
137+
138+
(defn current-week
139+
"Returns a list of days for the current week"
140+
[date]
141+
(let [dow (days-of-week date)
142+
start-day (first dow)]
143+
(map (fn [d]
144+
{:day (time/day d)
145+
:month (time/month d)
146+
:year (time/year d)
147+
:belongs-to-month (cond
148+
(< (time/month d) (time/month start-day)) :previous
149+
(> (time/month d) (time/month start-day)) :next
150+
:else :current)} )
151+
dow)))
152+
153+
(defn week-component [app owner]
154+
(reify
155+
om/IDisplayName
156+
(display-name [_] "DatepickerWeek")
157+
om/IRenderState
158+
(render-state [this {:keys [date path onChange] :as state}]
159+
(dom/tbody nil
160+
(apply dom/tr nil
161+
(map (fn [d]
162+
(om/build day-component app {:state {:day d :path path :date date :onChange onChange}}))
163+
(current-week date)))))))
164+
130165
(defn- weeks-component [app owner]
131166
(reify
132167
om/IDisplayName

0 commit comments

Comments
 (0)