Skip to content
This repository was archived by the owner on Nov 29, 2021. It is now read-only.

Commit b9b4ddd

Browse files
committed
Initial commit
0 parents  commit b9b4ddd

9 files changed

+265
-0
lines changed

.babelrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"env"
4+
],
5+
"plugins": [
6+
"transform-runtime"
7+
]
8+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
/yarn.lock
3+
/dist

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Mario Juárez <[email protected]> (http://www.mjp.one)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# A Vue component to easily style checkbox and radio inputs
2+
3+
## WIP

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "vue-checkbox-radio-component",
3+
"version": "0.1.0",
4+
"description": "Checkbox and radio component for Vue.js",
5+
"keywords": [
6+
"checkbox",
7+
"radio",
8+
"vue"
9+
],
10+
"main": "dist/index.js",
11+
"author": {
12+
"name": "Mario Juárez",
13+
"email": "[email protected]",
14+
"url": "http://www.mjp.one"
15+
},
16+
"license": "MIT",
17+
"devDependencies": {
18+
"babel-core": "^6.24.1",
19+
"babel-loader": "^7.0.0",
20+
"babel-plugin-transform-runtime": "^6.23.0",
21+
"babel-preset-env": "^1.5.1",
22+
"css-loader": "^0.28.2",
23+
"vue-loader": "^12.1.0",
24+
"vue-template-compiler": "^2.3.3",
25+
"webpack": "^2.6.0"
26+
}
27+
}

src/components/Checkbox.vue

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<style>
2+
.checkbox-component > input {
3+
opacity: 0;
4+
position: absolute;
5+
}
6+
7+
.checkbox-component > input + label:before {
8+
content: '';
9+
display: inline-block;
10+
cursor: pointer;
11+
border: 1px solid #000;
12+
margin: 0;
13+
padding: 0;
14+
width: 16px;
15+
height: 16px;
16+
font-size: 14px;
17+
text-align: center;
18+
line-height: 1;
19+
color: transparent;
20+
background: #fff;
21+
}
22+
23+
.checkbox-component > input:checked + label:before {
24+
color: #000;
25+
}
26+
27+
.checkbox-component > input:focus + label:before {
28+
outline-color: #73b9ff;
29+
}
30+
</style>
31+
32+
<template>
33+
<div class="checkbox-component">
34+
<input type="checkbox"
35+
:id="id"
36+
:name="name"
37+
:value="value"
38+
:class="className"
39+
:checked="checked"
40+
:required="required"
41+
@change="onChange">
42+
<label :for="id">
43+
<slot></slot>
44+
</label>
45+
</div>
46+
</template>
47+
48+
<script>
49+
export default {
50+
props: {
51+
id: {
52+
type: String,
53+
default: function () {
54+
return 'checkbox-id-' + this._uid;
55+
},
56+
},
57+
name: {
58+
type: String,
59+
default: null,
60+
},
61+
value: {
62+
type: String,
63+
default: null,
64+
},
65+
className: {
66+
type: String,
67+
default: null,
68+
},
69+
checked: {
70+
type: Boolean,
71+
default: false,
72+
},
73+
required: {
74+
type: Boolean,
75+
default: false,
76+
},
77+
},
78+
79+
methods: {
80+
onChange: function (event) {
81+
this.$emit('change', event);
82+
},
83+
},
84+
};
85+
</script>

src/components/Radio.vue

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<style>
2+
.radio-component > input {
3+
opacity: 0;
4+
position: absolute;
5+
}
6+
7+
.radio-component > input + label:before {
8+
content: '';
9+
display: inline-block;
10+
cursor: pointer;
11+
border: 1px solid #000;
12+
margin: 0;
13+
padding: 0;
14+
width: 16px;
15+
height: 16px;
16+
font-size: 14px;
17+
text-align: center;
18+
line-height: 1;
19+
color: transparent;
20+
background: #fff;
21+
}
22+
23+
.radio-component > input:checked + label:before {
24+
color: #000;
25+
}
26+
27+
.radio-component > input:focus + label:before {
28+
outline-color: #73b9ff;
29+
}
30+
</style>
31+
32+
<template>
33+
<div class="radio-component">
34+
<input type="radio"
35+
:id="id"
36+
:name="name"
37+
:value="value"
38+
:class="className"
39+
:checked="checked"
40+
:required="required"
41+
@change="onChange">
42+
<label :for="id">
43+
<slot></slot>
44+
</label>
45+
</div>
46+
</template>
47+
48+
<script>
49+
export default {
50+
props: {
51+
id: {
52+
type: String,
53+
default: function () {
54+
return 'radio-id-' + this._uid;
55+
}
56+
},
57+
name: {
58+
type: String,
59+
default: null
60+
},
61+
value: {
62+
type: String,
63+
default: null
64+
},
65+
className: {
66+
type: String,
67+
default: null
68+
},
69+
checked: {
70+
type: Boolean,
71+
default: false
72+
},
73+
required: {
74+
type: Boolean,
75+
default: false
76+
},
77+
},
78+
79+
methods: {
80+
onChange: function (event) {
81+
this.$emit('change', event);
82+
}
83+
},
84+
}
85+
</script>

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Checkbox } from './components/Checkbox.vue';
2+
export { default as Radio } from './components/Radio.vue';

webpack.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
entry: './src/index.js',
5+
6+
output: {
7+
path: path.resolve(__dirname, 'dist'),
8+
filename: 'index.js',
9+
library: 'vue-checkbox-radio',
10+
libraryTarget: 'umd',
11+
},
12+
13+
externals: {
14+
vue: 'vue',
15+
},
16+
17+
module: {
18+
rules: [
19+
{
20+
test: /\.vue$/,
21+
loader: 'vue-loader',
22+
exclude: /node_modules/,
23+
},
24+
{
25+
test: /\.js$/,
26+
loader: 'babel-loader',
27+
exclude: /node_modules/,
28+
},
29+
]
30+
},
31+
};

0 commit comments

Comments
 (0)