|
| 1 | +# svelte-switch |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/svelte-switch) |
| 4 | +[](https://www.npmjs.com/package/svelte-switch) |
| 5 | + |
| 6 | +SvelteJS component for switch or toggle a boolean.The component is Svelte implementation of [react-switch](https://github.com/markusenglund/react-switch). |
| 7 | + |
| 8 | +## Demo |
| 9 | + |
| 10 | +[Click here for Storybook link](https://svelte-switch.netlify.app/) |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +``` |
| 15 | +npm install svelte-switch |
| 16 | +
|
| 17 | +or |
| 18 | +
|
| 19 | +yarn add svelte-switch |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +``` |
| 25 | +<script> |
| 26 | + import Switch from "./../../src"; |
| 27 | +
|
| 28 | + let checkedValue = true; |
| 29 | +
|
| 30 | + function handleChange(e) { |
| 31 | + const { checked } = e.detail; |
| 32 | + checkedValue = checked; |
| 33 | + } |
| 34 | +</script> |
| 35 | +
|
| 36 | +<h1>Simple usage</h1> |
| 37 | +Switch with default style |
| 38 | +<Switch on:change={handleChange} checked={checkedValue} /> |
| 39 | +<br /> |
| 40 | +The switch is {checkedValue ? 'on' : 'off'}. |
| 41 | +
|
| 42 | +``` |
| 43 | + |
| 44 | +## API |
| 45 | + |
| 46 | +### Props |
| 47 | + |
| 48 | +| Prop Name | Description | Default Value | |
| 49 | +| --------------------- | ---------------------------------------------------------------------------------------- | ------------- | |
| 50 | +| accept | Set accepted file types. See https://github.com/okonet/attr-accept for more information. | undefined | |
| 51 | +| disabled | | false | |
| 52 | +| maxSize | | Infinity | |
| 53 | +| minSize | | 0 | |
| 54 | +| multiple | if true, multiple files can be selected at once | true | |
| 55 | +| preventDropOnDocument | 1231 | true | |
| 56 | +| noClick | disable click events | false | |
| 57 | +| noKeyboard | disable keyboard events | false | |
| 58 | +| noDrag | disable drag events | false | |
| 59 | +| containerClasses | custom container classes | "" | |
| 60 | +| containerStyles | custom inline container styles | "" | |
| 61 | +| disableDefaultStyles | don't apply default styles to container | false | |
| 62 | + |
| 63 | +### Events |
| 64 | + |
| 65 | +| Event Name | Description | `event.detail` info | |
| 66 | +| ---------- | ----------- | ------------------------- | |
| 67 | +| change | | `{event: event, checked}` | |
| 68 | + |
| 69 | +### Examples |
| 70 | + |
| 71 | +[Click here](https://github.com/thecodejack/svelte-switch/tree/master/stories/views) to view stories implementation |
| 72 | + |
| 73 | +## Credits |
| 74 | + |
| 75 | +Component is reimplementation [react-switch](https://github.com/markusenglund/react-switch). Complete credit goes to author and contributors of [react-dropzone](https://github.com/markusenglund/react-switch). |
| 76 | + |
| 77 | +## License |
| 78 | + |
| 79 | +MIT |
0 commit comments