@coreui/react-pro 5.11.0 → 5.12.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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/components/accordion/CAccordionBody.js +2 -2
  3. package/dist/cjs/components/accordion/CAccordionBody.js.map +1 -1
  4. package/dist/cjs/components/accordion/CAccordionItem.d.ts +4 -0
  5. package/dist/cjs/components/accordion/CAccordionItem.js +4 -4
  6. package/dist/cjs/components/accordion/CAccordionItem.js.map +1 -1
  7. package/dist/cjs/components/dropdown/CDropdown.d.ts +77 -20
  8. package/dist/cjs/components/dropdown/CDropdown.js +6 -3
  9. package/dist/cjs/components/dropdown/CDropdown.js.map +1 -1
  10. package/dist/cjs/components/dropdown/CDropdownMenu.js +1 -1
  11. package/dist/cjs/components/dropdown/CDropdownMenu.js.map +1 -1
  12. package/dist/cjs/components/popover/CPopover.d.ts +75 -20
  13. package/dist/cjs/components/popover/CPopover.js +8 -21
  14. package/dist/cjs/components/popover/CPopover.js.map +1 -1
  15. package/dist/cjs/components/smart-table/CSmartTableHead.js +3 -1
  16. package/dist/cjs/components/smart-table/CSmartTableHead.js.map +1 -1
  17. package/dist/cjs/components/smart-table/types.d.ts +1 -1
  18. package/dist/cjs/components/tooltip/CTooltip.d.ts +67 -15
  19. package/dist/cjs/components/tooltip/CTooltip.js +8 -21
  20. package/dist/cjs/components/tooltip/CTooltip.js.map +1 -1
  21. package/dist/cjs/hooks/useColorModes.js +5 -5
  22. package/dist/cjs/hooks/useColorModes.js.map +1 -1
  23. package/dist/esm/components/accordion/CAccordionBody.js +2 -2
  24. package/dist/esm/components/accordion/CAccordionBody.js.map +1 -1
  25. package/dist/esm/components/accordion/CAccordionItem.d.ts +4 -0
  26. package/dist/esm/components/accordion/CAccordionItem.js +4 -4
  27. package/dist/esm/components/accordion/CAccordionItem.js.map +1 -1
  28. package/dist/esm/components/dropdown/CDropdown.d.ts +77 -20
  29. package/dist/esm/components/dropdown/CDropdown.js +6 -3
  30. package/dist/esm/components/dropdown/CDropdown.js.map +1 -1
  31. package/dist/esm/components/dropdown/CDropdownMenu.js +1 -1
  32. package/dist/esm/components/dropdown/CDropdownMenu.js.map +1 -1
  33. package/dist/esm/components/popover/CPopover.d.ts +75 -20
  34. package/dist/esm/components/popover/CPopover.js +8 -21
  35. package/dist/esm/components/popover/CPopover.js.map +1 -1
  36. package/dist/esm/components/smart-table/CSmartTableHead.js +3 -1
  37. package/dist/esm/components/smart-table/CSmartTableHead.js.map +1 -1
  38. package/dist/esm/components/smart-table/types.d.ts +1 -1
  39. package/dist/esm/components/tooltip/CTooltip.d.ts +67 -15
  40. package/dist/esm/components/tooltip/CTooltip.js +8 -21
  41. package/dist/esm/components/tooltip/CTooltip.js.map +1 -1
  42. package/dist/esm/hooks/useColorModes.js +5 -5
  43. package/dist/esm/hooks/useColorModes.js.map +1 -1
  44. package/package.json +4 -4
  45. package/src/components/accordion/CAccordionBody.tsx +3 -3
  46. package/src/components/accordion/CAccordionItem.tsx +9 -5
  47. package/src/components/dropdown/CDropdown.tsx +106 -26
  48. package/src/components/dropdown/CDropdownMenu.tsx +0 -1
  49. package/src/components/popover/CPopover.tsx +103 -43
  50. package/src/components/smart-table/CSmartTableHead.tsx +3 -0
  51. package/src/components/smart-table/types.ts +7 -1
  52. package/src/components/tooltip/CTooltip.tsx +94 -38
  53. package/src/hooks/useColorModes.ts +5 -5
@@ -9,6 +9,7 @@ import React, {
9
9
  } from 'react'
10
10
  import classNames from 'classnames'
11
11
  import PropTypes from 'prop-types'
12
+ import type { Options } from '@popperjs/core'
12
13
 
13
14
  import { CConditionalPortal } from '../conditional-portal'
14
15
  import { useForkedRef, usePopper } from '../../hooks'
@@ -18,61 +19,124 @@ import { executeAfterTransition, getRTLPlacement } from '../../utils'
18
19
 
19
20
  export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
20
21
  /**
21
- * Apply a CSS fade transition to the tooltip.
22
+ * Enables or disables the CSS fade transition for the React Tooltip.
22
23
  *
23
24
  * @since 4.9.0
24
25
  */
25
26
  animation?: boolean
27
+
26
28
  /**
27
- * A string of all className you want applied to the component.
29
+ * Adds a custom class name to the React Tooltip container. Useful for overriding default styles or applying additional design choices.
28
30
  */
29
31
  className?: string
32
+
30
33
  /**
31
- * Appends the react tooltip to a specific element. You can pass an HTML element or function that returns a single element. By default `document.body`.
34
+ * Appends the React Tooltip to a specific element instead of the default `document.body`. You may pass:
35
+ * - A DOM element (`HTMLElement` or `DocumentFragment`)
36
+ * - A function that returns a single element
37
+ * - `null`
32
38
  *
39
+ * @example
40
+ * <CTooltip container={document.getElementById('my-container')}>...</CTooltip>
41
+ *
42
+ * @default document.body
33
43
  * @since 4.11.0
34
44
  */
35
45
  container?: DocumentFragment | Element | (() => DocumentFragment | Element | null) | null
46
+
36
47
  /**
37
- * Content node for your component.
48
+ * Content to be displayed within the React Tooltip. Can be a string or any valid React node.
38
49
  */
39
50
  content: ReactNode | string
51
+
40
52
  /**
41
- * The delay for displaying and hiding the tooltip (in milliseconds). When a numerical value is provided, the delay applies to both the hide and show actions. The object structure for specifying the delay is as follows: delay: `{ 'show': 500, 'hide': 100 }`.
53
+ * The delay (in milliseconds) before showing or hiding the React Tooltip.
54
+ * - If provided as a number, the delay is applied to both "show" and "hide".
55
+ * - If provided as an object, it should have distinct "show" and "hide" values.
56
+ *
57
+ * @example
58
+ * // Delays 300ms on both show and hide
59
+ * <CTooltip delay={300}>...</CTooltip>
60
+ *
61
+ * // Delays 500ms on show and 100ms on hide
62
+ * <CTooltip delay={{ show: 500, hide: 100 }}>...</CTooltip>
42
63
  *
43
64
  * @since 4.9.0
44
65
  */
45
66
  delay?: number | { show: number; hide: number }
67
+
46
68
  /**
47
- * Specify the desired order of fallback placements by providing a list of placements as an array. The placements should be prioritized based on preference.
69
+ * Array of fallback placements for the React Tooltip to use when the preferred placement cannot be achieved. These placements are tried in order.
48
70
  *
71
+ * @type 'top', 'right', 'bottom', 'left' | ('top', 'right', 'bottom', 'left')[]
49
72
  * @since 4.9.0
50
73
  */
51
74
  fallbackPlacements?: Placements | Placements[]
75
+
52
76
  /**
53
- * Offset of the tooltip relative to its target.
77
+ * Adjusts the offset of the React Tooltip relative to its target. Expects a tuple `[x-axis, y-axis]`.
78
+ *
79
+ * @example
80
+ * // Offset the menu 0px in X and 10px in Y direction
81
+ * <CTooltip offset={[0, 10]}>...</CTooltip>
82
+ *
83
+ * // Offset the menu 5px in both X and Y direction
84
+ * <CTooltip offset={[5, 5]}>...</CTooltip>
54
85
  */
55
86
  offset?: [number, number]
87
+
56
88
  /**
57
- * Callback fired when the component requests to be hidden.
89
+ * Callback fired immediately after the React Tooltip is hidden.
58
90
  */
59
91
  onHide?: () => void
92
+
60
93
  /**
61
- * Callback fired when the component requests to be shown.
94
+ * Callback fired immediately after the React Tooltip is shown.
62
95
  */
63
96
  onShow?: () => void
97
+
64
98
  /**
65
- * Sets which event handlers you’d like provided to your toggle prop. You can specify one trigger or an array of them.
99
+ * Initial placement of the React Tooltip. Note that Popper.js modifiers may alter this placement automatically if there's insufficient space in the chosen position.
100
+ */
101
+ placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
102
+
103
+ /**
104
+ * Customize the Popper.js configuration used to position the React Tooltip. Pass either an object or a function returning a modified config. [Learn more](https://popper.js.org/docs/v2/constructors/#options)
105
+ *
106
+ * @example
107
+ * <CTooltip
108
+ * popperConfig={(defaultConfig) => ({
109
+ * ...defaultConfig,
110
+ * strategy: 'fixed',
111
+ * modifiers: [
112
+ * ...defaultConfig.modifiers,
113
+ * { name: 'computeStyles', options: { adaptive: false } },
114
+ * ],
115
+ * })}
116
+ * >...</CTooltip>
66
117
  *
67
- * @type 'hover' | 'focus' | 'click'
118
+ * @since 5.5.0
68
119
  */
69
- trigger?: Triggers | Triggers[]
120
+ popperConfig?: Partial<Options> | ((defaultPopperConfig: Partial<Options>) => Partial<Options>)
121
+
70
122
  /**
71
- * Describes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.
123
+ * Determines the events that toggle the visibility of the React Tooltip. Can be a single trigger or an array of triggers.
124
+ *
125
+ * @example
126
+ * // Hover-only tooltip
127
+ * <CTooltip trigger="hover">...</CTooltip>
128
+ *
129
+ * // Hover + click combined
130
+ * <CTooltip trigger={['hover', 'click']}>...</CTooltip>
131
+ *
132
+ * @type 'hover' | 'focus' | 'click' | ('hover' | 'focus' | 'click')[]
72
133
  */
73
- placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
134
+ trigger?: Triggers | Triggers[]
135
+
74
136
  /**
75
- * Toggle the visibility of tooltip component.
137
+ * Controls the visibility of the React Tooltip.
138
+ * - `true` to show the tooltip.
139
+ * - `false` to hide the tooltip.
76
140
  */
77
141
  visible?: boolean
78
142
  }
@@ -91,11 +155,12 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
91
155
  onHide,
92
156
  onShow,
93
157
  placement = 'top',
158
+ popperConfig,
94
159
  trigger = ['hover', 'focus'],
95
160
  visible,
96
161
  ...rest
97
162
  },
98
- ref,
163
+ ref
99
164
  ) => {
100
165
  const tooltipRef = useRef<HTMLDivElement>(null)
101
166
  const togglerRef = useRef(null)
@@ -109,30 +174,20 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
109
174
 
110
175
  const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
111
176
 
112
- const popperConfig = {
177
+ const defaultPopperConfig: Partial<Options> = {
113
178
  modifiers: [
114
- {
115
- name: 'arrow',
116
- options: {
117
- element: '.tooltip-arrow',
118
- },
119
- },
120
- {
121
- name: 'flip',
122
- options: {
123
- fallbackPlacements: fallbackPlacements,
124
- },
125
- },
126
- {
127
- name: 'offset',
128
- options: {
129
- offset: offset,
130
- },
131
- },
179
+ { name: 'arrow', options: { element: '.tooltip-arrow' } },
180
+ { name: 'flip', options: { fallbackPlacements } },
181
+ { name: 'offset', options: { offset } },
132
182
  ],
133
183
  placement: getRTLPlacement(placement, togglerRef.current),
134
184
  }
135
185
 
186
+ const computedPopperConfig: Partial<Options> = {
187
+ ...defaultPopperConfig,
188
+ ...(typeof popperConfig === 'function' ? popperConfig(defaultPopperConfig) : popperConfig),
189
+ }
190
+
136
191
  useEffect(() => {
137
192
  if (visible) {
138
193
  handleShow()
@@ -144,7 +199,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
144
199
 
145
200
  useEffect(() => {
146
201
  if (mounted && togglerRef.current && tooltipRef.current) {
147
- initPopper(togglerRef.current, tooltipRef.current, popperConfig)
202
+ initPopper(togglerRef.current, tooltipRef.current, computedPopperConfig)
148
203
  setTimeout(() => {
149
204
  setVisible(true)
150
205
  }, _delay.show)
@@ -214,7 +269,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
214
269
  fade: animation,
215
270
  show: _visible,
216
271
  },
217
- className,
272
+ className
218
273
  )}
219
274
  id={id}
220
275
  ref={forkedRef}
@@ -228,7 +283,7 @@ export const CTooltip = forwardRef<HTMLDivElement, CTooltipProps>(
228
283
  </CConditionalPortal>
229
284
  </>
230
285
  )
231
- },
286
+ }
232
287
  )
233
288
 
234
289
  CTooltip.propTypes = {
@@ -248,6 +303,7 @@ CTooltip.propTypes = {
248
303
  onHide: PropTypes.func,
249
304
  onShow: PropTypes.func,
250
305
  placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
306
+ popperConfig: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
251
307
  trigger: triggerPropType,
252
308
  visible: PropTypes.bool,
253
309
  }
@@ -7,13 +7,13 @@ interface UseColorModesOutput {
7
7
  }
8
8
 
9
9
  const getStoredTheme = (localStorageItemName: string) =>
10
- typeof globalThis !== 'undefined' && localStorage.getItem(localStorageItemName)
10
+ typeof window !== 'undefined' && localStorage.getItem(localStorageItemName)
11
11
 
12
12
  const setStoredTheme = (localStorageItemName: string, colorMode: string) =>
13
13
  localStorage.setItem(localStorageItemName, colorMode)
14
14
 
15
15
  const getPreferredColorScheme = (localStorageItemName: string) => {
16
- if (typeof globalThis === 'undefined') {
16
+ if (typeof window === 'undefined') {
17
17
  return 'light'
18
18
  }
19
19
 
@@ -23,12 +23,12 @@ const getPreferredColorScheme = (localStorageItemName: string) => {
23
23
  return storedTheme
24
24
  }
25
25
 
26
- return globalThis.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
26
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
27
27
  }
28
28
 
29
29
  const setTheme = (colorMode: string) => {
30
30
  document.documentElement.dataset.coreuiTheme =
31
- colorMode === 'auto' && globalThis.matchMedia('(prefers-color-scheme: dark)').matches
31
+ colorMode === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches
32
32
  ? 'dark'
33
33
  : colorMode
34
34
 
@@ -51,7 +51,7 @@ export const useColorModes = (
51
51
  }, [colorMode])
52
52
 
53
53
  useEffect(() => {
54
- globalThis.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
54
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
55
55
  const storedTheme = getStoredTheme(localStorageItemName)
56
56
  if (storedTheme !== 'light' && storedTheme !== 'dark' && colorMode) {
57
57
  setTheme(colorMode)