<script lang="ts">
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={5}>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index} />
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
export default function Default() {
return (
<RatingGroup count={5}>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) => ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} />)}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
Allow Half
<script lang="ts">
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={5} allowHalf={true}>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index} />
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
export default function Half() {
return (
<RatingGroup count={5} allowHalf>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) => ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} />)}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
Custom Icons
<script lang="ts">
import { BoneIcon, SkullIcon } from '@lucide/svelte';
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={3}>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index}>
{#snippet empty()}
<BoneIcon />
{/snippet}
{#snippet full()}
<SkullIcon />
{/snippet}
</RatingGroup.Item>
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
import { BoneIcon, SkullIcon } from 'lucide-react';
export default function CustomIcons() {
return (
<RatingGroup count={3}>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) =>
ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} empty={<BoneIcon />} full={<SkullIcon />} />)
}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
Label
<script lang="ts">
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={5}>
<RatingGroup.Label>Rate us:</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index} />
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
export default function Label() {
return (
<RatingGroup count={5}>
<RatingGroup.Label>Rate us:</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) => ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} />)}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
Disabled
<script lang="ts">
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={5} disabled={true}>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index} />
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
export default function Page() {
return (
<RatingGroup count={5} disabled>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) => ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} />)}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
Direction
<script lang="ts">
import { RatingGroup } from '@skeletonlabs/skeleton-svelte';
</script>
<RatingGroup count={5} dir="rtl">
<RatingGroup.Label>Label</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context>
{#snippet children(ratingGroup)}
{#each ratingGroup().items as index (index)}
<RatingGroup.Item {index} />
{/each}
{/snippet}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
import { RatingGroup } from '@skeletonlabs/skeleton-react';
export default function Dir() {
return (
<RatingGroup count={5} dir="rtl">
<RatingGroup.Label>Label</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context>
{(ratingGroup) => ratingGroup.items.map((index) => <RatingGroup.Item key={index} index={index} />)}
</RatingGroup.Context>
</RatingGroup.Control>
<RatingGroup.HiddenInput />
</RatingGroup>
);
}
API Reference
Root
| Property | Default | Type |
|---|---|---|
ids | - | Partial<{ root: string; label: string; hiddenInput: string; control: string; item: (id: string) => string; }> | undefined The ids of the elements in the rating. Useful for composition. |
translations | - | IntlTranslations | undefinedSpecifies the localized strings that identifies the accessibility elements and their states |
count | 5 | number | undefinedThe total number of ratings. |
name | - | string | undefinedThe name attribute of the rating element (used in forms). |
form | - | string | undefinedThe associate form of the underlying input element. |
value | - | number | undefinedThe controlled value of the rating |
defaultValue | - | number | undefinedThe initial value of the rating when rendered. Use when you don't need to control the value of the rating. |
readOnly | - | boolean | undefinedWhether the rating is readonly. |
disabled | - | boolean | undefinedWhether the rating is disabled. |
required | - | boolean | undefinedWhether the rating is required. |
allowHalf | - | boolean | undefinedWhether to allow half stars. |
autoFocus | - | boolean | undefinedWhether to autofocus the rating. |
onValueChange | - | ((details: ValueChangeDetails) => void) | undefinedFunction to be called when the rating value changes. |
onHoverChange | - | ((details: HoverChangeDetails) => void) | undefinedFunction to be called when the rating value is hovered. |
dir | "ltr" | "ltr" | "rtl" | undefinedThe document's text/writing direction. |
getRootNode | - | (() => ShadowRoot | Node | Document) | undefinedA root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
RootProvider
| Property | Default | Type |
|---|---|---|
value | - | RatingGroupApi<PropTypes> |
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
RootContext
| Property | Default | Type |
|---|---|---|
children | - | (ratingGroup: RatingGroupApi<PropTypes>) => ReactNode |
Label
| Property | Default | Type |
|---|---|---|
element | - | ((attributes: HTMLAttributes<"label">) => Element) | undefinedRender the element yourself |
Control
| Property | Default | Type |
|---|---|---|
element | - | ((attributes: HTMLAttributes<"div">) => Element) | undefinedRender the element yourself |
Item
| Property | Default | Type |
|---|---|---|
empty | StarEmpty (SVG) | ReactNodeThe content to render when the item is in the empty state. |
half | StarHalf (SVG) | ReactNodeThe content to render when the item is in the half state. |
full | StarFull (SVG) | ReactNodeThe content to render when the item is in the full state. |
index | - | number |
element | - | ((attributes: HTMLAttributes<"span">) => Element) | undefinedRender the element yourself |
HiddenInput
| Property | Default | Type |
|---|---|---|
element | - | ((attributes: HTMLAttributes<"input">) => Element) | undefinedRender the element yourself |