Skip to content

Commit 3507f4a

Browse files
committed
feat: better sortable
1 parent 7621c76 commit 3507f4a

30 files changed

+425
-925
lines changed

docs/__registry__/icons.tsx

-267
This file was deleted.

docs/__registry__/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,17 @@ export const Index: Record<string, any> = {
357357
subcategory: "",
358358
chunks: []
359359
},
360-
"sortable-grip-demo": {
361-
name: "sortable-grip-demo",
360+
"sortable-handle-demo": {
361+
name: "sortable-handle-demo",
362362
description: "",
363363
type: "registry:example",
364364
registryDependencies: ["button","table"],
365365
files: [{
366-
path: "registry/default/example/sortable-grip-demo.tsx",
366+
path: "registry/default/example/sortable-handle-demo.tsx",
367367
type: "registry:example",
368368
target: ""
369369
}],
370-
component: React.lazy(() => import("@/registry/default/example/sortable-grip-demo.tsx")),
370+
component: React.lazy(() => import("@/registry/default/example/sortable-handle-demo.tsx")),
371371
source: "",
372372
category: "",
373373
subcategory: "",

docs/content/docs/components/sortable.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import * as Sortable from "@/components/ui/sortable";
5151
<Sortable.Root>
5252
<Sortable.Content>
5353
<Sortable.Item >
54-
<Sortable.ItemGrip />
54+
<Sortable.ItemHandle />
5555
</Sortable.Item>
5656
<Sortable.Item />
5757
</Sortable.Content>
@@ -125,13 +125,13 @@ Individual sortable item component.
125125
]}
126126
/>
127127

128-
### ItemGrip
128+
### ItemHandle
129129

130130
A button component that acts as a drag handle for sortable items.
131131

132132
<AutoTypeTable
133133
path="./types/docs/sortable.ts"
134-
name="ItemGripProps"
134+
name="ItemHandleProps"
135135
/>
136136

137137
<DataAttributesTable

docs/hooks/use-callback-ref.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @see https://github.com/radix-ui/primitives/blob/main/packages/react/use-callback-ref/src/useCallbackRef.tsx
3+
*/
4+
5+
import * as React from "react";
6+
7+
/**
8+
* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
9+
* prop or avoid re-executing effects when passed as a dependency
10+
*/
11+
function useCallbackRef<T extends (...args: never[]) => unknown>(
12+
callback: T | undefined,
13+
): T {
14+
const callbackRef = React.useRef(callback);
15+
16+
React.useEffect(() => {
17+
callbackRef.current = callback;
18+
});
19+
20+
// https://github.com/facebook/react/issues/19240
21+
return React.useMemo(
22+
() => ((...args) => callbackRef.current?.(...args)) as T,
23+
[],
24+
);
25+
}
26+
27+
export { useCallbackRef };

0 commit comments

Comments
 (0)