Skip to content

Commit 91f2bd4

Browse files
domnantaseuvl
authored andcommitted
Add margin prop (#99)
1 parent 57debd2 commit 91f2bd4

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Vue.component('ToggleButton', ToggleButton)
7676
| switch-color | [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)'}` |
7777
| width | Number | 50 | Width of the button |
7878
| height | Number | 22 | Height of the button |
79+
| margin | Number | 3 | Space between the switch and background border |
7980
| name | String | undefined | Name to attach to the generated input field |
8081
| font-size | Number | undefined | Font size |
8182

demo/src/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
:disabled="true"/>
4444

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

66+
<toggle-button
67+
:value="true"
68+
:width="80"
69+
:labels="{checked: 'Custom', unchecked: 'Margin'}"
70+
:margin="7"/>
6671
</div>
6772
<div style="padding-top: 20px;">
6873
<toggle-button

dist/index.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.index.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Button.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const DEFAULT_COLOR_UNCHECKED = '#bfcbd9'
3636
const DEFAULT_LABEL_CHECKED = 'on'
3737
const DEFAULT_LABEL_UNCHECKED = 'off'
3838
const DEFAULT_SWITCH_COLOR = '#fff'
39-
const MARGIN = 3
4039
4140
const contains = (object, title) =>
4241
typeof object === 'object' && object.hasOwnProperty(title)
@@ -102,6 +101,10 @@ export default {
102101
type: Number,
103102
default: 50
104103
},
104+
margin: {
105+
type: Number,
106+
default: 3
107+
},
105108
fontSize: {
106109
type: Number
107110
}
@@ -125,19 +128,19 @@ export default {
125128
},
126129
127130
buttonRadius () {
128-
return this.height - MARGIN * 2;
131+
return this.height - this.margin * 2;
129132
},
130133
131134
distance () {
132-
return px(this.width - this.height + MARGIN)
135+
return px(this.width - this.height + this.margin)
133136
},
134137
135138
buttonStyle () {
136139
const transition = `transform ${this.speed}ms`
137140
138141
const transform = this.toggled
139-
? `translate3d(${this.distance}, 3px, 0px)`
140-
: null
142+
? `translate3d(${this.distance}, ${px(this.margin)}, 0px)`
143+
: `translate3d(${px(this.margin)}, ${px(this.margin)}, 0px)`
141144
142145
const background = this.switchColor
143146
? this.switchColorCurrent
@@ -264,12 +267,10 @@ export default {
264267
</script>
265268

266269
<style lang="scss" scoped>
267-
$margin: 3px;
268270
269271
.vue-js-switch {
270272
display: inline-block;
271273
position: relative;
272-
overflow: hidden;
273274
vertical-align: middle;
274275
user-select: none;
275276
font-size: 10px;
@@ -317,7 +318,6 @@ $margin: 3px;
317318
top: 0;
318319
left: 0;
319320
320-
transform: translate3d($margin, $margin, 0);
321321
border-radius: 100%;
322322
background-color: #fff;
323323
z-index: 2;

0 commit comments

Comments
 (0)