@octane-xplat/date-picker 0.18.0 → 0.20.0
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/README.md +2 -139
- package/package.json +87 -81
- package/src/AppKitDatePicker.macos.css +1 -0
- package/src/AppKitDatePicker.macos.tsrx +43 -41
- package/src/AppKitDatePicker.tsrx +2 -0
- package/src/MaterialDatePicker.android.tsrx +51 -36
- package/src/MaterialDatePicker.tsrx +2 -0
- package/src/SwiftUIDatePicker.ios.tsrx +56 -37
- package/src/SwiftUIDatePicker.tsrx +2 -0
- package/src/android/index.ts +4 -4
- package/src/android/types.ts +151 -66
- package/src/date-picker-owner.macos.ts +264 -0
- package/src/ios/index.ts +3 -3
- package/src/ios/types.ts +29 -20
- package/src/macos/index.ts +3 -3
- package/src/macos/types.ts +27 -18
- package/src/style-merge.ts +59 -0
- package/types/generated/.tsrx-typegen-manifest.json +17 -0
- package/types/generated/AppKitDatePicker.macos.d.ts +10 -0
- package/types/generated/MaterialDatePicker.android.d.ts +15 -0
- package/types/generated/SwiftUIDatePicker.ios.d.ts +15 -0
- package/types/generated/android/index.d.ts +2 -0
- package/types/generated/android/types.d.ts +126 -0
- package/types/generated/date-picker-owner.macos.d.ts +29 -0
- package/types/generated/index.d.ts +1 -0
- package/types/generated/ios/index.d.ts +2 -0
- package/types/generated/ios/types.d.ts +33 -0
- package/types/generated/macos/index.d.ts +2 -0
- package/types/generated/macos/types.d.ts +31 -0
- package/types/generated/style-merge.d.ts +8 -0
- package/LICENSE +0 -21
- package/types/android/index.d.ts +0 -61
- package/types/index.d.ts +0 -1
- package/types/ios/index.d.ts +0 -21
- package/types/macos/index.d.ts +0 -20
package/src/android/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Date-picker presentation variant. */
|
|
1
2
|
export type MaterialDatePickerVariant = 'picker' | 'input'
|
|
2
3
|
|
|
4
|
+
/** Per-part Material color slots. */
|
|
3
5
|
export type MaterialDatePickerComponents = 'date' | 'hourAndMinute' | 'dateAndTime'
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -8,73 +10,156 @@ export type MaterialDatePickerComponents = 'date' | 'hourAndMinute' | 'dateAndTi
|
|
|
8
10
|
* Material 3 theme defaults.
|
|
9
11
|
*/
|
|
10
12
|
export interface MaterialDatePickerElementColors {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
13
|
+
/** Part color override (any platform color string). */
|
|
14
|
+
|
|
15
|
+
containerColor?: string
|
|
16
|
+
/** Part color override (any platform color string). */
|
|
17
|
+
|
|
18
|
+
titleContentColor?: string
|
|
19
|
+
/** Part color override (any platform color string). */
|
|
20
|
+
|
|
21
|
+
headlineContentColor?: string
|
|
22
|
+
/** Part color override (any platform color string). */
|
|
23
|
+
|
|
24
|
+
weekdayContentColor?: string
|
|
25
|
+
/** Part color override (any platform color string). */
|
|
26
|
+
|
|
27
|
+
subheadContentColor?: string
|
|
28
|
+
/** Part color override (any platform color string). */
|
|
29
|
+
|
|
30
|
+
navigationContentColor?: string
|
|
31
|
+
/** Part color override (any platform color string). */
|
|
32
|
+
|
|
33
|
+
yearContentColor?: string
|
|
34
|
+
/** Part color override (any platform color string). */
|
|
35
|
+
|
|
36
|
+
disabledYearContentColor?: string
|
|
37
|
+
/** Part color override (any platform color string). */
|
|
38
|
+
|
|
39
|
+
currentYearContentColor?: string
|
|
40
|
+
/** Part color override (any platform color string). */
|
|
41
|
+
|
|
42
|
+
selectedYearContentColor?: string
|
|
43
|
+
/** Part color override (any platform color string). */
|
|
44
|
+
|
|
45
|
+
disabledSelectedYearContentColor?: string
|
|
46
|
+
/** Part color override (any platform color string). */
|
|
47
|
+
|
|
48
|
+
selectedYearContainerColor?: string
|
|
49
|
+
/** Part color override (any platform color string). */
|
|
50
|
+
|
|
51
|
+
disabledSelectedYearContainerColor?: string
|
|
52
|
+
/** Part color override (any platform color string). */
|
|
53
|
+
|
|
54
|
+
dayContentColor?: string
|
|
55
|
+
/** Part color override (any platform color string). */
|
|
56
|
+
|
|
57
|
+
disabledDayContentColor?: string
|
|
58
|
+
/** Part color override (any platform color string). */
|
|
59
|
+
|
|
60
|
+
selectedDayContentColor?: string
|
|
61
|
+
/** Part color override (any platform color string). */
|
|
62
|
+
|
|
63
|
+
disabledSelectedDayContentColor?: string
|
|
64
|
+
/** Part color override (any platform color string). */
|
|
65
|
+
|
|
66
|
+
selectedDayContainerColor?: string
|
|
67
|
+
/** Part color override (any platform color string). */
|
|
68
|
+
|
|
69
|
+
disabledSelectedDayContainerColor?: string
|
|
70
|
+
/** Part color override (any platform color string). */
|
|
71
|
+
|
|
72
|
+
todayContentColor?: string
|
|
73
|
+
/** Part color override (any platform color string). */
|
|
74
|
+
|
|
75
|
+
todayDateBorderColor?: string
|
|
76
|
+
/** Part color override (any platform color string). */
|
|
77
|
+
|
|
78
|
+
dayInSelectionRangeContentColor?: string
|
|
79
|
+
/** Part color override (any platform color string). */
|
|
80
|
+
|
|
81
|
+
dayInSelectionRangeContainerColor?: string
|
|
82
|
+
/** Part color override (any platform color string). */
|
|
83
|
+
|
|
84
|
+
dividerColor?: string
|
|
85
|
+
/** Part color override (any platform color string). */
|
|
86
|
+
|
|
87
|
+
clockDialColor?: string
|
|
88
|
+
/** Part color override (any platform color string). */
|
|
89
|
+
|
|
90
|
+
clockDialSelectedContentColor?: string
|
|
91
|
+
/** Part color override (any platform color string). */
|
|
92
|
+
|
|
93
|
+
clockDialUnselectedContentColor?: string
|
|
94
|
+
/** Part color override (any platform color string). */
|
|
95
|
+
|
|
96
|
+
selectorColor?: string
|
|
97
|
+
/** Part color override (any platform color string). */
|
|
98
|
+
|
|
99
|
+
periodSelectorBorderColor?: string
|
|
100
|
+
/** Part color override (any platform color string). */
|
|
101
|
+
|
|
102
|
+
periodSelectorSelectedContainerColor?: string
|
|
103
|
+
/** Part color override (any platform color string). */
|
|
104
|
+
|
|
105
|
+
periodSelectorUnselectedContainerColor?: string
|
|
106
|
+
/** Part color override (any platform color string). */
|
|
107
|
+
|
|
108
|
+
periodSelectorSelectedContentColor?: string
|
|
109
|
+
/** Part color override (any platform color string). */
|
|
110
|
+
|
|
111
|
+
periodSelectorUnselectedContentColor?: string
|
|
112
|
+
/** Part color override (any platform color string). */
|
|
113
|
+
|
|
114
|
+
timeSelectorSelectedContainerColor?: string
|
|
115
|
+
/** Part color override (any platform color string). */
|
|
116
|
+
|
|
117
|
+
timeSelectorUnselectedContainerColor?: string
|
|
118
|
+
/** Part color override (any platform color string). */
|
|
119
|
+
|
|
120
|
+
timeSelectorSelectedContentColor?: string
|
|
121
|
+
/** Part color override (any platform color string). */
|
|
122
|
+
|
|
123
|
+
timeSelectorUnselectedContentColor?: string
|
|
48
124
|
}
|
|
49
125
|
|
|
126
|
+
/** Android date-picker props (Material3 date picker). */
|
|
50
127
|
export interface MaterialDatePickerProps {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
128
|
+
/** Element id passed through to the host element. */
|
|
129
|
+
id?: string
|
|
130
|
+
/** Class list applied to the picker element. */
|
|
131
|
+
className?: any
|
|
132
|
+
/** Inline style (string CSS or object). */
|
|
133
|
+
style?: any
|
|
134
|
+
/** Date the picker starts on. The picker keeps its own selection after mount. */
|
|
135
|
+
initialDate?: Date
|
|
136
|
+
/** Calendar grid or text-field input. @default 'picker' */
|
|
137
|
+
variant?: MaterialDatePickerVariant
|
|
138
|
+
/**
|
|
139
|
+
* `'date'` renders the M3 DatePicker, `'hourAndMinute'` the M3 TimePicker.
|
|
140
|
+
* `'dateAndTime'` renders the date picker (combined input is not supported).
|
|
141
|
+
* @default 'date'
|
|
142
|
+
*/
|
|
143
|
+
displayedComponents?: MaterialDatePickerComponents
|
|
144
|
+
/** Show the picker/input mode toggle. @default true */
|
|
145
|
+
showVariantToggle?: boolean
|
|
146
|
+
/** 24-hour dial for the time picker. @default true */
|
|
147
|
+
is24Hour?: boolean
|
|
148
|
+
/** Accent applied to a subset of elements when `elementColors` is unset. */
|
|
149
|
+
/** Part color override (any platform color string). */
|
|
150
|
+
|
|
151
|
+
color?: string
|
|
152
|
+
/** Part color override (any platform color string). */
|
|
153
|
+
|
|
154
|
+
elementColors?: MaterialDatePickerElementColors
|
|
155
|
+
/** Bounds the selectable date range; also derives the calendar year range. */
|
|
156
|
+
selectableDates?: { start?: Date; end?: Date }
|
|
157
|
+
/** Spoken name for assistive tech. */
|
|
158
|
+
accessibilityLabel?: string
|
|
159
|
+
/**
|
|
160
|
+
* Called with the selected timestamp (null when the selection clears). The
|
|
161
|
+
* DatePicker emits the chosen UTC day; the TimePicker emits the chosen
|
|
162
|
+
* hour/minute on the initial date's day.
|
|
163
|
+
*/
|
|
164
|
+
onDateSelected?: (date: Date | null) => void
|
|
80
165
|
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { AppKitDatePickerProps } from './macos/types'
|
|
2
|
+
|
|
3
|
+
export interface DatePickerOptions {
|
|
4
|
+
mode: NonNullable<AppKitDatePickerProps['components']>
|
|
5
|
+
style: NonNullable<AppKitDatePickerProps['pickerStyle']>
|
|
6
|
+
selectionMillis: number
|
|
7
|
+
minimumMillis?: number
|
|
8
|
+
maximumMillis?: number
|
|
9
|
+
enabled: boolean
|
|
10
|
+
accessibilityLabel?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DatePickerHandle {
|
|
14
|
+
update(options: DatePickerOptions): void
|
|
15
|
+
detach(): void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type DatePickerAttach = (
|
|
19
|
+
view: object,
|
|
20
|
+
options: DatePickerOptions,
|
|
21
|
+
onChange: (millis: number) => void,
|
|
22
|
+
) => DatePickerHandle | null
|
|
23
|
+
|
|
24
|
+
export type DatePickerStatus = 'ready' | 'invalid' | 'unavailable'
|
|
25
|
+
|
|
26
|
+
function milliseconds(date: Date | undefined): number | undefined {
|
|
27
|
+
try {
|
|
28
|
+
return date === undefined ? undefined : date.getTime()
|
|
29
|
+
} catch {
|
|
30
|
+
return NaN
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const valid = (value: number) =>
|
|
35
|
+
Number.isFinite(value) && Number.isFinite(new Date(value).getTime())
|
|
36
|
+
|
|
37
|
+
/** Own one mounted attachment. Default selection seeds once; mode/view changes
|
|
38
|
+
* retain the accepted selection. This model does not prove native editing. */
|
|
39
|
+
export function createDatePickerOwner(deps: {
|
|
40
|
+
props(): AppKitDatePickerProps
|
|
41
|
+
attach(): DatePickerAttach | undefined
|
|
42
|
+
status?(status: DatePickerStatus): void
|
|
43
|
+
now?(): number
|
|
44
|
+
}): {
|
|
45
|
+
update: () => void
|
|
46
|
+
bind(next: object | null): void
|
|
47
|
+
dispose(): void
|
|
48
|
+
getStatus: () => DatePickerStatus
|
|
49
|
+
} {
|
|
50
|
+
let view: object | null = null,
|
|
51
|
+
disposed = false,
|
|
52
|
+
retained: number | undefined
|
|
53
|
+
|
|
54
|
+
let status: DatePickerStatus = 'unavailable'
|
|
55
|
+
type Session = {
|
|
56
|
+
view: object
|
|
57
|
+
mode: string
|
|
58
|
+
style: string
|
|
59
|
+
writing: number
|
|
60
|
+
handle: DatePickerHandle | null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let session: Session | null = null
|
|
64
|
+
const report = (next: DatePickerStatus) => {
|
|
65
|
+
if (!disposed && next !== status) {
|
|
66
|
+
status = next
|
|
67
|
+
deps.status?.(next)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const detach = () => {
|
|
72
|
+
const old = session
|
|
73
|
+
|
|
74
|
+
session = null
|
|
75
|
+
try {
|
|
76
|
+
old?.handle?.detach()
|
|
77
|
+
} catch {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const plan = (): DatePickerOptions | null => {
|
|
81
|
+
const props = deps.props(),
|
|
82
|
+
min = milliseconds(props.minimumDate),
|
|
83
|
+
max = milliseconds(props.maximumDate)
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
(min !== undefined && !valid(min)) ||
|
|
87
|
+
(max !== undefined && !valid(max)) ||
|
|
88
|
+
(min !== undefined && max !== undefined && min > max)
|
|
89
|
+
) {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const controlled = props.selection !== undefined
|
|
94
|
+
let selected = controlled
|
|
95
|
+
? milliseconds(props.selection)!
|
|
96
|
+
: (retained ?? milliseconds(props.defaultSelection) ?? (deps.now ?? Date.now)())
|
|
97
|
+
|
|
98
|
+
if (!valid(selected)) {
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
controlled &&
|
|
104
|
+
((min !== undefined && selected < min) || (max !== undefined && selected > max))
|
|
105
|
+
) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!controlled) {
|
|
110
|
+
selected = Math.min(max ?? Infinity, Math.max(min ?? -Infinity, selected))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const mode = props.components ?? 'date'
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
mode,
|
|
117
|
+
style: mode === 'date' ? (props.pickerStyle ?? 'textField') : 'textField',
|
|
118
|
+
selectionMillis: selected,
|
|
119
|
+
minimumMillis: min,
|
|
120
|
+
maximumMillis: max,
|
|
121
|
+
enabled: !props.disabled,
|
|
122
|
+
accessibilityLabel: props.accessibilityLabel,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const update = () => {
|
|
127
|
+
if (disposed || !view) {
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const options = plan()
|
|
132
|
+
|
|
133
|
+
if (!options) {
|
|
134
|
+
detach()
|
|
135
|
+
report('invalid')
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
retained = options.selectionMillis
|
|
140
|
+
if (
|
|
141
|
+
session &&
|
|
142
|
+
(session.view !== view || session.mode !== options.mode || session.style !== options.style)
|
|
143
|
+
) {
|
|
144
|
+
detach()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (session?.handle) {
|
|
148
|
+
const owner = session
|
|
149
|
+
|
|
150
|
+
owner.writing++
|
|
151
|
+
try {
|
|
152
|
+
owner.handle!.update(options)
|
|
153
|
+
if (session === owner) {
|
|
154
|
+
report('ready')
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
if (session === owner) {
|
|
158
|
+
detach()
|
|
159
|
+
report('unavailable')
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
owner.writing--
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const attach = deps.attach()
|
|
169
|
+
|
|
170
|
+
if (!attach) {
|
|
171
|
+
report('unavailable')
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const owner: Session = {
|
|
176
|
+
view,
|
|
177
|
+
mode: options.mode,
|
|
178
|
+
style: options.style,
|
|
179
|
+
writing: 1,
|
|
180
|
+
handle: null,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
session = owner
|
|
184
|
+
try {
|
|
185
|
+
const handle = attach(view, options, (millis) => {
|
|
186
|
+
if (disposed || session !== owner || owner.writing || !owner.handle) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const current = plan()
|
|
191
|
+
|
|
192
|
+
if (!current || !current.enabled || !valid(millis)) {
|
|
193
|
+
update()
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const picked = new Date(millis).getTime()
|
|
198
|
+
|
|
199
|
+
if (
|
|
200
|
+
(current.minimumMillis !== undefined && picked < current.minimumMillis) ||
|
|
201
|
+
(current.maximumMillis !== undefined && picked > current.maximumMillis)
|
|
202
|
+
) {
|
|
203
|
+
update()
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (picked === current.selectionMillis) {
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (deps.props().selection === undefined) {
|
|
212
|
+
retained = picked
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
deps.props().onSelectionChange?.(new Date(picked))
|
|
217
|
+
} finally {
|
|
218
|
+
update()
|
|
219
|
+
} // Restore a rejected controlled value; suppress programmatic echoes.
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
if (disposed || session !== owner) {
|
|
223
|
+
handle?.detach()
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
owner.handle = handle
|
|
228
|
+
if (!handle) {
|
|
229
|
+
session = null
|
|
230
|
+
report('unavailable')
|
|
231
|
+
} else {
|
|
232
|
+
report('ready')
|
|
233
|
+
}
|
|
234
|
+
} catch {
|
|
235
|
+
if (session === owner) {
|
|
236
|
+
detach()
|
|
237
|
+
report('unavailable')
|
|
238
|
+
}
|
|
239
|
+
} finally {
|
|
240
|
+
owner.writing--
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
update,
|
|
246
|
+
bind(next: object | null) {
|
|
247
|
+
if (!disposed && next !== view) {
|
|
248
|
+
detach()
|
|
249
|
+
view = next
|
|
250
|
+
if (view) {
|
|
251
|
+
update()
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
dispose() {
|
|
256
|
+
if (!disposed) {
|
|
257
|
+
disposed = true
|
|
258
|
+
detach()
|
|
259
|
+
view = null
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
getStatus: () => status,
|
|
263
|
+
}
|
|
264
|
+
}
|
package/src/ios/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SwiftUIDatePicker } from '../SwiftUIDatePicker.ios.tsrx'
|
|
2
2
|
export type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
SwiftUIDatePickerComponent,
|
|
4
|
+
SwiftUIDatePickerProps,
|
|
5
|
+
SwiftUIDatePickerStyle,
|
|
6
6
|
} from './types'
|
package/src/ios/types.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
|
+
/** SwiftUI date-picker style. */
|
|
1
2
|
export type SwiftUIDatePickerStyle = 'automatic' | 'compact' | 'graphical' | 'wheel'
|
|
2
3
|
|
|
4
|
+
/** SwiftUI picker component selector. */
|
|
3
5
|
export type SwiftUIDatePickerComponent = 'date' | 'hourAndMinute'
|
|
4
6
|
|
|
7
|
+
/** iOS date-picker props (SwiftUI DatePicker). */
|
|
5
8
|
export interface SwiftUIDatePickerProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
/** Element id passed through to the host element. */
|
|
10
|
+
id?: string
|
|
11
|
+
/** Class list applied to the picker element. */
|
|
12
|
+
className?: any
|
|
13
|
+
/** Inline style (string CSS or object). */
|
|
14
|
+
style?: any
|
|
15
|
+
/** Label shown next to the picker. When omitted, the label is hidden. */
|
|
16
|
+
title?: string
|
|
17
|
+
/** Controlled selection. Pair with `onSelectionChange`. */
|
|
18
|
+
selection?: Date
|
|
19
|
+
/** Initial selection when `selection` is not provided. */
|
|
20
|
+
defaultSelection?: Date
|
|
21
|
+
/** Earliest selectable date. */
|
|
22
|
+
minimumDate?: Date
|
|
23
|
+
/** Latest selectable date. */
|
|
24
|
+
maximumDate?: Date
|
|
25
|
+
/** Which components the picker displays. @default ['date'] */
|
|
26
|
+
displayedComponents?: readonly SwiftUIDatePickerComponent[]
|
|
27
|
+
/** SwiftUI presentation style. `graphical` renders an inline calendar. @default 'automatic' */
|
|
28
|
+
pickerStyle?: SwiftUIDatePickerStyle
|
|
29
|
+
/** Disables interaction with the picker. */
|
|
30
|
+
disabled?: boolean
|
|
31
|
+
/** Spoken name for assistive tech. */
|
|
32
|
+
accessibilityLabel?: string
|
|
33
|
+
/** Called when the user picks a new date; programmatic `selection` updates do not emit. */
|
|
34
|
+
onSelectionChange?: (date: Date) => void
|
|
26
35
|
}
|
package/src/macos/index.ts
CHANGED
package/src/macos/types.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
+
/** AppKit picker component slots. */
|
|
1
2
|
export type AppKitDatePickerComponents = 'date' | 'time' | 'dateAndTime'
|
|
2
3
|
|
|
4
|
+
/** macOS date-picker style. */
|
|
3
5
|
export type AppKitDatePickerStyle = 'textField' | 'graphical'
|
|
4
6
|
|
|
7
|
+
/** macOS date-picker props (NSDatePicker). */
|
|
5
8
|
export interface AppKitDatePickerProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
/** Element id passed through to the host element. */
|
|
10
|
+
id?: string
|
|
11
|
+
/** Class list applied to the picker element. */
|
|
12
|
+
className?: any
|
|
13
|
+
/** Inline style (string CSS or object). */
|
|
14
|
+
style?: any
|
|
15
|
+
/** Which element groups the NSDatePicker shows. @default 'date' */
|
|
16
|
+
components?: AppKitDatePickerComponents
|
|
17
|
+
/** 'graphical' embeds the inline calendar (date mode only). @default 'textField' */
|
|
18
|
+
pickerStyle?: AppKitDatePickerStyle
|
|
19
|
+
/** Controlled selection. Pair with `onSelectionChange`. */
|
|
20
|
+
selection?: Date
|
|
21
|
+
/** Initial uncontrolled seed. Later defaults do not reset the mounted picker. */
|
|
22
|
+
defaultSelection?: Date
|
|
23
|
+
/** Earliest selectable date. */
|
|
24
|
+
minimumDate?: Date
|
|
25
|
+
/** Latest selectable date. */
|
|
26
|
+
maximumDate?: Date
|
|
27
|
+
/** Disables interaction with the picker. */
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
/** Spoken name for assistive tech. */
|
|
30
|
+
accessibilityLabel?: string
|
|
31
|
+
/** User selection changes; programmatic updates and retired controls do not emit. */
|
|
32
|
+
onSelectionChange?: (date: Date) => void
|
|
24
33
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const kebab = (key: string) => key.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase())
|
|
2
|
+
|
|
3
|
+
/** Anything accepted as a style value, including nested arrays. */
|
|
4
|
+
export type StyleInput = string | Record<string, any> | null | undefined | readonly StyleInput[]
|
|
5
|
+
|
|
6
|
+
/** Merge component-emitted style defaults under the authored `style` prop.
|
|
7
|
+
* Authored keys win; array styles fold in order; a string style is appended
|
|
8
|
+
* after the serialized defaults so its declarations override them too. */
|
|
9
|
+
export function mergeStyle(
|
|
10
|
+
base: Record<string, any>,
|
|
11
|
+
style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null,
|
|
12
|
+
): Record<string, any>
|
|
13
|
+
|
|
14
|
+
export function mergeStyle(
|
|
15
|
+
base: Record<string, any>,
|
|
16
|
+
style?: StyleInput,
|
|
17
|
+
): string | Record<string, any>
|
|
18
|
+
|
|
19
|
+
export function mergeStyle(
|
|
20
|
+
base: Record<string, any>,
|
|
21
|
+
style?: StyleInput,
|
|
22
|
+
): string | Record<string, any> {
|
|
23
|
+
if (style == null) {
|
|
24
|
+
return base
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let obj: Record<string, any> = { ...base }
|
|
28
|
+
const strings: string[] = []
|
|
29
|
+
const add = (s: StyleInput) => {
|
|
30
|
+
if (s == null) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof s === 'string') {
|
|
35
|
+
strings.push(s)
|
|
36
|
+
} else if (Array.isArray(s)) {
|
|
37
|
+
for (const part of s) {
|
|
38
|
+
add(part)
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
obj = { ...obj, ...s }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
add(style)
|
|
46
|
+
|
|
47
|
+
if (strings.length === 0) {
|
|
48
|
+
return obj
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const prefix = Object.entries(obj)
|
|
52
|
+
.filter(([, v]) => v != null)
|
|
53
|
+
.map(([k, v]) => `${kebab(k)}:${v}`)
|
|
54
|
+
.join(';')
|
|
55
|
+
|
|
56
|
+
return [prefix, ...strings].filter(Boolean).join(';')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type StyleProp = string | Record<string, any> | readonly StyleProp[] | null | undefined
|