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

Checkbox update #22

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package-lock.json

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

21 changes: 12 additions & 9 deletions src/components/MewCheckbox/MewCheckbox.vue
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
v-model="isChecked"
/>
<span
@click="onToggle()"
class="titlePrimary--text mr-2 cursor-pointer"
>{{ label }}
<a
@@ -20,11 +19,6 @@
export default {
name: 'MewCheckbox',
data() {
return {
isChecked: false
}
},
props: {
label: {
type: String,
@@ -35,11 +29,20 @@ export default {
default: function() {
return { title: '', url: ''};
}
},
value: {
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm is this suppose to match the prop name isChecked ?

Copy link
Contributor

Choose a reason for hiding this comment

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

oohh i think i get it now

Copy link
Contributor Author

@gamalielhere gamalielhere Sep 14, 2020

Choose a reason for hiding this comment

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

yeah no. so v-model is the same as passing :value="something" @value="something" ie:

  <mew-checkbox v-model="something"></mew-checkbox>
  
  <mew-checkbox :value="something" @input="something = $event"></mew-checkbox>

So it should work the same but when the value changes, the parent can react to it aswell. Only thing is that there's no data object in storybook so I cant use it there at the moment since I cant mutate props.

type: Boolean,
default: false
}
},
methods: {
onToggle() {
this.isChecked = !this.isChecked;
computed: {
isChecked: {
get() {
return this.value;
},
set(val) {
this.$emit('input', val)
}
}
}
}
4 changes: 4 additions & 0 deletions stories/MewCheckbox/MewCheckbox.stories.js
Original file line number Diff line number Diff line change
@@ -30,6 +30,9 @@ export const MEWCheckbox = () => ({
},
link: {
default: object('link', linkObj)
},
isChecked: {
default: boolean('checked?', false)
}
},
watch: {
@@ -43,6 +46,7 @@ export const MEWCheckbox = () => ({
<mew-checkbox
:label="label"
:link="link"
v-model="isChecked"
/>
</div>`
});