Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Vue.component('ToggleButton', ToggleButton)
| switchColor | [String, Object] | `#BFCBD9` | If `String` - color or background property of the switch when checked <br>If `Object` - colors or background property for the switch when checked/uncheked <br>Example: `{checked: '#25EF02', unchecked: 'linear-gradient(red, yellow)'}` |
| width | Number | 50 | Width of the button |
| height | Number | 22 | Height of the button |
| margin | Number | 3 | Space between the switch and background border |
| name | String | undefined | Name to attach to the generated input field |
| fontSize | Number | undefined | Font size |

Expand Down
7 changes: 6 additions & 1 deletion demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
:disabled="true"/>

<toggle-button :value="true"
:labels="{checked: 'Button', unchecked: 'Collor'}"
:labels="{checked: 'Button', unchecked: 'Color'}"
:color="{checked: '#7DCE94', unchecked: '#82C7EB'}"
:width="80"
:switchColor="{checked: 'linear-gradient(red, yellow)', unchecked: '#F2C00B'}"/>
Expand All @@ -63,6 +63,11 @@
</template>
</toggle-button>

<toggle-button
:value="true"
:width="80"
:labels="{checked: 'Custom', unchecked: 'Margin'}"
:margin="7"/>
</div>
<div style="padding-top: 20px;">
<toggle-button
Expand Down
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions dist/ssr.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const DEFAULT_COLOR_UNCHECKED = '#bfcbd9'
const DEFAULT_LABEL_CHECKED = 'on'
const DEFAULT_LABEL_UNCHECKED = 'off'
const DEFAULT_SWITCH_COLOR = '#fff'
const MARGIN = 3

const contains = (object, title) =>
typeof object === 'object' && object.hasOwnProperty(title)
Expand Down Expand Up @@ -101,6 +100,10 @@ export default {
type: Number,
default: 50
},
margin: {
type: Number,
default: 3
},
fontSize: {
type: Number
}
Expand All @@ -124,19 +127,19 @@ export default {
},

buttonRadius () {
return this.height - MARGIN * 2;
return this.height - this.margin * 2;
},

distance () {
return px(this.width - this.height + MARGIN)
return px(this.width - this.height + this.margin)
},

buttonStyle () {
const transition = `transform ${this.speed}ms`

const transform = this.toggled
? `translate3d(${this.distance}, 3px, 0px)`
: null
? `translate3d(${this.distance}, ${px(this.margin)}, 0px)`
: `translate3d(${px(this.margin)}, ${px(this.margin)}, 0px)`

const background = this.switchColor
? this.switchColorCurrent
Expand Down Expand Up @@ -263,12 +266,10 @@ export default {
</script>

<style lang="scss" scoped>
$margin: 3px;

.vue-js-switch {
display: inline-block;
position: relative;
overflow: hidden;
vertical-align: middle;
user-select: none;
font-size: 10px;
Expand Down Expand Up @@ -316,7 +317,6 @@ $margin: 3px;
top: 0;
left: 0;

transform: translate3d($margin, $margin, 0);
border-radius: 100%;
background-color: #fff;
z-index: 2;
Expand Down