Skip to content

Commit

Permalink
fix(action bar): adds slots for title and description
Browse files Browse the repository at this point in the history
  • Loading branch information
suwarno-ong committed Mar 20, 2019
1 parent 8f2b280 commit 4bdbf1c
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 30 deletions.
File renamed without changes.
26 changes: 26 additions & 0 deletions docs/src/pages/Action Bar/1-title-slot.vue
@@ -0,0 +1,26 @@
<title>Action bar with title and description as slots.</title>

<template>
<FdActionBar title="Page Title" description="Action bar Description">
<template #title>
<FdIdentifier size="s" circle thumbnail url="/images/headshot-male.jpg" />
<span class="name">Matthew Spark</span>
</template>
<template #description>
<FdBadge pill type="success">UI/UX</FdBadge>
<FdBadge pill type="success">Developer</FdBadge>
<FdBadge pill type="success">VIP</FdBadge>
<FdBadge pill type="success">Star</FdBadge>
</template>
<FdButton slot="back" styling="light" compact icon="nav-back" />
</FdActionBar>
</template>

<style scoped>
.name {
margin-left: 5px;
}
.fd-badge {
margin-right: 3px;
}
</style>
17 changes: 13 additions & 4 deletions ui/src/components/ActionBar/ActionBar.vue
Expand Up @@ -4,9 +4,15 @@
<slot name="back" />
</div>
<div class="fd-action-bar__header">
<h1 class="fd-action-bar__title">{{ title }}</h1>
<p v-if="description != null" class="fd-action-bar__description">
{{ description }}
<h1 class="fd-action-bar__title">
<slot name="title">
{{ title }}
</slot>
</h1>
<p v-if="hasDescription" class="fd-action-bar__description">
<slot name="description">
{{ description }}
</slot>
</p>
</div>
<div v-if="hasActions" class="fd-action-bar__actions">
Expand All @@ -20,10 +26,13 @@ import Vue from "vue";
export default Vue.extend({
name: "FdActionBar",
props: {
title: { type: String, required: true },
title: { type: String, required: false },
description: { type: String, default: null }
},
computed: {
hasDescription(): boolean {
return this.$slots.description != null || this.description != null;
},
hasActions(): boolean {
return this.$slots.default != null;
},
Expand Down
94 changes: 80 additions & 14 deletions ui/src/components/ActionBar/__tests__/ActionBar.test.ts
@@ -1,32 +1,98 @@
import { mount } from "@vue/test-utils";
import { CreateElement, VNode } from "vue";
import { shallowMount } from "@vue/test-utils";
import ActionBar from "../ActionBar.vue";

describe("ActionBar", () => {
const title = "Page Title";
const description = "Action bar description";
const back = "Back";
const actions = "Actions";

const wrapper = shallowMount(ActionBar, {
propsData: {
title,
description
},
slots: {
back,
default: actions
}
});

it("renders correctly", () => {
const wrapper = mount(ActionBar, {
expect(wrapper.element).toMatchSnapshot();
});

it("renders correct props and slots", () => {
expect(wrapper.find(".fd-action-bar__title").text()).toEqual(title);
expect(wrapper.find(".fd-action-bar__description").text()).toEqual(
description
);
expect(wrapper.find(".fd-action-bar__back").text()).toEqual(back);
expect(wrapper.find(".fd-action-bar__actions").text()).toEqual(actions);
});

describe("Without description", () => {
const wrapper = shallowMount(ActionBar, {
propsData: {
title: "Page Title",
description: "Action bar descrtiption"
title: "Page Title"
},
slots: {
back: "Back",
default: "Actions"
}
});
expect(wrapper.element).toMatchSnapshot();

it("renders correctly", () => {
expect(wrapper.element).toMatchSnapshot();
});

it("does not have description", () => {
expect(wrapper.contains(".fd-action-bar__description")).toBe(false);
});
});

it("renders without description", () => {
const wrapper = mount(ActionBar, {
propsData: {
title: "Page Title"
},
describe("Title as slot", () => {
const title = "Page Title (slot)";
const wrapper = shallowMount(ActionBar, {
slots: {
back: "Back",
default: "Actions"
title: {
render(h: CreateElement): VNode {
return h("div", {}, title);
}
}
}
});
expect(wrapper.element).toMatchSnapshot();
expect(wrapper.find(".fd-action-bar__description").exists()).toBe(false);

it("renders correctly", () => {
expect(wrapper.element).toMatchSnapshot();
});

it("renders title as slot", () => {
expect(wrapper.find(".fd-action-bar__title div").text()).toBe(title);
});
});

describe("Description as slot", () => {
const description = "Page Description (slot)";
const wrapper = shallowMount(ActionBar, {
slots: {
description: {
render(h: CreateElement): VNode {
return h("div", {}, description);
}
}
}
});

it("renders correctly", () => {
expect(wrapper.element).toMatchSnapshot();
});

it("renders title as slot", () => {
expect(wrapper.find(".fd-action-bar__description div").text()).toBe(
description
);
});
});
});
@@ -1,31 +1,81 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ActionBar renders correctly 1`] = `
exports[`ActionBar Description as slot renders correctly 1`] = `
<div
class="fd-action-bar"
>
<!---->
<div
class="fd-action-bar__back"
class="fd-action-bar__header"
>
Back
<h1
class="fd-action-bar__title"
>
</h1>
<p
class="fd-action-bar__description"
>
<div>
Page Description (slot)
</div>
</p>
</div>
<!---->
</div>
`;

exports[`ActionBar Title as slot renders correctly 1`] = `
<div
class="fd-action-bar"
>
<!---->
<div
class="fd-action-bar__header"
>
<h1
class="fd-action-bar__title"
>
Page Title
<div>
Page Title (slot)
</div>
</h1>
<p
class="fd-action-bar__description"
<!---->
</div>
<!---->
</div>
`;

exports[`ActionBar Without description renders correctly 1`] = `
<div
class="fd-action-bar"
>
<div
class="fd-action-bar__back"
>
Back
</div>
<div
class="fd-action-bar__header"
>
<h1
class="fd-action-bar__title"
>
Action bar descrtiption
</p>
Page Title
</h1>
<!---->
</div>
<div
Expand All @@ -36,7 +86,7 @@ exports[`ActionBar renders correctly 1`] = `
</div>
`;

exports[`ActionBar renders without description 1`] = `
exports[`ActionBar renders correctly 1`] = `
<div
class="fd-action-bar"
>
Expand All @@ -52,10 +102,18 @@ exports[`ActionBar renders without description 1`] = `
<h1
class="fd-action-bar__title"
>
Page Title
Page Title
</h1>
<!---->
<p
class="fd-action-bar__description"
>
Action bar description
</p>
</div>
<div
Expand Down

0 comments on commit 4bdbf1c

Please sign in to comment.