npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

segmented-control-svelte

v3.8.3

Published

Segmented Control is a set of two or more Segments, each of which functions as a mutually exclusive button. It features a background, which can be animated with a sliding effect.

Downloads

109

Readme

Segmented Control

Segmented Control is a set of two or more Segments, each of which functions as a mutually exclusive button. It features a background, which can be animated with a sliding effect.

Installation and Usage

Installation

To add a component to a Svelte/SvelteKit project, run:

npm i segmented-control-svelte

Usage

Include component on a webpage by adding

import 'segmented-control-svelte/lightMode.css' // Optional, alternatively use darkMode.css or a custom stylesheet
import { SegmentedControl, Segment } from 'segmented-control-svelte'

within the script tag of a Svelte file. You can further use the component as such:

<SegmentedControl>
  <Segment>First</Segment>
  <Segment>Second</Segment>
</SegmentedControl>

The generated HTML will be as such:

<div class="segmented-control" role="tablist" aria-orientation="horizontal">
  <button class="segment selected" role="tab" aria-selected="true" aria-disabled="false" tabindex="0">First</button>
  <button class="segment" role="tab" aria-disabled="false" aria-selected="false" aria-disabled="false" tabindex="-1">Second</button>
  <div class="segmented-control-background" role="presentation" style="width: 75px; transform: translateX(2px);"></div>
</div>

API

You can specify additional options for Segmented Control and each separate Segment.

Segmented Control

selectedIndex

Use this option to specify an index of an element to be selected by default, starting with 0.

<SegmentedControl selectedIndex={1}>
  <Segment>First</Segment>
  <Segment>Second</Segment> <!-- This element will be selected initially -->
</SegmentedControl>

You can bind to this value to have changes to the selected index be reflected both in the Segmented Control component and any other part of the interface that uses it.

<script>
  import 'segmented-control-svelte/lightMode.css'
  import { SegmentedControl, Segment } from 'segmented-control-svelte'

  let segmentedControlSelectedIndex = 1
</script>

<SegmentedControl bind:selectedIndex={segmentedControlSelectedIndex}>
  <Segment>First</Segment>
  <Segment>Second</Segment>
</SegmentedControl>

<p>Index of a selected element: {segmentedControlSelectedIndex}</p>

orientation

Use this option to specify orientation of the Segmented Control. Accepted options are "horizontal" and "vertical". Default orientation is "horizontal".

<SegmentedControl orientation='vertical'>
  <Segment>First</Segment>
  <Segment>Second</Segment>
</SegmentedControl>

Segment

label

Use this option to specify a Segment's label.

<SegmentedControl>
  <Segment label='First' />
  <Segment label='Second' />
</SegmentedControl>

Alternatively, a label can be specified between component tags:

<SegmentedControl>
  <Segment>First</Segment>
  <Segment>Second</Segment>
</SegmentedControl>

isDisabled

Use this option to disable selection of a Segment.

<SegmentedControl>
  <Segment>First</Segment>
  <Segment isDisabled={true}>Second</Segment>
</SegmentedControl>

Demo

Launch a demo by running in the terminal:

git clone --depth=1 https://github.com/stuymedova/segmented-control-svelte . # Clone the latest commit from this repository to your current directory
npm install
npm run dev

The demo will be available at http://localhost:3000. Navigate to src/routes/index.svelte to make any changes.