diff --git a/components/fab/Fab.vue b/components/fab/Fab.vue index bdb43ce45..8eed1f0e2 100644 --- a/components/fab/Fab.vue +++ b/components/fab/Fab.vue @@ -6,7 +6,14 @@ v-bind="$attrs" v-on="$listeners" > - + +
+ +
+ - + +
+ +
+
@@ -52,8 +66,8 @@ export default { data () { return { mdcRipple: undefined, - extended: false, - slotObserver: undefined + slotObserver: undefined, + extended: false } }, computed: { @@ -91,16 +105,21 @@ export default { }, methods: { updateSlot () { + if (this.$slots.icon) { + this.$slots.icon.map(n => { + if (n.elm instanceof Element) n.elm.classList.add('mdc-fab__icon') + }) + } + if (this.$slots.trailingIcon) { + this.$slots.trailingIcon.map(n => { + if (n.elm instanceof Element) n.elm.classList.add('mdc-fab__icon') + }) + } + this.extended = false if (this.$slots.default) { - const defaults = this.$slots.default - let i = 0 - for (; i < defaults.length; i++) { - if (defaults[i].elm instanceof Element && defaults[i].elm.classList.contains('mdc-fab__label')) { - this.extended = true - break - } - } - if (i === defaults.length) this.extended = false // no label found + this.$slots.default.map(n => { + if (n.elm instanceof Element || n.text.trim().length > 0) this.extended = true + }) } }, reInstantiateRipple () { diff --git a/components/fab/FabIcon.vue b/components/fab/FabIcon.vue deleted file mode 100644 index bbaa64aa6..000000000 --- a/components/fab/FabIcon.vue +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/components/fab/FabLabel.vue b/components/fab/FabLabel.vue deleted file mode 100644 index f0b75743a..000000000 --- a/components/fab/FabLabel.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/components/fab/README.md b/components/fab/README.md index 802e371d0..ce6a194c1 100644 --- a/components/fab/README.md +++ b/components/fab/README.md @@ -61,45 +61,6 @@ Developers must position `` as needed within their application’s design ``` -## Fab Icon - -```html -favorite -``` - -or use SVG, Font Awesome or any other icon library you wish. - -```html - - - - -``` - -```html - -``` - -### Props - -| Prop | Type | Default | Description | -|------|------|---------|-------------| -| tag | String | 'span' | specify which tag to render to, can be `span`, `i`, `img`, or `svg` | - -### Slots - -| Slot | Description | -|------|-------------| -| default | icon content | - -## Fab Label - -Applicable only for Extended FAB. A FAB will be automatically extended if includes a FAB label. - -```html -create -``` - ### Slots | Slot | Description | diff --git a/components/fab/__test__/Fab.spec.js b/components/fab/__test__/Fab.spec.js index 19c6f575e..a4ddca5c2 100644 --- a/components/fab/__test__/Fab.spec.js +++ b/components/fab/__test__/Fab.spec.js @@ -1,8 +1,6 @@ import 'mutationobserver-shim' import { mount } from '@vue/test-utils' import Fab from '../Fab.vue' -import FabLabel from '../FabLabel' -import FabIcon from '../FabIcon' describe('Fab', () => { it('should mount', () => { @@ -41,7 +39,7 @@ describe('Fab', () => { it('should render as extended', () => { const wrapper = mount(Fab, { slots: { - default: FabLabel + default: 'create' } }) expect(wrapper).toMatchSnapshot() @@ -68,35 +66,3 @@ describe('Fab', () => { expect(wrapper.vm.$data.mdcRipple).toBeUndefined() }) }) - -describe('Fab Icon', () => { - it('should mount', () => { - const wrapper = mount(FabIcon, {}) - expect(wrapper.isVueInstance()).toBeTruthy() - }) - - it('should render with no prop', () => { - const wrapper = mount(FabIcon, { - slots: { - default: 'favorite' - } - }) - expect(wrapper.isVueInstance()).toBeTruthy() - expect(wrapper).toMatchSnapshot() - expect(wrapper.classes()).toContain('mdc-fab__icon') - }) -}) - -describe('Fab Label', () => { - it('should mount', () => { - const wrapper = mount(FabLabel, {}) - expect(wrapper.isVueInstance()).toBeTruthy() - }) - - it('should render with no prop', () => { - const wrapper = mount(FabLabel, {}) - expect(wrapper.isVueInstance()).toBeTruthy() - expect(wrapper).toMatchSnapshot() - expect(wrapper.classes()).toContain('mdc-fab__label') - }) -}) diff --git a/components/fab/__test__/__snapshots__/Fab.spec.js.snap b/components/fab/__test__/__snapshots__/Fab.spec.js.snap index cb33890d3..8703b62c2 100644 --- a/components/fab/__test__/__snapshots__/Fab.spec.js.snap +++ b/components/fab/__test__/__snapshots__/Fab.spec.js.snap @@ -1,17 +1,32 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Fab Icon should render with no prop 1`] = `favorite`; - -exports[`Fab Label should render with no prop 1`] = ``; - -exports[`Fab should render as absolute right 1`] = ``; - -exports[`Fab should render as exited 1`] = ``; - -exports[`Fab should render as extended 1`] = ``; - -exports[`Fab should render as mini 1`] = ``; - -exports[`Fab should render with no prop 1`] = ``; - -exports[`Fab should render without ripple 1`] = ``; +exports[`Fab should render as absolute right 1`] = ` + +`; + +exports[`Fab should render as exited 1`] = ` + +`; + +exports[`Fab should render as extended 1`] = ` + +`; + +exports[`Fab should render as mini 1`] = ` + +`; + +exports[`Fab should render with no prop 1`] = ` + +`; + +exports[`Fab should render without ripple 1`] = ` + +`; diff --git a/components/fab/index.js b/components/fab/index.js index 1851005d6..437c2ebe7 100644 --- a/components/fab/index.js +++ b/components/fab/index.js @@ -1,6 +1,4 @@ import Fab from './Fab.vue' -import FabLabel from './FabLabel' -import FabIcon from './FabIcon' import './styles.scss' import { initPlugin } from '../' @@ -8,8 +6,6 @@ import { initPlugin } from '../' const plugin = { install (vm) { vm.component('m-fab', Fab) - vm.component('m-fab-label', FabLabel) - vm.component('m-fab-icon', FabIcon) } } export default plugin diff --git a/docs/.vuepress/components/FabDemo.vue b/docs/.vuepress/components/FabDemo.vue index c10a5317c..61063e418 100644 --- a/docs/.vuepress/components/FabDemo.vue +++ b/docs/.vuepress/components/FabDemo.vue @@ -6,9 +6,9 @@ :absoluteRight="checkboxProps[0].value" :exited="checkboxProps[1].value" :ripple="checkboxProps[2].value"> - add - create - add + + {{text}} +