Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SettingsCheckbox components #649

Closed
wants to merge 1 commit into from
Closed
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
167 changes: 167 additions & 0 deletions src/components/Checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<!--
-
GretaD marked this conversation as resolved.
Show resolved Hide resolved
- @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
- @copyright Copyright (c) 2019 Greta Doci <gretadoci@gmail.com>
-
- @author Julius Härtl <jus@bitgrid.net>
- @author Greta Doci <gretadoci@gmail.com>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<docs>
## One checkbox

```vue
<template>
<Checkbox
label="some text"
v-model="checkedTarget"/>
</template>
Comment on lines +29 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkedTarget is undefined

Suggested change
<template>
<Checkbox
label="some text"
v-model="checkedTarget"/>
</template>
<template>
<Checkbox
label="some text"
v-model="checkedTarget"/>
</template>
<script>
export default {
data() {
return {
checkedTarget: false
}
},
}
</script>

```
</docs>

<template>
<label>
<input
:id="id"
type="checkbox"
:checked="value"
:disabled="disabled"
@change="onChange">
{{ label }}
</label>
</template>

<script>
import GenRandomId from '../../utils/GenRandomId'
export default {
name: 'Checkbox',
props: {
/**
* id attribute of the checkbox element
*/
id: {
type: String,
default: () => 'checkbox-' + GenRandomId(5),

},
label: {
type: String,
required: true,
},
/**
* value of the checkbox input
*/
value: {
type: Boolean,
default: true,
},
/**
* disabled state of the checkbox element
*/
disabled: {
type: Boolean,
default: false,
},
},
methods: {
onChange(event) {
/**
* Emitted when the checkbox state is changed
* @type {boolean}
*/
this.$emit('update:value', this.$refs.checkbox.checked)
this.$emit('input', this.$refs.checkbox.checked)
/**
* Emitted when the checkbox state is changed
* @type {Event}
*/
this.$emit('change', event)
if (this.$refs.checkbox.checked) {
/**
* Emitted when the checkbox is checked
* @type {Event}
*/
this.$emit('check')
} else {
/**
* Emitted when the checkbox is unchecked
* @type {Event}
*/
this.$emit('uncheck')
}
},
},
}
</script>

<style lang="scss" scoped>
.checkbox {
display: flex;
align-items: flex-start;
width: 100%;
height: auto;
margin: 0;
padding: 0;
cursor: pointer;
white-space: nowrap;
color: var(--color-main-text);
border: 0;
border-radius: 0;
background-color: transparent;
box-shadow: none;
font-weight: normal;
line-height: $clickable-area;

&__checkbox {
position: absolute;
top: auto;
left: -10000px;
overflow: hidden;
width: 1px;
height: 1px;
&:focus + .checkbox__label {
opacity: $opacity_full;
}
}
&__label {
display: flex;
align-items: center; // align checkbox to text
width: 100%;
padding: 0 !important;
padding-right: $icon-margin !important;
opacity: $opacity_normal;
&::before {
margin: 0 14px 0 !important;
}
}
&--disabled {
&,
.checkbox__label {
cursor: pointer;
display: inline-block;
}
}
&:not(.checkbox--disabled):hover,
&:not(.checkbox--disabled):focus {
.checkbox__label {
opacity: $opacity_full;
}
Comment on lines +130 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you lose some code while rebasing or something?
This seems unrelated now?

}
}

</style>
24 changes: 24 additions & 0 deletions src/components/Checkbox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @copyright Copyright (c) 2019 Greta Doci <gretadoci@gmail.com>
*
* @author Greta Doci <gretadoci@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import Checkbox from './Checkbox'

export default Checkbox