Docs Components Commerce

Rating

React example follows below.
ts
import * as React from "react";
const ratingFixture = {
id: "rating",
value: 4,
label: "Rate this trowel",
readOnlyValue: 4.5,
readOnlySize: "sm",
} satisfies {
id: string;
value: number;
label: string;
readOnlyValue: number;
readOnlySize: "sm" | "md" | "lg";
};
import { Rating } from "@grassroot/ui-react";
export default function RatingDemo() {
const [value, setValue] = React.useState(ratingFixture.value);
return (
<div>
<Rating value={value} onChange={setValue} label={ratingFixture.label} />
<Rating value={ratingFixture.readOnlyValue} readOnly size={ratingFixture.readOnlySize} />
</div>
);
}
ts
<script setup lang="ts">
import { ref } from "vue";
const ratingFixture = {
id: "rating",
value: 4,
label: "Rate this trowel",
readOnlyValue: 4.5,
readOnlySize: "sm",
} satisfies {
id: string;
value: number;
label: string;
readOnlyValue: number;
readOnlySize: "sm" | "md" | "lg";
};
import { Rating } from "@grassroot/ui-vue";
const value = ref(ratingFixture.value);
</script>
<template>
<div>
<Rating v-model="value" :label="ratingFixture.label" />
<Rating
:model-value="ratingFixture.readOnlyValue"
read-only
:size="ratingFixture.readOnlySize"
/>
</div>
</template>
ts
import { Component, signal } from "@angular/core";
const ratingFixture = {
id: "rating",
value: 4,
label: "Rate this trowel",
readOnlyValue: 4.5,
readOnlySize: "sm",
} satisfies {
id: string;
value: number;
label: string;
readOnlyValue: number;
readOnlySize: "sm" | "md" | "lg";
};
import { GrassrootRating } from "@grassroot/ui-angular";
@Component({
selector: "app-rating-demo",
standalone: true,
imports: [GrassrootRating],
template: `
<div>
<grassroot-rating
[value]="value()"
(valueChange)="value.set($event)"
[label]="fixture.label"
/>
<grassroot-rating
[value]="fixture.readOnlyValue"
[readOnly]="true"
[size]="fixture.readOnlySize"
/>
</div>
`,
})
export class RatingDemoComponent {
protected readonly fixture = ratingFixture;
readonly value = signal(ratingFixture.value);
}
export default RatingDemoComponent;
ts
<script lang="ts">
import { Rating } from "@grassroot/ui-svelte";
const ratingFixture = {
id: "rating",
value: 4,
label: "Rate this trowel",
readOnlyValue: 4.5,
readOnlySize: "sm",
} satisfies {
id: string;
value: number;
label: string;
readOnlyValue: number;
readOnlySize: "sm" | "md" | "lg";
};
let value = $state(ratingFixture.value);
</script>
<div>
<Rating {value} onChange={(next) => (value = next)} label={ratingFixture.label} /><Rating
value={ratingFixture.readOnlyValue}
readOnly
size={ratingFixture.readOnlySize}
/>
</div>
ts
/** @jsxImportSource solid-js */
import { createSignal } from "solid-js";
import { Rating } from "@grassroot/ui-solid";
const ratingFixture = {
id: "rating",
value: 4,
label: "Rate this trowel",
readOnlyValue: 4.5,
readOnlySize: "sm",
} satisfies {
id: string;
value: number;
label: string;
readOnlyValue: number;
readOnlySize: "sm" | "md" | "lg";
};
export default function RatingDemo() {
const [value, setValue] = createSignal(ratingFixture.value);
return (
<div>
<Rating value={value()} onChange={setValue} label={ratingFixture.label} />
<Rating value={ratingFixture.readOnlyValue} readOnly size={ratingFixture.readOnlySize} />
</div>
);
}

Installation

API Reference

Import

import * as React from "react";
import { Rating } from "@grassroot/ui-react";

Props

Prop
Type
Default
Requirement
value
number | undefined
optional
defaultValue
number | undefined
optional
max
number | undefined
optional
readOnly
boolean | undefined
optional
onChange
((value: number) => void) | undefined
optional
size
"sm" | "md" | "lg" | undefined
optional
label
string | undefined
optional
className
string | undefined
optional
Prop
value
Type
number | undefined
Default
Requirement
optional
Prop
defaultValue
Type
number | undefined
Default
Requirement
optional
Prop
max
Type
number | undefined
Default
Requirement
optional
Prop
readOnly
Type
boolean | undefined
Default
Requirement
optional
Prop
onChange
Type
((value: number) => void) | undefined
Default
Requirement
optional
Prop
size
Type
"sm" | "md" | "lg" | undefined
Default
Requirement
optional
Prop
label
Type
string | undefined
Default
Requirement
optional
Prop
className
Type
string | undefined
Default
Requirement
optional

Events

EventPayload
onChange((value: number) => void) | undefined

Import

import { ref } from "vue";
import { Rating } from "@grassroot/ui-vue";

Props

Prop
Type
Default
Requirement
modelValue
number | undefined
0
optional
max
number | undefined
5
optional
readOnly
boolean | undefined
true
optional
size
"sm" | "md" | "lg" | undefined
"md"
optional
label
string | undefined
"Rating"
optional
Prop
modelValue
Type
number | undefined
Default
0
Requirement
optional
Prop
max
Type
number | undefined
Default
5
Requirement
optional
Prop
readOnly
Type
boolean | undefined
Default
true
Requirement
optional
Prop
size
Type
"sm" | "md" | "lg" | undefined
Default
"md"
Requirement
optional
Prop
label
Type
string | undefined
Default
"Rating"
Requirement
optional

Events

EventPayload
update:modelValue[value: number]

Import

import { Component, signal } from "@angular/core";
import { GrassrootRating } from "@grassroot/ui-angular";

Props

Prop
Type
Default
Requirement
value
number
0
optional
max
number
5
optional
readOnly
boolean
true
optional
size
"sm" | "md" | "lg"
"md"
optional
label
string
"Rating"
optional
Prop
value
Type
number
Default
0
Requirement
optional
Prop
max
Type
number
Default
5
Requirement
optional
Prop
readOnly
Type
boolean
Default
true
Requirement
optional
Prop
size
Type
"sm" | "md" | "lg"
Default
"md"
Requirement
optional
Prop
label
Type
string
Default
"Rating"
Requirement
optional

Events

EventPayload
valueChangenumber

Import

import { Rating } from "@grassroot/ui-svelte";

Props

Prop
Type
Default
Requirement
value
number
optional
defaultValue
number
0
optional
modelValue
number
optional
max
number
5
optional
readOnly
boolean
true
optional
size
"sm" | "md" | "lg"
"md"
optional
label
string
"Rating"
optional
onChange
(value: number) => void
optional
className
string
optional
Prop
value
Type
number
Default
Requirement
optional
Prop
defaultValue
Type
number
Default
0
Requirement
optional
Prop
modelValue
Type
number
Default
Requirement
optional
Prop
max
Type
number
Default
5
Requirement
optional
Prop
readOnly
Type
boolean
Default
true
Requirement
optional
Prop
size
Type
"sm" | "md" | "lg"
Default
"md"
Requirement
optional
Prop
label
Type
string
Default
"Rating"
Requirement
optional
Prop
onChange
Type
(value: number) => void
Default
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional

Events

EventPayload
onChange(value: number) => void

Import

import { createSignal } from "solid-js";
import { Rating } from "@grassroot/ui-solid";

Props

Prop
Type
Default
Requirement
value
number
optional
defaultValue
number
0
optional
max
number
5
optional
readOnly
boolean
true
optional
onChange
(value: number) => void
optional
size
"sm" | "md" | "lg"
"md"
optional
label
string
"Rating"
optional
className
string
optional
Prop
value
Type
number
Default
Requirement
optional
Prop
defaultValue
Type
number
Default
0
Requirement
optional
Prop
max
Type
number
Default
5
Requirement
optional
Prop
readOnly
Type
boolean
Default
true
Requirement
optional
Prop
onChange
Type
(value: number) => void
Default
Requirement
optional
Prop
size
Type
"sm" | "md" | "lg"
Default
"md"
Requirement
optional
Prop
label
Type
string
Default
"Rating"
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional

Events

EventPayload
onChange(value: number) => void