UNPKG

3.73 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { InternalStandardProps as StandardProps, Theme } from '..';
5import { RatingClasses } from './ratingClasses';
6
7export interface IconContainerProps extends React.HTMLAttributes<HTMLSpanElement> {
8 value: number;
9}
10
11export interface RatingPropsSizeOverrides {}
12
13export interface RatingProps
14 extends StandardProps<React.HTMLAttributes<HTMLSpanElement>, 'children' | 'onChange'> {
15 /**
16 * Override or extend the styles applied to the component.
17 */
18 classes?: Partial<RatingClasses>;
19 /**
20 * The default value. Use when the component is not controlled.
21 * @default null
22 */
23 defaultValue?: number;
24 /**
25 * If `true`, the component is disabled.
26 * @default false
27 */
28 disabled?: boolean;
29 /**
30 * The icon to display when empty.
31 * @default <StarBorder fontSize="inherit" />
32 */
33 emptyIcon?: React.ReactNode;
34 /**
35 * The label read when the rating input is empty.
36 * @default 'Empty'
37 */
38 emptyLabelText?: React.ReactNode;
39 /**
40 * Accepts a function which returns a string value that provides a user-friendly name for the current value of the rating.
41 * This is important for screen reader users.
42 *
43 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
44 * @param {number} value The rating label's value to format.
45 * @returns {string}
46 * @default function defaultLabelText(value) {
47 * return `${value || '0'} Star${value !== 1 ? 's' : ''}`;
48 * }
49 */
50 getLabelText?: (value: number) => string;
51 /**
52 * If `true`, only the selected icon will be highlighted.
53 * @default false
54 */
55 highlightSelectedOnly?: boolean;
56 /**
57 * The icon to display.
58 * @default <Star fontSize="inherit" />
59 */
60 icon?: React.ReactNode;
61 /**
62 * The component containing the icon.
63 * @default function IconContainer(props) {
64 * const { value, ...other } = props;
65 * return <span {...other} />;
66 * }
67 */
68 IconContainerComponent?: React.ElementType<IconContainerProps>;
69 /**
70 * Maximum rating.
71 * @default 5
72 */
73 max?: number;
74 /**
75 * The name attribute of the radio `input` elements.
76 * This input `name` should be unique within the page.
77 * Being unique within a form is insufficient since the `name` is used to generate IDs.
78 */
79 name?: string;
80 /**
81 * Callback fired when the value changes.
82 * @param {React.SyntheticEvent} event The event source of the callback.
83 * @param {number|null} value The new value.
84 */
85 onChange?: (event: React.SyntheticEvent, value: number | null) => void;
86 /**
87 * Callback function that is fired when the hover state changes.
88 * @param {React.SyntheticEvent} event The event source of the callback.
89 * @param {number} value The new value.
90 */
91 onChangeActive?: (event: React.SyntheticEvent, value: number) => void;
92 /**
93 * The minimum increment value change allowed.
94 * @default 1
95 */
96 precision?: number;
97 /**
98 * Removes all hover effects and pointer events.
99 * @default false
100 */
101 readOnly?: boolean;
102 /**
103 * The size of the component.
104 * @default 'medium'
105 */
106 size?: OverridableStringUnion<'small' | 'medium' | 'large', RatingPropsSizeOverrides>;
107 /**
108 * The system prop that allows defining system overrides as well as additional CSS styles.
109 */
110 sx?: SxProps<Theme>;
111 /**
112 * The rating value.
113 */
114 value?: number | null;
115}
116
117/**
118 *
119 * Demos:
120 *
121 * - [Rating](https://mui.com/material-ui/react-rating/)
122 *
123 * API:
124 *
125 * - [Rating API](https://mui.com/material-ui/api/rating/)
126 */
127export default function Rating(props: RatingProps): React.JSX.Element;