Skip to content

Commit

Permalink
feat: add info about Slider React component (#120)
Browse files Browse the repository at this point in the history
* docs: add info about `Slider` React component

* remove direction

very new but not very useful

* correct usage example
  • Loading branch information
SunsetTechuila authored Dec 10, 2023
1 parent edcb2b6 commit f47a61f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/development/api-wrapper/properties/react-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ReactComponent {
const PanelSkeleton: any;
const PanelContent: any;
const PanelHeader: any;
const Slider: any
};
```

Expand Down Expand Up @@ -316,6 +317,33 @@ const ConfirmButton = () => {
}
```

### `Slider`

Component to render sliders. It is used by Spotify for the volume/playing bars and on the settings page.

#### Props

See [`SliderProps`](/docs/development/api-wrapper/types/react-component/slider-props).

#### Example

```tsx
const Slider = () => {
const [value, setValue] = useState(0);

return (
<Spicetify.ReactComponent.Slider
max={100}
step={1}
value={value}
onDragStart={() => {}}
onDragMove={setValue}
onDragEnd={(value) => {console.log(`final value is ${value}`)}}
></Spicetify.ReactComponent.Slider>
);
}
```

### `PanelSkeleton`, `PanelContent`, `PanelHeader`

Components to render Spotify-style panel. Used by Spotify on their right sidebar panels (e.g. BuddyFeed, Now Playing, etc).
Expand Down
44 changes: 44 additions & 0 deletions docs/development/api-wrapper/types/react-component/slider-props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: SliderProps
description: Type definition for props of ReactComponent.PanelSkeleton.
---

The `SliderProps` object is used to render a slider.

:::note

This type is deducted from Spotify's internal usage. It may not be accurate and may change in the future.

:::

```ts
type SliderProps = {
value: number;
max: number;
step: number;
labelText?: string;
isInteractive?: boolean;
forceActiveStyles?: boolean;
onDragStart: (value: number) => void;
onDragMove: (value: number) => void;
onDragEnd: (value: number) => void;
onStepForward?: (value: number) => void;
onStepBackward?: (value: number) => void;
}
```
#### Properties
| Property | Type | Description |
| :--- | :--- | :--- |
| value | `number` | The current value of the slider. |
| max | `number` | The maximum value the slider can have. |
| step | `number` | The increment/decrement value when the slider is moved. |
| labelText | `string` &#124; `undefined` | The label text displayed for the slider. |
| isInteractive | `boolean` &#124; `undefined` | Determines if the slider is interactive. |
| forceActiveStyles | `boolean` &#124; `undefined` | Forces the active styles regardless of interaction state. |
| onDragStart | `(value: number) => void` | Callback function when dragging starts. |
| onDragMove | `(value: number) => void` | Callback function when the slider is being dragged. |
| onDragEnd | `(value: number) => void` | Callback function when dragging ends. |
| onStepForward | `(value: number) => void` &#124; `undefined` | Callback function when the slider steps forward. **Deprecated.** |
| onStepBackward | `(value: number) => void` &#124; `undefined` | Callback function when the slider steps backward. **Deprecated.** |
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const sidebars = {
'development/api-wrapper/types/react-component/panel-skeleton-props',
'development/api-wrapper/types/react-component/panel-content-props',
'development/api-wrapper/types/react-component/panel-header-props',
'development/api-wrapper/types/react-component/slider-props',
],
},
{
Expand Down

0 comments on commit f47a61f

Please sign in to comment.