-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,118 @@ | ||
# create-svelte | ||
# svelte-knobs | ||
|
||
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte). | ||
![Version](https://img.shields.io/npm/v/svelte-knobs) | ||
![License](https://img.shields.io/badge/license-MIT-lightgrey) | ||
|
||
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging). | ||
`svelte-knobs` is a Svelte component library for building customizable knob controls. | ||
|
||
## Creating a project | ||
Inspired by: | ||
|
||
If you're seeing this, you've probably already done this step. Congrats! | ||
- [solid-knobs](https://github.com/tahti-studio/solid-knobs) | ||
- [nih-plug](https://github.com/robbert-vdh/nih-plug) | ||
|
||
[Web demo](https://eye-wave.github.io/svelte-knobs) | ||
|
||
## Installation | ||
|
||
Add the library to your project: | ||
|
||
```bash | ||
# create a new project in the current directory | ||
npm create svelte@latest | ||
npm install svelte-knobs | ||
``` | ||
|
||
## Usage | ||
|
||
Import the `Knob` component and use it in your Svelte application: | ||
|
||
```svelte | ||
<script> | ||
import { Knob } from 'svelte-knobs'; | ||
let volume = 50; | ||
</script> | ||
# create a new project in my-app | ||
npm create svelte@latest my-app | ||
<Knob bind:value={volume} label="Volume" unit="%" /> | ||
``` | ||
|
||
## Developing | ||
### Examples | ||
|
||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: | ||
#### Basic Knob | ||
|
||
```bash | ||
npm run dev | ||
```typescript | ||
import { createFloatParam, createRange } from 'svelte-knobs'; | ||
|
||
const basicParam = createFloatParam(createRange('lin', 0, 100)); | ||
let basicValue = 0; | ||
``` | ||
|
||
# or start the server and open the app in a new browser tab | ||
npm run dev -- --open | ||
```svelte | ||
<Knob param={basicParam} bind:value={basicValue} label="Volume" unit="%" /> | ||
``` | ||
|
||
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app. | ||
A basic knob control with linear scaling. | ||
|
||
## Building | ||
#### Logarithmic Knob | ||
|
||
To build your library: | ||
```typescript | ||
import { createFloatParam, createRange } from 'svelte-knobs'; | ||
|
||
```bash | ||
npm run package | ||
const logParam = createFloatParam(createRange('log', 20, 20_000)); | ||
let logValue = 20; | ||
``` | ||
|
||
To create a production version of your showcase app: | ||
```svelte | ||
<Knob param={logParam} bind:value={logValue} label="Frequency" unit="Hz" /> | ||
``` | ||
|
||
```bash | ||
npm run build | ||
Knob with logarithmic scaling (default base is 10). | ||
|
||
#### Smoothness Control | ||
|
||
Control the knob's smoothness by adjusting the `stiffness` property. | ||
|
||
```svelte | ||
<Knob param={smoothParam} bind:value={smoothValue} label="Amount" unit="%" stiffness={0.1} /> | ||
<Knob param={smoothParam} bind:value={smoothValue} label="Amount" unit="%" stiffness={1} /> | ||
``` | ||
|
||
You can preview the production build with `npm run preview`. | ||
#### Snap Points | ||
|
||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. | ||
Set specific snap points and adjust snapping sensitivity using `snapThreshold`. | ||
|
||
## Publishing | ||
```typescript | ||
import { createFloatParam, createRange } from 'svelte-knobs'; | ||
|
||
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)). | ||
const snapParam = createFloatParam(createRange('lin', 0, 2000)); | ||
const snapPoints = Array.from({ length: 5 }, (_, i) => i * 500); | ||
|
||
To publish your library to [npm](https://www.npmjs.com): | ||
let snapValue = 0; | ||
``` | ||
|
||
```bash | ||
npm publish | ||
```svelte | ||
<Knob | ||
param={snapParam} | ||
bind:value={snapValue} | ||
snapValues={snapPoints} | ||
snapThreshold={0.1} | ||
label="Release" | ||
unit="ms" | ||
/> | ||
``` | ||
|
||
#### Enum Parameter | ||
|
||
Example usage of `EnumParam` for working with enumerated options. | ||
|
||
```typescript | ||
import { createEnumParam, type Variant } from 'svelte-knobs'; | ||
|
||
const fruitParam = createEnumParam(['🍍', '🍉', '🍌', '🍋'] as const); | ||
let fruitValue: Variant<typeof fruitParam> = '🍉'; | ||
``` | ||
|
||
```svelte | ||
<Knob param={fruitParam} bind:value={fruitValue} label="Fruit" /> | ||
``` | ||
|
||
## License | ||
|
||
MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters