Coder Social home page Coder Social logo

sunify / svelte-select Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 459 KB

Simple component that allows you to customize select button appearance

Home Page: https://sunify.github.io/svelte-select/

JavaScript 32.11% HTML 67.89%
svelte svelte-v3 svelte3 svelte-components sveltejs select svelte-framework

svelte-select's Introduction

svelte-select

Simple component that allows you to customize select button appearance

<script>
  import Select from '../src/index.svelte';

  const emptyValue = '';

  let value = emptyValue;
  let options = [
    ['0', { brand: 'Shimano', material: 'Steel' }],
    ['1', { brand: 'Campangnolo', material: 'Alluminium' }],
    ['2', { brand: 'Sram', material: 'Alluminium' }],
  ];
</script>

<style>
  .button {
    display: inline-block;
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 3px;
  }

  select:focus + .button {
    border-color: #00f;
  }
</style>

<Select
  options={options}
  {emptyValue}
  placeholder="Freehub body"
  bind:value={value}
  let:currentOption
>
  <slot>
    <span class="button">
      {currentOption.brand || currentOption} ▾
    </span>
  </slot>
  <span slot="option" let:option>
    {#if typeof option === 'object'}
      {option.brand} ({option.material})
    {:else}
      {option}
    {/if}
  </span>
</Select>

Install

npm install @sunify/svelte-select or yarn add @sunify/svelte-select

Props

  • options: [string, any][] — an array of key-value pairs
  • emptyValue: string = '' — default value when no selected option
  • placeholder: string = ''
  • value: string — current option key

Slots

  • default — to customize select button appearance or add anything you want to select
  • option — to customize select options (see example above)

svelte-select's People

Contributors

sunify avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.