@coreui/react-pro 4.9.0 → 4.11.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 (38) hide show
  1. package/README.md +1 -1
  2. package/dist/components/calendar/CCalendar.d.ts +12 -0
  3. package/dist/components/date-range-picker/CDateRangePicker.d.ts +6 -0
  4. package/dist/components/multi-select/CMultiSelect.d.ts +18 -1
  5. package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -0
  6. package/dist/components/multi-select/types.d.ts +1 -0
  7. package/dist/components/multi-select/utils.d.ts +5 -0
  8. package/dist/components/smart-table/CSmartTableInterface.d.ts +1 -1
  9. package/dist/components/time-picker/CTimePicker.d.ts +6 -0
  10. package/dist/index.es.js +126 -61
  11. package/dist/index.es.js.map +1 -1
  12. package/dist/index.js +126 -61
  13. package/dist/index.js.map +1 -1
  14. package/package.json +2 -2
  15. package/src/components/calendar/CCalendar.tsx +79 -44
  16. package/src/components/calendar/utils.ts +1 -0
  17. package/src/components/date-range-picker/CDateRangePicker.tsx +14 -0
  18. package/src/components/dropdown/CDropdown.tsx +33 -30
  19. package/src/components/multi-select/CMultiSelect.tsx +99 -14
  20. package/src/components/multi-select/CMultiSelectOptions.tsx +29 -16
  21. package/src/components/multi-select/types.ts +1 -0
  22. package/src/components/multi-select/utils.ts +42 -25
  23. package/src/components/smart-table/CSmartTableInterface.tsx +1 -1
  24. package/src/components/time-picker/CTimePicker.tsx +9 -0
  25. package/src/components/virtual-scroller/CVirtualScroller.tsx +8 -7
  26. package/dist/components/Types.d.ts +0 -14
  27. package/dist/components/multi-select/CMultiSelectCleaner.d.ts +0 -2
  28. package/dist/components/multi-select/CMultiSelectSearchInput.d.ts +0 -5
  29. package/dist/components/pagination/CSmartPagination.d.ts +0 -80
  30. package/dist/components/time-picker/CTimePicker copy.d.ts +0 -46
  31. package/dist/utils/calendar.d.ts +0 -23
  32. package/dist/utils/getNextSibling.d.ts +0 -2
  33. package/dist/utils/getPreviousSibling.d.ts +0 -2
  34. package/dist/utils/hooks/index.d.ts +0 -3
  35. package/dist/utils/hooks/useForkedRef.d.ts +0 -7
  36. package/dist/utils/hooks/useStateWithCallback.d.ts +0 -2
  37. package/dist/utils/isVisible.d.ts +0 -2
  38. package/dist/utils/time.d.ts +0 -21
@@ -6,9 +6,11 @@ import { CVirtualScroller } from './../virtual-scroller'
6
6
 
7
7
  import { getNextSibling, getPreviousSibling } from './utils'
8
8
  import type { Option } from './types'
9
+ import { CElementCover } from '../element-cover'
9
10
 
10
11
  export interface CMultiSelectOptionsProps extends HTMLAttributes<HTMLDivElement> {
11
12
  handleOptionOnClick?: (option: Option) => void
13
+ loading?: boolean
12
14
  options: Option[]
13
15
  optionsMaxHeight?: number | string
14
16
  optionsStyle?: 'checkbox' | 'text'
@@ -22,6 +24,7 @@ export const CMultiSelectOptions = forwardRef<HTMLDivElement, CMultiSelectOption
22
24
  (
23
25
  {
24
26
  handleOptionOnClick,
27
+ loading,
25
28
  options,
26
29
  optionsMaxHeight,
27
30
  optionsStyle,
@@ -44,7 +47,7 @@ export const CMultiSelectOptions = forwardRef<HTMLDivElement, CMultiSelectOption
44
47
  const target = event.target as HTMLElement
45
48
  const next = getNextSibling(target, '.form-multi-select-option')
46
49
  if (next) {
47
- (next as HTMLElement).focus() // eslint-disable-line prettier/prettier
50
+ ;(next as HTMLElement).focus() // eslint-disable-line prettier/prettier
48
51
  }
49
52
  }
50
53
 
@@ -53,7 +56,7 @@ export const CMultiSelectOptions = forwardRef<HTMLDivElement, CMultiSelectOption
53
56
  const target = event.target as HTMLElement
54
57
  const prev = getPreviousSibling(target, '.form-multi-select-option')
55
58
  if (prev) {
56
- (prev as HTMLElement).focus() // eslint-disable-line prettier/prettier
59
+ ;(prev as HTMLElement).focus() // eslint-disable-line prettier/prettier
57
60
  }
58
61
  }
59
62
  }
@@ -86,26 +89,36 @@ export const CMultiSelectOptions = forwardRef<HTMLDivElement, CMultiSelectOption
86
89
  <div className="form-multi-select-options-empty">{searchNoResultsLabel}</div>
87
90
  )
88
91
 
89
- return virtualScroller ? (
90
- <CVirtualScroller className="form-multi-select-options" visibleItems={visibleItems} ref={ref}>
91
- {createOptions(options)}
92
- </CVirtualScroller>
93
- ) : (
94
- <div
95
- className="form-multi-select-options"
96
- {...(optionsMaxHeight !== 'auto' && {
97
- style: { maxHeight: optionsMaxHeight, overflow: 'scroll' },
98
- })}
99
- ref={ref}
100
- >
101
- {createOptions(options)}
102
- </div>
92
+ return (
93
+ <>
94
+ {virtualScroller ? (
95
+ <CVirtualScroller
96
+ className="form-multi-select-options"
97
+ visibleItems={visibleItems}
98
+ ref={ref}
99
+ >
100
+ {createOptions(options)}
101
+ </CVirtualScroller>
102
+ ) : (
103
+ <div
104
+ className="form-multi-select-options"
105
+ {...(optionsMaxHeight !== 'auto' && {
106
+ style: { maxHeight: optionsMaxHeight, overflow: 'scroll' },
107
+ })}
108
+ ref={ref}
109
+ >
110
+ {createOptions(options)}
111
+ </div>
112
+ )}
113
+ {loading && <CElementCover />}
114
+ </>
103
115
  )
104
116
  },
105
117
  )
106
118
 
107
119
  CMultiSelectOptions.propTypes = {
108
120
  handleOptionOnClick: PropTypes.func,
121
+ loading: PropTypes.bool,
109
122
  options: PropTypes.array.isRequired,
110
123
  optionsMaxHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
111
124
  optionsStyle: PropTypes.oneOf(['checkbox', 'text']),
@@ -1,4 +1,5 @@
1
1
  export type Option = {
2
+ custom?: boolean
2
3
  disabled?: boolean
3
4
  label?: string
4
5
  options?: Option[]
@@ -1,33 +1,50 @@
1
1
  import type { Option, SelectedOption } from './types'
2
2
 
3
- export const filterOptionsList = (search: string, _options: Option[]) => {
4
- return search.length > 0
3
+ export const createOption = (text: string, options: Option[]) => {
4
+ const value = text.toLowerCase().replace(/\s/g, '-')
5
+ let uniqueValue = value
6
+ let i = 1
7
+
8
+ while (options.find((option) => String(option.value) === uniqueValue)) {
9
+ uniqueValue = `${value}-${i}`
10
+ i++
11
+ }
12
+
13
+ return [
14
+ {
15
+ value: uniqueValue,
16
+ text,
17
+ custom: true,
18
+ },
19
+ ]
20
+ }
21
+
22
+ export const filterOptionsList = (search: string, _options: Option[]) =>
23
+ search.length > 0
5
24
  ? _options &&
6
- _options.reduce((acc: Option[], val: Option) => {
7
- const options =
8
- val.options &&
9
- val.options.filter(
10
- (element) =>
11
- element.text && element.text.toLowerCase().includes(search.toLowerCase()),
12
- )
13
-
14
- if (
15
- (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
16
- (options && options.length > 0)
17
- ) {
18
- acc.push(Object.assign({}, val, options && options.length > 0 && { options }))
19
- }
20
-
21
- return acc
22
- }, [])
25
+ _options.reduce((acc: Option[], val: Option) => {
26
+ const options =
27
+ val.options &&
28
+ val.options.filter(
29
+ (element) => element.text && element.text.toLowerCase().includes(search.toLowerCase()),
30
+ )
31
+ if (
32
+ (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
33
+ (options && options.length > 0)
34
+ ) {
35
+ acc.push(Object.assign({}, val, options && options.length > 0 && { options }))
36
+ }
37
+
38
+ return acc
39
+ }, [])
23
40
  : _options
24
- }
25
41
 
26
- export const flattenArray = (options: Option[]): Option[] => {
27
- return options.reduce((acc: Option[], val: Option) => {
28
- return acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val)
29
- }, [])
30
- }
42
+ export const flattenArray = (options: Option[]): Option[] =>
43
+ options.reduce(
44
+ (acc: Option[], val: Option) =>
45
+ acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val),
46
+ [],
47
+ )
31
48
 
32
49
  export const getNextSibling = (elem: HTMLElement, selector?: string) => {
33
50
  // Get the next sibling element
@@ -121,7 +121,7 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
121
121
  */
122
122
  itemsPerPageSelect?: boolean | ItemsPerPageSelect
123
123
  /**
124
- * When set, table will have loading style: loading spinner and reduced opacity. When 'small' prop is enabled spinner will be also smaller.
124
+ * When set, table will have loading style: loading spinner and reduced opacity.
125
125
  */
126
126
  loading?: boolean
127
127
  /**
@@ -60,6 +60,12 @@ export interface CTimePickerProps
60
60
  * Specifies a short hint that is visible in the input.
61
61
  */
62
62
  placeholder?: string
63
+ /**
64
+ * When present, it specifies that time must be filled out before submitting the form.
65
+ *
66
+ * @since 4.10.0
67
+ */
68
+ required?: boolean
63
69
  /**
64
70
  * Show seconds.
65
71
  *
@@ -102,6 +108,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
102
108
  onHide,
103
109
  onShow,
104
110
  placeholder = 'Select time',
111
+ required,
105
112
  seconds = true,
106
113
  size,
107
114
  text,
@@ -195,6 +202,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
195
202
  }
196
203
  placeholder={placeholder}
197
204
  readOnly={inputReadOnly}
205
+ required={required}
198
206
  ref={inputRef}
199
207
  />
200
208
  {(indicator || cleaner) && (
@@ -397,6 +405,7 @@ CTimePicker.propTypes = {
397
405
  className: PropTypes.string,
398
406
  locale: PropTypes.string,
399
407
  onTimeChange: PropTypes.func,
408
+ required: PropTypes.bool,
400
409
  seconds: PropTypes.bool,
401
410
  time: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
402
411
  variant: PropTypes.oneOf(['roll', 'select']),
@@ -43,17 +43,17 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
43
43
  })
44
44
 
45
45
  useEffect(() => {
46
- setItemsNumber(itemsNumber || React.Children.count(children))
47
- }, [children, itemsNumber])
46
+ setItemsNumber(React.Children.count(children))
47
+ }, [children])
48
48
 
49
49
  useEffect(() => {
50
- setViewportHeight(visibleItems * itemHeight + 2 * viewportPadding)
51
- }, [viewportPadding, visibleItems, itemHeight])
50
+ setViewportHeight(Math.min(visibleItems, itemsNumber) * itemHeight + 2 * viewportPadding)
51
+ }, [itemHeight, itemsNumber, viewportPadding, visibleItems])
52
52
 
53
53
  useEffect(() => {
54
- setMaxHeight(itemsNumber * itemHeight + 2 * viewportPadding)
54
+ setMaxHeight(itemsNumber * itemHeight)
55
55
  virtualScrollRef.current && virtualScrollRef.current.scrollTop
56
- }, [itemsNumber, itemHeight])
56
+ }, [itemHeight, itemsNumber])
57
57
 
58
58
  useEffect(() => {
59
59
  setBuffer(Math.floor(visibleItems / 2))
@@ -73,7 +73,8 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
73
73
  }
74
74
  ref={forkedRef}
75
75
  style={{
76
- height: maxHeight > viewportHeight ? viewportHeight : maxHeight,
76
+ // height: maxHeight > viewportHeight ? viewportHeight : maxHeight,
77
+ height: viewportHeight,
77
78
  overflowY: 'auto',
78
79
  }}
79
80
  >
@@ -1,14 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- export type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
3
- export type Colors = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string;
4
- export declare const colorPropType: PropTypes.Requireable<string>;
5
- export type Gradients = 'primary-gradient' | 'secondary-gradient' | 'success-gradient' | 'danger-gradient' | 'warning-gradient' | 'info-gradient' | 'dark-gradient' | 'light-gradient';
6
- export declare const gradientsPropType: PropTypes.Requireable<string>;
7
- export type Placements = 'auto' | 'auto-start' | 'auto-end' | 'top-end' | 'top' | 'top-start' | 'bottom-end' | 'bottom' | 'bottom-start' | 'right-start' | 'right' | 'right-end' | 'left-start' | 'left' | 'left-end' | undefined;
8
- export declare const placementPropType: PropTypes.Requireable<Placements>;
9
- export type Shapes = 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string;
10
- export declare const shapePropType: PropTypes.Requireable<string>;
11
- export type TextColors = Colors | 'white' | 'muted' | 'high-emphasis' | 'medium-emphasis' | 'disabled' | 'high-emphasis-inverse' | 'medium-emphasis-inverse' | 'disabled-inverse' | string;
12
- export declare const textColorsPropType: PropTypes.Requireable<string>;
13
- export type Triggers = 'hover' | 'focus' | 'click';
14
- export declare const triggerPropType: PropTypes.Requireable<Triggers>;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const CMultiSelectCleaner: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
@@ -1,5 +0,0 @@
1
- import React, { InputHTMLAttributes } from 'react';
2
- export interface CMultiSelectSearchInputProps extends InputHTMLAttributes<HTMLInputElement> {
3
- placeholder?: string;
4
- }
5
- export declare const CMultiSelectSearchInput: React.ForwardRefExoticComponent<CMultiSelectSearchInputProps & React.RefAttributes<HTMLInputElement>>;
@@ -1,80 +0,0 @@
1
- import React, { ReactNode, HTMLAttributes } from 'react';
2
- export interface CSmartPaginationProps extends HTMLAttributes<HTMLUListElement> {
3
- /**
4
- * A string of all className you want applied to the base component. [docs]
5
- */
6
- className?: string;
7
- /**
8
- * Current page number. [docs]
9
- *
10
- * @default 1
11
- */
12
- activePage?: number;
13
- /**
14
- * Show/hide dots. [docs]
15
- *
16
- * @default true
17
- */
18
- dots?: boolean;
19
- /**
20
- * Show/hide arrows. [docs]
21
- *
22
- * @default true
23
- */
24
- arrows?: boolean;
25
- /**
26
- * Show double arrows buttons. [docs]
27
- *
28
- * @default doubleArrows
29
- */
30
- doubleArrows?: boolean;
31
- /**
32
- * The content of 'firstButton' button. [docs]
33
- *
34
- * @default '<React.Fragment>&laquo;</React.Fragment>''
35
- */
36
- firstButton?: ReactNode | string;
37
- /**
38
- * The content of 'previousButton' button. [docs]
39
- *
40
- * @default '<React.Fragment>&lsaquo;</React.Fragment>'
41
- */
42
- previousButton?: ReactNode | string;
43
- /**
44
- * The content of 'nextButton' button. [docs]
45
- *
46
- * @default '<React.Fragment>&rsaquo;</React.Fragment>''
47
- */
48
- nextButton?: ReactNode | string;
49
- /**
50
- * The content of 'lastButton' button. [docs]
51
- *
52
- * @default '<React.Fragment>&raquo;</React.Fragment>'
53
- */
54
- lastButton?: ReactNode | string;
55
- /**
56
- * Size of pagination, valid values: 'sm', 'lg'. [docs]
57
- */
58
- size?: 'sm' | 'lg';
59
- /**
60
- * Horizontall align. [docs]
61
- *
62
- * @default 'start'
63
- */
64
- align?: 'start' | 'center' | 'end';
65
- /**
66
- * Maximum items number. [docs]
67
- *
68
- * @default 5
69
- */
70
- limit?: number;
71
- /**
72
- * Number of pages. [docs]
73
- */
74
- pages: number;
75
- /**
76
- * On active page change callback. [docs]
77
- */
78
- onActivePageChange: (a: number, b?: boolean) => void;
79
- }
80
- export declare const CSmartPagination: React.ForwardRefExoticComponent<CSmartPaginationProps & React.RefAttributes<HTMLUListElement>>;
@@ -1,46 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { CFormControlWrapperProps } from '../form/CFormControlWrapper';
3
- import { CPickerProps } from './../picker/CPicker';
4
- export interface CTimePickerProps extends Omit<CFormControlWrapperProps, 'floatingLabel'>, Omit<CPickerProps, 'autoClose' | 'component' | 'dark' | 'placeholder' | 'variant' | 'onChange'> {
5
- /**
6
- * A string of all className you want applied to the component.
7
- */
8
- className?: string;
9
- /**
10
- * Toggle visibility or set the content of the cleaner button.
11
- */
12
- cleaner?: ReactNode | boolean;
13
- /**
14
- * Toggle visibility or set the content of the input indicator.
15
- */
16
- indicator?: ReactNode | boolean;
17
- /**
18
- * Toggle the readonly state for the component.
19
- */
20
- inputReadOnly?: boolean;
21
- /**
22
- * Sets the default locale for components. If not set, it is inherited from the browser.
23
- */
24
- locale?: string;
25
- /**
26
- * Callback fired when the time changed.
27
- */
28
- onTimeChange?: (timeString: string | null, localeTimeString?: string, date?: Date) => void;
29
- /**
30
- * Specifies a short hint that is visible in the input.
31
- */
32
- placeholder?: string;
33
- /**
34
- * Size the component small or large.
35
- */
36
- size?: 'sm' | 'lg';
37
- /**
38
- * Initial selected time.
39
- */
40
- time?: Date | string | null;
41
- /**
42
- * Set the time picker variant to a roll or select.
43
- */
44
- variant?: 'roll' | 'select';
45
- }
46
- export declare const CTimePicker: React.ForwardRefExoticComponent<CTimePickerProps & React.RefAttributes<HTMLDivElement | HTMLLIElement>>;
@@ -1,23 +0,0 @@
1
- export declare const convertToLocalDate: (d: Date, locale: string, options?: {}) => string;
2
- export declare const convertToLocalTime: (d: Date, locale: string, options?: {}) => string;
3
- export declare const createGroupsInArray: (arr: any[], numberOfGroups: number) => any[][];
4
- export declare const getCurrentYear: () => number;
5
- export declare const getCurrentMonth: () => number;
6
- export declare const getLocalDateFromString: (string: string, locale: string, time?: boolean) => Date | undefined;
7
- export declare const getMonthName: (month: number, locale: string) => string;
8
- export declare const getMonthsNames: (locale: string) => string[];
9
- export declare const getYears: (year: number) => number[];
10
- export declare const getMonthDetails: (year: number, month: number, firstDayOfWeek: number) => {
11
- date: Date;
12
- month: string;
13
- }[][];
14
- export declare const isDisableDateInRange: (startDate?: Date | null, endDate?: Date | null, dates?: Date[] | Date[][] | (Date | Date[])[]) => boolean;
15
- export declare const isDateDisabled: (date: Date, min?: Date | null, max?: Date | null, dates?: Date[] | Date[][] | (Date | Date[])[]) => boolean | undefined;
16
- export declare const isDateInRange: (date: Date, start: Date | null, end: Date | null) => boolean | null;
17
- export declare const isDateSelected: (date: Date, start: Date | null, end: Date | null) => boolean | null;
18
- export declare const isEndDate: (date: Date, start: Date | null, end: Date | null) => boolean | null;
19
- export declare const isLastDayOfMonth: (date: Date) => boolean;
20
- export declare const isSameDateAs: (date: Date | null, date2: Date | null) => boolean;
21
- export declare const isStartDate: (date: Date, start: Date | null, end: Date | null) => boolean | null;
22
- export declare const isToday: (date: Date) => boolean;
23
- export declare const isValidDate: (date: string) => number | false;
@@ -1,2 +0,0 @@
1
- declare const getNextSibling: (elem: HTMLElement, selector?: string) => Element | null | undefined;
2
- export default getNextSibling;
@@ -1,2 +0,0 @@
1
- declare const getPreviousSibling: (elem: HTMLElement, selector?: string) => Element | null | undefined;
2
- export default getPreviousSibling;
@@ -1,3 +0,0 @@
1
- import { useForkedRef } from './useForkedRef';
2
- import { useStateWithCallback } from './useStateWithCallback';
3
- export { useForkedRef, useStateWithCallback };
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- export type AssignableRef<ValueType> = {
3
- bivarianceHack(instance: ValueType | null): void;
4
- }['bivarianceHack'] | React.MutableRefObject<ValueType | null>;
5
- export declare function useForkedRef<RefValueType = any>(...refs: (AssignableRef<RefValueType> | null | undefined)[]): ((node: any) => void) | null;
6
- export declare function assignRef<RefValueType = any>(ref: AssignableRef<RefValueType> | null | undefined, value: any): void;
7
- export declare function isFunction(value: any): value is Function;
@@ -1,2 +0,0 @@
1
- import { Dispatch, SetStateAction } from 'react';
2
- export declare const useStateWithCallback: <S>(initialState: S, handler?: ((prevState: S) => void) | undefined, runHandler?: boolean) => [S, Dispatch<SetStateAction<S>>];
@@ -1,2 +0,0 @@
1
- declare const isVisible: (element: HTMLElement) => boolean;
2
- export default isVisible;
@@ -1,21 +0,0 @@
1
- export declare const convert12hTo24h: (abbr: 'am' | 'pm', hour: number) => number;
2
- export declare const convert24hTo12h: (hour: number) => number;
3
- export declare const convertTimeToDate: (time: Date | string | null | undefined) => Date | null;
4
- export declare const getAmPm: (date: Date, locale: string) => "am" | "pm";
5
- export declare const getListOfHours: (locale: string, ampm?: 'auto' | boolean) => {
6
- value: number;
7
- label: string;
8
- }[];
9
- export declare const getListOfMinutes: (locale: string, valueAsString?: boolean) => {
10
- value: string | number;
11
- label: string;
12
- }[];
13
- export declare const getListOfSeconds: (locale: string, valueAsString?: boolean) => {
14
- value: string | number;
15
- label: string;
16
- }[];
17
- export declare const getSelectedHour: (date: Date | null, locale: string, ampm?: 'auto' | boolean) => number | "";
18
- export declare const getSelectedMinutes: (date: Date | null) => number | "";
19
- export declare const getSelectedSeconds: (date: Date | null) => number | "";
20
- export declare const isAmPm: (locale: string) => boolean;
21
- export declare const isValidTime: (time: string) => number | false;