@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.
Files changed (84) hide show
  1. package/dist/cjs/icons/baseIcons/fal/falStar.d.ts +4 -0
  2. package/dist/cjs/icons/baseIcons/fal/falStar.d.ts.map +1 -0
  3. package/dist/cjs/icons/baseIcons/fal/falStar.js +8 -0
  4. package/dist/cjs/icons/baseIcons/fal/falStar.js.map +1 -0
  5. package/dist/cjs/icons/baseIcons/icons.d.ts +1 -0
  6. package/dist/cjs/icons/baseIcons/icons.d.ts.map +1 -1
  7. package/dist/cjs/icons/baseIcons/icons.js +4 -2
  8. package/dist/cjs/icons/baseIcons/icons.js.map +1 -1
  9. package/dist/cjs/icons/baseIcons/types.d.ts +1 -1
  10. package/dist/cjs/icons/baseIcons/types.d.ts.map +1 -1
  11. package/dist/cjs/index.d.ts +1 -0
  12. package/dist/cjs/index.d.ts.map +1 -1
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/rating/index.d.ts +3 -0
  16. package/dist/cjs/rating/index.d.ts.map +1 -0
  17. package/dist/cjs/rating/index.js +24 -0
  18. package/dist/cjs/rating/index.js.map +1 -0
  19. package/dist/cjs/rating/rating.d.ts +4 -0
  20. package/dist/cjs/rating/rating.d.ts.map +1 -0
  21. package/dist/cjs/rating/rating.js +115 -0
  22. package/dist/cjs/rating/rating.js.map +1 -0
  23. package/dist/cjs/rating/rating.types.d.ts +19 -0
  24. package/dist/cjs/rating/rating.types.d.ts.map +1 -0
  25. package/dist/cjs/rating/rating.types.js +3 -0
  26. package/dist/cjs/rating/rating.types.js.map +1 -0
  27. package/dist/cjs/rating/theme.d.ts +35 -0
  28. package/dist/cjs/rating/theme.d.ts.map +1 -0
  29. package/dist/cjs/rating/theme.js +41 -0
  30. package/dist/cjs/rating/theme.js.map +1 -0
  31. package/dist/cjs/theme/components.d.ts +33 -0
  32. package/dist/cjs/theme/components.d.ts.map +1 -1
  33. package/dist/cjs/theme/components.js +30 -28
  34. package/dist/cjs/theme/components.js.map +1 -1
  35. package/dist/cjs/theme/defaultTheme.d.ts +33 -0
  36. package/dist/cjs/theme/defaultTheme.d.ts.map +1 -1
  37. package/dist/esm/icons/baseIcons/fal/falStar.d.ts +4 -0
  38. package/dist/esm/icons/baseIcons/fal/falStar.d.ts.map +1 -0
  39. package/dist/esm/icons/baseIcons/fal/falStar.js +6 -0
  40. package/dist/esm/icons/baseIcons/fal/falStar.js.map +1 -0
  41. package/dist/esm/icons/baseIcons/icons.d.ts +1 -0
  42. package/dist/esm/icons/baseIcons/icons.d.ts.map +1 -1
  43. package/dist/esm/icons/baseIcons/icons.js +1 -0
  44. package/dist/esm/icons/baseIcons/icons.js.map +1 -1
  45. package/dist/esm/icons/baseIcons/types.d.ts +1 -1
  46. package/dist/esm/icons/baseIcons/types.d.ts.map +1 -1
  47. package/dist/esm/index.d.ts +1 -0
  48. package/dist/esm/index.d.ts.map +1 -1
  49. package/dist/esm/index.js +1 -0
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/rating/index.d.ts +3 -0
  52. package/dist/esm/rating/index.d.ts.map +1 -0
  53. package/dist/esm/rating/index.js +3 -0
  54. package/dist/esm/rating/index.js.map +1 -0
  55. package/dist/esm/rating/rating.d.ts +4 -0
  56. package/dist/esm/rating/rating.d.ts.map +1 -0
  57. package/dist/esm/rating/rating.js +97 -0
  58. package/dist/esm/rating/rating.js.map +1 -0
  59. package/dist/esm/rating/rating.types.d.ts +19 -0
  60. package/dist/esm/rating/rating.types.d.ts.map +1 -0
  61. package/dist/esm/rating/rating.types.js +2 -0
  62. package/dist/esm/rating/rating.types.js.map +1 -0
  63. package/dist/esm/rating/theme.d.ts +35 -0
  64. package/dist/esm/rating/theme.d.ts.map +1 -0
  65. package/dist/esm/rating/theme.js +39 -0
  66. package/dist/esm/rating/theme.js.map +1 -0
  67. package/dist/esm/theme/components.d.ts +33 -0
  68. package/dist/esm/theme/components.d.ts.map +1 -1
  69. package/dist/esm/theme/components.js +2 -0
  70. package/dist/esm/theme/components.js.map +1 -1
  71. package/dist/esm/theme/defaultTheme.d.ts +33 -0
  72. package/dist/esm/theme/defaultTheme.d.ts.map +1 -1
  73. package/dist/tsconfig.legacy.tsbuildinfo +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +1 -1
  76. package/src/icons/baseIcons/fal/falStar.ts +8 -0
  77. package/src/icons/baseIcons/icons.ts +1 -0
  78. package/src/icons/baseIcons/types.ts +1 -0
  79. package/src/index.ts +1 -0
  80. package/src/rating/index.ts +2 -0
  81. package/src/rating/rating.tsx +158 -0
  82. package/src/rating/rating.types.ts +20 -0
  83. package/src/rating/theme.ts +43 -0
  84. 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.26.0",
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'
@@ -363,6 +363,7 @@ export type BaseIcon =
363
363
  | 'falSortZA'
364
364
  | 'falSpinner'
365
365
  | 'falSquare'
366
+ | 'falStar'
366
367
  | 'falStepForward'
367
368
  | 'falStop'
368
369
  | 'falStopCircle'
package/src/index.ts CHANGED
@@ -44,6 +44,7 @@ export * from './progress'
44
44
  export * from './progressCircular'
45
45
  export * from './radio'
46
46
  export * from './range'
47
+ export * from './rating'
47
48
  export * from './select'
48
49
  export * from './sidemenu'
49
50
  export * from './skeleton'
@@ -0,0 +1,2 @@
1
+ export * from './rating'
2
+ export { default } from './rating'
@@ -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
+ }
@@ -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,