@coreui/vue-pro 4.7.0-alpha.1 → 4.8.0-next.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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/components/calendar/utils.d.ts +23 -0
  3. package/dist/components/element-cover/CElementCover.d.ts +14 -11
  4. package/dist/components/modal/CModal.d.ts +4 -20
  5. package/dist/components/offcanvas/COffcanvas.d.ts +35 -18
  6. package/dist/components/smart-table/CSmartTable.d.ts +83 -94
  7. package/dist/components/smart-table/CSmartTableBody.d.ts +16 -40
  8. package/dist/components/smart-table/CSmartTableHead.d.ts +20 -61
  9. package/dist/components/smart-table/CSmartTableInterface.d.ts +5 -1
  10. package/dist/components/smart-table/types.d.ts +50 -0
  11. package/dist/components/smart-table/utils.d.ts +17 -0
  12. package/dist/components/table/CTable.d.ts +5 -11
  13. package/dist/components/time-picker/types.d.ts +15 -0
  14. package/dist/components/time-picker/utils.d.ts +23 -0
  15. package/dist/index.es.js +1114 -4423
  16. package/dist/index.es.js.map +1 -1
  17. package/dist/index.js +1115 -4424
  18. package/dist/index.js.map +1 -1
  19. package/dist/utils/calendar.d.ts +2 -2
  20. package/dist/utils/index.d.ts +2 -2
  21. package/dist/utils/isInViewport.d.ts +2 -0
  22. package/dist/utils/isObjectInArray.d.ts +2 -0
  23. package/package.json +10 -14
  24. package/src/components/calendar/CCalendar.ts +1 -1
  25. package/src/{utils/calendar.ts → components/calendar/utils.ts} +3 -3
  26. package/src/components/carousel/CCarousel.ts +3 -3
  27. package/src/components/date-range-picker/CDateRangePicker.ts +1 -1
  28. package/src/components/element-cover/CElementCover.ts +45 -30
  29. package/src/components/form/CFormControlWrapper.ts +36 -22
  30. package/src/components/modal/CModal.ts +10 -10
  31. package/src/components/multi-select/CMultiSelect.ts +0 -10
  32. package/src/components/offcanvas/COffcanvas.ts +50 -28
  33. package/src/components/sidebar/CSidebar.ts +5 -5
  34. package/src/components/smart-table/CSmartTable.ts +409 -272
  35. package/src/components/smart-table/CSmartTableBody.ts +126 -137
  36. package/src/components/smart-table/CSmartTableHead.ts +54 -139
  37. package/src/components/smart-table/CSmartTableInterface.ts +7 -1
  38. package/src/components/smart-table/types.ts +61 -0
  39. package/src/components/smart-table/utils.ts +212 -0
  40. package/src/components/table/CTable.ts +45 -42
  41. package/src/components/time-picker/CTimePicker.ts +49 -26
  42. package/src/components/time-picker/types.ts +15 -0
  43. package/src/{utils/time.ts → components/time-picker/utils.ts} +49 -10
  44. package/src/utils/index.ts +2 -2
  45. package/src/utils/isInViewport.ts +11 -0
  46. package/src/utils/isVisible.ts +0 -11
@@ -0,0 +1,212 @@
1
+ import type {
2
+ Column,
3
+ ColumnFilter,
4
+ ColumnFilterValue,
5
+ Item,
6
+ Sorter,
7
+ SorterValue,
8
+ TableFilter,
9
+ } from './types'
10
+
11
+ export const filterColumns = (
12
+ items: Item[],
13
+ columnFilter: boolean | ColumnFilter | undefined,
14
+ columnFilterState: ColumnFilterValue,
15
+ itemsDataColumns: string[],
16
+ ) => {
17
+ if (columnFilter && typeof columnFilter === 'object' && columnFilter.external) {
18
+ return items
19
+ }
20
+
21
+ Object.entries(columnFilterState).forEach(([key, value]) => {
22
+ if (value instanceof Function) {
23
+ items = items.filter((item) => value(item[key]))
24
+ return
25
+ }
26
+
27
+ const columnFilter = String(value).toLowerCase()
28
+ if (columnFilter && itemsDataColumns.includes(key)) {
29
+ items = items.filter((item) => {
30
+ return String(item[key]).toLowerCase().includes(columnFilter)
31
+ })
32
+ }
33
+ })
34
+
35
+ return items
36
+ }
37
+
38
+ export const filterTable = (
39
+ items: Item[],
40
+ tableFilter: boolean | TableFilter | undefined,
41
+ tableFilterState: string,
42
+ itemsDataColumns: string[],
43
+ ) => {
44
+ if (
45
+ !tableFilterState ||
46
+ (tableFilter && typeof tableFilter === 'object' && tableFilter.external)
47
+ ) {
48
+ return items
49
+ }
50
+
51
+ const filter = tableFilterState.toLowerCase()
52
+ const valueContainFilter = (val: any) => String(val).toLowerCase().includes(filter)
53
+ items = items.filter((item) => {
54
+ return !!itemsDataColumns.find((key) => valueContainFilter(item[key]))
55
+ })
56
+
57
+ return items
58
+ }
59
+
60
+ export const getClickedColumnName = (
61
+ target: HTMLTextAreaElement,
62
+ columnNames: string[],
63
+ ): string => {
64
+ const closest = target.closest('tr')
65
+ const children = closest ? Array.from(closest.children) : []
66
+ const clickedCell = children.filter((child) => child.contains(target))[0]
67
+ return columnNames[children.indexOf(clickedCell)]
68
+ }
69
+
70
+ export const getColumnKey = (column: Column | string) =>
71
+ typeof column === 'object' ? column.key : column
72
+
73
+ export const getColumnLabel = (column: Column | string) =>
74
+ typeof column === 'object'
75
+ ? column.label !== undefined
76
+ ? column.label
77
+ : pretifyName(column.key)
78
+ : pretifyName(column)
79
+
80
+ export const getColumnNames = (columns: (string | Column)[] | undefined, items: Item[]) =>
81
+ columns
82
+ ? columns.map((column: Column | string) => {
83
+ if (typeof column === 'object') return column.key
84
+ else return column
85
+ })
86
+ : getColumnNamesFromItems(items)
87
+
88
+ export const getColumnNamesFromItems = (items: Item[]) =>
89
+ Object.keys(items[0] || {}).filter((el) => el.charAt(0) !== '_')
90
+
91
+ export const getColumnSorterState = (
92
+ key: string,
93
+ sorterState: SorterValue | undefined,
94
+ ): string | number => {
95
+ if (sorterState && sorterState.column === key) {
96
+ if (sorterState.state) {
97
+ return sorterState.state
98
+ }
99
+ return 0
100
+ }
101
+
102
+ return 0
103
+ }
104
+
105
+ export const getColumnValues = (items: Item[], key: string) => {
106
+ return items.map((item) => item[key])
107
+ }
108
+
109
+ export const getTableDataCellProps = (item: Item, colName: string) => {
110
+ const props = item._cellProps && {
111
+ ...(item._cellProps['all'] && { ...item._cellProps['all'] }),
112
+ ...(item._cellProps[colName] && { ...item._cellProps[colName] }),
113
+ }
114
+
115
+ return props
116
+ }
117
+
118
+ export const getTableHeaderCellProps = (column: Column | string) => {
119
+ if (typeof column === 'object' && column._props) {
120
+ return column._props
121
+ }
122
+
123
+ return {}
124
+ }
125
+
126
+ export const getTableHeaderCellStyles = (
127
+ column: Column | string,
128
+ columnSorter: boolean | Sorter | undefined,
129
+ ) => {
130
+ const style = {}
131
+
132
+ if (
133
+ columnSorter &&
134
+ (typeof column !== 'object' ||
135
+ (typeof column === 'object' && (typeof column.sorter === 'undefined' || column.sorter)))
136
+ ) {
137
+ style['cursor'] = 'pointer'
138
+ }
139
+
140
+ if (typeof column === 'object' && column._style) {
141
+ return { ...style, ...column._style }
142
+ }
143
+ return style
144
+ }
145
+
146
+ export const isObjectInArray = <T>(array: T[], item: T, ignore: string[] = []) =>
147
+ array.some((_item: T) => {
148
+ let result = true
149
+ for (const key in item) {
150
+ if (!ignore.includes(key) && item[key] !== _item[key]) {
151
+ result = false
152
+ break
153
+ }
154
+ }
155
+
156
+ return result
157
+ })
158
+
159
+ export const isSortable = (
160
+ i: number,
161
+ columns: (string | Column)[] | undefined,
162
+ columnSorter: Sorter | boolean | undefined,
163
+ itemsDataColumns: string[],
164
+ columnNames: string[],
165
+ ): boolean | undefined => {
166
+ const isDataColumn = itemsDataColumns.includes(columnNames[i])
167
+ let column
168
+ if (columns) column = columns[i]
169
+ return (
170
+ columnSorter &&
171
+ (!columns ||
172
+ typeof column !== 'object' ||
173
+ (typeof column === 'object' && (typeof column.sorter === 'undefined' || column.sorter))) &&
174
+ isDataColumn
175
+ )
176
+ }
177
+
178
+ export const pretifyName = (name: string) => {
179
+ return name
180
+ .replace(/[-_.]/g, ' ')
181
+ .replace(/ +/g, ' ')
182
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
183
+ .split(' ')
184
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
185
+ .join(' ')
186
+ }
187
+
188
+ export const sortItems = (
189
+ columnSorter: boolean | Sorter | undefined,
190
+ items: Item[],
191
+ itemsDataColumns: string[],
192
+ sorterState: SorterValue,
193
+ ) => {
194
+ const column = sorterState.column
195
+ if (
196
+ !column ||
197
+ !itemsDataColumns.includes(column) ||
198
+ (columnSorter && typeof columnSorter === 'object' && columnSorter.external)
199
+ ) {
200
+ return items
201
+ }
202
+
203
+ const flip = sorterState.state === 'asc' ? 1 : sorterState.state === 'desc' ? -1 : 0
204
+ const sorted = items.slice().sort((item, item2) => {
205
+ const value = item[column]
206
+ const value2 = item2[column]
207
+ const a = typeof value === 'number' ? value : String(value).toLowerCase()
208
+ const b = typeof value2 === 'number' ? value2 : String(value2).toLowerCase()
209
+ return a > b ? 1 * flip : b > a ? -1 * flip : 0
210
+ })
211
+ return sorted
212
+ }
@@ -117,7 +117,7 @@ const CTable = defineComponent({
117
117
  * @since 4.5.0
118
118
  */
119
119
  columns: {
120
- type: Array as PropType<Column[] | string[]>,
120
+ type: Array as PropType<(Column | string)[]>,
121
121
  required: false,
122
122
  },
123
123
  /**
@@ -137,8 +137,7 @@ const CTable = defineComponent({
137
137
  * @since 4.5.0
138
138
  */
139
139
  footer: {
140
- type: Array as PropType<FooterItem[]>,
141
- default: () => [],
140
+ type: Array as PropType<(FooterItem | string)[]>,
142
141
  required: false,
143
142
  },
144
143
  /**
@@ -158,7 +157,6 @@ const CTable = defineComponent({
158
157
  */
159
158
  items: {
160
159
  type: Array as PropType<Item[]>,
161
- default: () => [],
162
160
  required: false,
163
161
  },
164
162
  responsive: {
@@ -228,7 +226,7 @@ const CTable = defineComponent({
228
226
  if (typeof column === 'object') return column.key
229
227
  else return column
230
228
  })
231
- : Object.keys(props.items[0] || {}).filter((el) => el.charAt(0) !== '_'),
229
+ : Object.keys((props.items && props.items[0]) || {}).filter((el) => el.charAt(0) !== '_'),
232
230
  )
233
231
 
234
232
  const table = () =>
@@ -301,34 +299,37 @@ const CTable = defineComponent({
301
299
  {},
302
300
  {
303
301
  default: () => [
304
- props.items.map((item: Item) =>
305
- h(
306
- CTableRow,
307
- {
308
- ...(item._props && { ...item._props }),
309
- },
310
- {
311
- default: () => [
312
- rawColumnNames.value.map(
313
- (colName: string) =>
314
- item[colName] &&
315
- h(
316
- CTableDataCell,
317
- {
318
- ...(item._cellProps &&
319
- item._cellProps['all'] && { ...item._cellProps['all'] }),
320
- ...(item._cellProps &&
321
- item._cellProps[colName] && { ...item._cellProps[colName] }),
322
- },
323
- {
324
- default: () => item[colName],
325
- },
326
- ),
327
- ),
328
- ],
329
- },
302
+ props.items &&
303
+ props.items.map((item: Item) =>
304
+ h(
305
+ CTableRow,
306
+ {
307
+ ...(item._props && { ...item._props }),
308
+ },
309
+ {
310
+ default: () => [
311
+ rawColumnNames.value.map(
312
+ (colName: string) =>
313
+ item[colName] &&
314
+ h(
315
+ CTableDataCell,
316
+ {
317
+ ...(item._cellProps &&
318
+ item._cellProps['all'] && { ...item._cellProps['all'] }),
319
+ ...(item._cellProps &&
320
+ item._cellProps[colName] && {
321
+ ...item._cellProps[colName],
322
+ }),
323
+ },
324
+ {
325
+ default: () => item[colName],
326
+ },
327
+ ),
328
+ ),
329
+ ],
330
+ },
331
+ ),
330
332
  ),
331
- ),
332
333
  ],
333
334
  },
334
335
  ),
@@ -346,17 +347,19 @@ const CTable = defineComponent({
346
347
  {},
347
348
  {
348
349
  default: () => [
349
- props.footer.map((item: FooterItem | string) =>
350
- h(
351
- CTableDataCell,
352
- {
353
- ...(typeof item === 'object' && item._props && { ...item._props }),
354
- },
355
- {
356
- default: () => (typeof item === 'object' ? item.label : item),
357
- },
350
+ props.footer &&
351
+ props.footer.map((item: FooterItem | string) =>
352
+ h(
353
+ CTableDataCell,
354
+ {
355
+ ...(typeof item === 'object' &&
356
+ item._props && { ...item._props }),
357
+ },
358
+ {
359
+ default: () => (typeof item === 'object' ? item.label : item),
360
+ },
361
+ ),
358
362
  ),
359
- ),
360
363
  ],
361
364
  },
362
365
  ),
@@ -1,25 +1,24 @@
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
+ import { CFormControlWrapper } from '../form/CFormControlWrapper'
5
5
  import { CPicker } from '../picker'
6
+
6
7
  import { CTimePickerRollCol } from './CTimePickerRollCol'
7
8
 
8
9
  import {
9
10
  convert12hTo24h,
10
11
  convertTimeToDate,
11
12
  getAmPm,
12
- getListOfHours,
13
- getListOfMinutes,
14
- getListOfSeconds,
13
+ getLocalizedTimePartials,
15
14
  getSelectedHour,
16
15
  getSelectedMinutes,
17
16
  getSelectedSeconds,
18
- isAmPm,
19
17
  isValidTime,
20
- } from '../../utils/time'
18
+ } from './utils'
21
19
 
22
20
  import { Color } from '../props'
21
+ import type { LocalizedTimePartials } from './types'
23
22
 
24
23
  const CTimePicker = defineComponent({
25
24
  name: 'CTimePicker',
@@ -281,10 +280,16 @@ const CTimePicker = defineComponent({
281
280
  'update:time',
282
281
  ],
283
282
  setup(props, { emit, attrs, slots }) {
284
- const visible = ref(props.visible)
285
283
  const date = ref<Date | null>(convertTimeToDate(props.time))
286
- const initialDate = ref<Date | null>(null)
287
284
  const ampm = ref<'am' | 'pm'>(date.value ? getAmPm(new Date(date.value), props.locale) : 'am')
285
+ const initialDate = ref<Date | null>(null)
286
+ const visible = ref(props.visible)
287
+ const localizedTimePartials = ref<LocalizedTimePartials>({
288
+ listOfHours: [],
289
+ listOfMinutes: [],
290
+ listOfSeconds: [],
291
+ hour12: false,
292
+ })
288
293
 
289
294
  watch(
290
295
  () => props.time,
@@ -294,6 +299,8 @@ const CTimePicker = defineComponent({
294
299
  )
295
300
 
296
301
  watch(date, () => {
302
+ localizedTimePartials.value = getLocalizedTimePartials(props.locale, props.ampm)
303
+
297
304
  if (date.value) {
298
305
  ampm.value = getAmPm(new Date(date.value), props.locale)
299
306
  }
@@ -313,13 +320,14 @@ const CTimePicker = defineComponent({
313
320
  if (value === 'am') {
314
321
  _date.setHours(_date.getHours() - 12)
315
322
  }
323
+
316
324
  if (value === 'pm') {
317
325
  _date.setHours(_date.getHours() + 12)
318
326
  }
319
327
  }
320
328
 
321
329
  if (set === 'hours') {
322
- if ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) {
330
+ if (localizedTimePartials.value && localizedTimePartials.value.hour12) {
323
331
  _date.setHours(convert12hTo24h(ampm.value, parseInt(value)))
324
332
  } else {
325
333
  _date.setHours(parseInt(value))
@@ -353,8 +361,7 @@ const CTimePicker = defineComponent({
353
361
  readonly: props.inputReadOnly,
354
362
  value: date.value
355
363
  ? date.value.toLocaleTimeString(props.locale, {
356
- hour12:
357
- (props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm ? true : false,
364
+ hour12: localizedTimePartials.value && localizedTimePartials.value.hour12,
358
365
  ...(!props.seconds && { timeStyle: 'short' }),
359
366
  })
360
367
  : '',
@@ -390,35 +397,50 @@ const CTimePicker = defineComponent({
390
397
  h('span', { class: 'time-picker-inline-icon' }),
391
398
  h(CFormSelect, {
392
399
  disabled: props.disabled,
393
- options: getListOfHours(props.locale).map((option) => {
394
- return {
395
- value: option.value.toString(),
396
- label: option.label,
397
- }
398
- }),
400
+ options:
401
+ localizedTimePartials.value &&
402
+ localizedTimePartials.value.listOfHours?.map((option) => {
403
+ return {
404
+ value: option.value.toString(),
405
+ label: option.label,
406
+ }
407
+ }),
399
408
  onChange: (event) => handleTimeChange('hours', event.target.value),
400
409
  ...(date.value && { value: getSelectedHour(date.value, props.locale) }),
401
410
  }),
402
411
  ':',
403
- // @ts-expect-error the getListOfMinutes function returns corect type
404
412
  h(CFormSelect, {
405
413
  disabled: props.disabled,
406
- options: getListOfMinutes(props.locale, true),
414
+ options:
415
+ localizedTimePartials.value &&
416
+ localizedTimePartials.value.listOfMinutes.map((option) => {
417
+ return {
418
+ value: option.value.toString(),
419
+ label: option.label,
420
+ }
421
+ }),
407
422
  onChange: (event: Event) =>
408
423
  handleTimeChange('minutes', (event.target as HTMLSelectElement).value),
409
424
  ...(date.value && { value: getSelectedMinutes(date.value) }),
410
425
  }),
411
426
  props.seconds && ':',
412
427
  props.seconds &&
413
- // @ts-expect-error the getListOfMinutes function returns corect type
414
428
  h(CFormSelect, {
415
429
  disabled: props.disabled,
416
- options: getListOfSeconds(props.locale, true),
430
+ options:
431
+ localizedTimePartials.value &&
432
+ localizedTimePartials.value.listOfSeconds.map((option) => {
433
+ return {
434
+ value: option.value.toString(),
435
+ label: option.label,
436
+ }
437
+ }),
417
438
  onChange: (event: Event) =>
418
439
  handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
419
440
  ...(date.value && { value: getSelectedSeconds(date.value) }),
420
441
  }),
421
- isAmPm(props.locale) &&
442
+ localizedTimePartials.value &&
443
+ localizedTimePartials.value.hour12 &&
422
444
  h(CFormSelect, {
423
445
  disabled: props.disabled,
424
446
  options: [
@@ -432,22 +454,23 @@ const CTimePicker = defineComponent({
432
454
 
433
455
  const TimePickerRoll = () => [
434
456
  h(CTimePickerRollCol, {
435
- elements: getListOfHours(props.locale, props.ampm),
457
+ elements: localizedTimePartials.value && localizedTimePartials.value.listOfHours,
436
458
  onClick: (index: number) => handleTimeChange('hours', index.toString()),
437
459
  selected: getSelectedHour(date.value, props.locale, props.ampm),
438
460
  }),
439
461
  h(CTimePickerRollCol, {
440
- elements: getListOfMinutes(props.locale),
462
+ elements: localizedTimePartials.value && localizedTimePartials.value.listOfMinutes,
441
463
  onClick: (index: number) => handleTimeChange('minutes', index.toString()),
442
464
  selected: getSelectedMinutes(date.value),
443
465
  }),
444
466
  props.seconds &&
445
467
  h(CTimePickerRollCol, {
446
- elements: getListOfSeconds(props.locale),
468
+ elements: localizedTimePartials.value && localizedTimePartials.value.listOfSeconds,
447
469
  onClick: (index: number) => handleTimeChange('seconds', index.toString()),
448
470
  selected: getSelectedSeconds(date.value),
449
471
  }),
450
- ((props.ampm === 'auto' && isAmPm(props.locale)) || props.ampm) &&
472
+ localizedTimePartials.value &&
473
+ localizedTimePartials.value.hour12 &&
451
474
  h(CTimePickerRollCol, {
452
475
  elements: [
453
476
  { value: 'am', label: 'AM' },
@@ -0,0 +1,15 @@
1
+ export type LocalizedTimePartials = {
2
+ listOfHours: {
3
+ value: number
4
+ label: string
5
+ }[]
6
+ listOfMinutes: {
7
+ value: number
8
+ label: string
9
+ }[]
10
+ listOfSeconds: {
11
+ value: number
12
+ label: string
13
+ }[]
14
+ hour12: boolean
15
+ }
@@ -1,3 +1,5 @@
1
+ import type { LocalizedTimePartials } from './types'
2
+
1
3
  export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
2
4
  if (abbr === 'am' && hour === 12) {
3
5
  return 0
@@ -26,14 +28,18 @@ export const getAmPm = (date: Date, locale: string) => {
26
28
  return date.getHours() >= 12 ? 'pm' : 'am'
27
29
  }
28
30
 
31
+ // TODO: clean-up
29
32
  export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto') =>
30
- Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm ? 12 : 24 }, (_, i) => {
33
+ Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm === true ? 12 : 24 }, (_, i) => {
31
34
  return {
32
- value: (ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i,
33
- label: ((ampm === 'auto' && isAmPm(locale)) || ampm ? i + 1 : i).toLocaleString(locale),
35
+ value: (ampm === 'auto' && isAmPm(locale)) || ampm === true ? i + 1 : i,
36
+ label: ((ampm === 'auto' && isAmPm(locale)) || ampm === true ? i + 1 : i).toLocaleString(
37
+ locale,
38
+ ),
34
39
  }
35
40
  })
36
41
 
42
+ // TODO: clean-up
37
43
  export const getListOfMinutes = (locale: string, valueAsString = false) =>
38
44
  Array.from({ length: 60 }, (_, i) => {
39
45
  const d = new Date()
@@ -42,15 +48,14 @@ export const getListOfMinutes = (locale: string, valueAsString = false) =>
42
48
  value: valueAsString ? i.toString() : i,
43
49
  label: d
44
50
  .toLocaleTimeString(locale, {
45
- hour: '2-digit',
46
- hour12: false,
47
51
  minute: '2-digit',
48
52
  second: '2-digit',
49
53
  })
50
- .split(':')[1],
54
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
51
55
  }
52
56
  })
53
57
 
58
+ // TODO: clean-up
54
59
  export const getListOfSeconds = (locale: string, valueAsString = false) =>
55
60
  Array.from({ length: 60 }, (_, i) => {
56
61
  const d = new Date()
@@ -59,22 +64,56 @@ export const getListOfSeconds = (locale: string, valueAsString = false) =>
59
64
  value: valueAsString ? i.toString() : i,
60
65
  label: d
61
66
  .toLocaleTimeString(locale, {
62
- hour: '2-digit',
63
- hour12: false,
64
67
  minute: '2-digit',
65
68
  second: '2-digit',
66
69
  })
67
- .split(':')[2],
70
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
71
+ }
72
+ })
73
+
74
+ export const getLocalizedTimePartials = (
75
+ locale: string,
76
+ ampm: 'auto' | boolean = 'auto',
77
+ ): LocalizedTimePartials => {
78
+ const date = new Date()
79
+ const hour12 = ['am', 'AM', 'pm', 'PM'].some((el) => date.toLocaleString(locale).includes(el))
80
+ const listOfHours = Array.from(
81
+ { length: (ampm === 'auto' && hour12) || ampm === true ? 12 : 24 },
82
+ (_, i) => {
83
+ return {
84
+ value: (ampm === 'auto' && hour12) || ampm === true ? i + 1 : i,
85
+ label: ((ampm === 'auto' && hour12) || ampm === true ? i + 1 : i).toLocaleString(locale),
86
+ }
87
+ },
88
+ )
89
+ const listOfMinutesSeconds = Array.from({ length: 60 }, (_, i) => {
90
+ date.setMinutes(i)
91
+ return {
92
+ value: i,
93
+ label: date
94
+ .toLocaleTimeString(locale, {
95
+ minute: '2-digit',
96
+ second: '2-digit',
97
+ })
98
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
68
99
  }
69
100
  })
70
101
 
102
+ return {
103
+ listOfHours,
104
+ listOfMinutes: listOfMinutesSeconds,
105
+ listOfSeconds: listOfMinutesSeconds,
106
+ hour12,
107
+ }
108
+ }
109
+
71
110
  export const getSelectedHour = (
72
111
  date: Date | null,
73
112
  locale: string,
74
113
  ampm: 'auto' | boolean = 'auto',
75
114
  ) =>
76
115
  date
77
- ? (ampm === 'auto' && isAmPm(locale)) || ampm
116
+ ? (ampm === 'auto' && isAmPm(locale)) || ampm === true
78
117
  ? convert24hTo12h(date.getHours())
79
118
  : date.getHours()
80
119
  : ''
@@ -1,5 +1,5 @@
1
1
  import getNextSibling from './getNextSibling'
2
2
  import getPreviousSibling from './getPreviousSibling'
3
- import isVisible from './isVisible'
3
+ import isInViewport from './isInViewport'
4
4
 
5
- export { getNextSibling, getPreviousSibling, isVisible }
5
+ export { getNextSibling, getPreviousSibling, isInViewport }
@@ -0,0 +1,11 @@
1
+ const isInViewport = (element: HTMLElement) => {
2
+ const rect = element.getBoundingClientRect()
3
+ return (
4
+ Math.floor(rect.top) >= 0 &&
5
+ Math.floor(rect.left) >= 0 &&
6
+ Math.floor(rect.bottom) <= (window.innerHeight || document.documentElement.clientHeight) &&
7
+ Math.floor(rect.right) <= (window.innerWidth || document.documentElement.clientWidth)
8
+ )
9
+ }
10
+
11
+ export default isInViewport
@@ -1,11 +0,0 @@
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