BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/diceui/base/rating

rating

diceui-base/rating
FreeComponent

diceui/base publishes no description for this item.

Install it

npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/rating.json

Source

ui/rating.tsxraw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/rating.json · first 6 KB
1"use client";
2
3import { mergeProps } from "@base-ui/react/merge-props";
4import { useRender } from "@base-ui/react/use-render";
5import { Star } from "lucide-react";
6import * as React from "react";
7import { cn } from "@/lib/utils";
8import { VisuallyHiddenInput } from "@/registry/bases/base/components/visually-hidden-input";
9import { useAsRef } from "@/registry/bases/base/hooks/use-as-ref";
10import { useIsomorphicLayoutEffect } from "@/registry/bases/base/hooks/use-isomorphic-layout-effect";
11import { useLazyRef } from "@/registry/bases/base/hooks/use-lazy-ref";
12import { useComposedRefs } from "@/registry/bases/base/lib/compose-refs";
13import { useDirection } from "@/registry/bases/base/ui/direction";
14
15type Direction = "ltr" | "rtl";
16type Orientation = "horizontal" | "vertical";
17type ActivationMode = "automatic" | "manual";
18type Size = "default" | "sm" | "lg";
19type Step = 0.5 | 1;
20type DataState = "full" | "partial" | "empty";
21type FocusIntent = "first" | "last" | "prev" | "next";
22
23type RootElement = HTMLDivElement;
24type ItemElement = HTMLButtonElement;
25
26const ROOT_NAME = "Rating";
27const ITEM_NAME = "RatingItem";
28
29const ENTRY_FOCUS = "ratingFocusGroup.onEntryFocus";
30const EVENT_OPTIONS = { bubbles: false, cancelable: true };
31
32function getItemId(id: string, value: number) {
33 return `${id}-item-${value}`;
34}
35
36function getPartialFillGradientId(id: string, step: Step) {
37 return `partial-fill-gradient-${id}-${step}`;
38}
39
40const MAP_KEY_TO_FOCUS_INTENT: Record<string, FocusIntent> = {
41 ArrowLeft: "prev",
42 ArrowUp: "prev",
43 ArrowRight: "next",
44 ArrowDown: "next",
45 Home: "first",
46 End: "last",
47};
48
49function getDirectionAwareKey(key: string, dir?: Direction) {
50 if (dir !== "rtl") return key;
51 return key === "ArrowLeft"
52 ? "ArrowRight"
53 : key === "ArrowRight"
54 ? "ArrowLeft"
55 : key;
56}
57
58function getFocusIntent(
59 event: React.KeyboardEvent<ItemElement>,
60 dir?: Direction,
61 orientation?: Orientation,
62) {
63 const key = getDirectionAwareKey(event.key, dir);
64 if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key))
65 return undefined;
66 if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key))
67 return undefined;
68 return MAP_KEY_TO_FOCUS_INTENT[key];
69}
70
71function focusFirst(
72 candidates: React.RefObject<ItemElement | null>[],
73 preventScroll = false,
74) {
75 const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
76 for (const candidateRef of candidates) {
77 const candidate = candidateRef.current;
78// … truncated

What it pulls in

npm packages

  • @base-ui/react

Other registry items

  • direction
  • @diceui/use-as-ref
  • @diceui/use-isomorphic-layout-effect
  • @diceui/use-lazy-ref

Files it writes

  • ui/rating.tsx
  • components/visually-hidden-input.tsx
  • lib/compose-refs.ts

Facts

Registry
diceui/base
Type
registry:ui
Access
Free
Files written
3
Licence
the repository states none
First indexed
2026-08-09
Last confirmed
yesterday

Go to the source

www.diceui.com sadmann7/diceui on GitHub Raw registry item This item as JSON

More from diceui/base

All 192 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
action-baraction-bardiceui/baseComponentsFree1 dep
angle-sliderangle-sliderdiceui/baseComponentsFree1 dep · 3 files
avatar-groupavatar-groupdiceui/baseComponentsFree1 dep
badge-overflowbadge-overflowdiceui/baseComponentsFree1 dep · 2 files
bannerbannerdiceui/baseComponentsFree1 dep
circular-progresscircular-progressdiceui/baseComponentsFree1 dep
client-onlyclient-onlydiceui/baseComponentsFreeno deps
color-pickercolor-pickerdiceui/baseComponentsFree1 dep · 2 files
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex