ywana-core8 0.0.549 → 0.0.552

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.549",
3
+ "version": "0.0.552",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/site/site.js CHANGED
@@ -9,8 +9,6 @@ import { ReactNotifications, Store } from 'react-notifications-component'
9
9
  import 'react-notifications-component/dist/theme.css'
10
10
  import './site.css'
11
11
 
12
-
13
-
14
12
  /**
15
13
  * Site Provider
16
14
  */
@@ -0,0 +1,83 @@
1
+
2
+ .calendar {
3
+ margin: 0rem;
4
+ overflow: hidden;
5
+ display: flex;
6
+ flex-direction: column;
7
+ padding: .5rem;
8
+ }
9
+
10
+ .calendar>nav {
11
+ display: flex;
12
+ padding: .5rem;
13
+ display: flex;
14
+ align-items: center;
15
+ }
16
+
17
+ .calendar>nav>label {
18
+ flex: 1;
19
+ font-size: 1.3rem;
20
+ font-weight: 500;
21
+ }
22
+
23
+ .calendar>nav>button {
24
+ margin-left: 1px;
25
+ }
26
+
27
+ .calendar>header {
28
+ border: solid 1px var(--divider-color);
29
+ border-width: 1px 1px 0 0px;
30
+ display: grid;
31
+ grid-template-columns: repeat(7, 1fr);
32
+ font-size: .8rem;
33
+ }
34
+
35
+ .calendar>main {
36
+ flex: 1;
37
+ border: solid 1px var(--divider-color);
38
+ border-width: 1px 1px 0 0;
39
+ display: grid;
40
+ grid-template-columns: repeat(7, 1fr);
41
+ grid-gap: 0px;
42
+ grid-auto-rows: minmax(5rem, auto);
43
+ overflow: hidden;
44
+ font-size: .8rem;
45
+ }
46
+
47
+ .week-day-cell {
48
+ border-left: solid 1px var(--divider-color);
49
+ padding: 2px;
50
+ text-align: center;
51
+ min-width: 5rem;
52
+ }
53
+
54
+ .day-cell {
55
+ border: solid 1px var(--divider-color);
56
+ border-width: 0 0 1px 1px;
57
+ padding: .5rem;
58
+ text-align: right;
59
+ min-height: 5rem;
60
+ min-width: 5rem;
61
+ }
62
+
63
+ .day-cell.today>header {
64
+ background-color: var(--primary-color-lighter);
65
+ padding: .3rem
66
+ }
67
+
68
+ .day-cell:hover {
69
+ background-color: rgba(200,200,200,.1);
70
+ cursor: pointer;
71
+ }
72
+
73
+ .day-cell.today:hover {
74
+ background-color: var(--primary-color-lighter);
75
+ }
76
+
77
+ .day-cell .event {
78
+ background-color: var(--primary-color);
79
+ color: var(--primary-color-text);
80
+ padding: .3rem;
81
+ border-radius: 3px;
82
+ margin: 3px 1px;
83
+ }
@@ -0,0 +1,121 @@
1
+ import React, { useState, useEffect } from 'react'
2
+ import { Button } from '../../html'
3
+ import Moment from 'moment'
4
+ import { extendMoment } from 'moment-range';
5
+ import 'moment/locale/es'
6
+ import './Calendar.css'
7
+
8
+ Moment.locale('es')
9
+ const moment = extendMoment(Moment)
10
+
11
+ export const Calendar = (props) => {
12
+
13
+ const { events = [], children, onChange } = props
14
+ const [position, setPosition] = useState()
15
+
16
+ useEffect(() => {
17
+ const today = moment()
18
+ setPosition(today)
19
+ }, [])
20
+
21
+ useEffect(() => {
22
+ if (onChange) {
23
+ const firstDayOfMonth = position.clone().startOf('month');
24
+ const firstDayOfRange = firstDayOfMonth.clone().startOf('isoweek');
25
+ const lastDayOfMonth = position.clone().endOf('month');
26
+ const lastDayOfRange = lastDayOfMonth.clone().endOf('isoweek');
27
+ const range = moment.range(firstDayOfRange, lastDayOfRange)
28
+ onChange(position, range)
29
+ }
30
+ }, [position])
31
+
32
+ function next() {
33
+ const next = position.clone().add(1, 'month')
34
+ setPosition(next)
35
+ }
36
+
37
+ function prev() {
38
+ const prev = position.clone().subtract(1, 'month')
39
+ setPosition(prev)
40
+ }
41
+
42
+ function today() {
43
+ const today = moment()
44
+ setPosition(today)
45
+ }
46
+
47
+ if (!position) return "..."
48
+
49
+ const monthName = position.format("MMMM")
50
+ const year = position.format("YYYY")
51
+ const firstDayOfMonth = position.clone().startOf('month');
52
+ const firstDayOfRange = firstDayOfMonth.clone().startOf('isoweek');
53
+ const lastDayOfMonth = position.clone().endOf('month');
54
+ const lastDayOfRange = lastDayOfMonth.clone().endOf('isoweek');
55
+ const range = moment.range(firstDayOfRange, lastDayOfRange)
56
+ const days = Array.from(range.by('days'))
57
+
58
+ const cells = days.map(day => {
59
+ const dayEvents = events.filter(event => {
60
+ const eventDate = moment(event.date, "YYYY-MM-DD")
61
+ return eventDate.isSame(day, 'day')
62
+ })
63
+ return { day, events: dayEvents }
64
+ })
65
+
66
+ return (
67
+ <div className="calendar">
68
+ <nav>
69
+ <label> {monthName} {year}</label>
70
+ <Button icon="chevron_left" raised action={prev} />
71
+ <Button label="Hoy" outlined action={today}/>
72
+ <Button icon="chevron_right" raised action={next} />
73
+ </nav>
74
+ <header>
75
+ <div className='week-day-cell'>Lun</div>
76
+ <div className='week-day-cell'>Mar</div>
77
+ <div className='week-day-cell'>Mié</div>
78
+ <div className='week-day-cell'>Jue</div>
79
+ <div className='week-day-cell'>Vie</div>
80
+ <div className='week-day-cell'>Sab</div>
81
+ <div className='week-day-cell'>Dom</div>
82
+ </header>
83
+ <main>
84
+ {cells.map(cell => <DayCell cell={cell} >{children}</DayCell>)}
85
+ </main>
86
+ </div>
87
+ )
88
+ }
89
+
90
+ const DayCell = (props) => {
91
+ const { cell = [], children } = props
92
+ const {day, events} = cell
93
+ const todayStyle = day.isSame(moment(), 'day') ? 'today' : ''
94
+
95
+ return (
96
+ <div className={`day-cell ${todayStyle}`}>
97
+ <header>
98
+ {day.format("DD")}
99
+ </header>
100
+ <main>
101
+ {events.map(event => <Event key={event.id} event={event} >{children}</Event>)}
102
+ </main>
103
+ </div>
104
+ )
105
+ }
106
+
107
+ const Event = (props) => {
108
+ const { event, children } = props
109
+ if (children) {
110
+ const element = React.Children.toArray(children)[0]
111
+ return React.cloneElement(element, { event })
112
+ } else {
113
+ return (
114
+ <div className="event">
115
+ <div className="event-name">
116
+ {event.title}
117
+ </div>
118
+ </div>
119
+ )
120
+ }
121
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react'
2
+ import { Calendar } from './Calendar'
3
+ import moment from 'moment'
4
+
5
+ const CalendarTest = (prop) => {
6
+
7
+ const events = [
8
+ { id: 1, date: "2022-05-26", title: 'Event 1' },
9
+ { id: 1, date: "2022-05-27", title: 'Event 1' },
10
+ { id: 1, date: "2022-05-28", title: 'Event 1' },
11
+ { id: 1, date: "2022-05-29", title: 'Event 1' },
12
+ ]
13
+
14
+ return (
15
+ <Calendar events={events} >
16
+ <CustomEvent />
17
+ </Calendar>
18
+ )
19
+ }
20
+
21
+ const CustomEvent = (props) => {
22
+ const { event } = props
23
+ return (
24
+ <div className="custom-event" onClick={() => alert("!xxx")}>
25
+ C {event.title}
26
+ </div>
27
+ )
28
+ }
@@ -4,6 +4,7 @@ export * from './viewer/Viewer'
4
4
  export * from './kanban/Kanban'
5
5
  export * from './avatar/avatar'
6
6
  export * from './waiter'
7
+ export * from './calendar/Calendar'
7
8
  export * from './planner/Planner'
8
9
  export * from './upload'
9
10
  export * from './explorer/Explorer'