Skip to content

Commit

Permalink
Merge pull request #96 from flowforge/feat-disabled-list-item
Browse files Browse the repository at this point in the history
Add disabled attr to list-items
  • Loading branch information
hardillb authored Nov 14, 2022
2 parents fbd1ad9 + 24bbcd8 commit be48121
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/data/utilities.docs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Utilities",
"id": "utilities",
"description": "A collection of smaller components that can be used in conjuction with, or as child elements, of any of the other components in this library.",
"description": "A collection of smaller components that can be used in conjunction with, or as child elements, of any of the other components in this library.",
"components": [{
"name": "ff-check",
"examples": [{
Expand All @@ -23,6 +23,10 @@
"key": "label",
"default": "",
"description": "A string label to display in the list item."
}, {
"key": "disabled",
"default": "false",
"description": "Should this list item visually disabled"
}]
}]
}
11 changes: 10 additions & 1 deletion src/components/ListItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<li class="ff-list-item" :class="'ff-list-item--' + kind">
<li class="ff-list-item" :class="[className, this.disabled ? 'disabled' : ''] ">
<component :is="icon" />
<label>{{ label }}</label>
</li>
Expand All @@ -20,6 +20,15 @@ export default {
kind: {
type: String,
default: ''
},
disabled: {
type: Boolean,
default: false
}
},
computed: {
className () {
return 'ff-list-item--' + this.kind
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/stylesheets/ff-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ li.ff-list-item {
cursor: pointer;
background-color: $ff-grey-200;
}
&.disabled {
pointer-events: none;

label {
opacity: 0.5;
}
}
}

/*
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/components/ListItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mount } from '@vue/test-utils'
import ListItem from '@/components/ListItem.vue'

describe('ListItem', () => {
it('renders the passed label', async () => {
const wrapper = mount(ListItem, {
props: {
label: 'my list item'
}
})

expect(wrapper.text()).toMatch('my list item')

await wrapper.setProps({ label: 'new label' })

expect(wrapper.text()).toMatch('new label')
})

it('can be visually disabled', async () => {
const wrapper = mount(ListItem, {
props: {
disabled: true
}
})

expect(wrapper.classes('disabled')).toBe(true)

await wrapper.setProps({ disabled: false })

expect(wrapper.classes('disabled')).toBe(false)
})
})

0 comments on commit be48121

Please sign in to comment.