@symbo.ls/datepicker 2.11.29 → 2.11.43

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 (3) hide show
  1. package/index.js +358 -112
  2. package/package.json +2 -2
  3. package/style.js +0 -18
package/index.js CHANGED
@@ -1,157 +1,403 @@
1
1
  'use strict'
2
2
 
3
- import style from './style'
4
-
5
- import { SquareButton, Button } from '@symbo.ls/button'
3
+ import { Button } from '@symbo.ls/button'
6
4
  import { Flex, Grid } from '@symbo.ls/atoms'
7
5
 
8
- const buttonProps = {
9
- theme: 'quaternary',
10
- background: 'transparent',
11
- color: '--theme-quinary-dark-color',
12
- ':hover': {
13
- theme: 'quinary .child'
14
- }
15
- }
16
-
17
- const aside = {
6
+ export const DatePickerYears = {
7
+ tag: 'aside',
18
8
  props: {
19
- gap: 'X2',
20
- margin: '-Z - -Z -X2',
21
- padding: 'Z - Z X2',
22
- minHeight: '100%',
23
- height: '100%',
24
- width: '--spacing-D'
9
+ overflow: 'hidden',
10
+ position: 'relative',
11
+
12
+ ':before': {
13
+ content: '""',
14
+ boxSize: 'A1 100%',
15
+ position: 'absolute',
16
+ top: '0',
17
+ left: '0',
18
+ background: 'linear-gradient(to bottom, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)',
19
+ zIndex: '10'
20
+ },
21
+ ':after': {
22
+ content: '""',
23
+ boxSize: 'B 100%',
24
+ position: 'absolute',
25
+ bottom: '0',
26
+ left: '0',
27
+ background: 'linear-gradient(to top, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)'
28
+ }
25
29
  },
26
30
 
27
- cnt: {
28
- extend: Flex,
31
+ Flex: {
29
32
  props: {
30
33
  flow: 'column',
31
- overflow: 'hidden auto',
32
- boxSize: '100% --spacing-D',
33
- top: '0',
34
- position: 'absolute',
34
+ gap: 'B',
35
+ padding: 'A Z A1 B1',
35
36
  maxHeight: '100%',
36
- justifyContent: 'flex-end'
37
+ overflow: 'hidden auto',
38
+ '::-webkit-scrollbar': { display: 'none' }
37
39
  },
38
40
 
39
41
  childExtend: {
40
42
  extend: Button,
41
- props: {
42
- ...buttonProps,
43
- fontSize: 'Z1'
44
- },
45
- text: ({ state }) => state.value
43
+ props: ({ state, text }) => ({
44
+ fontSize: 'Y1',
45
+ color: 'white',
46
+ opacity: '.4',
47
+ background: 'transparent',
48
+ transition: 'opacity .25s ease',
49
+ isActive: state.activeYear === text,
50
+ '.isActive': { opacity: '1' },
51
+ ':hover': { opacity: '1' }
52
+ }),
53
+ on: {
54
+ click: (event, element, state) => state.update({ activeYear: element.text }),
55
+ render: (el, state) => {
56
+ const { props } = el
57
+ const { isActive } = props
58
+ if (isActive) {
59
+ window.requestAnimationFrame(() => {
60
+ el.parent.parent.node.scrollTop = el.node.offsetTop - 100
61
+ })
62
+ }
63
+ }
64
+ }
65
+ },
66
+
67
+ $setCollection: ({ state, parent }) => {
68
+ const { yearRange } = parent.parent.props
69
+
70
+ if (yearRange) {
71
+ const [start, end] = yearRange
72
+ const yearsArray = (new Array(end + 1 - start)).fill(undefined).map((v, k) => {
73
+ return { text: start + k }
74
+ }).reverse()
75
+ return yearsArray
76
+ }
77
+
78
+ return [
79
+ { text: '2023' },
80
+ { text: '2022' },
81
+ { text: '2021' },
82
+ { text: '2020' },
83
+ { text: '2019' },
84
+ { text: '2018' },
85
+ { text: '2017' },
86
+ { text: '2016' },
87
+ { text: '2015' },
88
+ { text: '2014' },
89
+ { text: '2013' },
90
+ { text: '2012' },
91
+ { text: '2012' },
92
+ { text: '2012' }
93
+ ]
46
94
  }
47
95
  }
48
-
49
96
  }
50
97
 
51
- const main = {
98
+ const months = {
52
99
  extend: Flex,
53
-
54
100
  props: {
55
- flex: 1,
56
- gap: 'X2',
57
- flow: 'column',
58
-
59
- header: {
60
- align: 'center space-between'
61
- }
62
- },
63
-
64
- header: {
65
- extend: Flex,
66
- left: {
67
- extend: SquareButton,
68
- props: {
69
- ...buttonProps,
70
- round: 'C',
71
- icon: 'arrowAngleLeft'
72
- }
101
+ position: 'relative',
102
+ overflow: 'hidden',
103
+ alignItems: 'center',
104
+ padding: '- - B -',
105
+ maxWidth: `${272 / 16}em`,
106
+ boxSizing: 'border-box',
107
+ ':before': {
108
+ content: '""',
109
+ position: 'absolute',
110
+ boxSize: '100% 100px',
111
+ background: 'linear-gradient(to right, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)',
112
+ left: '0',
113
+ top: '0',
114
+ zIndex: '30',
115
+ pointerEvents: 'none'
73
116
  },
74
- month: {
75
- tag: 'span',
76
- text: 'December'
117
+ ':after': {
118
+ content: '""',
119
+ position: 'absolute',
120
+ boxSize: '100% 100px',
121
+ background: 'linear-gradient(to left, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)',
122
+ right: '0',
123
+ top: '0',
124
+ zIndex: '30',
125
+ pointerEvents: 'none'
77
126
  },
78
- right: {
79
- extend: SquareButton,
80
- props: {
81
- ...buttonProps,
82
- round: 'C',
83
- icon: 'arrowAngleRight'
127
+
128
+ style: {
129
+ '> button': {
130
+ width: '16px',
131
+ height: '16px',
132
+ position: 'absolute',
133
+ zIndex: '35',
134
+ background: 'transparent',
135
+ color: '#0079FD',
136
+ ':first-child': { left: '18px' },
137
+ ':last-child': { right: '18px' }
84
138
  }
85
139
  }
86
140
  },
87
- days: {
88
- extend: Flex,
141
+
142
+ leftButton: {
143
+ extend: Button,
144
+ props: { icon: 'arrowLeft' }
145
+ },
146
+
147
+ Flex: {
89
148
  props: {
90
- flow: 'column',
91
- gap: 'X2'
149
+ flex: '1',
150
+ overflow: 'auto hidden',
151
+ '::-webkit-scrollbar': { display: 'none' }
92
152
  },
153
+
93
154
  childExtend: {
94
- extend: Grid,
95
- props: {
96
- columns: 'repeat(7, 1fr)',
97
- gap: 'X2'
155
+ tag: 'h6',
156
+ props: ({ state, key }) => ({
157
+ fontSize: 'Z1',
158
+ textAlign: 'center',
159
+ boxSizing: 'content-box',
160
+ minWidth: '272px',
161
+
162
+ isActive: state.activeMonth === parseInt(key),
163
+ '.isActive': { opacity: '1' }
164
+ }),
165
+
166
+ render: (el, state) => {
167
+ const { props } = el
168
+ const { isActive } = props
169
+ if (isActive) {
170
+ window.requestAnimationFrame(() => {
171
+ el.parent.parent.node.scrollLeft = el.node.offsetLeft
172
+ })
173
+ }
98
174
  }
99
175
  },
100
- weekDays: {
101
- childExtend: {
102
- extend: Button,
103
- props: {
104
- ...buttonProps,
105
- fontSize: 'Z1',
106
- padding: 'X2'
107
- }
108
- },
109
- ...[
110
- { text: 'Mo' },
111
- { text: 'Tu' },
112
- { text: 'We' },
113
- { text: 'Th' },
114
- { text: 'Fr' },
115
- { text: 'Sa' },
116
- { text: 'Su' }
176
+
177
+ $setCollection: ({ state, parent }) => {
178
+ return [
179
+ { text: 'January' },
180
+ { text: 'February' },
181
+ { text: 'March' },
182
+ { text: 'April' },
183
+ { text: 'May' },
184
+ { text: 'June' },
185
+ { text: 'July' },
186
+ { text: 'August' },
187
+ { text: 'September' },
188
+ { text: 'October' },
189
+ { text: 'November' },
190
+ { text: 'December' }
117
191
  ]
118
- },
192
+ }
193
+ },
119
194
 
120
- cnt: {
121
- childExtend: {
122
- extend: SquareButton,
195
+ rightButton: { extend: Button, props: { icon: 'arrowRight' } }
196
+ }
123
197
 
124
- props: ({ key, state }) => ({
125
- ...buttonProps,
126
- theme: 'quaternary',
127
- active: key === '18',
128
- '.active': {
129
- theme: 'quinary'
130
- }
131
- })
132
- },
198
+ const weekDays = {
199
+ extend: Grid,
200
+ childExtend: {
201
+ tag: 'span',
202
+ extend: Flex
203
+ },
204
+ ...[
205
+ { text: 'Mo' },
206
+ { text: 'Tu' },
207
+ { text: 'We' },
208
+ { text: 'Th' },
209
+ { text: 'Fr' },
210
+ { text: 'Sa' },
211
+ { text: 'Su' }
212
+ ]
213
+ }
133
214
 
134
- ...new Array(31).fill(undefined).map((_, i) => ({ text: i + 1 }))
215
+ const monthNumbers = {
216
+ extend: Grid,
217
+ props: {
218
+ columns: 'repeat(7, 32px)',
219
+ gap: '4px',
220
+ boxSizing: 'content-box',
221
+ padding: `- ${12 / 16}em`
222
+ },
223
+ childExtend: {
224
+ extend: Button,
225
+ props: ({ state, key }) => ({
226
+ color: 'white',
227
+ textAlign: 'center',
228
+ background: 'transparent',
229
+ fontSize: 'Z1',
230
+ round: '100%',
231
+ height: '32px',
232
+ ':hover': { theme: 'secondary' },
233
+ ':nth-child(7n-1)': { color: 'rgba(255, 255, 255, .5)' },
234
+ ':nth-child(7n)': { color: 'rgba(255, 255, 255, .5)' },
235
+ isActive: state.activeDay === parseInt(key) + 1,
236
+ '.isActive': { theme: 'secondary' }
237
+ }),
238
+ on: {
239
+ click: (event, element, state) => {
240
+ state.update({ activeDay: element.text })
241
+ console.log(state.activeDay + '.' + state.activeMonth + '.' + state.activeYear)
242
+ }
135
243
  }
244
+ },
245
+ $setCollection: (el, s) => {
246
+ const daysInMonth = new Date(s.activeYear, s.activeMonth, 0).getDate()
247
+ const days = (new Array(daysInMonth)).fill(undefined)
248
+ .map((v, k) => ({ text: k + 1 }))
249
+ return days
136
250
  }
137
251
  }
138
252
 
139
- export const DatePicker = {
140
- style,
253
+ const confirmButtons = {
141
254
  extend: Flex,
255
+ childExtend: Button,
256
+ ...[
257
+ {
258
+ text: 'cancel',
259
+ on: {
260
+ click: (event, element, state) => {
261
+ }
262
+ }
263
+ },
264
+ {
265
+ text: 'ok'
266
+ }
267
+ ]
268
+ }
142
269
 
270
+ const monthNumbersContainer = {
143
271
  props: {
272
+ maxWidth: `${272 / 16}em`,
144
273
  position: 'relative',
145
- theme: 'quaternary',
146
- transition: 'A all',
147
- round: 'Z',
148
- padding: 'Z Z2 Z X2',
149
- gap: 'X2',
150
- depth: 16,
151
- minHeight: '0',
152
- align: 'stretch center'
274
+ ':before': {
275
+ content: '""',
276
+ position: 'absolute',
277
+ boxSize: '100% 12px',
278
+ background: 'linear-gradient(to right, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)',
279
+ left: '0',
280
+ top: '0',
281
+ zIndex: '30'
282
+ },
283
+ ':after': {
284
+ content: '""',
285
+ position: 'absolute',
286
+ boxSize: '100% 12px',
287
+ background: 'linear-gradient(to left, rgba(20, 20, 22, 1) 0%, rgba(20, 20, 22, 0) 100%)',
288
+ right: '0',
289
+ top: '0',
290
+ zIndex: '30'
291
+ },
292
+ content: {
293
+ style: { overflowX: 'auto' }
294
+ }
153
295
  },
296
+ content: {
297
+ extend: Flex,
298
+ childExtend: monthNumbers,
299
+ ...[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
300
+ }
301
+ }
154
302
 
155
- aside,
156
- main
303
+ const props = {
304
+ yearRange: [1993, 2023],
305
+ round: 'Z2',
306
+ margin: 'E',
307
+ overflow: 'hidden',
308
+ maxHeight: '318px',
309
+ boxSize: 'fit-content fit-content',
310
+ background: '#141416',
311
+ padding: '- Z - -',
312
+ style: {
313
+ button: {
314
+ padding: '0'
315
+ }
316
+ },
317
+
318
+ calendar: {
319
+ flow: 'column',
320
+ padding: '20px - - -',
321
+ position: 'relative',
322
+
323
+ weekDaysContainer: {
324
+ overflow: 'hidden',
325
+ padding: '- - Z1 -',
326
+ boxSizing: 'content-box',
327
+ maxWidth: `${272 / 16}em`,
328
+ childProps: {
329
+ maxWidth: 'fit-content',
330
+ columns: 'repeat(7, 32px)',
331
+ gap: '4px',
332
+ boxSizing: 'content-box',
333
+ padding: `- ${12 / 16}em`,
334
+ childProps: {
335
+ fontSize: 'Y1',
336
+ textTransform: 'capitalize',
337
+ ':nth-child(7n-1)': { color: 'rgba(255, 255, 255, .5)' },
338
+ ':nth-child(7n)': { color: 'rgba(255, 255, 255, .5)' },
339
+ align: 'center center'
340
+ }
341
+ }
342
+ },
343
+
344
+ confirmButtons: {
345
+ align: 'center flex-end',
346
+ gap: 'A1',
347
+ padding: 'A A1 - -',
348
+ childProps: {
349
+ color: '#0079FD',
350
+ fontSize: 'Y',
351
+ textTransform: 'uppercase',
352
+ background: 'transparent'
353
+ }
354
+ }
355
+
356
+ }
357
+ }
358
+
359
+ export const DatePicker = {
360
+ extend: Flex,
361
+ state: {
362
+ activeYear: 1993,
363
+ activeMonth: 8,
364
+ activeDay: 14
365
+ },
366
+
367
+ props,
368
+
369
+ DatePickerYears: {},
370
+
371
+ calendar: {
372
+ extend: Flex,
373
+
374
+ months,
375
+
376
+ weekDaysContainer: {
377
+ extend: Flex,
378
+ childExtend: weekDays,
379
+ ...[{}, {}]
380
+ },
381
+
382
+ monthNumbersContainer,
383
+
384
+ confirmButtons
385
+ }
386
+ }
387
+
388
+ export const DatePickerTwoColumns = {
389
+ extend: DatePicker,
390
+ props: {
391
+ calendar: {
392
+ months: {
393
+ maxWidth: `${544 / 16}em`
394
+ },
395
+ weekDaysContainer: {
396
+ maxWidth: `${544 / 16}em`
397
+ },
398
+ monthNumbersContainer: {
399
+ maxWidth: `${544 / 16}em`
400
+ }
401
+ }
402
+ }
157
403
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/datepicker",
3
- "version": "2.11.29",
3
+ "version": "2.11.43",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "cb520b92aca9016f8c18fcbd79dd6199cbb9353a",
6
+ "gitHead": "9fc7b25250ed06e3c759f7539edff7855b31ec21",
7
7
  "dependencies": {
8
8
  "@symbo.ls/block": "latest",
9
9
  "@symbo.ls/icon": "latest",
package/style.js DELETED
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- export default {
4
- main: {
5
- 'section > header span:nth-child(6)': {
6
- opacity: 0.5
7
- },
8
- 'section > header span:nth-child(7)': {
9
- opacity: 0.5
10
- },
11
- 'section > div button:nth-child(7n)': {
12
- opacity: 0.5
13
- },
14
- 'section > div button:nth-child(7n - 1)': {
15
- opacity: 0.5
16
- }
17
- }
18
- }