ywana-core8 0.0.909 → 0.0.911

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.0.909",
3
+ "version": "0.0.911",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -1,40 +1,161 @@
1
+ .calendar {
2
+ display: flex;
3
+ flex-direction: column;
4
+ flex: 1;
5
+ overflow: hidden;
6
+ }
1
7
 
2
- .calendar {
8
+ .calendar-range-control {
9
+ margin: .3rem;
10
+ border: solid 1px var(--divider-color);
11
+ background-color: var(--background-color);
12
+ border-radius: 3px;
13
+ padding: .2rem;
14
+ display: flex;
15
+ justify-content: space-between;
16
+ align-items: center;
17
+
18
+ &>.btn {
19
+ flex: 1;
20
+ margin-left: 1rem;
21
+ border-radius: 2px;
22
+ background-color: var(--background-color);
23
+ &.outlined {
24
+ border: solid 1px var(--divider-color);
25
+ background-color: var(--paper-color);
26
+ }
27
+ }
28
+ }
29
+
30
+ .year-calendar {
3
31
  margin: 1rem;
4
32
  overflow: hidden;
5
33
  display: flex;
6
34
  flex-direction: column;
7
35
  padding: 0rem;
8
-
9
36
  }
10
37
 
11
- .calendar>nav {
38
+ .year-calendar>nav {
12
39
  display: flex;
13
40
  padding: .5rem;
14
41
  display: flex;
15
42
  align-items: center;
16
43
  }
17
44
 
18
- .calendar>nav>label {
45
+ .year-calendar>nav>label {
19
46
  flex: 1;
20
47
  font-size: 1.3rem;
21
48
  font-weight: 500;
22
49
  }
23
50
 
24
- .calendar>nav>button {
51
+ .year-calendar>nav>button {
25
52
  margin-left: 1px;
53
+ border-radius: 3px;
26
54
  }
27
55
 
28
- .calendar>header {
56
+ .year-calendar>main {
57
+ flex: 1;
29
58
  border: solid 1px var(--divider-color);
30
- border-top: 0px;
31
- border-width: 1px 1px 0 0px;
59
+ border-width: 1px 1px 0 0;
60
+ display: grid;
61
+ grid-template-columns: repeat(3, 1fr);
62
+ grid-gap: 1rem;
63
+ grid-auto-rows: minmax(12rem, auto);
64
+ overflow: hidden;
65
+ font-size: .8rem;
66
+ }
67
+
68
+ .year-calendar .month-cell {
69
+ border-width: 0 0 1px 1px;
70
+ overflow: hidden;
71
+ padding: .5rem;
72
+ text-align: right;
73
+ font-weight: 400;
74
+
75
+ &>nav {
76
+ display: flex;
77
+ padding: .5rem;
78
+ display: flex;
79
+ align-items: center;
80
+ }
81
+
82
+ &>header {
83
+ display:flex;
84
+
85
+ &>.week-day-cell {
86
+ flex: 1;
87
+ border: solid 0px var(--divider-color);
88
+ padding: 2px;
89
+ text-align: right;
90
+ min-width: 2rem !important;
91
+ }
92
+ }
93
+
94
+ &>main {
95
+ flex: 1;
96
+ border: solid 0px var(--divider-color);
97
+ display: grid;
98
+ grid-template-columns: repeat(7, 1fr);
99
+ grid-gap: 0px;
100
+ grid-auto-rows: minmax(2rem, auto);
101
+ overflow: hidden;
102
+ font-size: .8rem;
103
+
104
+ &>.day-cell {
105
+ border: solid 0px;
106
+ padding: .5rem;
107
+ text-align: right;
108
+ min-height: 1rem;
109
+ width: 1rem;
110
+ min-width: 1rem !important;
111
+ font-weight: 400;
112
+ color: var(--text-color);
113
+ }
114
+
115
+
116
+ &>.day-cell.other-month {
117
+ color: var(--text-color-lighter);
118
+ }
119
+
120
+ }
121
+ }
122
+
123
+
124
+
125
+ .month-calendar {
126
+ margin: 1rem;
127
+ overflow: hidden;
128
+ display: flex;
129
+ flex-direction: column;
130
+ padding: 0rem;
131
+
132
+ }
133
+
134
+ .month-calendar>nav {
135
+ display: flex;
136
+ padding: .5rem;
137
+ display: flex;
138
+ align-items: center;
139
+ }
140
+
141
+ .month-calendar>nav>label {
142
+ flex: 1;
143
+ font-size: 1.3rem;
144
+ font-weight: 500;
145
+ }
146
+
147
+ .month-calendar>nav>button {
148
+ margin-left: 1px;
149
+ border-radius: 3px;
150
+ }
151
+
152
+ .month-calendar>header {
32
153
  display: grid;
33
154
  grid-template-columns: repeat(7, 1fr);
34
155
  font-size: .8rem;
35
156
  }
36
157
 
37
- .calendar>main {
158
+ .month-calendar>main {
38
159
  flex: 1;
39
160
  border: solid 1px var(--divider-color);
40
161
  border-width: 1px 1px 0 0;
@@ -58,7 +179,7 @@
58
179
  border-width: 0 0 1px 1px;
59
180
  padding: .5rem;
60
181
  text-align: right;
61
- min-height: 5rem;
182
+ min-height: 6rem;
62
183
  min-width: 5rem;
63
184
  font-weight: 400;
64
185
  }
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect } from 'react'
2
- import { Button } from '../../html'
2
+ import { Button, Text } from '../../html'
3
3
  import Moment from 'moment'
4
4
  import { extendMoment } from 'moment-range';
5
5
  import 'moment/locale/es'
@@ -8,8 +8,45 @@ import './Calendar.css'
8
8
  Moment.locale('es')
9
9
  const moment = extendMoment(Moment)
10
10
 
11
+ /**
12
+ * Calendar
13
+ */
11
14
  export const Calendar = (props) => {
12
15
 
16
+ const { events = [], children, onChange } = props
17
+ const [range, setRange] = useState(props.range || "year")
18
+
19
+ function onChangeRange(range) {
20
+ setRange(range)
21
+ }
22
+
23
+ return (
24
+ <div className="calendar">
25
+ <CalendarRangeControl range={range} onChange={onChangeRange} />
26
+ {range === "year" && <YearCalendar events={events} onChange={onChange}>{children}</YearCalendar>}
27
+ {range === "month" && <MonthCalendar events={events} onChange={onChange} onRange={onChangeRange}>{children}</MonthCalendar>}
28
+ </div>
29
+ )
30
+ }
31
+
32
+ /**
33
+ * CalendarRangeControl
34
+ */
35
+ const CalendarRangeControl = (props) => {
36
+ const { range, onChange } = props
37
+ return (
38
+ <div className="calendar-range-control">
39
+ <Button label="Year" outlined={range == "year"} action={() => onChange("year")} />
40
+ <Button label="Month" outlined={range == "month"} action={() => onChange("month")} />
41
+ </div>
42
+ )
43
+ }
44
+
45
+ /**
46
+ * MonthCalendar
47
+ */
48
+ export const MonthCalendar = (props) => {
49
+
13
50
  const { events = [], children, onChange } = props
14
51
  const [position, setPosition] = useState()
15
52
 
@@ -58,33 +95,35 @@ export const Calendar = (props) => {
58
95
  const cells = days.map(day => {
59
96
 
60
97
  const eventsOfDay = events.filter(event => {
61
- console.log(event.date, day.format("YYYY-MM-DD"))
62
98
  const eventDay = moment(event.date)
63
99
  return eventDay.isSame(day, 'day')
64
100
  })
65
101
 
102
+ const sameMonthStyle = day.isSame(moment(position), 'month') ? '' : 'other-month'
103
+
66
104
  return {
67
105
  day,
68
- events: eventsOfDay
106
+ events: eventsOfDay,
107
+ sameMonthStyle
69
108
  }
70
109
  })
71
110
 
72
111
  return (
73
- <div className="calendar">
112
+ <div className="month-calendar">
74
113
  <nav>
75
- <label> {monthName} {year}</label>
76
- <Button icon="chevron_left" raised action={prev} />
77
- <Button label="Hoy" outlined action={today} />
78
- <Button icon="chevron_right" raised action={next} />
114
+ <label> <Text>{monthName}</Text> {year}</label>
115
+ <Button icon="chevron_left" action={prev} />
116
+ <Button label="Today" outlined action={today} />
117
+ <Button icon="chevron_right" action={next} />
79
118
  </nav>
80
119
  <header>
81
- <div className='week-day-cell'>Lun</div>
82
- <div className='week-day-cell'>Mar</div>
83
- <div className='week-day-cell'>Mié</div>
84
- <div className='week-day-cell'>Jue</div>
85
- <div className='week-day-cell'>Vie</div>
86
- <div className='week-day-cell'>Sab</div>
87
- <div className='week-day-cell'>Dom</div>
120
+ <div className='week-day-cell'><Text>Mon</Text></div>
121
+ <div className='week-day-cell'><Text>Tue</Text></div>
122
+ <div className='week-day-cell'><Text>Wed</Text></div>
123
+ <div className='week-day-cell'><Text>Thu</Text></div>
124
+ <div className='week-day-cell'><Text>Fri</Text></div>
125
+ <div className='week-day-cell'><Text>Sat</Text></div>
126
+ <div className='week-day-cell'><Text>Sun</Text></div>
88
127
  </header>
89
128
  <main>
90
129
  {cells.map(cell => <DayCell key={cell.day} cell={cell} >{children}</DayCell>)}
@@ -95,10 +134,9 @@ export const Calendar = (props) => {
95
134
 
96
135
  const DayCell = (props) => {
97
136
  const { cell = [], children } = props
98
- const { day, events } = cell
137
+ const { day, events, sameMonthStyle } = cell
99
138
  const todayStyle = day.isSame(moment(), 'day') ? 'today' : ''
100
- const sameMonthStyle = day.isSame(moment(), 'month') ? '' : 'other-month'
101
-
139
+
102
140
  return (
103
141
  <div className={`day-cell ${todayStyle} ${sameMonthStyle}`}>
104
142
  <header>
@@ -111,6 +149,9 @@ const DayCell = (props) => {
111
149
  )
112
150
  }
113
151
 
152
+ /**
153
+ * Event
154
+ */
114
155
  const Event = (props) => {
115
156
  const { event, children } = props
116
157
  if (children) {
@@ -125,4 +166,132 @@ const Event = (props) => {
125
166
  </div>
126
167
  )
127
168
  }
128
- }
169
+ }
170
+
171
+ /**
172
+ * YearCalendar
173
+ */
174
+ const YearCalendar = (props) => {
175
+
176
+ const { events = [], children, onChange } = props
177
+ const [position, setPosition] = useState()
178
+
179
+ useEffect(() => {
180
+ const today = moment()
181
+ setPosition(today)
182
+ }, [])
183
+
184
+ useEffect(() => {
185
+ if (position && onChange) {
186
+ const firstDayOfYear = position.clone().startOf('year');
187
+ const firstDayOfRange = firstDayOfYear.clone().startOf('isoweek');
188
+ const lastDayOfYear = position.clone().endOf('year');
189
+ const lastDayOfRange = lastDayOfYear.clone().endOf('isoweek');
190
+ const range = moment.range(firstDayOfRange, lastDayOfRange)
191
+ onChange(position, range)
192
+ }
193
+ }, [position])
194
+
195
+ function next() {
196
+ const next = position.clone().add(1, 'year')
197
+ setPosition(next)
198
+ }
199
+
200
+ function prev() {
201
+ const prev = position.clone().subtract(1, 'year')
202
+ setPosition(prev)
203
+ }
204
+
205
+ function today() {
206
+ const today = moment()
207
+ setPosition(today)
208
+ }
209
+
210
+ if (!position) return "..."
211
+
212
+ const year = position.format("YYYY");
213
+ const firstDayOfYear = moment(position).startOf('year');
214
+ const lastDayOfYear = moment(position).endOf('year');
215
+ const months = [];
216
+
217
+ for (let currentMonth = moment(firstDayOfYear); currentMonth.isBefore(lastDayOfYear); currentMonth.add(1, 'month')) {
218
+ months.push(moment(currentMonth));
219
+ }
220
+
221
+ const cells = months.map(month => {
222
+
223
+ const firstDayOfMonth = month.clone().startOf('month');
224
+ const firstDayOfRange = firstDayOfMonth.clone().startOf('isoweek');
225
+ const lastDayOfMonth = month.clone().endOf('month');
226
+ const lastDayOfRange = lastDayOfMonth.clone().endOf('isoweek');
227
+ const range = moment.range(firstDayOfRange, lastDayOfRange)
228
+ const days = Array.from(range.by('days'))
229
+
230
+ const cells = days.map(day => {
231
+
232
+ const eventsOfDay = events.filter(event => {
233
+ const eventDay = moment(event.date)
234
+ return eventDay.isSame(day, 'day')
235
+ })
236
+
237
+ const sameMonthStyle = day.isSame(moment(month), 'month') ? '' : 'other-month'
238
+
239
+ return {
240
+ day,
241
+ events: eventsOfDay,
242
+ sameMonthStyle
243
+ }
244
+ })
245
+
246
+ return {
247
+ month,
248
+ cells
249
+ }
250
+ })
251
+
252
+
253
+ return (
254
+ <div className="year-calendar">
255
+ <nav>
256
+ <label> <Text>{year}</Text></label>
257
+ <Button icon="chevron_left" action={prev} />
258
+ <Button label="Today" outlined action={today} />
259
+ <Button icon="chevron_right" action={next} />
260
+ </nav>
261
+ <main>
262
+ {cells.map(cell => <MonthCell key={cell.month} cell={cell} >{children}</MonthCell>)}
263
+ </main>
264
+ </div>
265
+ )
266
+ }
267
+
268
+ /**
269
+ * MonthCell
270
+ */
271
+ const MonthCell = (props) => {
272
+ const { cell = [], children } = props
273
+ const { month, cells } = cell
274
+ const monthName = month.format("MMMM")
275
+
276
+ return (
277
+ <div className={`month-cell`}>
278
+ <nav>
279
+ {monthName}
280
+ </nav>
281
+ <header>
282
+ <div className='week-day-cell'><Text>Mon</Text></div>
283
+ <div className='week-day-cell'><Text>Tue</Text></div>
284
+ <div className='week-day-cell'><Text>Wed</Text></div>
285
+ <div className='week-day-cell'><Text>Thu</Text></div>
286
+ <div className='week-day-cell'><Text>Fri</Text></div>
287
+ <div className='week-day-cell'><Text>Sat</Text></div>
288
+ <div className='week-day-cell'><Text>Sun</Text></div>
289
+ </header>
290
+ <main>
291
+ {cells.map(cell => <DayCell key={cell.day} cell={cell} >{children}</DayCell>)}
292
+ </main>
293
+ </div>
294
+ )
295
+ }
296
+
297
+