• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Checkbox based Toggle Switches for Ember

ember-toggle

Checkbox based Toggle Switch component with swipe/drag support for Ember.

NPM CI Ember Observer Score

Based on this codepen. Here's the official demo using this component.

Compatibility

  • Ember.js v3.24 or above
  • Ember CLI v3.24 or above
  • Node.js v12 or above

Install

ember install ember-toggle

Basic Usage

<XToggle @value={{this.myValue}} @onToggle={{fn (mut this.myValue)}} />

Themes

Examples Of Available Themes

There are many themes which change the visual appearance of the toggle. Check the demo for interactive examples.

  • 'default'
  • 'ios'
  • 'light'
  • 'flat'
  • 'flip'
  • 'skewed'
  • 'material'

Dark Themes

Use it along with the @variant='auto' or @variant='dark' option to get a dark themed version, works only with 'ios', 'flat' and 'material' theme.

Example of changing the theme

<XToggle
  @theme='ios'
  @variant='dark'
  @value={{this.toggled}}
  @onToggle={{fn (mut this.toggled)}}
/>

Note: By default all themes are included, see the Configuration section to change which themes are included/excluded.

Size

You can also adjust the size of the widget by use of the size property. Valid sizes are:

  • 'small'
  • 'medium'
  • 'large'

This option is available on all themes but is a less sensible choice for those themes which actually include the label within the control (e.g., skew and flip).

Labels

You can customize labels (The text the user sees for the two states) and their associated values:

<XToggle
  @onLabel='Enabled'
  @offLabel='Disabled'
  @showLabels={{true}}
  @value={{this.myValue}}
  @onToggle={{fn (mut this.myValue)}}
/>

If you want your labels to be displayed, then you must set showLabels to true.

Available Options

  • value - The state of the switch, can be true or false. Defaults to false.
  • onToggle - The action that should change the state of value.
  • theme - One of 'light', 'ios', 'flat', 'material', 'flip', 'skewed', 'default'.
  • variant - One of dark or auto. Use auto for system dependent light/dark theme. Works only with ios, flat and material theme. Defaults to 'default' if not specified.
  • size - One of 'small', 'medium', 'large'. Defaults to 'medium' if not specified.
  • onLabel - The label for the on state. Defaults to 'On'.
  • offLabel - The label for the off state. Defaults to 'Off'.
  • showLabels - Defaults to 'false', if 'true' will display labels on left and ride side of toggle switch
  • disabled - Defaults to false, which means you can click the toggle. When true, an .x-toggle-disabled class is set on the toggle and an .x-toggle-container-disabled class is set on the component.
  • name - A name to differentiate multiple toggles, gets passed to the toggle action. Defaults to 'default'.

Configuring

Add a configuration for ember-toggle to include only the themes that you will use, as well as any other default settings that apply to all toggles in your app. These defaults can be overriden on a per toggle basis (except the options regarding themes being added to your app's build step).

This configuration is located in config/environment.js.
The following is an example of how you can configure this addon:

ENV['ember-toggle'] = {
  includedThemes: ['light', 'default', 'flip'],
  excludedThemes: ['flip'],
  excludeBaseStyles: false, // defaults to false
  defaultShowLabels: true, // defaults to false
  defaultTheme: 'light', // defaults to 'default'
  defaultSize: 'small', // defaults to 'medium'
  defaultOffLabel: 'False', // defaults to 'Off'
  defaultOnLabel: 'True', // defaults to 'On'
};

note: the IOS theme is referred to as just ios not ios7 as was indicated in the originating CSS source

To exclude (not include) a theme, means that it's css styles will not be bundled with your application, keeping your app's css bundle size smaller.

Note: including a blank array e.g. includeThemes: [] will not include any themes, leaving you to define your own theme styles. See the vendor/ember-toggle/themes directory for reference. Note: you may also want to set excludeBaseStyles: true so that this addon doesn't include the styles used by all the themes.

Advanced Usage

If you need custom labels, additional markup, or non-standard behavior, you are in the right section.

The x-toggle component also provides a composable component API.

<XToggle
  @showLabels={{true}}
  @value={{this.value}}
  @onToggle={{fn (mut this.value)}}
  as |toggle|
>
  <toggle.offLabel />
  <toggle.switch />
  <toggle.onLabel />
</XToggle>

The above is a simple example that returns a basic toggle, but you can see how this could be used to wrap the switch or the labels in custom markup or logic.

Single Label

This format allows greater flexibility with labels, like the single label use-case.

<XToggle
  @showLabels={{true}}
  @value={{this.value}}
  @onToggle={{fn (mut this.value)}}
  as |toggle|
>
  <toggle.label @value={{not this.value}}>
    <b>turn {{if this.value 'off' 'on'}}</b>
  </toggle.label>

  <toggle.switch @theme='flip' @onLabel='diff on' @offLabel='diff off' />
</XToggle>

Note: The not helper is a custom Ember helper in the above example.

Contributing

See the Contributing guide for details.

License

MIT

More Repositories

1

ember-plupload

Ember component for handling uploads using plupload
JavaScript
87
star
2

hapi-decorators

Decorators for HapiJS routes
JavaScript
63
star
3

pagination-pager

Ember.js Component for Bootstrap 3 pagination & pager components
JavaScript
56
star
4

jquery-highlight

A Bower wrapper for @bartaz modification to the jQuery Term Highlighting plugin.
JavaScript
45
star
5

ember-toastr

Wrapper for Toastr.js notifications
JavaScript
44
star
6

ember-query-params

Ember service for your query params
JavaScript
44
star
7

ember-shadow-dom

Write templates for your components inside of a Shadow DOM root.
JavaScript
27
star
8

ember-data-tasks

An alternative Ember Data store that returns Ember Concurrency tasks instead of promises.
JavaScript
24
star
9

cli-width

Fallback to a default if `process.stdout.getWindowSize` doesn't exist
JavaScript
24
star
10

ember-named-yields

Named Yields for Ember Components
JavaScript
17
star
11

ember-template-imports

Pods + angle bracket component = modern Ember-y goodness
JavaScript
14
star
12

ember-addon-viewer

View information about addons used in your Ember app.
JavaScript
14
star
13

npm-scripts

Run your npm scripts more efficiently
JavaScript
13
star
14

google-maps-markup

Ember markup component for Google Maps - Draw and Measure
JavaScript
12
star
15

ember-highlight

Highlight a given term(s) inside the `{{highlight-terms}}` component block.
JavaScript
10
star
16

testing-express-api

Testing Express APIs with Supertest
JavaScript
9
star
17

breach-module-manager

A module manager for Breach
JavaScript
9
star
18

google-maps-drawing-tools

Tools for drawing different types of shapes/items on a Google Map
TypeScript
8
star
19

ember-supabase

Ember Data and Ember Simple Auth integrations for Supabase.
TypeScript
8
star
20

ember-cli-deploy-gcloud-storage

An Ember-CLI-Deploy plugin to upload assets to Google Cloud Storage.
JavaScript
8
star
21

sword

Simple Bible passage parser. Converts text based passages into a usable object.
JavaScript
8
star
22

ember-template-input

Ember input component for easily building template strings from an available list of options
JavaScript
8
star
23

ember-palette

Simple palette component for choosing a predefined color
JavaScript
7
star
24

aws-subdomain

Create subdomains for AWS without diving into the AWS SDK
JavaScript
7
star
25

eslint-plugin-doc-code-blocks

Lint JavaScript in fenced code blocks inside of your block comments
JavaScript
6
star
26

glimmer-pong

Pong game written using Glimmer.js and SVGs
TypeScript
5
star
27

Ambience

Online media rental system (VHS, DVD, Video Games)
Java
5
star
28

interval

A small library for creating and using time intervals using common units of time instead.
JavaScript
5
star
29

paratrooper

Deployment CLI for Node on Ubuntu (nginx & upstart) with Git
JavaScript
5
star
30

d3.chart.pie

Pie/Donut chart using d3 and d3.chart.
JavaScript
5
star
31

geojson-to-vt

Proof of concept GeoJSON served as Vector Tiles
JavaScript
4
star
32

data-table

Ember Component for comparing two or more similar datasets.
JavaScript
4
star
33

bitbucket-filters

Chrome Extension for adding custom filters to Bitbucket Issues
JavaScript
4
star
34

just-auth

Simple token based authentication for Express.js
JavaScript
3
star
35

beakerbrowser-webdb-testapp

JavaScript
3
star
36

pizza-locator

Basic Google Maps app for locating pizza restaurants
JavaScript
3
star
37

ember-mobiledoc-grid

Grid layout cards for ember-mobiledoc-editor
JavaScript
3
star
38

ember-zipline

Pass Ember components from one location to another (engine)
JavaScript
3
star
39

ArcGisAdapter

Ember Data adapter/serializer for ArcGis Server feature data.
JavaScript
3
star
40

ember-inline-component

Blueprint Addon for Ember Components that have inline templates
JavaScript
3
star
41

ember-yielded-portals

Complex component APIs with portals and contextual components
JavaScript
3
star
42

ember-flow

Declarative Node/Edge Graph
TypeScript
3
star
43

battle-chess

Deployed version doesn't contain server yet. Try locally.
TypeScript
3
star
44

liturgical-year

JavaScript
2
star
45

ember-leaflet-cartodb

Ember-Leaflet CartoDB.js Layer
JavaScript
2
star
46

ember-cli-pen

Pen Editor (https://github.com/sofish/pen) component addon
JavaScript
2
star
47

docker-shell

Run commands against a docker container
JavaScript
2
star
48

book-search

Secret playground for custom glimmerx router library
TypeScript
2
star
49

knownasilya.github.io

Personal Blog
JavaScript
2
star
50

denali-rethinkdb

RethinkDB adapter for the Denali node framework
JavaScript
2
star
51

ember-cli-deploy-gcloud-pubsub

Notify that a deployment has been activated via Google PubSub.
JavaScript
2
star
52

app-blueprint

Ember CLI app blueprint
JavaScript
2
star
53

ember-receive

A teleporter there and back again (or not)!
JavaScript
2
star
54

d3.chart.legend

Legend "chart" for mixin with other charts.
JavaScript
1
star
55

signal-light

Signal Light Web App (for fun)
JavaScript
1
star
56

dusty-sandals

Interactive Fiction Game
HTML
1
star
57

form-data-parser

Middleware for connect or express that parses FormData in a sane way, no streams necessary.
JavaScript
1
star
58

core

experimental strider core in denali
TypeScript
1
star
59

DtoD

Day to Day: Event Media
JavaScript
1
star
60

test-dotnet-core-mvc-api

C#
1
star
61

plastictrees

Wordpress Theme (2/3 columns, vertical navigation, custom plugin)
1
star
62

logux-poc

TypeScript
1
star
63

test-ember-microstates

Trying out how microstates would work
JavaScript
1
star
64

quotes

Wholesome Quotes
1
star
65

goat

Serve static files for development, simple and unobstructive.
JavaScript
1
star
66

carto-utils

Util cli/modules for working with carto
JavaScript
1
star
67

Ember-Components

Variety of Ember Components
JavaScript
1
star
68

index-html-loader

Load and cache index.html using GCP PubSub, works great with ember-cli-deploy
JavaScript
1
star
69

moonshot

Rust
1
star
70

denali-knex

JavaScript
1
star
71

test-shadowdom

Theming web components
HTML
1
star
72

ember-cssgrid-editor

CSS Grid layout editor components
JavaScript
1
star
73

paper-origami

Ember app layout/wrapper for addons (or anything else)
JavaScript
1
star
74

PrayerJournal

An online prayer journal that sends prayer reminders and asks when prayers have been answered. A Meteor app.
JavaScript
1
star
75

async-workflow

Async Task Workflow
JavaScript
1
star
76

google-maps-zoom

Google Maps zoom control component addon for Ember CLI
JavaScript
1
star
77

ember-cli-range-input

Range Slider component backed by jQueryTool's rangeinput
JavaScript
1
star
78

pair-me-up

Gives a range, each paired with one another
JavaScript
1
star
79

parky

Re-mapping object keys to new names
JavaScript
1
star
80

ember-action-services

Action services contain immutable state and actions that mutate that state
JavaScript
1
star
81

lf-test

test the liquid-fire issue
JavaScript
1
star
82

ember-glimmer-components-test

JavaScript
1
star