Skip to content

Commit ac549ab

Browse files
committed
initial commit
1 parent e1a86a1 commit ac549ab

File tree

7 files changed

+9116
-71
lines changed

7 files changed

+9116
-71
lines changed

README.md

+36-16
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,56 @@
11
<p>
2-
<img width="100%" src="https://assets.solidjs.com/banner?type={{name_of_lib}}&background=tiles&project=%20" alt="{{name_of_lib}}">
2+
<img width="100%" src="https://assets.solidjs.com/banner?type=solid-sortablejs&background=tiles&project=%20" alt="solid-sortablejs">
33
</p>
44

55
# {{name_of_lib}}
66

77
[![pnpm](https://img.shields.io/badge/maintained%20with-pnpm-cc00ff.svg?style=for-the-badge&logo=pnpm)](https://pnpm.io/)
88

9-
{{desc_of_lib}}
9+
Easily sort your list. solid-sortablejs is using the SortableJS library to sort your list.
1010

11-
> **Note** After using this template, you have to search and replace all `{{name_of_lib}}` and similar strings
12-
> with appropriate texts.
13-
>
14-
> `{{name_of_lib}}` should be a **kebab-case** string representing the name of you monorepo.
15-
>
16-
> `{{desc_of_lib}}` should be a **Normal case** string with the description of the repository.
17-
>
18-
> `{{me}}` should be a **kebab-case** string from your profile URL.
1911

2012
## Quick start
2113

2214
Install it:
2315

2416
```bash
25-
npm i {{name_of_lib}}
26-
# or
27-
yarn add {{name_of_lib}}
28-
# or
29-
pnpm add {{name_of_lib}}
17+
npm add solid-sortablejs
3018
```
3119

3220
Use it:
3321

3422
```tsx
35-
import {{name_of_lib}} from '{{name_of_lib}}'
23+
import {createStore} from 'solid-js/store'
24+
import Sortable from 'solid-sortablejs'
25+
26+
const App = () => {
27+
28+
const itemStyles = {background: 'green', padding: "10px", minWidth: "100px", margin: "5px", "border-radius": "4px", color: "white"};
29+
const containerStyles = {display: "inline-block", background: 'gray', padding: "10px", "border-radius": "4px"};
30+
31+
const [items, setItems] = createStore([
32+
{ id: 0, name: 0 },
33+
{ id: 1, name: 1 },
34+
{ id: 2, name: 2 },
35+
{ id: 3, name: 3 },
36+
])
37+
38+
const onEnd = (event: SortableOnEndEvent<typeof items[0]>) => {
39+
// event.movedItem -> the item that was moved
40+
// event.newList -> the new list of items
41+
// event.oldIndex -> the index of the item that was moved
42+
// event.newIndex -> the index of the item that was moved to
43+
44+
setItems(event.newList);
45+
}
46+
47+
return (
48+
<div style={containerStyles}>
49+
<Sortable items={items} onEnd={onEnd}>
50+
{item => <div style={itemStyles}>{item.name} {Math.random()}</div>}
51+
</Sortable>
52+
</div>
53+
);
54+
55+
};
3656
```

dev/App.tsx

+28-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
import type { Component } from "solid-js";
2-
import logo from "./logo.svg";
3-
import styles from "./App.module.css";
4-
import { Hello } from "../src";
1+
import Sortable, { SortableOnEndEvent } from "../src";
2+
import {createStore} from 'solid-js/store'
3+
4+
const App = () => {
5+
6+
const itemStyles = {background: 'green', padding: "10px", minWidth: "100px", margin: "5px", "border-radius": "4px", color: "white"};
7+
const containerStyles = {display: "inline-block", background: 'gray', padding: "10px", "border-radius": "4px"};
8+
9+
const [items, setItems] = createStore([
10+
{ id: 0, name: 0 },
11+
{ id: 1, name: 1 },
12+
{ id: 2, name: 2 },
13+
{ id: 3, name: 3 },
14+
])
15+
16+
const onEnd = (event: SortableOnEndEvent<typeof items[0]>) => {
17+
// event.movedItem -> the item that was moved
18+
// event.newList -> the new list of items
19+
// event.oldIndex -> the index of the item that was moved
20+
// event.newIndex -> the index of the item that was moved to
21+
22+
setItems(event.newList);
23+
}
524

6-
const App: Component = () => {
725
return (
8-
<div class={styles.App}>
9-
<header class={styles.header}>
10-
<img src={logo} class={styles.logo} alt="logo" />
11-
<h1>
12-
<Hello></Hello>
13-
</h1>
14-
<p>
15-
Edit <code>src/App.tsx</code> and save to reload.
16-
</p>
17-
<a
18-
class={styles.link}
19-
href="https://github.com/solidjs/solid"
20-
target="_blank"
21-
rel="noopener noreferrer"
22-
>
23-
Learn Solid
24-
</a>
25-
</header>
26+
<div style={containerStyles}>
27+
<Sortable items={items} onEnd={onEnd}>
28+
{item => <div style={itemStyles}>{item.name} {Math.random()}</div>}
29+
</Sortable>
2630
</div>
2731
);
32+
2833
};
2934

3035
export default App;

dev/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render } from "solid-js/web";
2-
import "./styles.css";
32

43
import App from "./App";
54

dev/styles.css

-11
This file was deleted.

0 commit comments

Comments
 (0)