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/selection-toolbar

selection-toolbar

diceui-base/selection-toolbar
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/selection-toolbar.json

Source

ui/selection-toolbar.tsxraw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/selection-toolbar.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 {
6 autoUpdate,
7 flip,
8 hide,
9 limitShift,
10 type Middleware,
11 offset,
12 type Placement,
13 shift,
14 size,
15 useFloating,
16} from "@floating-ui/react-dom";
17import * as React from "react";
18import * as ReactDOM from "react-dom";
19import { useComposedRefs } from "@/lib/compose-refs";
20import { cn } from "@/lib/utils";
21import { useAsRef } from "@/registry/bases/base/hooks/use-as-ref";
22import { useIsomorphicLayoutEffect } from "@/registry/bases/base/hooks/use-isomorphic-layout-effect";
23import { useLazyRef } from "@/registry/bases/base/hooks/use-lazy-ref";
24import { Button } from "@/registry/bases/base/ui/button";
25
26const ROOT_NAME = "SelectionToolbar";
27const ITEM_NAME = "SelectionToolbarItem";
28
29const SIDE_OPTIONS = ["top", "right", "bottom", "left"] as const;
30const ALIGN_OPTIONS = ["start", "center", "end"] as const;
31
32type Side = (typeof SIDE_OPTIONS)[number];
33type Align = (typeof ALIGN_OPTIONS)[number];
34type Boundary = Element | null;
35
36interface DivProps
37 extends React.ComponentProps<"div">,
38 useRender.ComponentProps<"div"> {}
39
40function getSideAndAlignFromPlacement(placement: Placement) {
41 const [side, align = "center"] = placement.split("-");
42 return [side as Side, align as Align] as const;
43}
44
45function isNotNull<T>(value: T | null): value is T {
46 return value !== null;
47}
48
49interface SelectionRect {
50 top: number;
51 left: number;
52 width: number;
53 height: number;
54}
55
56interface StoreState {
57 open: boolean;
58 selectedText: string;
59 selectionRect: SelectionRect | null;
60}
61
62interface Store {
63 subscribe: (callback: () => void) => () => void;
64 getState: () => StoreState;
65 setState: <K extends keyof StoreState>(key: K, value: StoreState[K]) => void;
66 notify: () => void;
67 batch: (fn: () => void) => void;
68}
69
70const StoreContext = React.createContext<Store | null>(null);
71
72function useStoreContext(consumerName: string) {
73 const context = React.useContext(StoreContext);
74 if (!context) {
75 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
76 }
77 return context;
78}
79
80function useStore<T>(
81 selector: (state: StoreState) => T,
82 ogStore?: Store | null,
83): T {
84 const contextStore = React.useContext(StoreContext);
85
86 const store = ogStore ?? contextStore;
87
88 if (!store) {
89 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);
90 }
91
92 const getSnapshot = React.useCallback(
93// … truncated

What it pulls in

npm packages

  • @base-ui/react
  • @floating-ui/react-dom

Other registry items

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

Files it writes

  • ui/selection-toolbar.tsx
  • lib/compose-refs.ts

Facts

Registry
diceui/base
Type
registry:ui
Access
Free
Files written
2
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