@symbo.ls/datepicker 3.1.2 → 3.3.2

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,14 +1,22 @@
1
1
  {
2
2
  "name": "@symbo.ls/datepicker",
3
- "version": "3.1.2",
3
+ "version": "3.3.2",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "429b36616aa04c8587a26ce3c129815115e35897",
6
+ "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
7
7
  "dependencies": {
8
- "@symbo.ls/atoms": "^3.1.2",
9
- "@symbo.ls/button": "^3.1.2",
10
- "@symbo.ls/dialog": "^3.1.2",
8
+ "@symbo.ls/atoms": "^3.2.3",
9
+ "@symbo.ls/button": "^3.2.3",
10
+ "@symbo.ls/dialog": "^3.2.3",
11
11
  "headless-datepicker": "^1.0.1"
12
12
  },
13
- "source": "src/index.js"
13
+ "source": "index.js",
14
+ "type": "module",
15
+ "module": "index.js",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./index.js",
19
+ "default": "./index.js"
20
+ }
21
+ }
14
22
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 symbo.ls
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/days.js DELETED
@@ -1,47 +0,0 @@
1
- 'use strict'
2
-
3
- export const DatePickerDay = {
4
- extends: 'Button',
5
- state: true,
6
-
7
- props: ({ state, key }) => {
8
- const rootState = state.parent.parent.parent
9
- const date = new Date(state._d)
10
- const isSelected = rootState.activeDay === date.toString()
11
- const gridColumnStart = 7 - state.parent.weekItems.weeks[0].dates.length
12
- const { moment } = state
13
- moment._d = date
14
- const isWeekend = moment.day() === 0 || moment.day() === 6
15
- // const isWeekend = state.moment.day() === 0 || state.moment.day() === 6
16
- // const isWeekend = state.moment.isWeekend
17
-
18
- return {
19
- isSelected,
20
- isWeekend,
21
- date: date.toString(),
22
- textAlign: 'center',
23
- fontSize: 'Z1',
24
- round: '100%',
25
- height: 'B1',
26
- aspectRatio: '1/1',
27
- lineHeight: '.9',
28
- background: 'transparent',
29
- theme: 'field @dark .color',
30
- text: parseInt(key) + 1,
31
- ':first-child': {
32
- style: { gridColumnStart }
33
- },
34
- '.isSelected': { theme: 'primary' },
35
- '!isSelected': {
36
- '.isWeekend': { opacity: '.5' },
37
- ':hover': { theme: 'field' }
38
- }
39
- }
40
- },
41
-
42
- onClick: (event, element, state) => {
43
- state.parent.parent.parent.update({
44
- activeDay: element.props.date
45
- })
46
- }
47
- }
package/grid.js DELETED
@@ -1,107 +0,0 @@
1
- 'use strict'
2
-
3
- import { DatePickerDay } from './days'
4
- import { HeadlessDatepicker } from 'headless-datepicker'
5
-
6
- export const calendar = new HeadlessDatepicker.Calendar({
7
- calendarMode: 'exact'
8
- })
9
-
10
- const extractMonthDays = (data) => {
11
- const result = []
12
-
13
- data.weeks.forEach((week) => {
14
- week.dates.forEach((date) => {
15
- result.push({ ...date, _d: date.moment._d.toString() })
16
- })
17
- })
18
-
19
- return result
20
- }
21
-
22
- export const DatePickerGrid = {
23
- extends: 'Grid',
24
-
25
- props: {
26
- columns: 'repeat(7, 1fr)',
27
- minWidth: '100%',
28
- gap: 'W2',
29
- padding: '- Z',
30
- style: { scrollSnapAlign: 'center' }
31
- },
32
-
33
- childExtends: DatePickerDay,
34
- childrenAs: 'state',
35
- children: ({ state }) => state.days
36
- }
37
-
38
- export const DatePickerGridContainer = {
39
- props: {
40
- maxWidth: 'F3+B',
41
- position: 'relative',
42
- content: {
43
- overflow: 'hidden',
44
- style: { scrollSnapType: 'x mandatory' }
45
- },
46
- style: {
47
- button: {
48
- padding: '0'
49
- }
50
- },
51
- ':before': {
52
- content: '""',
53
- position: 'absolute',
54
- boxSize: '100% 12px',
55
- background: 'linear-gradient(to right, var(--theme-tertiary-dark-background) 0%, transparent 100%)',
56
- left: '0',
57
- top: '0',
58
- zIndex: '30'
59
- },
60
- ':after': {
61
- content: '""',
62
- position: 'absolute',
63
- boxSize: '100% 12px',
64
- background: 'linear-gradient(to left, var(--theme-tertiary-dark-background) 0%, transparent 100%)',
65
- right: '0',
66
- top: '0',
67
- zIndex: '30'
68
- }
69
- },
70
-
71
- state: ({ parent }) => {
72
- const state = parent.state
73
- if (!state.activeYear) return
74
- return (new Array(12)).fill(undefined).map((v, k) => {
75
- const year = state.activeYear
76
- const month = k + 1
77
- const weekItems = calendar.getMonth({ year, month })
78
- return {
79
- year,
80
- month,
81
- weekItems,
82
- days: extractMonthDays(weekItems)
83
- }
84
- })
85
- },
86
-
87
- Flex: {
88
- childProps: {
89
- onRender: (el, state) => {
90
- const { key } = el
91
- const isSelected = state.parent.parent.activeMonth === parseInt(key)
92
- if (isSelected) {
93
- window.requestAnimationFrame(() => {
94
- el.parent.parent.node.scrollTo({
95
- left: el.node.offsetLeft,
96
- behavior: state.initialized ? 'smooth' : 'instant'
97
- })
98
- })
99
- // if (!state.initialized) state.update({ initialized: true }, { preventUpdate: true, isHoisted: true })
100
- }
101
- }
102
- },
103
- childExtends: 'DatePickerGrid',
104
- childrenAs: 'state',
105
- children: ({ state }) => state.parse()
106
- }
107
- }
package/index.js DELETED
@@ -1,75 +0,0 @@
1
- 'use strict'
2
-
3
- import { Flex } from '@symbo.ls/atoms'
4
- import { Dialog } from '@symbo.ls/dialog'
5
-
6
- export * from './days'
7
- export * from './weekdays'
8
- export * from './months'
9
- export * from './years'
10
- export * from './grid'
11
-
12
- export const DatePicker = {
13
- extends: [Dialog, Flex],
14
-
15
- state: ({ props }) => {
16
- const date = new Date()
17
- const activeYear = date.getFullYear()
18
- const activeMonth = date.getMonth()
19
- const activeDay = date.getDate()
20
- return {
21
- yearRange: props.yearRange || [activeYear - 30, activeYear],
22
- activeYear: props.activeYear || activeYear,
23
- activeMonth: props.activeMonth || activeMonth,
24
- activeDay: props.activeDay || activeDay,
25
- selectedDay: props.selectedDay || null
26
- }
27
- },
28
-
29
- props: {
30
- width: 'fit-content',
31
- margin: '0',
32
- userSelect: 'none',
33
- maxHeight: 'G+B2'
34
- },
35
-
36
- DatePickerYears: {},
37
-
38
- Flex: {
39
- props: {
40
- flow: 'column',
41
- padding: 'A1 - - -',
42
- position: 'relative'
43
- },
44
-
45
- DatePickerMonthsSlider: {},
46
-
47
- DatePickerWeekDays: {},
48
-
49
- DatePickerGridContainer: {},
50
-
51
- DialogFooter: {}
52
- }
53
- }
54
-
55
- export const DatePickerTwoColumns = {
56
- extends: DatePicker,
57
- DatePickerYears: {},
58
- Flex: {
59
- DatePickerMonthsSlider: {
60
- props: {
61
- maxWidth: `${544 / 16}em`
62
- }
63
- },
64
- DatePickerWeekDays: {
65
- props: {
66
- maxWidth: `${544 / 16}em`
67
- }
68
- },
69
- monthNumbersContainer: {
70
- props: {
71
- maxWidth: `${544 / 16}em`
72
- }
73
- }
74
- }
75
- }
package/months.js DELETED
@@ -1,145 +0,0 @@
1
- 'use strict'
2
-
3
- export const DatePickerMonthsSlider = {
4
- display: 'flex',
5
- props: {
6
- position: 'relative',
7
- overflow: 'hidden',
8
- alignItems: 'center',
9
- padding: '- - A2 -',
10
- maxWidth: `${272 / 16}em`,
11
- boxSizing: 'border-box',
12
- ':before': {
13
- content: '""',
14
- position: 'absolute',
15
- boxSize: '100% 100px',
16
- background:
17
- 'linear-gradient(to right, var(--theme-tertiary-dark-background) 0%, transparent 100%)',
18
- left: '0',
19
- top: '0',
20
- zIndex: '30',
21
- pointerEvents: 'none'
22
- },
23
- ':after': {
24
- content: '""',
25
- position: 'absolute',
26
- boxSize: '100% 100px',
27
- background:
28
- 'linear-gradient(to left, var(--theme-tertiary-dark-background) 0%, transparent 100%)',
29
- right: '0',
30
- top: '0',
31
- zIndex: '30',
32
- pointerEvents: 'none'
33
- },
34
-
35
- style: {
36
- '> button': {
37
- padding: '0',
38
- width: 'A',
39
- height: 'A',
40
- position: 'absolute',
41
- zIndex: '35',
42
- background: 'transparent',
43
- ':first-child': { left: '18px' },
44
- ':last-child': { right: '18px' }
45
- }
46
- }
47
- },
48
-
49
- Button_left: {
50
- props: {
51
- icon: 'arrowLeft',
52
- '@dark': {
53
- theme: 'primary @dark .color-only'
54
- },
55
- '@light': {
56
- theme: 'primary @light .color-only'
57
- }
58
- },
59
- onClick: (ev, el, s) => {
60
- const { activeMonth, activeYear } = s
61
- if (activeMonth > 0) s.update({ activeMonth: activeMonth - 1 })
62
- else {
63
- s.update({
64
- activeYear: activeYear - 1,
65
- activeMonth: 11
66
- })
67
- }
68
- }
69
- },
70
-
71
- Flex: {
72
- props: {
73
- flex: '1',
74
- overflow: 'hidden',
75
- style: { scrollSnapType: 'x mandatory' },
76
- '::-webkit-scrollbar': { display: 'none' }
77
- },
78
-
79
- childExtends: {
80
- tag: 'h6',
81
- fontSize: 'Z1',
82
- textAlign: 'center',
83
- boxSizing: 'content-box',
84
- minWidth: '272px',
85
- style: { scrollSnapAlign: 'center' },
86
-
87
- isSelected: ({ state, key }) => state.activeMonth === parseInt(key),
88
- '.isSelected': { opacity: '1' },
89
-
90
- onUpdate: (el, state) => {
91
- const { props } = el
92
- const { isSelected } = props
93
- if (isSelected) {
94
- window.requestAnimationFrame(() => {
95
- el.parent.parent.node.scrollTo({
96
- left: el.node.offsetLeft,
97
- behavior: state.initialized ? 'smooth' : 'instant'
98
- })
99
- })
100
- // if (!state.initialized) state.update({ initialized: true }, { preventUpdate: true, isHoisted: true })
101
- }
102
- }
103
- },
104
-
105
- children: ({ state, parent }) => {
106
- return [
107
- { text: 'January' },
108
- { text: 'February' },
109
- { text: 'March' },
110
- { text: 'April' },
111
- { text: 'May' },
112
- { text: 'June' },
113
- { text: 'July' },
114
- { text: 'August' },
115
- { text: 'September' },
116
- { text: 'October' },
117
- { text: 'November' },
118
- { text: 'December' }
119
- ]
120
- }
121
- },
122
-
123
- Button_right: {
124
- props: {
125
- icon: 'arrowRight',
126
- '@dark': {
127
- theme: 'primary @dark .color-only'
128
- },
129
- '@light': {
130
- theme: 'primary @light .color-only'
131
- }
132
- },
133
-
134
- onClick: (ev, el, s) => {
135
- const { activeMonth, activeYear } = s
136
- if (activeMonth < 11) s.update({ activeMonth: activeMonth + 1 })
137
- else {
138
- s.update({
139
- activeYear: activeYear + 1,
140
- activeMonth: 0
141
- })
142
- }
143
- }
144
- }
145
- }
package/weekdays.js DELETED
@@ -1,36 +0,0 @@
1
- 'use strict'
2
-
3
- export const DatePickerWeekDays = {
4
- extends: 'Grid',
5
- props: {
6
- overflow: 'hidden',
7
- padding: '- Z A',
8
- width: '100%',
9
- columns: 'repeat(7, 1fr)',
10
- gap: 'W2',
11
- style: {
12
- button: {
13
- padding: '0'
14
- }
15
- }
16
- },
17
- childExtends: {
18
- tag: 'span',
19
- display: 'flex',
20
- props: {
21
- fontSize: 'Y1',
22
- textTransform: 'capitalize',
23
- align: 'center center',
24
- ':nth-child(7n-1), &:nth-child(7n)': { opacity: '.5' }
25
- }
26
- },
27
- ...[
28
- { text: 'Mo' },
29
- { text: 'Tu' },
30
- { text: 'We' },
31
- { text: 'Th' },
32
- { text: 'Fr' },
33
- { text: 'Sa' },
34
- { text: 'Su' }
35
- ]
36
- }
package/years.js DELETED
@@ -1,85 +0,0 @@
1
- 'use strict'
2
-
3
- export const DatePickerYears = {
4
- tag: 'aside',
5
- overflow: 'hidden',
6
- position: 'relative',
7
-
8
- style: {
9
- button: {
10
- padding: '0'
11
- }
12
- },
13
-
14
- ':before': {
15
- content: '""',
16
- boxSize: 'A1 100%',
17
- position: 'absolute',
18
- top: '0',
19
- left: '0',
20
- background:
21
- 'linear-gradient(to bottom, var(--theme-tertiary-dark-background) 0%, transparent 100%)',
22
- zIndex: '10'
23
- },
24
-
25
- ':after': {
26
- content: '""',
27
- boxSize: 'B 100%',
28
- position: 'absolute',
29
- bottom: '0',
30
- left: '0',
31
- background:
32
- 'linear-gradient(to top, var(--theme-tertiary-dark-background) 0%, transparent 100%)'
33
- },
34
-
35
- if: ({ state }) => state.yearRange,
36
-
37
- Flex: {
38
- flow: 'column',
39
- gap: 'B',
40
- padding: 'A Z A1 B',
41
- maxHeight: '100%',
42
- overflow: 'hidden auto',
43
- '::-webkit-scrollbar': { display: 'none' },
44
- childExtends: {
45
- extends: 'Button',
46
-
47
- fontSize: 'Y1',
48
- opacity: '.4',
49
- background: 'transparent',
50
- transition: 'opacity .25s ease',
51
- isSelected: ({ state, text }) => state.activeYear === text,
52
- '.isSelected': { opacity: '1' },
53
- ':hover': { opacity: '1' },
54
- onClick: (event, element, state) =>
55
- state.update(
56
- {
57
- activeYear: element.text
58
- },
59
- { isHoisted: true }
60
- ),
61
- onRender: (el, state) => {
62
- const { props } = el
63
- const { isSelected } = props
64
- if (!isSelected) return
65
- window.requestAnimationFrame(() => {
66
- el.parent.parent.node.scrollTop = el.node.offsetTop - 100
67
- })
68
- }
69
- },
70
-
71
- children: element => {
72
- const { yearRange } = element.state
73
- if (!yearRange) return
74
-
75
- const [start, end] = yearRange
76
- const yearsArray = new Array(end + 1 - start)
77
- .fill(undefined)
78
- .map((v, k) => {
79
- return { text: start + k }
80
- })
81
- .reverse()
82
- return yearsArray
83
- }
84
- }
85
- }