Skip to content

Commit 5898c1f

Browse files
committed
chore: update docs
1 parent dc9eeee commit 5898c1f

File tree

3 files changed

+59
-47
lines changed

3 files changed

+59
-47
lines changed

README.md

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,87 +26,100 @@ npm install svelte-knobs
2626
#### Basic Knob
2727

2828
```svelte
29-
<script lang="ts">
30-
import { createFloatParam, Knob } from 'svelte-knobs';
29+
<script>
30+
import { SvgKnob } from 'svelte-knobs';
3131
32-
const basicParam = createFloatParam('lin', 0, 100);
33-
let basicValue = 0;
32+
let value = $state(0.0);
3433
</script>
3534
36-
<Knob param={basicParam} bind:value={basicValue} label="Volume" unit="%" />
35+
<SvgKnob bind:value />
36+
<span>{value.toFixed(2)}</span>
3737
```
3838

39-
A basic knob control with linear scaling.
40-
41-
#### Logarithmic Knob
42-
39+
A basic knob control with parameter scaling.
4340
```svelte
4441
<script lang="ts">
45-
import { createFloatParam } from 'svelte-knobs';
46-
47-
const logParam = createFloatParam('log', 20, 20_000);
48-
let logValue = 20;
49-
</script>
42+
import { LinearParam, LogParam } from 'svelte-knobs/params';
43+
import { SvgKnob } from 'svelte-knobs';
5044
51-
<Knob param={logParam} bind:value={logValue} label="Frequency" unit="Hz" />
52-
```
53-
54-
Knob with logarithmic scaling (default base is 10).
45+
let value = $state(0.0);
5546
56-
#### Smoothness Control
47+
const freqParam = new LogParam(20, 20_000, 10);
48+
const linParam = new LinearParam(0, 100);
49+
</script>
5750
58-
Control the knob's smoothness by adjusting the `stiffness` property.
51+
<SvgKnob bind:value />
52+
<span>{freqParam.denormalize(value) | 0}hz</span>
5953
60-
```svelte
61-
<Knob param={smoothParam} bind:value={smoothValue} label="Amount" unit="%" stiffness={0.1} />
62-
<Knob param={smoothParam} bind:value={smoothValue} label="Amount" unit="%" stiffness={1} />
54+
<SvgKnob bind:value />
55+
<span>{linParam.denormalize(value) | 0}%</span>
6356
```
6457

6558
#### Snap Points
6659

6760
Set specific snap points and adjust snapping sensitivity using `snapThreshold`.
6861

69-
```typescript
70-
import { createFloatParam, createRange } from 'svelte-knobs';
62+
```svelte
63+
<script>
64+
import { SvgKnob } from 'svelte-knobs';
7165
72-
const snapParam = createFloatParam('lin', 0, 2000);
73-
const snapPoints = [0, 500, 1000, 1500, 2000];
66+
let value = $state(0.0);
67+
</script>
7468
75-
let snapValue = 0;
76-
```
69+
<div>
70+
<SvgKnob bind:value snapPoints={[0.5]} />
71+
<span>{value.toFixed(2)}</span>
72+
</div>
7773
78-
```svelte
79-
<Knob
80-
param={snapParam}
81-
bind:value={snapValue}
82-
snapValues={snapPoints}
83-
snapThreshold={0.1}
84-
label="Release"
85-
unit="ms"
86-
/>
8774
```
8875

8976
#### Enum Parameter
9077

9178
Example usage of `EnumParam` for working with enumerated options.
9279

9380
```typescript
94-
import { createEnumParam, type Variant } from 'svelte-knobs';
95-
96-
const fruitParam = createEnumParam(['🍍', '🍉', '🍌', '🍋'] as const);
97-
let fruitValue: Variant<typeof fruitParam> = '🍉';
81+
import { BoolParam, EnumParam } from 'svelte-knobs/params';
82+
import { SvgKnob } from 'svelte-knobs';
83+
84+
let value = $state(0);
85+
86+
const fruitParam = new EnumParam(['🍍', '🍉', '🍌', '🍋', '🍇'] as const);
87+
const filterTypeParam = new EnumParam([
88+
'Low pass',
89+
'High pass',
90+
'Low shelf',
91+
'High shelf',
92+
'Bell',
93+
'Notch',
94+
'Allpass'
95+
] as const);
96+
97+
const booleanParam = new BoolParam();
9898
```
9999

100100
```svelte
101-
<Knob param={fruitParam} bind:value={fruitValue} label="Fruit" />
101+
<SvgKnob
102+
bind:value
103+
snapPoints={fruitParam.snapPoints}
104+
snapThreshold={fruitParam.snapThreshold}
105+
/>
106+
<p>{fruitParam.denormalize(value)}</p>
107+
108+
<SvgKnob bind:value {...filterTypeParam.knobProps} />
109+
<p>{filterTypeParam.denormalize(value)}</p>
110+
111+
<SvgKnob bind:value {...booleanParam.knobProps} />
112+
<p>{booleanParam.denormalize(value)}</p>
102113
```
103114

104115
#### Disabled Knob
105116

106117
Disable knob interactivity
107118

108119
```svelte
109-
<Knob param={basicParam} value={58} disabled />
120+
<SvgKnob disabled />
121+
<ImageKnob disabled />
122+
<Draggable disabled />
110123
```
111124

112125
## License

src/routes/examples/EnumParam.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { BoolParam, EnumParam } from '$lib/params';
3-
import SvgKnob from '$lib/SvgKnob.svelte';
3+
import { SvgKnob } from '$lib';
44
55
let value = $state(0);
66
@@ -22,7 +22,6 @@
2222
bind:value
2323
snapPoints={fruitParam.snapPoints}
2424
snapThreshold={fruitParam.snapThreshold}
25-
step={fruitParam.step}
2625
/>
2726
<p>{fruitParam.denormalize(value)}</p>
2827

src/routes/examples/ParamKnob.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { LinearParam, LogParam } from '$lib/params';
3-
import SvgKnob from '$lib/SvgKnob.svelte';
3+
import { SvgKnob } from '$lib';
44
55
let value = $state(0.0);
66

0 commit comments

Comments
 (0)