@symbo.ls/datepicker 2.11.49 → 2.11.55

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 +97 -56
  2. package/package.json +6 -4
package/index.js CHANGED
@@ -1,7 +1,24 @@
1
1
  'use strict'
2
2
 
3
- import { Button } from '@symbo.ls/button'
4
3
  import { Flex, Grid } from '@symbo.ls/atoms'
4
+ import { Button } from '@symbo.ls/button'
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
+ }
5
22
 
6
23
  export const DatePickerYears = {
7
24
  tag: 'aside',
@@ -46,16 +63,16 @@ export const DatePickerYears = {
46
63
  opacity: '.4',
47
64
  background: 'transparent',
48
65
  transition: 'opacity .25s ease',
49
- isActive: state.activeYear === text,
50
- '.isActive': { opacity: '1' },
66
+ isSelected: state.activeYear === text,
67
+ '.isSelected': { opacity: '1' },
51
68
  ':hover': { opacity: '1' }
52
69
  }),
53
70
  on: {
54
71
  click: (event, element, state) => state.update({ activeYear: element.text }),
55
72
  render: (el, state) => {
56
73
  const { props } = el
57
- const { isActive } = props
58
- if (isActive) {
74
+ const { isSelected } = props
75
+ if (isSelected) {
59
76
  window.requestAnimationFrame(() => {
60
77
  el.parent.parent.node.scrollTop = el.node.offsetTop - 100
61
78
  })
@@ -159,14 +176,14 @@ export const DatePickerMonthsSlider = {
159
176
  boxSizing: 'content-box',
160
177
  minWidth: '272px',
161
178
 
162
- isActive: state.activeMonth === parseInt(key),
163
- '.isActive': { opacity: '1' }
179
+ isSelected: state.activeMonth === parseInt(key),
180
+ '.isSelected': { opacity: '1' }
164
181
  }),
165
182
 
166
183
  render: (el, state) => {
167
184
  const { props } = el
168
- const { isActive } = props
169
- if (isActive) {
185
+ const { isSelected } = props
186
+ if (isSelected) {
170
187
  window.requestAnimationFrame(() => {
171
188
  el.parent.parent.node.scrollLeft = el.node.offsetLeft
172
189
  })
@@ -211,7 +228,7 @@ export const DatePickerWeekDays = {
211
228
  fontSize: 'Y1',
212
229
  textTransform: 'capitalize',
213
230
  align: 'center center',
214
- ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' },
231
+ ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' }
215
232
  }
216
233
  },
217
234
  ...[
@@ -225,18 +242,16 @@ export const DatePickerWeekDays = {
225
242
  ]
226
243
  }
227
244
 
228
- export const DatePickerGrid = {
229
- extend: Grid,
230
- props: {
231
- columns: 'repeat(7, 1fr)',
232
- minWidth: '100%',
233
- gap: 'W2',
234
- padding: `- Z`
235
- },
236
- childExtend: {
237
- extend: Button,
238
- props: ({ state, key }) => ({
239
- isActive: state.activeDay === parseInt(key) + 1,
245
+ export const DatePickerDay = {
246
+ extend: Button,
247
+ state: true,
248
+
249
+ props: ({ state, key }) => {
250
+ const isSelected = state.parent.activeDay === parseInt(key) + 1
251
+ const gridColumnStart = 7 - state.parent.weekItems.weeks[0].dates.length
252
+
253
+ return {
254
+ isSelected,
240
255
  textAlign: 'center',
241
256
  fontSize: 'Z1',
242
257
  round: '100%',
@@ -245,24 +260,42 @@ export const DatePickerGrid = {
245
260
  lineHeight: '.9',
246
261
  background: 'transparent',
247
262
  theme: 'secondary @dark .color',
248
- '.isActive': { theme: 'primary' },
249
- '!isActive': {
263
+ text: parseInt(key) + 1,
264
+ ':first-child': {
265
+ style: { gridColumnStart }
266
+ },
267
+ '.isSelected': { theme: 'primary' },
268
+ '!isSelected': {
250
269
  ':hover': { theme: 'secondary' },
251
- ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' },
252
- },
253
- }),
254
- on: {
255
- click: (event, element, state) => {
256
- state.update({ activeDay: element.text })
257
- console.log(state.activeDay + '.' + state.activeMonth + '.' + state.activeYear)
270
+ ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' }
258
271
  }
259
272
  }
260
273
  },
261
- $setPropsCollection: (el, s) => {
262
- const daysInMonth = new Date(s.activeYear, s.activeMonth, 0).getDate()
263
- const days = (new Array(daysInMonth)).fill(undefined)
264
- .map((v, k) => ({ text: k + 1 }))
265
- return days
274
+
275
+ on: {
276
+ click: (event, element, state) => {
277
+ state.parent.parent.update({
278
+ active: state.parse()
279
+ })
280
+ console.log(state)
281
+ }
282
+ }
283
+ }
284
+
285
+ export const DatePickerGrid = {
286
+ extend: Grid,
287
+
288
+ props: {
289
+ columns: 'repeat(7, 1fr)',
290
+ minWidth: '100%',
291
+ gap: 'W2',
292
+ padding: '- Z'
293
+ },
294
+
295
+ childExtend: DatePickerDay,
296
+
297
+ $setStateCollection: (el, s) => {
298
+ return s.days
266
299
  }
267
300
  }
268
301
 
@@ -293,22 +326,32 @@ const monthNumbersContainer = {
293
326
  }
294
327
  },
295
328
 
329
+ state: (el, s) => {
330
+ const state = el.parent.state
331
+ return (new Array(12)).fill(undefined).map((v, k) => {
332
+ const year = state.activeYear
333
+ const month = k + 1
334
+ const weekItems = calendar.getMonth({ year, month })
335
+ return {
336
+ year,
337
+ month,
338
+ weekItems,
339
+ days: extractMonthDays(weekItems)
340
+ }
341
+ })
342
+ },
343
+
296
344
  content: {
297
345
  extend: Flex,
298
346
  childExtend: DatePickerGrid,
299
- ...[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
347
+ $setStateCollection: (el, s) => s.parse()
300
348
  }
301
349
  }
302
350
 
303
351
  const props = {
304
352
  yearRange: [1993, 2023],
305
- theme: 'tertiary',
306
- round: 'Z2',
307
- margin: 'E',
308
- overflow: 'hidden',
309
353
  maxHeight: '318px',
310
354
  boxSize: 'fit-content fit-content',
311
- padding: '- Z - -',
312
355
  style: {
313
356
  button: {
314
357
  padding: '0'
@@ -317,7 +360,7 @@ const props = {
317
360
  }
318
361
 
319
362
  export const DatePicker = {
320
- extend: Flex,
363
+ extend: [Dialog, Flex],
321
364
  state: {
322
365
  activeYear: 1993,
323
366
  activeMonth: 8,
@@ -332,9 +375,9 @@ export const DatePicker = {
332
375
  props: {
333
376
  flow: 'column',
334
377
  padding: '20px - - -',
335
- position: 'relative',
378
+ position: 'relative'
336
379
  },
337
-
380
+
338
381
  DatePickerMonthsSlider: {},
339
382
 
340
383
  DatePickerWeekDays: {},
@@ -347,17 +390,15 @@ export const DatePicker = {
347
390
 
348
391
  export const DatePickerTwoColumns = {
349
392
  extend: DatePicker,
350
- props: {
351
- calendar: {
352
- months: {
353
- maxWidth: `${544 / 16}em`
354
- },
355
- weekDaysContainer: {
356
- maxWidth: `${544 / 16}em`
357
- },
358
- monthNumbersContainer: {
359
- maxWidth: `${544 / 16}em`
360
- }
393
+ Flex: {
394
+ DatePickerMonthsSlider: {
395
+ maxWidth: `${544 / 16}em`
396
+ },
397
+ DatePickerWeekDays: {
398
+ maxWidth: `${544 / 16}em`
399
+ },
400
+ monthNumbersContainer: {
401
+ maxWidth: `${544 / 16}em`
361
402
  }
362
403
  }
363
404
  }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@symbo.ls/datepicker",
3
- "version": "2.11.49",
3
+ "version": "2.11.55",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "396ff036bf106d7813a1688d842d7a36d407cf31",
6
+ "gitHead": "f4a6af272593be22cbf1337ddb25afec00ba359d",
7
7
  "dependencies": {
8
- "@symbo.ls/block": "latest",
8
+ "@symbo.ls/atoms": "latest",
9
+ "@symbo.ls/button": "latest",
10
+ "@symbo.ls/dialog": "latest",
9
11
  "@symbo.ls/icon": "latest",
10
- "@symbo.ls/shape": "latest"
12
+ "headless-datepicker": "^1.0.1"
11
13
  },
12
14
  "source": "src/index.js"
13
15
  }