createRating

function

createRating(config?): RatingWidget

Create a RatingWidget with given config props

Parameters

config?: PropsConfig<RatingProps>

an optional alert config

Returns

RatingWidget

a RatingWidget


getRatingDefaultConfig

function

getRatingDefaultConfig(): object

Returns a shallow copy of the default rating config.

Returns

object

a copy of the default config

ariaLabel

ariaLabel: string

The aria label

Default Value

'Rating'

ariaLabelledBy

ariaLabelledBy: string

The aria labelled by

Default Value

''

ariaValueTextFn

ariaValueTextFn: (rating, maxRating) => string

Return the value for the 'aria-valuetext' attribute.

Parameters

rating: number

Current rating value.

maxRating: number

maxRating value.

Returns

string

Default Value
(rating: number, maxRating: number) => `${rating} out of ${maxRating}`
className

className: string

CSS classes to be applied on the widget main container

Default Value

''

disabled

disabled: boolean

If true, the rating is disabled.

Default Value

false

maxRating

maxRating: number

The maximum rating that can be given.

Default Value

10

onHover

onHover: (rating) => void

An event emitted when the user is hovering over a given rating.

Event payload is equal to the rating being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}
onLeave

onLeave: (rating) => void

An event emitted when the user stops hovering over a given rating.

Event payload is equal to the rating of the last item being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}
onRatingChange

onRatingChange: (rating) => void

An event emitted when the rating is changed.

Event payload is equal to the newly selected rating.

Parameters

rating: number

Returns

void

Default Value
() => {}
rating

rating: number

The current rating. Could be a decimal value like 3.75.

Default Value

0

readonly

readonly: boolean

If true, the rating can't be changed.

Default Value

false

resettable

resettable: boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true

tabindex

tabindex: number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0


RatingActions

interface
Methods
click

click(index): void

Method to be used when a star is clicked.

To be used in the onclick event of a star

Parameters

index: number

Star index, starting from 1

Returns

void


handleKey

handleKey(event): void

Method to be used to handle the keyboard.

To be used in the onkeydown of the rating container

Parameters

event: KeyboardEvent

Returns

void


hover

hover(index): void

Method to be used when the mouse enter in a star.

To be used in the onmouseenter of a star

Parameters

index: number

Star index, starting from 1

Returns

void


leave

leave(): void

Method to be used when the mouse leave the widget.

To be used in the onmouseleave of the rating container

Returns

void


RatingDirectives

interface
Properties
containerDirective

containerDirective: Directive

A directive to be applied to the main container This will handle the keydown, mouseleave, tabindex and aria attributes


starDirective

starDirective: Directive<object>

A directive to be applied on each star element

Type declaration
index

index: number


RatingProps

interface
Properties
ariaLabel

ariaLabel: string

The aria label

Default Value

'Rating'


ariaLabelledBy

ariaLabelledBy: string

The aria labelled by

Default Value

''


ariaValueTextFn

ariaValueTextFn: (rating, maxRating) => string

Return the value for the 'aria-valuetext' attribute.

Parameters

rating: number

Current rating value.

maxRating: number

maxRating value.

Returns

string

Default Value
(rating: number, maxRating: number) => `${rating} out of ${maxRating}`

className

className: string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: boolean

If true, the rating is disabled.

Default Value

false


maxRating

maxRating: number

The maximum rating that can be given.

Default Value

10


onHover

onHover: (rating) => void

An event emitted when the user is hovering over a given rating.

Event payload is equal to the rating being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}

onLeave

onLeave: (rating) => void

An event emitted when the user stops hovering over a given rating.

Event payload is equal to the rating of the last item being hovered over.

Parameters

rating: number

Returns

void

Default Value
() => {}

onRatingChange

onRatingChange: (rating) => void

An event emitted when the rating is changed.

Event payload is equal to the newly selected rating.

Parameters

rating: number

Returns

void

Default Value
() => {}

rating

rating: number

The current rating. Could be a decimal value like 3.75.

Default Value

0


readonly

readonly: boolean

If true, the rating can't be changed.

Default Value

false


resettable

resettable: boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true


tabindex

tabindex: number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0


RatingState

interface
Properties
ariaLabel

ariaLabel: string

The aria label

Default Value

'Rating'


ariaLabelledBy

ariaLabelledBy: string

The aria labelled by

Default Value

''


ariaValueText

ariaValueText: string

the aria value of the rating


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: boolean

If true, the rating is disabled.

Default Value

false


interactive

interactive: boolean

is the rating interactive i.e. listening to hover, click and keyboard events


maxRating

maxRating: number

The maximum rating that can be given.

Default Value

10


rating

rating: number

The current rating. Could be a decimal value like 3.75.

Default Value

0


readonly

readonly: boolean

If true, the rating can't be changed.

Default Value

false


resettable

resettable: boolean

Define if the rating can be reset.

If set to true, the user can 'unset' the rating value by cliking on the current rating value.

Default Value

true


stars

stars: StarContext[]

the list of stars


tabindex

tabindex: number

Allows setting a custom rating tabindex. If the component is disabled, tabindex will still be set to -1.

Default Value

0


visibleRating

visibleRating: number

the visible value of the rating (it changes when hovering over the rating even though the real value did not change)


RatingWidget

type alias

RatingWidget: Widget<RatingProps, RatingState, object, RatingActions, RatingDirectives>


StarContext

interface
Properties
fill

fill: number

indicates how much the current star is filled, from 0 to 100


index

index: number

the position of the star in the rating