@veracity/vui 2.26.0 → 2.27.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/dist/cjs/icons/baseIcons/fal/falStar.d.ts +4 -0
- package/dist/cjs/icons/baseIcons/fal/falStar.d.ts.map +1 -0
- package/dist/cjs/icons/baseIcons/fal/falStar.js +8 -0
- package/dist/cjs/icons/baseIcons/fal/falStar.js.map +1 -0
- package/dist/cjs/icons/baseIcons/icons.d.ts +1 -0
- package/dist/cjs/icons/baseIcons/icons.d.ts.map +1 -1
- package/dist/cjs/icons/baseIcons/icons.js +4 -2
- package/dist/cjs/icons/baseIcons/icons.js.map +1 -1
- package/dist/cjs/icons/baseIcons/types.d.ts +1 -1
- package/dist/cjs/icons/baseIcons/types.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/rating/index.d.ts +3 -0
- package/dist/cjs/rating/index.d.ts.map +1 -0
- package/dist/cjs/rating/index.js +24 -0
- package/dist/cjs/rating/index.js.map +1 -0
- package/dist/cjs/rating/rating.d.ts +4 -0
- package/dist/cjs/rating/rating.d.ts.map +1 -0
- package/dist/cjs/rating/rating.js +115 -0
- package/dist/cjs/rating/rating.js.map +1 -0
- package/dist/cjs/rating/rating.types.d.ts +19 -0
- package/dist/cjs/rating/rating.types.d.ts.map +1 -0
- package/dist/cjs/rating/rating.types.js +3 -0
- package/dist/cjs/rating/rating.types.js.map +1 -0
- package/dist/cjs/rating/theme.d.ts +35 -0
- package/dist/cjs/rating/theme.d.ts.map +1 -0
- package/dist/cjs/rating/theme.js +41 -0
- package/dist/cjs/rating/theme.js.map +1 -0
- package/dist/cjs/theme/components.d.ts +33 -0
- package/dist/cjs/theme/components.d.ts.map +1 -1
- package/dist/cjs/theme/components.js +30 -28
- package/dist/cjs/theme/components.js.map +1 -1
- package/dist/cjs/theme/defaultTheme.d.ts +33 -0
- package/dist/cjs/theme/defaultTheme.d.ts.map +1 -1
- package/dist/esm/icons/baseIcons/fal/falStar.d.ts +4 -0
- package/dist/esm/icons/baseIcons/fal/falStar.d.ts.map +1 -0
- package/dist/esm/icons/baseIcons/fal/falStar.js +6 -0
- package/dist/esm/icons/baseIcons/fal/falStar.js.map +1 -0
- package/dist/esm/icons/baseIcons/icons.d.ts +1 -0
- package/dist/esm/icons/baseIcons/icons.d.ts.map +1 -1
- package/dist/esm/icons/baseIcons/icons.js +1 -0
- package/dist/esm/icons/baseIcons/icons.js.map +1 -1
- package/dist/esm/icons/baseIcons/types.d.ts +1 -1
- package/dist/esm/icons/baseIcons/types.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/rating/index.d.ts +3 -0
- package/dist/esm/rating/index.d.ts.map +1 -0
- package/dist/esm/rating/index.js +3 -0
- package/dist/esm/rating/index.js.map +1 -0
- package/dist/esm/rating/rating.d.ts +4 -0
- package/dist/esm/rating/rating.d.ts.map +1 -0
- package/dist/esm/rating/rating.js +97 -0
- package/dist/esm/rating/rating.js.map +1 -0
- package/dist/esm/rating/rating.types.d.ts +19 -0
- package/dist/esm/rating/rating.types.d.ts.map +1 -0
- package/dist/esm/rating/rating.types.js +2 -0
- package/dist/esm/rating/rating.types.js.map +1 -0
- package/dist/esm/rating/theme.d.ts +35 -0
- package/dist/esm/rating/theme.d.ts.map +1 -0
- package/dist/esm/rating/theme.js +39 -0
- package/dist/esm/rating/theme.js.map +1 -0
- package/dist/esm/theme/components.d.ts +33 -0
- package/dist/esm/theme/components.d.ts.map +1 -1
- package/dist/esm/theme/components.js +2 -0
- package/dist/esm/theme/components.js.map +1 -1
- package/dist/esm/theme/defaultTheme.d.ts +33 -0
- package/dist/esm/theme/defaultTheme.d.ts.map +1 -1
- package/dist/tsconfig.legacy.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/icons/baseIcons/fal/falStar.ts +8 -0
- package/src/icons/baseIcons/icons.ts +1 -0
- package/src/icons/baseIcons/types.ts +1 -0
- package/src/index.ts +1 -0
- package/src/rating/index.ts +2 -0
- package/src/rating/rating.tsx +158 -0
- package/src/rating/rating.types.ts +20 -0
- package/src/rating/theme.ts +43 -0
- package/src/theme/components.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veracity/vui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.27.0",
|
|
4
4
|
"description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
import { IconDefinition } from '../../types'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
details: [32, 32, [], '', 'M29.4429 11.3962C30.1897 11.4691 30.6751 11.8515 30.8992 12.5435C31.1232 13.2354 30.9739 13.8363 30.4511 14.3462L24.5138 19.973L25.9141 27.9489C26.0261 28.6409 25.7834 29.1872 25.186 29.5878C24.5885 30.0248 23.9724 30.0795 23.3376 29.7517L16 26.0369L8.66243 29.7517C8.02763 30.1159 7.4115 30.0795 6.81404 29.6424C6.21658 29.2054 5.97386 28.6409 6.08589 27.9489L7.48618 19.973L1.54892 14.3462C1.02614 13.8363 0.876774 13.2354 1.10082 12.5435C1.32487 11.8515 1.81031 11.4691 2.55713 11.3962L10.7349 10.1944L14.3757 2.98333C14.7117 2.32778 15.2532 2 16 2C16.7468 2 17.2883 2.32778 17.6243 2.98333L21.2651 10.1944L29.4429 11.3962ZM22.6094 19.3721L29.2188 13.0897L20.0889 11.8333L16 3.74814L11.9111 11.8333L2.78118 13.0897L9.39059 19.3721L7.82226 28.2221L16 24.0702L24.1777 28.2221L22.6094 19.3721Z'],
|
|
7
|
+
name: 'falStar'
|
|
8
|
+
} as IconDefinition
|
|
@@ -362,6 +362,7 @@ export { default as falSort } from './fal/falSort'
|
|
|
362
362
|
export { default as falSortZA } from './fal/falSortZA'
|
|
363
363
|
export { default as falSpinner } from './fal/falSpinner'
|
|
364
364
|
export { default as falSquare } from './fal/falSquare'
|
|
365
|
+
export { default as falStar } from './fal/falStar'
|
|
365
366
|
export { default as falStepForward } from './fal/falStepForward'
|
|
366
367
|
export { default as falStop } from './fal/falStop'
|
|
367
368
|
export { default as falStopCircle } from './fal/falStopCircle'
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { KeyboardEvent, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import Box from '../box'
|
|
4
|
+
import { KeyboardKeys, vui } from '../core'
|
|
5
|
+
import Icon from '../icon'
|
|
6
|
+
import { ColorGetter } from '../system'
|
|
7
|
+
import { Dict, mergeRefs } from '../utils'
|
|
8
|
+
import { RatingProps } from './rating.types'
|
|
9
|
+
import theme from './theme'
|
|
10
|
+
|
|
11
|
+
export const Rating = vui<'div', RatingProps>((props, ref) => {
|
|
12
|
+
const {
|
|
13
|
+
value: propValue = 0,
|
|
14
|
+
isDisabled = false,
|
|
15
|
+
max: propMax,
|
|
16
|
+
onChange,
|
|
17
|
+
showAll: showAllProp = true,
|
|
18
|
+
variant = 'yellow',
|
|
19
|
+
size,
|
|
20
|
+
...rest
|
|
21
|
+
} = props
|
|
22
|
+
const [hoverValue, setHoverValue] = useState<number | null>(null)
|
|
23
|
+
const [internalValue, setInternalValue] = useState(propValue || 0)
|
|
24
|
+
const [focusedStar, setFocusedStar] = useState<number | null>(null)
|
|
25
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
26
|
+
const isInteractive = !isDisabled && onChange !== undefined
|
|
27
|
+
const showAll = showAllProp || isInteractive
|
|
28
|
+
|
|
29
|
+
const { variants } = (theme as Dict) ?? {}
|
|
30
|
+
const color = isDisabled ? 'sandstone.79' : variants[variant].color
|
|
31
|
+
|
|
32
|
+
if (propValue < 0) {
|
|
33
|
+
console.error(`Rating: value (${propValue}) cannot be negative`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const value = Math.max(0, propValue)
|
|
37
|
+
const max = propMax ? propMax : Math.max(value, 5)
|
|
38
|
+
|
|
39
|
+
if (value > max) {
|
|
40
|
+
console.error(`Rating: value (${value}) cannot be greater than max (${max})`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const handleValueChange = (newValue: number) => {
|
|
44
|
+
if (!isInteractive) return
|
|
45
|
+
const clampedValue = Math.max(0, Math.min(newValue, max))
|
|
46
|
+
setInternalValue(clampedValue)
|
|
47
|
+
onChange?.(clampedValue)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const handleStarClick = (clickedValue: number) => {
|
|
51
|
+
if (!isInteractive) return
|
|
52
|
+
const newValue = clickedValue === internalValue ? 0 : clickedValue
|
|
53
|
+
handleValueChange(newValue)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const handleStarHover = (hoveredValue: number) => {
|
|
57
|
+
if (!isInteractive) return
|
|
58
|
+
setHoverValue(hoveredValue)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const handleMouseLeave = () => {
|
|
62
|
+
if (!isInteractive) return
|
|
63
|
+
setHoverValue(null)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
67
|
+
if (!isInteractive) return
|
|
68
|
+
const currentValue = propValue !== undefined ? propValue : internalValue
|
|
69
|
+
switch (event.key) {
|
|
70
|
+
case KeyboardKeys.ArrowRight:
|
|
71
|
+
case KeyboardKeys.ArrowUp:
|
|
72
|
+
event.preventDefault()
|
|
73
|
+
handleValueChange(Math.min(currentValue + 1, max))
|
|
74
|
+
break
|
|
75
|
+
case KeyboardKeys.ArrowLeft:
|
|
76
|
+
case KeyboardKeys.ArrowDown:
|
|
77
|
+
event.preventDefault()
|
|
78
|
+
handleValueChange(Math.max(currentValue - 1, 0))
|
|
79
|
+
break
|
|
80
|
+
case KeyboardKeys.Home:
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
handleValueChange(0)
|
|
83
|
+
break
|
|
84
|
+
case KeyboardKeys.End:
|
|
85
|
+
event.preventDefault()
|
|
86
|
+
handleValueChange(max)
|
|
87
|
+
break
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const handleFocus = () => {
|
|
92
|
+
if (!isInteractive) return
|
|
93
|
+
if (focusedStar === null) {
|
|
94
|
+
setFocusedStar(propValue !== undefined ? propValue : internalValue)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const handleBlur = () => {
|
|
99
|
+
if (!isInteractive) return
|
|
100
|
+
setFocusedStar(null)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const displayValue = hoverValue !== null ? hoverValue : value !== undefined ? value : internalValue
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Box
|
|
107
|
+
aria-label="Rating"
|
|
108
|
+
aria-valuemax={max}
|
|
109
|
+
aria-valuemin={0}
|
|
110
|
+
aria-valuenow={displayValue}
|
|
111
|
+
className="vui-rating"
|
|
112
|
+
focusRing={3}
|
|
113
|
+
focusRingColor="focusColor"
|
|
114
|
+
onBlur={handleBlur}
|
|
115
|
+
onFocus={handleFocus}
|
|
116
|
+
onKeyDown={handleKeyDown}
|
|
117
|
+
onMouseLeave={handleMouseLeave}
|
|
118
|
+
outline="none"
|
|
119
|
+
ref={mergeRefs(ref, containerRef)}
|
|
120
|
+
role="slider"
|
|
121
|
+
tabIndex={isInteractive ? 0 : -1}
|
|
122
|
+
{...rest}
|
|
123
|
+
>
|
|
124
|
+
{Array.from({ length: max }).map((_, index) => {
|
|
125
|
+
const starValue = index + 1
|
|
126
|
+
const fullStar = index < displayValue
|
|
127
|
+
return (
|
|
128
|
+
<Box
|
|
129
|
+
className="vui-rating-star"
|
|
130
|
+
cursor={isInteractive ? 'pointer' : undefined}
|
|
131
|
+
gap="1px"
|
|
132
|
+
key={index}
|
|
133
|
+
onClick={() => handleStarClick(starValue)}
|
|
134
|
+
onFocus={() => setFocusedStar(starValue)}
|
|
135
|
+
onMouseEnter={() => handleStarHover(starValue)}
|
|
136
|
+
tabIndex={-1}
|
|
137
|
+
>
|
|
138
|
+
{fullStar ? (
|
|
139
|
+
<FullStar color={color} size={size} />
|
|
140
|
+
) : showAll ? (
|
|
141
|
+
<EmptyStar color="sandstone.79" size={size} />
|
|
142
|
+
) : null}
|
|
143
|
+
</Box>
|
|
144
|
+
)
|
|
145
|
+
})}
|
|
146
|
+
</Box>
|
|
147
|
+
)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const FullStar = (props: { color: ColorGetter; size: RatingProps['size'] }) => (
|
|
151
|
+
<Icon color={props.color} name="fasStar" size={props.size} />
|
|
152
|
+
)
|
|
153
|
+
const EmptyStar = (props: { color: ColorGetter; size: RatingProps['size'] }) => (
|
|
154
|
+
<Icon color={props.color} name="falStar" size={props.size} />
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
Rating.displayName = 'Rating'
|
|
158
|
+
export default Rating
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SystemProps } from '../system'
|
|
2
|
+
import { ThemingProps } from '../theme'
|
|
3
|
+
|
|
4
|
+
export type RatingProps = SystemProps &
|
|
5
|
+
ThemingProps<'Rating'> & {
|
|
6
|
+
/** The current rating value. */
|
|
7
|
+
value: number
|
|
8
|
+
/** The maximum rating value. @default 5 */
|
|
9
|
+
max?: number
|
|
10
|
+
/** Whether to display all stars up to the maximum value. @default true */
|
|
11
|
+
showAll?: boolean
|
|
12
|
+
/** The color variant of the rating component. @default yellow */
|
|
13
|
+
variant?: 'yellow' | 'blue'
|
|
14
|
+
/** The size of the rating component. @default md */
|
|
15
|
+
size?: 'sm' | 'md' | 'lg'
|
|
16
|
+
/** Callback function that is called when the rating value changes. */
|
|
17
|
+
onChange?: (value: number) => void
|
|
18
|
+
/** Whether the rating component is disabled. @default false */
|
|
19
|
+
isDisabled?: boolean
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const baseStyle = {}
|
|
2
|
+
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
size: 'md',
|
|
5
|
+
variant: 'yellow',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const parts = ['icon']
|
|
9
|
+
|
|
10
|
+
const sizes = {
|
|
11
|
+
sm: {
|
|
12
|
+
icon: {
|
|
13
|
+
size: 'sm',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
md: {
|
|
17
|
+
icon: {
|
|
18
|
+
size: 'md',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
lg: {
|
|
22
|
+
icon: {
|
|
23
|
+
size: 'lg',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const variants = {
|
|
29
|
+
yellow: {
|
|
30
|
+
color: 'sunflower.50',
|
|
31
|
+
},
|
|
32
|
+
blue: {
|
|
33
|
+
color: 'seaBlue.28',
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
baseStyle,
|
|
39
|
+
defaultProps,
|
|
40
|
+
parts,
|
|
41
|
+
sizes,
|
|
42
|
+
variants,
|
|
43
|
+
}
|
package/src/theme/components.ts
CHANGED
|
@@ -37,6 +37,7 @@ import Progress from '../progress/theme'
|
|
|
37
37
|
import ProgressCircular from '../progressCircular/theme'
|
|
38
38
|
import Radio from '../radio/theme'
|
|
39
39
|
import Range from '../range/theme'
|
|
40
|
+
import Rating from '../rating/theme'
|
|
40
41
|
import Select from '../select/theme'
|
|
41
42
|
import Sidemenu from '../sidemenu/theme'
|
|
42
43
|
import Skeleton from '../skeleton/theme'
|
|
@@ -99,6 +100,7 @@ export default {
|
|
|
99
100
|
Popover,
|
|
100
101
|
Radio,
|
|
101
102
|
Range,
|
|
103
|
+
Rating,
|
|
102
104
|
Select,
|
|
103
105
|
Sidemenu,
|
|
104
106
|
Skeleton,
|