Skip to content

Commit 4314b15

Browse files
committed
Added disabled property and updated main README.md
1 parent d5c5a80 commit 4314b15

File tree

5 files changed

+7986
-8360
lines changed

5 files changed

+7986
-8360
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npm install vue-toggle-component --save
3131
</template>
3232

3333
<script>
34-
import VueToggle from "./components/VueToggle";
34+
import VueToggle from "vue-toggle-component";
3535
3636
export default {
3737
name: 'App',
@@ -43,20 +43,20 @@ export default {
4343
```
4444

4545
#### Properties that vue-toggle-component uses
46-
| Property name | Description |
47-
| ------------- | ---------------------------- |
48-
| `activeColor` | The active color the checked toggler uses. This is a hex code. Default: `#9FD6AE` |
49-
| `darkTheme` | Give this prop to the component to use the dark mode feature as shown in the GIF above. |
50-
| `id` | The ID the input and the label use in the component. |
51-
| `name` | The name attributes that will be set in the input. |
52-
| `title` | The title that is shown after the toggler itself. |
53-
| `toggled` | The value the toggler has by default, by default this is `false` |
46+
| Property name | Type | Default | Required |Description |
47+
| ------------- | --------- | --------- | -------- | -------------------------------------------------------------------------------------------------- |
48+
| name | `String` | - | X | Set's the name value of the input (checkbox). Useful for persisting data. |
49+
| title | `String` | - | X | The title that is displayed next to the toggle. |
50+
| activeColor | `String` | `#9FD6AE` | - | The color that is displayed when the toggler is active. |
51+
| darkTheme | `Boolean` | `false` | - | Set's dark mode to active. (note that this will not change the background like in the preview GIF. |
52+
| disabled | `Boolean` | `false` | - | Disables the toggler. |
53+
| toggled | `Boolean` | `true` | - | Sets the default value for the toggler. |
5454

5555
### Vue version support
5656

5757
The main v1 version supports Vue 3.x only, for previous versions of Vue, check the following the table.
5858

59-
| vue Version | vue-toggle-component version |
59+
| Vue version | vue-toggle-component version |
6060
| ----------- | ---------------------------- |
6161
| `2.x` | `0.1.x` |
6262
| `3.x` | `1.x` |

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<VueToggle title="Toggle me" id="1"/>
2+
<VueToggle title="Toggle me" name="VueToggle" disabled/>
33
</template>
44

55
<script>

src/components/VueToggle.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<template>
2-
<section class="wrapper" :class="{dark: darkTheme}" :title="title">
2+
<section :class="{'dark': darkTheme, 'disabled': disabled}" :title="title" class="wrapper">
33
<input
4-
:id="id"
5-
:name="name"
4+
:id="`_${name}`"
65
v-model="toggleState"
6+
:disabled="disabled"
7+
:name="name"
78
class="toggle"
89
type="checkbox"
910
@click="toggleState = !toggleState"
1011
/>
11-
<label :for="id" class="toggler" :style="[toggleState && {'background': activeColor}]"/>
12-
<span class="title" v-text="title" @click="toggleState = !toggleState"/>
12+
<label :for="name" :style="[toggleState && {'background': activeColor}]" class="toggler"/>
13+
<span class="title" @click="toggleState = !toggleState" v-text="title"/>
1314
</section>
1415
</template>
1516

@@ -20,8 +21,8 @@ export default {
2021
props: {
2122
activeColor: {type: String, default: '#9FD6AE'},
2223
darkTheme: {type: Boolean, default: false},
23-
id: {type: String, required: true},
24-
name: {type: [String, Boolean], default: false},
24+
disabled: {type: Boolean, default: false },
25+
name: {type: String, required: true},
2526
title: {type: String, required: true},
2627
toggled: {type: Boolean, default: false},
2728
},
@@ -100,6 +101,14 @@ export default {
100101
will-change: left;
101102
}
102103
104+
.disabled & {
105+
opacity: 50%;
106+
107+
&:hover {
108+
cursor: not-allowed;
109+
}
110+
}
111+
103112
.dark & {
104113
background: #374151;
105114
}

vue-toggle-component/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npm install vue-toggle-component --save
3131
</template>
3232

3333
<script>
34-
import VueToggle from "./components/VueToggle";
34+
import VueToggle from "vue-toggle-component";
3535
3636
export default {
3737
name: 'App',
@@ -56,7 +56,7 @@ export default {
5656

5757
The main v1 version supports Vue 3.x only, for previous versions of Vue, check the following the table.
5858

59-
| vue Version | vue-toggle-component version |
59+
| Vue version | vue-toggle-component version |
6060
| ----------- | ---------------------------- |
6161
| `2.x` | `0.1.x` |
6262
| `3.x` | `1.x` |

0 commit comments

Comments
 (0)