@symbo.ls/datepicker 2.11.52 → 2.11.70

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.
Files changed (2) hide show
  1. package/index.js +95 -46
  2. package/package.json +4 -3
package/index.js CHANGED
@@ -3,6 +3,22 @@
3
3
  import { Flex, Grid } from '@symbo.ls/atoms'
4
4
  import { Button } from '@symbo.ls/button'
5
5
  import { Dialog } from '@symbo.ls/dialog'
6
+ import { HeadlessDatepicker } from 'headless-datepicker'
7
+ const calendar = new HeadlessDatepicker.Calendar({
8
+ calendarMode: 'exact'
9
+ })
10
+
11
+ const extractMonthDays = (data) => {
12
+ const result = []
13
+
14
+ data.weeks.forEach((week) => {
15
+ week.dates.forEach((date) => {
16
+ result.push(date)
17
+ })
18
+ })
19
+
20
+ return result
21
+ }
6
22
 
7
23
  export const DatePickerYears = {
8
24
  tag: 'aside',
@@ -47,16 +63,16 @@ export const DatePickerYears = {
47
63
  opacity: '.4',
48
64
  background: 'transparent',
49
65
  transition: 'opacity .25s ease',
50
- isActive: state.activeYear === text,
51
- '.isActive': { opacity: '1' },
66
+ isSelected: state.activeYear === text,
67
+ '.isSelected': { opacity: '1' },
52
68
  ':hover': { opacity: '1' }
53
69
  }),
54
70
  on: {
55
71
  click: (event, element, state) => state.update({ activeYear: element.text }),
56
72
  render: (el, state) => {
57
73
  const { props } = el
58
- const { isActive } = props
59
- if (isActive) {
74
+ const { isSelected } = props
75
+ if (isSelected) {
60
76
  window.requestAnimationFrame(() => {
61
77
  el.parent.parent.node.scrollTop = el.node.offsetTop - 100
62
78
  })
@@ -140,10 +156,7 @@ export const DatePickerMonthsSlider = {
140
156
  }
141
157
  },
142
158
 
143
- leftButton: {
144
- extend: Button,
145
- props: { icon: 'arrowLeft' }
146
- },
159
+ Button_left: { icon: 'arrowLeft' },
147
160
 
148
161
  Flex: {
149
162
  props: {
@@ -160,14 +173,14 @@ export const DatePickerMonthsSlider = {
160
173
  boxSizing: 'content-box',
161
174
  minWidth: '272px',
162
175
 
163
- isActive: state.activeMonth === parseInt(key),
164
- '.isActive': { opacity: '1' }
176
+ isSelected: state.activeMonth === parseInt(key),
177
+ '.isSelected': { opacity: '1' }
165
178
  }),
166
179
 
167
180
  render: (el, state) => {
168
181
  const { props } = el
169
- const { isActive } = props
170
- if (isActive) {
182
+ const { isSelected } = props
183
+ if (isSelected) {
171
184
  window.requestAnimationFrame(() => {
172
185
  el.parent.parent.node.scrollLeft = el.node.offsetLeft
173
186
  })
@@ -193,7 +206,7 @@ export const DatePickerMonthsSlider = {
193
206
  }
194
207
  },
195
208
 
196
- rightButton: { extend: Button, props: { icon: 'arrowRight' } }
209
+ Button_right: { icon: 'arrowRight' }
197
210
  }
198
211
 
199
212
  export const DatePickerWeekDays = {
@@ -226,18 +239,16 @@ export const DatePickerWeekDays = {
226
239
  ]
227
240
  }
228
241
 
229
- export const DatePickerGrid = {
230
- extend: Grid,
231
- props: {
232
- columns: 'repeat(7, 1fr)',
233
- minWidth: '100%',
234
- gap: 'W2',
235
- padding: '- Z'
236
- },
237
- childExtend: {
238
- extend: Button,
239
- props: ({ state, key }) => ({
240
- isActive: state.activeDay === parseInt(key) + 1,
242
+ export const DatePickerDay = {
243
+ extend: Button,
244
+ state: true,
245
+
246
+ props: ({ state, key }) => {
247
+ const isSelected = state.parent.activeDay === parseInt(key) + 1
248
+ const gridColumnStart = 7 - state.parent.weekItems.weeks[0].dates.length
249
+
250
+ return {
251
+ isSelected,
241
252
  textAlign: 'center',
242
253
  fontSize: 'Z1',
243
254
  round: '100%',
@@ -246,24 +257,42 @@ export const DatePickerGrid = {
246
257
  lineHeight: '.9',
247
258
  background: 'transparent',
248
259
  theme: 'secondary @dark .color',
249
- '.isActive': { theme: 'primary' },
250
- '!isActive': {
260
+ text: parseInt(key) + 1,
261
+ ':first-child': {
262
+ style: { gridColumnStart }
263
+ },
264
+ '.isSelected': { theme: 'primary' },
265
+ '!isSelected': {
251
266
  ':hover': { theme: 'secondary' },
252
267
  ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' }
253
268
  }
254
- }),
255
- on: {
256
- click: (event, element, state) => {
257
- state.update({ activeDay: element.text })
258
- console.log(state.activeDay + '.' + state.activeMonth + '.' + state.activeYear)
259
- }
260
269
  }
261
270
  },
262
- $setPropsCollection: (el, s) => {
263
- const daysInMonth = new Date(s.activeYear, s.activeMonth, 0).getDate()
264
- const days = (new Array(daysInMonth)).fill(undefined)
265
- .map((v, k) => ({ text: k + 1 }))
266
- return days
271
+
272
+ on: {
273
+ click: (event, element, state) => {
274
+ state.parent.parent.update({
275
+ active: state.parse()
276
+ })
277
+ console.log(state)
278
+ }
279
+ }
280
+ }
281
+
282
+ export const DatePickerGrid = {
283
+ extend: Grid,
284
+
285
+ props: {
286
+ columns: 'repeat(7, 1fr)',
287
+ minWidth: '100%',
288
+ gap: 'W2',
289
+ padding: '- Z'
290
+ },
291
+
292
+ childExtend: DatePickerDay,
293
+
294
+ $setStateCollection: (el, s) => {
295
+ return s.days
267
296
  }
268
297
  }
269
298
 
@@ -294,10 +323,25 @@ const monthNumbersContainer = {
294
323
  }
295
324
  },
296
325
 
326
+ state: (el, s) => {
327
+ const state = el.parent.state
328
+ return (new Array(12)).fill(undefined).map((v, k) => {
329
+ const year = state.activeYear
330
+ const month = k + 1
331
+ const weekItems = calendar.getMonth({ year, month })
332
+ return {
333
+ year,
334
+ month,
335
+ weekItems,
336
+ days: extractMonthDays(weekItems)
337
+ }
338
+ })
339
+ },
340
+
297
341
  content: {
298
342
  extend: Flex,
299
343
  childExtend: DatePickerGrid,
300
- ...[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
344
+ $setStateCollection: (el, s) => s.parse()
301
345
  }
302
346
  }
303
347
 
@@ -343,15 +387,20 @@ export const DatePicker = {
343
387
 
344
388
  export const DatePickerTwoColumns = {
345
389
  extend: DatePicker,
346
- props: {
347
- calendar: {
348
- months: {
390
+ DatePickerYears: {},
391
+ Flex: {
392
+ DatePickerMonthsSlider: {
393
+ props: {
349
394
  maxWidth: `${544 / 16}em`
350
- },
351
- weekDaysContainer: {
395
+ }
396
+ },
397
+ DatePickerWeekDays: {
398
+ props: {
352
399
  maxWidth: `${544 / 16}em`
353
- },
354
- monthNumbersContainer: {
400
+ }
401
+ },
402
+ monthNumbersContainer: {
403
+ props: {
355
404
  maxWidth: `${544 / 16}em`
356
405
  }
357
406
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@symbo.ls/datepicker",
3
- "version": "2.11.52",
3
+ "version": "2.11.70",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "2e71da7acbdccc01e180f37d76f4ce0889791bf5",
6
+ "gitHead": "329c180a4cf02896ec76566a5b2f5368f62a6b06",
7
7
  "dependencies": {
8
8
  "@symbo.ls/atoms": "latest",
9
9
  "@symbo.ls/button": "latest",
10
10
  "@symbo.ls/dialog": "latest",
11
- "@symbo.ls/icon": "latest"
11
+ "@symbo.ls/icon": "latest",
12
+ "headless-datepicker": "^1.0.1"
12
13
  },
13
14
  "source": "src/index.js"
14
15
  }