@coreui/vue-pro 4.5.0 → 4.7.0-alpha.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.
Files changed (60) hide show
  1. package/dist/components/Types.d.ts +5 -5
  2. package/dist/components/calendar/CCalendar.d.ts +41 -3
  3. package/dist/components/date-picker/CDatePicker.d.ts +43 -4
  4. package/dist/components/date-range-picker/CDateRangePicker.d.ts +191 -4
  5. package/dist/components/form/CFormInput.d.ts +166 -1
  6. package/dist/components/form/CFormSelect.d.ts +1 -1
  7. package/dist/components/grid/CCol.d.ts +3 -3
  8. package/dist/components/grid/CRow.d.ts +1 -1
  9. package/dist/components/index.d.ts +1 -0
  10. package/dist/components/multi-select/CMultiSelect.d.ts +143 -4
  11. package/dist/components/multi-select/CMultiSelectOptions.d.ts +11 -0
  12. package/dist/components/multi-select/CMultiSelectSelection.d.ts +3 -3
  13. package/dist/components/pagination/index.d.ts +1 -2
  14. package/dist/components/picker/CPicker.d.ts +1 -1
  15. package/dist/components/popover/CPopover.d.ts +1 -1
  16. package/dist/components/smart-pagination/CSmartPagination.d.ts +257 -0
  17. package/dist/components/smart-pagination/index.d.ts +6 -0
  18. package/dist/components/smart-table/CSmartTable.d.ts +6 -4
  19. package/dist/components/smart-table/CSmartTableFilter.d.ts +2 -2
  20. package/dist/components/smart-table/CSmartTableHead.d.ts +2 -2
  21. package/dist/components/smart-table/CSmartTableInterface.d.ts +4 -1
  22. package/dist/components/table/CTable.d.ts +1 -1
  23. package/dist/components/table/CTableCaption.d.ts +2 -8
  24. package/dist/components/time-picker/CTimePicker.d.ts +2 -1
  25. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  26. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  27. package/dist/index.es.js +1560 -1017
  28. package/dist/index.es.js.map +1 -1
  29. package/dist/index.js +1559 -1015
  30. package/dist/index.js.map +1 -1
  31. package/dist/utils/getNextSibling.d.ts +2 -0
  32. package/dist/utils/getPreviousSibling.d.ts +2 -0
  33. package/dist/utils/index.d.ts +4 -0
  34. package/dist/utils/isVisible.d.ts +2 -0
  35. package/dist/utils/time.d.ts +2 -2
  36. package/package.json +2 -2
  37. package/src/components/calendar/CCalendar.ts +46 -4
  38. package/src/components/carousel/CCarousel.ts +1 -9
  39. package/src/components/date-picker/CDatePicker.ts +44 -3
  40. package/src/components/date-range-picker/CDateRangePicker.ts +340 -170
  41. package/src/components/form/CFormInput.ts +2 -0
  42. package/src/components/index.ts +1 -0
  43. package/src/components/loading-button/CLoadingButton.ts +1 -2
  44. package/src/components/multi-select/CMultiSelect.ts +295 -173
  45. package/src/components/multi-select/CMultiSelectOptions.ts +48 -10
  46. package/src/components/multi-select/CMultiSelectSelection.ts +1 -1
  47. package/src/components/pagination/index.ts +1 -3
  48. package/src/components/sidebar/CSidebar.ts +2 -10
  49. package/src/components/{pagination → smart-pagination}/CSmartPagination.ts +1 -2
  50. package/src/components/smart-pagination/index.ts +10 -0
  51. package/src/components/smart-table/CSmartTable.ts +10 -5
  52. package/src/components/smart-table/CSmartTableInterface.ts +4 -0
  53. package/src/components/table/CTableCaption.ts +0 -1
  54. package/src/components/time-picker/CTimePicker.ts +198 -64
  55. package/src/components/time-picker/CTimePickerRollCol.ts +9 -0
  56. package/src/utils/getNextSibling.ts +18 -0
  57. package/src/utils/getPreviousSibling.ts +18 -0
  58. package/src/utils/index.ts +5 -0
  59. package/src/utils/isVisible.ts +11 -0
  60. package/src/utils/time.ts +14 -6
@@ -1,19 +1,11 @@
1
1
  import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue'
2
2
  import { CBackdrop } from '../backdrop'
3
3
 
4
+ import { isVisible } from './../../utils'
5
+
4
6
  const isOnMobile = (element: HTMLDivElement) =>
5
7
  Boolean(getComputedStyle(element).getPropertyValue('--cui-is-mobile'))
6
8
 
7
- const isVisible = (element: HTMLDivElement) => {
8
- const rect = element.getBoundingClientRect()
9
- return (
10
- rect.top >= 0 &&
11
- rect.left >= 0 &&
12
- rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
13
- rect.right <= (window.innerWidth || document.documentElement.clientWidth)
14
- )
15
- }
16
-
17
9
  const CSidebar = defineComponent({
18
10
  name: 'CSidebar',
19
11
  props: {
@@ -1,7 +1,6 @@
1
1
  import { computed, defineComponent, h, ref, watch } from 'vue'
2
2
 
3
- import { CPagination } from './CPagination'
4
- import { CPaginationItem } from './CPaginationItem'
3
+ import { CPagination, CPaginationItem } from './../pagination'
5
4
 
6
5
  const CSmartPagination = defineComponent({
7
6
  name: 'CSmartPagination',
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CSmartPagination } from './CSmartPagination'
3
+
4
+ const CSmartPaginationPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CSmartPagination.name, CSmartPagination)
7
+ },
8
+ }
9
+
10
+ export { CSmartPaginationPlugin, CSmartPagination }
@@ -1,7 +1,7 @@
1
1
  import { computed, defineComponent, h, reactive, ref, PropType, watch, onMounted } from 'vue'
2
2
 
3
- import { CSmartPagination } from '../pagination/CSmartPagination'
4
3
  import { CElementCover } from '../element-cover/CElementCover'
4
+ import { CSmartPagination } from '../smart-pagination/CSmartPagination'
5
5
 
6
6
  import { CTable } from '../table/CTable'
7
7
 
@@ -21,6 +21,7 @@ import {
21
21
  ColumnFilterValue,
22
22
  Item,
23
23
  ItemsPerPageSelect,
24
+ Pagination,
24
25
  Sorter,
25
26
  SorterValue,
26
27
  TableFilter,
@@ -133,6 +134,7 @@ const CSmartTable = defineComponent({
133
134
  */
134
135
  itemsPerPage: {
135
136
  type: Number,
137
+ default: 10,
136
138
  required: false,
137
139
  },
138
140
  /**
@@ -181,7 +183,7 @@ const CSmartTable = defineComponent({
181
183
  * Enables default pagination. Set to true for default setup or pass an object with additional CPagination props. Default pagination will always have the computed number of pages that cannot be changed. The number of pages is generated based on the number of passed items and 'itemsPerPage' prop. If this restriction is an obstacle, you can make external CPagination instead.
182
184
  */
183
185
  pagination: {
184
- type: Boolean,
186
+ type: [Boolean, Object] as PropType<boolean | Pagination>,
185
187
  required: false,
186
188
  },
187
189
  /**
@@ -789,12 +791,15 @@ const CSmartTable = defineComponent({
789
791
  {
790
792
  class: 'col',
791
793
  },
792
- props.pagination && numberOfPages.value > 1
794
+ (props.pagination && numberOfPages.value > 1) || props.paginationProps
793
795
  ? h(CSmartPagination, {
794
- ...props.paginationProps,
795
796
  pages: numberOfPages.value,
796
797
  activePage: activePage.value,
797
- onActivePageChange: handleActivePageChange,
798
+ ...props.paginationProps,
799
+ onActivePageChange: (page) =>
800
+ typeof props.pagination === 'object' && props.pagination.external
801
+ ? emit('activePageChange', page)
802
+ : handleActivePageChange(page),
798
803
  })
799
804
  : '',
800
805
  ),
@@ -38,6 +38,10 @@ export interface ItemsPerPageSelect {
38
38
  values?: Array<number>
39
39
  }
40
40
 
41
+ export interface Pagination {
42
+ external?: boolean
43
+ }
44
+
41
45
  export interface Sorter {
42
46
  resetable?: boolean
43
47
  external?: boolean
@@ -2,7 +2,6 @@ import { defineComponent, h } from 'vue'
2
2
 
3
3
  const CTableCaption = defineComponent({
4
4
  name: 'CTableCaption',
5
- props: {},
6
5
  setup(_, { slots }) {
7
6
  return () => h('caption', {}, slots.default && slots.default())
8
7
  },
@@ -1,6 +1,7 @@
1
1
  import { defineComponent, h, ref, watch } from 'vue'
2
2
 
3
3
  import { CFormInput, CFormSelect, CInputGroup, CInputGroupText } from '../form/'
4
+ import { CFormControlWrapper } from './../form/CFormControlWrapper'
4
5
  import { CPicker } from '../picker'
5
6
  import { CTimePickerRollCol } from './CTimePickerRollCol'
6
7
 
@@ -24,6 +25,24 @@ const CTimePicker = defineComponent({
24
25
  name: 'CTimePicker',
25
26
  props: {
26
27
  ...CPicker.props,
28
+ /**
29
+ * Set if the component should use the 12/24 hour format. If `true` forces the interface to a 12-hour format. If `false` forces the interface into a 24-hour format. If `auto` the current locale will determine the 12 or 24-hour interface by default locales.
30
+ *
31
+ * @since 4.7.0
32
+ */
33
+ ampm: {
34
+ type: [Boolean, String],
35
+ default: 'auto',
36
+ validator: (value: boolean | string) => {
37
+ if (typeof value == 'string') {
38
+ return ['auto'].includes(value)
39
+ }
40
+ if (typeof value == 'boolean') {
41
+ return true
42
+ }
43
+ return false
44
+ },
45
+ },
27
46
  /**
28
47
  * Toggle visibility or set the content of cancel button.
29
48
  */
@@ -110,6 +129,34 @@ const CTimePicker = defineComponent({
110
129
  return ['ghost', 'outline'].includes(value)
111
130
  },
112
131
  },
132
+ /**
133
+ * Provide valuable, actionable feedback.
134
+ *
135
+ * @since 4.6.0
136
+ */
137
+ feedback: {
138
+ type: String,
139
+ },
140
+ /**
141
+ * Provide valuable, actionable feedback.
142
+ *
143
+ * @since 4.6.0
144
+ */
145
+ feedbackInvalid: {
146
+ type: String,
147
+ },
148
+ /**
149
+ * Provide valuable, actionable invalid feedback when using standard HTML form validation which applied two CSS pseudo-classes, `:invalid` and `:valid`.
150
+ *
151
+ * @since 4.6.0
152
+ */
153
+ feedbackValid: {
154
+ type: String,
155
+ },
156
+ /**
157
+ * The id global attribute defines an identifier (ID) that must be unique in the whole document.
158
+ */
159
+ id: String,
113
160
  /**
114
161
  * Toggle visibility or set the content of the input indicator.
115
162
  */
@@ -121,6 +168,20 @@ const CTimePicker = defineComponent({
121
168
  * Toggle the readonly state for the component.
122
169
  */
123
170
  inputReadOnly: Boolean,
171
+ /**
172
+ * Set component validation state to invalid.
173
+ *
174
+ * @since 4.6.0
175
+ */
176
+ invalid: Boolean,
177
+ /**
178
+ * Add a caption for a component.
179
+ *
180
+ * @since 4.6.0
181
+ */
182
+ label: {
183
+ type: String,
184
+ },
124
185
  /**
125
186
  * Sets the default locale for components. If not set, it is inherited from the navigator.language.
126
187
  */
@@ -135,6 +196,15 @@ const CTimePicker = defineComponent({
135
196
  type: String,
136
197
  default: 'Select time',
137
198
  },
199
+ /**
200
+ * Show seconds.
201
+ *
202
+ * @since 4.7.0
203
+ */
204
+ seconds: {
205
+ type: Boolean,
206
+ default: true,
207
+ },
138
208
  /**
139
209
  * Size the component small or large.
140
210
  *
@@ -147,12 +217,32 @@ const CTimePicker = defineComponent({
147
217
  return ['sm', 'lg'].includes(value)
148
218
  },
149
219
  },
220
+ /**
221
+ * Add helper text to the component.
222
+ *
223
+ * @since 4.6.0
224
+ */
225
+ text: {
226
+ type: String,
227
+ },
150
228
  /**
151
229
  * Initial selected time.
152
230
  */
153
231
  time: {
154
232
  type: [Date, String],
155
233
  },
234
+ /**
235
+ * Display validation feedback in a styled tooltip.
236
+ *
237
+ * @since 4.6.0
238
+ */
239
+ tooltipFeedback: Boolean,
240
+ /**
241
+ * Set component validation state to valid.
242
+ *
243
+ * @since 4.6.0
244
+ */
245
+ valid: Boolean,
156
246
  /**
157
247
  * Set the time picker variant to a roll or select.
158
248
  *
@@ -165,6 +255,10 @@ const CTimePicker = defineComponent({
165
255
  return ['roll', 'select'].includes(value)
166
256
  },
167
257
  },
258
+ /**
259
+ * Toggle the visibility of the component.
260
+ */
261
+ visible: Boolean,
168
262
  },
169
263
  emits: [
170
264
  /**
@@ -179,8 +273,15 @@ const CTimePicker = defineComponent({
179
273
  * Callback fired when the component requests to be shown.
180
274
  */
181
275
  'show',
276
+ /**
277
+ * Callback fired when the time changed.
278
+ *
279
+ * @since 4.7.0
280
+ */
281
+ 'update:time',
182
282
  ],
183
- setup(props, { emit, slots }) {
283
+ setup(props, { emit, attrs, slots }) {
284
+ const visible = ref(props.visible)
184
285
  const date = ref<Date | null>(convertTimeToDate(props.time))
185
286
  const initialDate = ref<Date | null>(null)
186
287
  const ampm = ref<'am' | 'pm'>(date.value ? getAmPm(new Date(date.value), props.locale) : 'am')
@@ -201,6 +302,8 @@ const CTimePicker = defineComponent({
201
302
  const handleClear = (event: Event) => {
202
303
  event.stopPropagation()
203
304
  date.value = null
305
+ emit('change', null)
306
+ emit('update:time', null)
204
307
  }
205
308
 
206
309
  const handleTimeChange = (set: 'hours' | 'minutes' | 'seconds' | 'toggle', value: string) => {
@@ -216,7 +319,7 @@ const CTimePicker = defineComponent({
216
319
  }
217
320
 
218
321
  if (set === 'hours') {
219
- if (isAmPm(props.locale)) {
322
+ if ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) {
220
323
  _date.setHours(convert12hTo24h(ampm.value, parseInt(value)))
221
324
  } else {
222
325
  _date.setHours(parseInt(value))
@@ -232,7 +335,8 @@ const CTimePicker = defineComponent({
232
335
  }
233
336
 
234
337
  date.value = new Date(_date)
235
- emit('change', _date.toTimeString(), _date.toLocaleTimeString(), _date)
338
+ emit('change', _date.toTimeString(), _date.toLocaleTimeString(props.locale), _date)
339
+ emit('update:time', _date.toLocaleTimeString(props.locale))
236
340
  }
237
341
 
238
342
  const InputGroup = () =>
@@ -247,7 +351,13 @@ const CTimePicker = defineComponent({
247
351
  },
248
352
  placeholder: props.placeholder,
249
353
  readonly: props.inputReadOnly,
250
- value: date.value ? date.value.toLocaleTimeString(props.locale) : '',
354
+ value: date.value
355
+ ? date.value.toLocaleTimeString(props.locale, {
356
+ hour12:
357
+ (props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm ? true : false,
358
+ ...(!props.seconds && { timeStyle: 'short' }),
359
+ })
360
+ : '',
251
361
  }),
252
362
  (props.indicator || props.cleaner) &&
253
363
  h(CInputGroupText, {}, () => [
@@ -298,15 +408,16 @@ const CTimePicker = defineComponent({
298
408
  handleTimeChange('minutes', (event.target as HTMLSelectElement).value),
299
409
  ...(date.value && { value: getSelectedMinutes(date.value) }),
300
410
  }),
301
- ':',
302
- // @ts-expect-error the getListOfMinutes function returns corect type
303
- h(CFormSelect, {
304
- disabled: props.disabled,
305
- options: getListOfSeconds(props.locale, true),
306
- onChange: (event: Event) =>
307
- handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
308
- ...(date.value && { value: getSelectedSeconds(date.value) }),
309
- }),
411
+ props.seconds && ':',
412
+ props.seconds &&
413
+ // @ts-expect-error the getListOfMinutes function returns corect type
414
+ h(CFormSelect, {
415
+ disabled: props.disabled,
416
+ options: getListOfSeconds(props.locale, true),
417
+ onChange: (event: Event) =>
418
+ handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
419
+ ...(date.value && { value: getSelectedSeconds(date.value) }),
420
+ }),
310
421
  isAmPm(props.locale) &&
311
422
  h(CFormSelect, {
312
423
  disabled: props.disabled,
@@ -321,21 +432,22 @@ const CTimePicker = defineComponent({
321
432
 
322
433
  const TimePickerRoll = () => [
323
434
  h(CTimePickerRollCol, {
324
- elements: getListOfHours(props.locale),
435
+ elements: getListOfHours(props.locale, props.ampm),
325
436
  onClick: (index: number) => handleTimeChange('hours', index.toString()),
326
- selected: getSelectedHour(date.value, props.locale),
437
+ selected: getSelectedHour(date.value, props.locale, props.ampm),
327
438
  }),
328
439
  h(CTimePickerRollCol, {
329
440
  elements: getListOfMinutes(props.locale),
330
441
  onClick: (index: number) => handleTimeChange('minutes', index.toString()),
331
442
  selected: getSelectedMinutes(date.value),
332
443
  }),
333
- h(CTimePickerRollCol, {
334
- elements: getListOfSeconds(props.locale),
335
- onClick: (index: number) => handleTimeChange('seconds', index.toString()),
336
- selected: getSelectedSeconds(date.value),
337
- }),
338
- isAmPm(props.locale) &&
444
+ props.seconds &&
445
+ h(CTimePickerRollCol, {
446
+ elements: getListOfSeconds(props.locale),
447
+ onClick: (index: number) => handleTimeChange('seconds', index.toString()),
448
+ selected: getSelectedSeconds(date.value),
449
+ }),
450
+ ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) &&
339
451
  h(CTimePickerRollCol, {
340
452
  elements: [
341
453
  { value: 'am', label: 'AM' },
@@ -348,56 +460,78 @@ const CTimePicker = defineComponent({
348
460
 
349
461
  return () =>
350
462
  h(
351
- CPicker,
463
+ CFormControlWrapper,
352
464
  {
353
- cancelButton: props.cancelButton,
354
- cancelButtonColor: props.cancelButtonColor,
355
- cancelButtonSize: props.cancelButtonSize,
356
- cancelButtonVariant: props.cancelButtonVariant,
357
- class: 'time-picker',
358
- confirmButton: props.confirmButton,
359
- confirmButtonColor: props.confirmButtonColor,
360
- confirmButtonSize: props.confirmButtonSize,
361
- confirmButtonVariant: props.confirmButtonVariant,
362
- container: props.container,
363
- disabled: props.disabled,
364
- footer: true,
365
- onCancel: () => {
366
- if (initialDate.value) {
367
- date.value = new Date(initialDate.value)
368
- }
369
- },
370
- onHide: () => {
371
- emit('hide')
372
- },
373
- onShow: () => {
374
- if (date.value) {
375
- initialDate.value = new Date(date.value)
376
- }
377
-
378
- emit('show')
379
- },
465
+ describedby: attrs['aria-describedby'],
466
+ feedback: props.feedback,
467
+ feedbackInvalid: props.feedbackInvalid,
468
+ feedbackValid: props.feedbackValid,
469
+ id: props.id,
470
+ invalid: props.invalid,
471
+ label: props.label,
472
+ text: props.text,
473
+ tooltipFeedback: props.tooltipFeedback,
474
+ valid: props.valid,
380
475
  },
381
476
  {
382
- ...(slots.cancelButton && {
383
- cancelButton: () => slots.cancelButton && slots.cancelButton(),
384
- }),
385
- ...(slots.confirmButton && {
386
- confirmButton: () => slots.confirmButton && slots.confirmButton(),
387
- }),
388
- toggler: () => InputGroup(),
389
477
  default: () =>
390
478
  h(
391
- 'div',
479
+ CPicker,
480
+ {
481
+ cancelButton: props.cancelButton,
482
+ cancelButtonColor: props.cancelButtonColor,
483
+ cancelButtonSize: props.cancelButtonSize,
484
+ cancelButtonVariant: props.cancelButtonVariant,
485
+ class: ['time-picker', { 'is-invalid': props.invalid, 'is-valid': props.valid }],
486
+ confirmButton: props.confirmButton,
487
+ confirmButtonColor: props.confirmButtonColor,
488
+ confirmButtonSize: props.confirmButtonSize,
489
+ confirmButtonVariant: props.confirmButtonVariant,
490
+ container: props.container,
491
+ disabled: props.disabled,
492
+ footer: true,
493
+ onCancel: () => {
494
+ if (initialDate.value) {
495
+ date.value = new Date(initialDate.value)
496
+ }
497
+ visible.value = false
498
+ },
499
+ onHide: () => {
500
+ visible.value = false
501
+ emit('hide')
502
+ },
503
+ onShow: () => {
504
+ if (date.value) {
505
+ initialDate.value = new Date(date.value)
506
+ }
507
+
508
+ visible.value = true
509
+ emit('show')
510
+ },
511
+ visible: visible.value,
512
+ },
392
513
  {
393
- class: [
394
- 'time-picker-body',
395
- {
396
- ['time-picker-roll']: props.variant === 'roll',
397
- },
398
- ],
514
+ ...(slots.cancelButton && {
515
+ cancelButton: () => slots.cancelButton && slots.cancelButton(),
516
+ }),
517
+ ...(slots.confirmButton && {
518
+ confirmButton: () => slots.confirmButton && slots.confirmButton(),
519
+ }),
520
+ toggler: () => InputGroup(),
521
+ default: () =>
522
+ h(
523
+ 'div',
524
+ {
525
+ class: [
526
+ 'time-picker-body',
527
+ {
528
+ ['time-picker-roll']: props.variant === 'roll',
529
+ },
530
+ ],
531
+ },
532
+ props.variant === 'select' ? TimePickerSelect() : TimePickerRoll(),
533
+ ),
399
534
  },
400
- props.variant === 'select' ? TimePickerSelect() : TimePickerRoll(),
401
535
  ),
402
536
  },
403
537
  )
@@ -32,6 +32,13 @@ const CTimePickerRollCol = defineComponent({
32
32
  init.value = false
33
33
  })
34
34
 
35
+ const handleKeyDown = (event: KeyboardEvent, value: number | string) => {
36
+ if (event.code === 'Space' || event.key === 'Enter') {
37
+ event.preventDefault()
38
+ emit('click', value)
39
+ }
40
+ }
41
+
35
42
  return () =>
36
43
  h(
37
44
  'div',
@@ -47,7 +54,9 @@ const CTimePickerRollCol = defineComponent({
47
54
  },
48
55
  ],
49
56
  onClick: () => emit('click', element.value),
57
+ onKeydown: (event: KeyboardEvent) => handleKeyDown(event, element.value),
50
58
  role: 'button',
59
+ tabindex: 0,
51
60
  },
52
61
  element.label,
53
62
  )
@@ -0,0 +1,18 @@
1
+ const getNextSibling = (elem: HTMLElement, selector?: string) => {
2
+ // Get the next sibling element
3
+ let sibling = elem.nextElementSibling
4
+
5
+ // If there's no selector, return the first sibling
6
+ if (!selector) return sibling
7
+
8
+ // If the sibling matches our selector, use it
9
+ // If not, jump to the next sibling and continue the loop
10
+ while (sibling) {
11
+ if (sibling.matches(selector)) return sibling
12
+ sibling = sibling.nextElementSibling
13
+ }
14
+
15
+ return
16
+ }
17
+
18
+ export default getNextSibling
@@ -0,0 +1,18 @@
1
+ const getPreviousSibling = (elem: HTMLElement, selector?: string) => {
2
+ // Get the next sibling element
3
+ let sibling = elem.previousElementSibling
4
+
5
+ // If there's no selector, return the first sibling
6
+ if (!selector) return sibling
7
+
8
+ // If the sibling matches our selector, use it
9
+ // If not, jump to the next sibling and continue the loop
10
+ while (sibling) {
11
+ if (sibling.matches(selector)) return sibling
12
+ sibling = sibling.previousElementSibling
13
+ }
14
+
15
+ return
16
+ }
17
+
18
+ export default getPreviousSibling
@@ -0,0 +1,5 @@
1
+ import getNextSibling from './getNextSibling'
2
+ import getPreviousSibling from './getPreviousSibling'
3
+ import isVisible from './isVisible'
4
+
5
+ export { getNextSibling, getPreviousSibling, isVisible }
@@ -0,0 +1,11 @@
1
+ const isVisible = (element: HTMLElement) => {
2
+ const rect = element.getBoundingClientRect()
3
+ return (
4
+ rect.top >= 0 &&
5
+ rect.left >= 0 &&
6
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
7
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth)
8
+ )
9
+ }
10
+
11
+ export default isVisible
package/src/utils/time.ts CHANGED
@@ -26,11 +26,11 @@ export const getAmPm = (date: Date, locale: string) => {
26
26
  return date.getHours() >= 12 ? 'pm' : 'am'
27
27
  }
28
28
 
29
- export const getListOfHours = (locale: string) =>
30
- Array.from({ length: isAmPm(locale) ? 12 : 24 }, (_, i) => {
29
+ export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto') =>
30
+ Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm ? 12 : 24 }, (_, i) => {
31
31
  return {
32
- value: isAmPm(locale) ? i + 1 : i,
33
- label: (isAmPm(locale) ? i + 1 : i).toLocaleString(locale),
32
+ value: (ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i,
33
+ label: ((ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i).toLocaleString(locale),
34
34
  }
35
35
  })
36
36
 
@@ -68,8 +68,16 @@ export const getListOfSeconds = (locale: string, valueAsString = false) =>
68
68
  }
69
69
  })
70
70
 
71
- export const getSelectedHour = (date: Date | null, locale: string) =>
72
- date ? (isAmPm(locale) ? convert24hTo12h(date.getHours()) : date.getHours()) : ''
71
+ export const getSelectedHour = (
72
+ date: Date | null,
73
+ locale: string,
74
+ ampm: 'auto' | boolean = 'auto',
75
+ ) =>
76
+ date
77
+ ? (ampm === 'auto' && isAmPm(locale)) || ampm
78
+ ? convert24hTo12h(date.getHours())
79
+ : date.getHours()
80
+ : ''
73
81
 
74
82
  export const getSelectedMinutes = (date: Date | null) => (date ? date.getMinutes() : '')
75
83