Gathering detailed insights and metrics for @cn-ui/sortable
Gathering detailed insights and metrics for @cn-ui/sortable
Gathering detailed insights and metrics for @cn-ui/sortable
Gathering detailed insights and metrics for @cn-ui/sortable
npm install @cn-ui/sortable
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
The SortableList
is a drag-and-drop sortable list component built with SolidJS and Sortable.js. It allows users to rearrange items within the list through drag-and-drop interactions, and it integrates seamlessly with reactive data, ensuring that both the data and the view are kept in sync.
@cn-ui/reactive
.data-id
attribute to each list item, simplifying the developer's task.Ensure your project has the following dependencies installed:
1npm install @cn-ui/reactive solid-js sortablejs
First, import the SortableList
component into your component file:
1import { SortableList, SortableShared } from "@cn-ui/sortable";
1import { atom } from "@cn-ui/reactive"; 2import { SortableList, SortableShared } from "@cn-ui/sortable"; 3export default () => { 4 const data = atom([ 5 { 6 id: "223232", 7 label: "info", 8 }, 9 { 10 id: "111", 11 label: "info1", 12 }, 13 { 14 id: "222", 15 label: "info2", 16 }, 17 ]); 18 return ( 19 <SortableList 20 v-model={data} 21 getId={(item) => { 22 return item.label; 23 }} 24 > 25 {(item) => { 26 return <button>{item.label}</button>; 27 }} 28 </SortableList> 29 ); 30};
item.id
.You can also use the SortableShared
context to share data and options among multiple SortableList
instances. This is useful when you have multiple lists that need to share the same data source or configuration.
1import { atom, computed, resource } from "@cn-ui/reactive"; 2import { SortableList, SortableShared } from "@cn-ui/sortable"; 3export default () => { 4 const data = resource<{ data: { id: string; label: string }[] }>( 5 async () => 6 Mock.mock({ 7 "data|10": [ 8 { 9 id: "@id", 10 label: "@cname", 11 }, 12 ], 13 }), 14 { initValue: { data: [] } }, 15 ); 16 const modelLeft = computed(() => data().data.slice(0, 5)); 17 const modelRight = computed(() => data().data.slice(5)); 18 return ( 19 <> 20 <Flex> 21 <SortableShared.Provider value={{ sharedData: [modelLeft, modelRight] }}> 22 <SortableList 23 v-model={modelLeft} 24 options={{ 25 group: "common", 26 }} 27 > 28 {(item) => { 29 return <div>{item.label}</div>; 30 }} 31 </SortableList> 32 <SortableList 33 v-model={modelRight} 34 options={{ 35 group: "common", 36 }} 37 > 38 {(item) => { 39 return <div>{item.label}</div>; 40 }} 41 </SortableList> 42 </SortableShared.Provider> 43 </Flex> 44 <Flex vertical> 45 <button onclick={() => data.refetch()}>重置</button> 46 <div>{JSON.stringify(modelLeft().map((i) => i.label))}</div> 47 <div>{JSON.stringify(modelRight().map((i) => i.label))}</div> 48 </Flex> 49 </> 50 ); 51};
SortableList
by passing additional props such as class
, style
, and event handlers via the props
object.RefreshData
function can be used to manually refresh the data if needed, although it's typically called automatically after a sort operation.v-model
array has a unique id
property, or provide a custom getId
function to avoid conflicts.disabled
prop can be used to conditionally enable or disable the sorting functionality based on your application's logic.By following these guidelines, you should be able to integrate and utilize the SortableList
component effectively in your SolidJS applications.
No vulnerabilities found.
No security vulnerabilities found.