logoMogu Design

⌘ K
  • Design
  • Development
  • Components
  • Components Overview
  • General
    • Button
    • Icon
    • Typography
  • Layout
    • Divider
    • Grid
    • Layout
    • Space
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPickerNew
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tabs
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
  • Other
    • Affix
    • App
    • ConfigProvider
    • FloatButton
    • Watermark
When To Use
Examples
Basic
Half star
Show copywriting
Read only
Clear star
Other Character
Customize character
API
Methods

Rate

RadioSelect

Rate component.

When To Use

  • Show evaluation.
  • A quick rating operation on something.

Examples

API

PropertyDescriptiontypeDefaultVersion
allowClearWhether to allow clear when click againbooleantrue
allowHalfWhether to allow semi selectionbooleanfalse
autoFocusIf get focus when component mountedbooleanfalse
characterThe custom character of rateReactNode | (RateProps) => ReactNode<StarFilled />function(): 4.4.0
classNameThe custom class name of ratestring-
countStar countnumber5
defaultValueThe default valuenumber0
disabledIf read only, unable to interactbooleanfalse
styleThe custom style object of rateCSSProperties-
tooltipsCustomize tooltip by each characterstring[]-
valueThe current valuenumber-
onBlurCallback when component lose focusfunction()-
onChangeCallback when select valuefunction(value: number)-
onFocusCallback when component get focusfunction()-
onHoverChangeCallback when hover itemfunction(value: number)-
onKeyDownCallback when keydown on componentfunction(event)-

Methods

NameDescription
blur()Remove focus
focus()Get focus
Basic

The simplest usage.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'mogud';

const App: React.FC = () => <Rate />;

export default App;
Show copywriting

Add copywriting in rate components.

expand codeexpand code
TypeScript
JavaScript
import React, { useState } from 'react';
import { Rate } from 'mogud';

const desc = ['terrible', 'bad', 'normal', 'good', 'wonderful'];

const App: React.FC = () => {
  const [value, setValue] = useState(3);

  return (
    <span>
      <Rate tooltips={desc} onChange={setValue} value={value} />
      {value ? <span className="ant-rate-text">{desc[value - 1]}</span> : ''}
    </span>
  );
};

export default App;
Clear star

Support set allow to clear star when click again.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'mogud';

const App: React.FC = () => (
  <>
    <Rate defaultValue={3} />
    <span className="ant-rate-text">allowClear: true</span>
    <br />
    <Rate allowClear={false} defaultValue={3} />
    <span className="ant-rate-text">allowClear: false</span>
  </>
);

export default App;
Customize character

Can customize each character using (RateProps) => ReactNode.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { FrownOutlined, MehOutlined, SmileOutlined } from '@ant-design/icons';
import { Rate } from 'mogud';

const customIcons: Record<number, React.ReactNode> = {
  1: <FrownOutlined />,
  2: <FrownOutlined />,
  3: <MehOutlined />,
  4: <SmileOutlined />,
  5: <SmileOutlined />,
};

const App: React.FC = () => (
  <>
    <Rate defaultValue={2} character={({ index }: { index: number }) => index + 1} />
    <br />
    <Rate defaultValue={3} character={({ index }: { index: number }) => customIcons[index + 1]} />
  </>
);

export default App;
Half star

Support select half star.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'mogud';

const App: React.FC = () => <Rate allowHalf defaultValue={2.5} />;

export default App;
Read only

Read only, can't use mouse to interact.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { Rate } from 'mogud';

const App: React.FC = () => <Rate disabled defaultValue={2} />;

export default App;
Other Character

Replace the default star to other character like alphabet, digit, iconfont or even Chinese word.

expand codeexpand code
TypeScript
JavaScript
import React from 'react';
import { HeartOutlined } from '@ant-design/icons';
import { Rate } from 'mogud';

const App: React.FC = () => (
  <>
    <Rate character={<HeartOutlined />} allowHalf />
    <br />
    <Rate character="A" allowHalf style={{ fontSize: 36 }} />
    <br />
    <Rate character="好" allowHalf />
  </>
);

export default App;
normal
allowClear: true
allowClear: false
  • 1
    1
  • 2
    2
  • 3
    3
  • 4
    4
  • 5
    5


  • A
    A
  • A
    A
  • A
    A
  • A
    A
  • A
    A

  • 好
    好
  • 好
    好
  • 好
    好
  • 好
    好
  • 好
    好