0.20.7 • Published 10 months ago

svelte-wheel-picker v0.20.7

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

svelte-wheel-picker

A customizable and interactive wheel picker component for Svelte applications, inspired by the classic iOS time selector.

npm version License: MIT

Features

  • Customizable wheel picker with smooth scrolling and inertia
  • Configurable number of visible options and density
  • Perspective effect for a 3D wheel appearance
  • Hover effects with unwrapping and stamping effect options
  • Responsive design with options to fill parent container
  • Touch and mouse event support for mobile and desktop
  • No dependencies

Installation

npm install svelte-wheel-picker

Basic Usage

<script>
  import WheelPicker from 'svelte-wheel-picker';

  let data = [
    {value: 1, label: "Option 1"},
    {value: 2, label: "Option 2"},
    {value: 3, label: "Option 3"},
    // Add more options as needed
  ];
</script>

<WheelPicker {data} />

Advanced Usage

Customizing Appearance and Behavior

<script>
  import WheelPicker from 'svelte-wheel-picker';

  let data = [
    // Your data array here
  ];

  let options = {
    visibleOptions: 5,
    density: 10,
    perspective: 30,
    friction: 3,
  };

  let rollOnHover = {
    enable: true,
    unwrap: 85,
    stamp: true,
    fixList: false,
    transformSpeed: 0.3
  };

  let fillParent = {
    enable: true
  };
</script>

<WheelPicker 
  {data}
  {options}
  {rollOnHover}
  {fillParent}
  classes="custom-class"
  style="background-color: #f0f0f0;"
/>

Props

PropTypeDefaultDescription
dataArray[...]Array of objects with value and label properties
selectedOptionobjectdata[0]Initially selected option
classesstring""Custom CSS classes
stylestring""Custom inline styles
optionsobject{}Configuration options for the wheel
rollOnHoverobject{enable: false}Configuration for hover effects
fillParentobject{enable: false}Configuration for filling parent container

options Object Properties

PropertyTypeDefaultDescription
visibleOptionsnumber7Number of visible options
densitynumbervisibleOptions * 2Density of options (affects scaling)
marginYnumber2Vertical margin (in %)
perspectivenumber0Perspective effect (0-180)
staticPointerTimernumber200Timer for static pointer (in ms)
frictionnumber4Friction for inertia effect
overflowstring"hidden"Overflow behavior ("hidden" or "visible")

rollOnHover Object Properties

PropertyTypeDefaultDescription
enablebooleanfalseEnable hover effects
unwrapnumber85Unwrap percentage on hover (0-99)
stampbooleanfalseEnable stamping effect
fixListbooleantrueFix list position on hover
transformSpeednumber0.3Animation speed for transformations

fillParent Object Properties

PropertyTypeDefaultDescription
enablebooleanfalseEnable filling parent container
heightstringundefinedCustom height when not filling parent

Events

The WheelPicker component does not emit custom events, but it updates the selectedOption internally. You can bind to this value to react to changes:

<script lang="ts">
  import WheelPicker from 'svelte-wheel-picker';
  import type {DataOption} from 'svelte-wheel-picker'
  
  let selectedOption:DataOption;
</script>

<WheelPicker bind:selectedOption {...otherProps} />

{#if selectedOption}
  <p>Selected: {selectedOption.label} (Value: {selectedOption.value})</p>
{/if}

Styling

The WheelPicker component uses inline styles for most of its styling needs. You can customize its appearance using the classes and style props, as well as by adjusting the options object.

Browser Compatibility

This component uses modern JavaScript features and CSS properties. Ensure you're using it in a compatible environment or provide appropriate polyfills.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

About

Created by um-dev

0.19.0

10 months ago

0.20.7

10 months ago

0.20.6

10 months ago

0.20.5

10 months ago

0.20.4

10 months ago

0.20.3

10 months ago

0.20.2

10 months ago

0.20.1

10 months ago

0.20.0

10 months ago

0.0.1

1 year ago