@coreui/react-pro 5.0.0-rc.3 → 5.1.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.
- package/README.md +1 -1
- package/dist/cjs/components/badge/CBadge.d.ts +1 -1
- package/dist/cjs/components/calendar/CCalendar.d.ts +3 -3
- package/dist/cjs/components/card/CCard.d.ts +1 -1
- package/dist/cjs/components/date-range-picker/CDateRangePicker.d.ts +3 -3
- package/dist/cjs/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/nav/CNavGroup.d.ts +1 -1
- package/dist/cjs/components/nav/CNavGroupItems.d.ts +1 -1
- package/dist/cjs/components/nav/CNavItem.d.ts +1 -1
- package/dist/cjs/components/popover/CPopover.js +41 -40
- package/dist/cjs/components/popover/CPopover.js.map +1 -1
- package/dist/cjs/components/rating/CRating.d.ts +70 -0
- package/dist/cjs/components/rating/CRating.js +123 -0
- package/dist/cjs/components/rating/CRating.js.map +1 -0
- package/dist/cjs/components/rating/index.d.ts +2 -0
- package/dist/cjs/components/sidebar/CSidebarBrand.d.ts +1 -1
- package/dist/cjs/components/sidebar/CSidebarNav.d.ts +1 -1
- package/dist/cjs/components/time-picker/CTimePicker.d.ts +3 -3
- package/dist/cjs/components/tooltip/CTooltip.js +44 -40
- package/dist/cjs/components/tooltip/CTooltip.js.map +1 -1
- package/dist/cjs/hooks/usePopper.d.ts +1 -0
- package/dist/cjs/hooks/usePopper.js +11 -4
- package/dist/cjs/hooks/usePopper.js.map +1 -1
- package/dist/cjs/hooks/useStateWithCallback.d.ts +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node_modules/classnames/index.js +45 -27
- package/dist/cjs/node_modules/classnames/index.js.map +1 -1
- package/dist/esm/components/badge/CBadge.d.ts +1 -1
- package/dist/esm/components/calendar/CCalendar.d.ts +3 -3
- package/dist/esm/components/card/CCard.d.ts +1 -1
- package/dist/esm/components/date-range-picker/CDateRangePicker.d.ts +3 -3
- package/dist/esm/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/nav/CNavGroup.d.ts +1 -1
- package/dist/esm/components/nav/CNavGroupItems.d.ts +1 -1
- package/dist/esm/components/nav/CNavItem.d.ts +1 -1
- package/dist/esm/components/popover/CPopover.js +41 -40
- package/dist/esm/components/popover/CPopover.js.map +1 -1
- package/dist/esm/components/rating/CRating.d.ts +70 -0
- package/dist/esm/components/rating/CRating.js +121 -0
- package/dist/esm/components/rating/CRating.js.map +1 -0
- package/dist/esm/components/rating/index.d.ts +2 -0
- package/dist/esm/components/sidebar/CSidebarBrand.d.ts +1 -1
- package/dist/esm/components/sidebar/CSidebarNav.d.ts +1 -1
- package/dist/esm/components/time-picker/CTimePicker.d.ts +3 -3
- package/dist/esm/components/tooltip/CTooltip.js +44 -40
- package/dist/esm/components/tooltip/CTooltip.js.map +1 -1
- package/dist/esm/hooks/usePopper.d.ts +1 -0
- package/dist/esm/hooks/usePopper.js +11 -4
- package/dist/esm/hooks/usePopper.js.map +1 -1
- package/dist/esm/hooks/useStateWithCallback.d.ts +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node_modules/classnames/index.js +45 -27
- package/dist/esm/node_modules/classnames/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/badge/CBadge.tsx +1 -1
- package/src/components/calendar/CCalendar.tsx +3 -3
- package/src/components/card/CCard.tsx +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +3 -3
- package/src/components/dropdown/CDropdownToggle.tsx +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/nav/CNavGroup.tsx +1 -1
- package/src/components/nav/CNavGroupItems.tsx +1 -1
- package/src/components/nav/CNavItem.tsx +1 -1
- package/src/components/popover/CPopover.tsx +51 -66
- package/src/components/rating/CRating.tsx +291 -0
- package/src/components/rating/index.ts +3 -0
- package/src/components/sidebar/CSidebarBrand.tsx +1 -1
- package/src/components/sidebar/CSidebarNav.tsx +1 -1
- package/src/components/time-picker/CTimePicker.tsx +3 -3
- package/src/components/tooltip/CTooltip.tsx +55 -66
- package/src/hooks/usePopper.ts +15 -5
|
@@ -122,7 +122,7 @@ export interface CCalendarProps {
|
|
|
122
122
|
/**
|
|
123
123
|
* Set whether to display week numbers in the calendar.
|
|
124
124
|
*
|
|
125
|
-
* @since 5.0.0
|
|
125
|
+
* @since 5.0.0
|
|
126
126
|
*/
|
|
127
127
|
showWeekNumber?: boolean
|
|
128
128
|
/**
|
|
@@ -132,7 +132,7 @@ export interface CCalendarProps {
|
|
|
132
132
|
/**
|
|
133
133
|
* Specify the type of date selection as day, week, month, or year.
|
|
134
134
|
*
|
|
135
|
-
* @since 5.0.0
|
|
135
|
+
* @since 5.0.0
|
|
136
136
|
*/
|
|
137
137
|
selectionType?: 'day' | 'week' | 'month' | 'year'
|
|
138
138
|
/**
|
|
@@ -148,7 +148,7 @@ export interface CCalendarProps {
|
|
|
148
148
|
/**
|
|
149
149
|
* Label displayed over week numbers in the calendar.
|
|
150
150
|
*
|
|
151
|
-
* @since 5.0.0
|
|
151
|
+
* @since 5.0.0
|
|
152
152
|
*/
|
|
153
153
|
weekNumbersLabel?: string
|
|
154
154
|
/**
|
|
@@ -26,7 +26,7 @@ export interface CCardProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
26
26
|
* Sets the component's color scheme to one of CoreUI's themed colors, ensuring the text color contrast adheres to the WCAG 4.5:1 contrast ratio standard for accessibility.
|
|
27
27
|
*
|
|
28
28
|
* @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
|
|
29
|
-
* @since 5.0.0
|
|
29
|
+
* @since 5.0.0
|
|
30
30
|
*/
|
|
31
31
|
textBgColor?: Colors
|
|
32
32
|
}
|
|
@@ -99,19 +99,19 @@ export interface CDateRangePickerProps
|
|
|
99
99
|
/**
|
|
100
100
|
* Custom function to format the selected date into a string according to a custom format.
|
|
101
101
|
*
|
|
102
|
-
* @since
|
|
102
|
+
* @since 5.0.0
|
|
103
103
|
*/
|
|
104
104
|
inputDateFormat?: (date: Date) => string
|
|
105
105
|
/**
|
|
106
106
|
* Custom function to parse the input value into a valid Date object.
|
|
107
107
|
*
|
|
108
|
-
* @since
|
|
108
|
+
* @since 5.0.0
|
|
109
109
|
*/
|
|
110
110
|
inputDateParse?: (date: string | Date) => Date
|
|
111
111
|
/**
|
|
112
112
|
* Defines the delay (in milliseconds) for the input field's onChange event.
|
|
113
113
|
*
|
|
114
|
-
* @since
|
|
114
|
+
* @since 5.0.0
|
|
115
115
|
*/
|
|
116
116
|
inputOnChangeDelay?: number
|
|
117
117
|
/**
|
|
@@ -21,7 +21,7 @@ export interface CDropdownToggleProps extends Omit<CButtonProps, 'type'> {
|
|
|
21
21
|
/**
|
|
22
22
|
* If a dropdown `variant` is set to `nav-item` then render the toggler as a link instead of a button.
|
|
23
23
|
*
|
|
24
|
-
* @since
|
|
24
|
+
* @since 5.0.0
|
|
25
25
|
*/
|
|
26
26
|
navLink?: boolean
|
|
27
27
|
/**
|
package/src/components/index.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React, { forwardRef, HTMLAttributes, ReactNode, useRef, useEffect, useState } from 'react'
|
|
2
2
|
import classNames from 'classnames'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
|
-
import { Transition } from 'react-transition-group'
|
|
5
4
|
|
|
6
5
|
import { CConditionalPortal } from '../conditional-portal'
|
|
7
6
|
import { useForkedRef, usePopper } from '../../hooks'
|
|
8
7
|
import { fallbackPlacementsPropType, triggerPropType } from '../../props'
|
|
9
8
|
import type { Placements, Triggers } from '../../types'
|
|
10
|
-
import {
|
|
9
|
+
import { executeAfterTransition, getRTLPlacement } from '../../utils'
|
|
11
10
|
|
|
12
11
|
export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'content'> {
|
|
13
12
|
/**
|
|
@@ -101,6 +100,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
101
100
|
const uID = useRef(`popover${Math.floor(Math.random() * 1_000_000)}`)
|
|
102
101
|
|
|
103
102
|
const { initPopper, destroyPopper } = usePopper()
|
|
103
|
+
const [mounted, setMounted] = useState(false)
|
|
104
104
|
const [_visible, setVisible] = useState(visible)
|
|
105
105
|
|
|
106
106
|
const _delay = typeof delay === 'number' ? { show: delay, hide: delay } : delay
|
|
@@ -133,14 +133,39 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
133
133
|
setVisible(visible)
|
|
134
134
|
}, [visible])
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (_visible) {
|
|
138
|
+
setMounted(true)
|
|
139
|
+
|
|
140
|
+
if (popoverRef.current) {
|
|
141
|
+
popoverRef.current.classList.remove('fade', 'show')
|
|
142
|
+
destroyPopper()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setTimeout(() => {
|
|
146
|
+
if (togglerRef.current && popoverRef.current) {
|
|
147
|
+
if (animation) {
|
|
148
|
+
popoverRef.current.classList.add('fade')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
initPopper(togglerRef.current, popoverRef.current, popperConfig)
|
|
152
|
+
popoverRef.current.classList.add('show')
|
|
153
|
+
onShow && onShow()
|
|
154
|
+
}
|
|
155
|
+
}, _delay.show)
|
|
140
156
|
}
|
|
141
157
|
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
return () => {
|
|
159
|
+
if (popoverRef.current) {
|
|
160
|
+
popoverRef.current.classList.remove('show')
|
|
161
|
+
onHide && onHide()
|
|
162
|
+
executeAfterTransition(() => {
|
|
163
|
+
destroyPopper()
|
|
164
|
+
setMounted(false)
|
|
165
|
+
}, popoverRef.current)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, [_visible])
|
|
144
169
|
|
|
145
170
|
return (
|
|
146
171
|
<>
|
|
@@ -150,71 +175,31 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
|
|
|
150
175
|
}),
|
|
151
176
|
ref: togglerRef,
|
|
152
177
|
...((trigger === 'click' || trigger.includes('click')) && {
|
|
153
|
-
onClick: () =>
|
|
178
|
+
onClick: () => setVisible(!_visible),
|
|
154
179
|
}),
|
|
155
180
|
...((trigger === 'focus' || trigger.includes('focus')) && {
|
|
156
|
-
onFocus: () =>
|
|
157
|
-
onBlur: () =>
|
|
181
|
+
onFocus: () => setVisible(true),
|
|
182
|
+
onBlur: () => setVisible(false),
|
|
158
183
|
}),
|
|
159
184
|
...((trigger === 'hover' || trigger.includes('hover')) && {
|
|
160
|
-
onMouseEnter: () =>
|
|
161
|
-
onMouseLeave: () =>
|
|
185
|
+
onMouseEnter: () => setVisible(true),
|
|
186
|
+
onMouseLeave: () => setVisible(false),
|
|
162
187
|
}),
|
|
163
188
|
})}
|
|
164
189
|
<CConditionalPortal container={container} portal={true}>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
popoverRef.current.style.display = 'initial'
|
|
179
|
-
}
|
|
180
|
-
}}
|
|
181
|
-
onExit={onHide}
|
|
182
|
-
onExited={() => {
|
|
183
|
-
destroyPopper()
|
|
184
|
-
}}
|
|
185
|
-
timeout={{
|
|
186
|
-
enter: 0,
|
|
187
|
-
exit: popoverRef.current
|
|
188
|
-
? getTransitionDurationFromElement(popoverRef.current) + 50
|
|
189
|
-
: 200,
|
|
190
|
-
}}
|
|
191
|
-
unmountOnExit
|
|
192
|
-
>
|
|
193
|
-
{(state) => (
|
|
194
|
-
<div
|
|
195
|
-
className={classNames(
|
|
196
|
-
'popover',
|
|
197
|
-
'bs-popover-auto',
|
|
198
|
-
{
|
|
199
|
-
fade: animation,
|
|
200
|
-
show: state === 'entered',
|
|
201
|
-
},
|
|
202
|
-
className,
|
|
203
|
-
)}
|
|
204
|
-
id={uID.current}
|
|
205
|
-
ref={forkedRef}
|
|
206
|
-
role="tooltip"
|
|
207
|
-
style={{
|
|
208
|
-
display: 'none',
|
|
209
|
-
}}
|
|
210
|
-
{...rest}
|
|
211
|
-
>
|
|
212
|
-
<div className="popover-arrow"></div>
|
|
213
|
-
<div className="popover-header">{title}</div>
|
|
214
|
-
<div className="popover-body">{content}</div>
|
|
215
|
-
</div>
|
|
216
|
-
)}
|
|
217
|
-
</Transition>
|
|
190
|
+
{mounted && (
|
|
191
|
+
<div
|
|
192
|
+
className={classNames('popover', 'bs-popover-auto', className)}
|
|
193
|
+
id={uID.current}
|
|
194
|
+
ref={forkedRef}
|
|
195
|
+
role="tooltip"
|
|
196
|
+
{...rest}
|
|
197
|
+
>
|
|
198
|
+
<div className="popover-arrow"></div>
|
|
199
|
+
<div className="popover-header">{title}</div>
|
|
200
|
+
<div className="popover-body">{content}</div>
|
|
201
|
+
</div>
|
|
202
|
+
)}
|
|
218
203
|
</CConditionalPortal>
|
|
219
204
|
</>
|
|
220
205
|
)
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import React, { forwardRef, Fragment, HTMLAttributes, ReactNode, useId, useState } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import { CTooltip } from '../tooltip'
|
|
5
|
+
|
|
6
|
+
type Icon = {
|
|
7
|
+
[key: number]: JSX.Element
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CRatingProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
11
|
+
/**
|
|
12
|
+
* The default icon to display when the item is selected.
|
|
13
|
+
*/
|
|
14
|
+
activeIcon?: string | JSX.Element | Icon
|
|
15
|
+
/**
|
|
16
|
+
* Enables the clearing upon clicking the selected item again.
|
|
17
|
+
*/
|
|
18
|
+
allowClear?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* A string of all className you want applied to the component.
|
|
21
|
+
*/
|
|
22
|
+
className?: string
|
|
23
|
+
/**
|
|
24
|
+
* Toggle the disabled state for the component.
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean
|
|
27
|
+
/**
|
|
28
|
+
* If enabled, only the currently selected icon will be visibly highlighted.
|
|
29
|
+
*/
|
|
30
|
+
highlightOnlySelected?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* The default icon to display when the item is not selected.
|
|
33
|
+
*/
|
|
34
|
+
icon?: string | JSX.Element | Icon
|
|
35
|
+
/**
|
|
36
|
+
* The maximum value the user can select.
|
|
37
|
+
*/
|
|
38
|
+
max?: number
|
|
39
|
+
/**
|
|
40
|
+
* The name attribute of the radio input elements.
|
|
41
|
+
*/
|
|
42
|
+
name?: string
|
|
43
|
+
/**
|
|
44
|
+
* Execute a function when a user changes the selected element.
|
|
45
|
+
*/
|
|
46
|
+
onChange?: (value: number | null) => void
|
|
47
|
+
/**
|
|
48
|
+
* Execute a function when a user hover the element.
|
|
49
|
+
*/
|
|
50
|
+
onHover?: (value: number) => void
|
|
51
|
+
/**
|
|
52
|
+
* Minimum increment value change allowed.
|
|
53
|
+
*/
|
|
54
|
+
precision?: number
|
|
55
|
+
/**
|
|
56
|
+
* Toggle the readonly state for the component.
|
|
57
|
+
*/
|
|
58
|
+
readOnly?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* Size the component small, large, or custom if you define custom icons with custom height.
|
|
61
|
+
*/
|
|
62
|
+
size?: 'sm' | 'lg' | 'custom'
|
|
63
|
+
/**
|
|
64
|
+
* Enable tooltips with default values or set specific labels for each icon.
|
|
65
|
+
*/
|
|
66
|
+
tooltips?: boolean | string[]
|
|
67
|
+
/**
|
|
68
|
+
* The `value` attribute of component.
|
|
69
|
+
*
|
|
70
|
+
* @controllable onChange
|
|
71
|
+
* */
|
|
72
|
+
value?: number
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const CConditionalTooltip = ({
|
|
76
|
+
children,
|
|
77
|
+
content,
|
|
78
|
+
tooltip,
|
|
79
|
+
}: {
|
|
80
|
+
children: ReactNode
|
|
81
|
+
content?: ReactNode
|
|
82
|
+
tooltip?: boolean
|
|
83
|
+
}) => {
|
|
84
|
+
return tooltip ? (
|
|
85
|
+
<CTooltip content={content}>
|
|
86
|
+
<span>{children}</span>
|
|
87
|
+
</CTooltip>
|
|
88
|
+
) : (
|
|
89
|
+
children
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const CRating = forwardRef<HTMLDivElement, CRatingProps>(
|
|
94
|
+
(
|
|
95
|
+
{
|
|
96
|
+
activeIcon,
|
|
97
|
+
allowClear,
|
|
98
|
+
className,
|
|
99
|
+
disabled,
|
|
100
|
+
highlightOnlySelected,
|
|
101
|
+
icon,
|
|
102
|
+
max = 5,
|
|
103
|
+
name,
|
|
104
|
+
onChange,
|
|
105
|
+
onHover,
|
|
106
|
+
precision = 1,
|
|
107
|
+
readOnly,
|
|
108
|
+
size,
|
|
109
|
+
tooltips,
|
|
110
|
+
value,
|
|
111
|
+
...rest
|
|
112
|
+
},
|
|
113
|
+
ref,
|
|
114
|
+
) => {
|
|
115
|
+
const [cleared, setCleared] = useState(false)
|
|
116
|
+
const [currentValue, setCurrentValue] = useState(value ?? null)
|
|
117
|
+
const [hoverValue, setHoverValue] = useState<number | null>(null)
|
|
118
|
+
const [tooltipValue, setTooltipValue] = useState<number | string | null>(null)
|
|
119
|
+
const _name = name || useId()
|
|
120
|
+
|
|
121
|
+
const handleMouseEnter = (value: number) => {
|
|
122
|
+
if (disabled || readOnly) {
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
onHover && onHover(value)
|
|
127
|
+
setHoverValue(value)
|
|
128
|
+
value && setTooltipValue(value)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const handleOnChange = (value: number) => {
|
|
132
|
+
if (disabled || readOnly) {
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (cleared) {
|
|
137
|
+
setCleared(false)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setCurrentValue(value)
|
|
142
|
+
onChange && onChange(value)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const handleOnClick = (value: number) => {
|
|
146
|
+
if (disabled || readOnly) {
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (allowClear && value === currentValue) {
|
|
151
|
+
setCleared(true)
|
|
152
|
+
onChange && onChange(null)
|
|
153
|
+
setCurrentValue(null)
|
|
154
|
+
setHoverValue(null)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<div
|
|
160
|
+
className={classNames(
|
|
161
|
+
'rating',
|
|
162
|
+
{
|
|
163
|
+
[`rating-${size}`]: size,
|
|
164
|
+
disabled: disabled,
|
|
165
|
+
readonly: readOnly,
|
|
166
|
+
},
|
|
167
|
+
className,
|
|
168
|
+
)}
|
|
169
|
+
onMouseLeave={() => !disabled && !readOnly && setHoverValue(null)}
|
|
170
|
+
role="radiogroup"
|
|
171
|
+
{...rest}
|
|
172
|
+
ref={ref}
|
|
173
|
+
>
|
|
174
|
+
{Array.from({ length: max }, (_, index) => {
|
|
175
|
+
const numberOfRadios = 1 / precision
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<CConditionalTooltip
|
|
179
|
+
key={index}
|
|
180
|
+
{...(tooltips && {
|
|
181
|
+
content: Array.isArray(tooltips)
|
|
182
|
+
? tooltips[index]
|
|
183
|
+
: precision
|
|
184
|
+
? tooltipValue
|
|
185
|
+
: index + 1,
|
|
186
|
+
tooltip: true,
|
|
187
|
+
})}
|
|
188
|
+
>
|
|
189
|
+
<div className="rating-item">
|
|
190
|
+
{Array.from({ length: numberOfRadios }, (_, _index) => {
|
|
191
|
+
const isNotLastItem = _index + 1 < numberOfRadios
|
|
192
|
+
const value =
|
|
193
|
+
numberOfRadios === 1 ? index + 1 : index + (_index + 1) * (1 * precision)
|
|
194
|
+
const id = useId()
|
|
195
|
+
|
|
196
|
+
const isItemChecked = () => value === currentValue
|
|
197
|
+
|
|
198
|
+
const isItemActive = () => {
|
|
199
|
+
if (
|
|
200
|
+
highlightOnlySelected
|
|
201
|
+
? hoverValue === value
|
|
202
|
+
: hoverValue && hoverValue >= value
|
|
203
|
+
) {
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (
|
|
208
|
+
hoverValue === null &&
|
|
209
|
+
(highlightOnlySelected
|
|
210
|
+
? isItemChecked()
|
|
211
|
+
: currentValue && currentValue >= value)
|
|
212
|
+
) {
|
|
213
|
+
return true
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return false
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<Fragment key={value}>
|
|
221
|
+
<label
|
|
222
|
+
className={classNames('rating-item-label', {
|
|
223
|
+
active: isItemActive(),
|
|
224
|
+
})}
|
|
225
|
+
htmlFor={id}
|
|
226
|
+
onClick={() => handleOnClick(value)}
|
|
227
|
+
onMouseEnter={() => handleMouseEnter(value)}
|
|
228
|
+
{...(isNotLastItem && {
|
|
229
|
+
style: {
|
|
230
|
+
zIndex: 1 / precision - _index,
|
|
231
|
+
position: 'absolute',
|
|
232
|
+
width: `${precision * (_index + 1) * 100}%`,
|
|
233
|
+
overflow: 'hidden',
|
|
234
|
+
opacity: 0,
|
|
235
|
+
},
|
|
236
|
+
})}
|
|
237
|
+
>
|
|
238
|
+
{icon ? (
|
|
239
|
+
<div className="rating-item-custom-icon">
|
|
240
|
+
{(icon as Icon)[value] ?? icon}
|
|
241
|
+
</div>
|
|
242
|
+
) : (
|
|
243
|
+
<div className="rating-item-icon"></div>
|
|
244
|
+
)}
|
|
245
|
+
{activeIcon && (
|
|
246
|
+
<div className="rating-item-custom-icon-active">
|
|
247
|
+
{(activeIcon as Icon)[value] ?? activeIcon}
|
|
248
|
+
</div>
|
|
249
|
+
)}
|
|
250
|
+
</label>
|
|
251
|
+
<input
|
|
252
|
+
className="rating-item-input"
|
|
253
|
+
checked={isItemChecked()}
|
|
254
|
+
disabled={disabled || readOnly}
|
|
255
|
+
id={id}
|
|
256
|
+
name={_name}
|
|
257
|
+
onChange={() => handleOnChange(value)}
|
|
258
|
+
onFocus={() => handleMouseEnter(value)}
|
|
259
|
+
type="radio"
|
|
260
|
+
value={value}
|
|
261
|
+
/>
|
|
262
|
+
</Fragment>
|
|
263
|
+
)
|
|
264
|
+
})}
|
|
265
|
+
</div>
|
|
266
|
+
</CConditionalTooltip>
|
|
267
|
+
)
|
|
268
|
+
})}
|
|
269
|
+
</div>
|
|
270
|
+
)
|
|
271
|
+
},
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
CRating.propTypes = {
|
|
275
|
+
children: PropTypes.node,
|
|
276
|
+
activeIcon: PropTypes.any,
|
|
277
|
+
allowClear: PropTypes.bool,
|
|
278
|
+
disabled: PropTypes.bool,
|
|
279
|
+
highlightOnlySelected: PropTypes.bool,
|
|
280
|
+
icon: PropTypes.any,
|
|
281
|
+
max: PropTypes.number,
|
|
282
|
+
name: PropTypes.string,
|
|
283
|
+
onChange: PropTypes.func,
|
|
284
|
+
onHover: PropTypes.func,
|
|
285
|
+
precision: PropTypes.number,
|
|
286
|
+
readOnly: PropTypes.bool,
|
|
287
|
+
size: PropTypes.oneOf(['sm', 'lg', 'custom']),
|
|
288
|
+
value: PropTypes.number,
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
CRating.displayName = 'CRating'
|
|
@@ -81,7 +81,7 @@ export interface CTimePickerProps
|
|
|
81
81
|
/**
|
|
82
82
|
* Specify a list of available hours using an array, or customize the filtering of hours through a function.
|
|
83
83
|
*
|
|
84
|
-
* @since 5.0.0
|
|
84
|
+
* @since 5.0.0
|
|
85
85
|
*/
|
|
86
86
|
hours?: number[] | ((hour: number) => number[])
|
|
87
87
|
/**
|
|
@@ -91,7 +91,7 @@ export interface CTimePickerProps
|
|
|
91
91
|
/**
|
|
92
92
|
* Defines the delay (in milliseconds) for the input field's onChange event.
|
|
93
93
|
*
|
|
94
|
-
* @since
|
|
94
|
+
* @since 5.0.0
|
|
95
95
|
*/
|
|
96
96
|
inputOnChangeDelay?: number
|
|
97
97
|
/**
|
|
@@ -105,7 +105,7 @@ export interface CTimePickerProps
|
|
|
105
105
|
/**
|
|
106
106
|
* Toggle the display of minutes, specify a list of available minutes using an array, or customize the filtering of minutes through a function.
|
|
107
107
|
*
|
|
108
|
-
* @since 5.0.0
|
|
108
|
+
* @since 5.0.0
|
|
109
109
|
*/
|
|
110
110
|
minutes?: boolean | number[] | ((minute: number) => number[])
|
|
111
111
|
/**
|