Skip to content

Commit

Permalink
feat: Add dark variant for ios, flat and material themes. (#144)
Browse files Browse the repository at this point in the history
* Added dark theme for ios, flat and material.

* Added @variant for dark theme.
  • Loading branch information
sarbikbetal committed Oct 2, 2020
1 parent 09c2c00 commit 70e49f4
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 7 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ Check the [demo] for interactive examples.
- `'skewed'`
- `'material'`


![Dark Themes](vendor/ember-toggle/example-images/themes-dark.png)

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

> Example of changing the theme
```hbs
<XToggle
@theme='ios'
@variant='dark'
@value={{this.toggled}}
@onToggle={{fn (mut this.toggled)}}
/>
Expand Down Expand Up @@ -86,7 +92,8 @@ If you want your labels to be displayed, then you must set `showLabels` to `true

- `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', 'flip', 'skewed', 'default'.
- `theme` - One of 'light', 'ios', 'flat', 'material', 'flip', 'skewed', 'default'.
- `variant` - Use `dark` for dark themed variants. 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.
Expand Down
1 change: 1 addition & 0 deletions addon/components/x-toggle-switch/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
role='checkbox'
class="x-toggle-btn
{{this.themeClass}}
{{this.variant}}
{{@size}}
{{if @disabled ' x-toggle-disabled'}}
"
Expand Down
2 changes: 2 additions & 0 deletions addon/components/x-toggle/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
onLabel=this.onLabel
size=this.size
theme=this.theme
variant=this.variant
toggled=this.toggled
value=this.value
sendToggle=this.sendToggle
Expand Down Expand Up @@ -64,6 +65,7 @@
onLabel=this.onLabel
size=this.size
theme=this.theme
variant=this.variant
toggled=this.toggled
value=this.value
sendToggle=this.sendToggle
Expand Down
1 change: 1 addition & 0 deletions app/components/x-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = ENV['ember-toggle'] || {};
export default XToggle.extend({
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
theme: config.defaultTheme || 'default',
variant: config.defaultVariant || '',
defaultOffLabel: config.defaultOffLabel || 'Off::off',
defaultOnLabel: config.defaultOnLabel || 'On::on',
showLabels: config.defaultShowLabels || false,
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ module.exports = {
var allThemes = [
'light',
'ios',
'ios dark',
'default',
'flat',
'flat dark',
'skewed',
'flip',
'material',
'material dark',
];
var included = config.includedThemes;
var excluded = config.excludedThemes;
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ table.condensed td {
margin: 0;
padding: 0;
}

table.dark {
background-color: #212121;
color: #eee;
}
20 changes: 16 additions & 4 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
{{! template-lint-disable block-indentation attribute-indentation}}
<table>
<tbody>

<tr>
<td><XToggle @name={{1}} @theme="default" @value={{v1}} @onToggle={{fn (mut v1)}} /></td>
<td>default</td>
<td><XToggle @name={{2}} @theme="light" @value={{v2}} @onToggle={{fn (mut v2)}} /></td>
<td>light</td>
</tr>
<tr>
<td>
<XToggle @name={{3}} @theme="ios" @value={{v3}} @onToggle={{fn (mut v3)}} />
</td>
<td><XToggle @name={{3}} @theme="ios" @value={{v3}} @onToggle={{fn (mut v3)}} /></td>
<td>ios</td>
<td><XToggle @name={{4}} @theme="flat" @value={{v4}} @onToggle={{fn (mut v4)}} /></td>
<td>flat</td>
Expand All @@ -32,6 +29,21 @@
</tbody>
</table>

<table class="dark">
<tbody>
<tr>
<td><XToggle @name={{3}} @theme="ios" @variant="dark" @value={{v3}} @onToggle={{fn (mut v3)}} /></td>
<td>ios dark</td>
<td><XToggle @name={{4}} @theme="flat" @variant="dark" @value={{v4}} @onToggle={{fn (mut v4)}} /></td>
<td>flat dark</td>
</tr>
<tr>
<td><XToggle @name={{7}} @theme="material" @variant="dark" @value={{v8}} @onToggle={{fn (mut v8)}} /></td>
<td>material dark</td>
</tr>
</tbody>
</table>

<h2>Sizes</h2>

<table>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion vendor/ember-toggle/themes/flat.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
border-radius: 1em;
}

.x-toggle:checked + .label .x-toggle-flat.x-toggle-btn {
.x-toggle:checked + label .x-toggle-flat.x-toggle-btn {
border: 4px solid #7fc6a6;
}

Expand All @@ -40,3 +40,18 @@
height: 2.1em;
padding: 4px;
}

/* Dark mode styling */

.x-toggle-flat.dark.x-toggle-btn {
background: #2121218f;
border: 3px solid #a3a3a3;
}

.x-toggle-flat.dark.x-toggle-btn::after {
background: #e2e2e2;
}

.x-toggle:checked + label .x-toggle-flat.dark.x-toggle-btn {
border: 3px solid #7fc6a6;
}
12 changes: 11 additions & 1 deletion vendor/ember-toggle/themes/ios.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

.x-toggle:checked + label > .x-toggle-ios.x-toggle-btn {
background: #86d993;
background: #54d159;
}

.x-toggle:checked + label > .x-toggle-ios.x-toggle-btn:active {
Expand All @@ -51,3 +51,13 @@
height: 2.1em;
padding: 4px;
}

/* Dark mode styling */
.x-toggle-ios.dark.x-toggle-btn {
background: #2121218f;
border: 1px solid #646464;
}

.x-toggle:checked + label > .x-toggle-ios.dark.x-toggle-btn {
background: #86d993;
}
16 changes: 16 additions & 0 deletions vendor/ember-toggle/themes/material.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@
.x-toggle-material.large::before {
margin: 0.4em 0;
}

/* Dark mode styling */

/* Background */
.x-toggle-material.dark.x-toggle-btn::before {
background-color: #727272;
}

/* Disabled */
.x-toggle-material.dark.x-toggle-btn.x-toggle-disabled::before,
.x-toggle:checked
+ label
> .x-toggle-material.dark.x-toggle-btn.x-toggle-disabled::before {
background-color: #727272;
opacity: 0.12;
}

0 comments on commit 70e49f4

Please sign in to comment.