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

Tab container beheer component #56

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
51 changes: 51 additions & 0 deletions src/__tests__/OeTabContainer.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { defineComponent, type Component } from 'vue';
import OeTabContainer from '@/components/dumb/OeTabContainer.vue';
import type { ITabView } from '@models/tab-container';

describe('TabContainer', () => {
const TestComponent = defineComponent({
components: { OeTabContainer },
setup() {
const tabs: ITabView[] = [
{
id: 'algemeen',
label: 'Algemeen',
component: {} as Component,
},
{
id: 'zone',
label: 'Zone',
component: {} as Component,
},
];

return { tabs };
},
template: `
<oe-tab-container :tabs="tabs">
<template #default="{ activeTab }">
<h2>Tab {{ activeTab.label }}</h2>
</template>
</oe-tab-container>
`,
});

beforeEach(() => {
cy.mount(TestComponent);
});

it('renders a tab container', () => {
cy.dataCy('tab-container').should('exist').should('have.class', 'tab-container');
});

it('renders a tab for each given tab', () => {
cy.mount(TestComponent).then(({ component }) => {
cy.dataCy('top-tabs')
.children()
.should('have.length', 2)
.each((tab, index) => {
expect(tab.text()).to.equal(`${component.tabs[index].label}`);
});
});
});
});
78 changes: 78 additions & 0 deletions src/components/dumb/OeTabContainer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<div class="tab-container" data-cy="tab-container">
<div class="top-tabs" data-cy="top-tabs">
<a
v-for="item in props.tabs"
:key="item.id"
:data-cy="`top-tabs-${item.id}`"
class="top-tabs__item"
:class="{
active: item === activeTab,
}"
@click="select(item)"
>
<span class="top-tabs__item__name">{{ item.label }}</span>
</a>
</div>
<div data-cy="tab-content" class="tab-container__content">
<slot :active-tab="activeTab"></slot>
</div>
</div>
</template>

<script setup lang="ts">
import { shallowRef } from 'vue';
import type { ITabView, ITabContainerProps } from '@models/tab-container';

const props = withDefaults(defineProps<ITabContainerProps>(), {
tabs: () => [],
});

const activeTab = shallowRef(props.tabs[0]);

const select = (item: ITabView) => {
activeTab.value = item;
};
</script>

<style lang="scss">
@import 'pyoes/scss/pyoes-settings';

.tab-container {
background-color: $white;
margin: 20px 20px 10px 20px;

&__content {
display: flex;
padding: 0.9375rem;
height: 100%;
overflow-y: auto;
}

.top-tabs {
display: flex;
justify-content: center;
max-width: 100%;
padding: 0 0.9375rem;

a.top-tabs__item {
margin-left: 3px;
background-color: $primary-color;
color: $white;
font-family: 'Flanders Art Sans', Arial, sans-serif;
padding: 0.75rem 1.5rem;
font-size: 0.875em;
cursor: pointer;
text-decoration: none;

&:hover {
background-color: $dark-purple;
}

&.active {
background-color: $very-dark-purple;
}
}
}
}
</style>
2 changes: 2 additions & 0 deletions src/components/dumb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import OeContainer from './OeContainer.vue';
import OeGrid from './OeGrid.vue';
import OeHeader from './OeHeader.vue';
import OeLoader from './OeLoader.vue';
import OeTabContainer from './OeTabContainer.vue';
import OeWizard from './OeWizard.vue';
import SystemFields from './SystemFields.vue';

Expand All @@ -26,6 +27,7 @@ export {
OeGrid,
OeHeader,
OeLoader,
OeTabContainer,
OeWizard,
SystemFields,
};
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './system-fields';
export * from './grid';
export * from './wizard';
export * from './input-phone';
export * from './tab-container';
11 changes: 11 additions & 0 deletions src/models/tab-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Component } from 'vue';

export interface ITabView {
id: string;
label: string;
component: Component;
}

export interface ITabContainerProps {
tabs: ITabView[];
}
69 changes: 69 additions & 0 deletions src/stories/dumb-components/tab-container.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { Meta, StoryObj } from '@storybook/vue3';
import OeTabContainer from '../../components/dumb/OeTabContainer.vue';
import type { ITabView } from '../../models/tab-container';
import type { Component } from 'vue';

import '@/scss/main.scss';

// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
const meta: Meta<typeof OeTabContainer> = {
title: 'Dumb components/TabContainer',
component: OeTabContainer,
parameters: {
layout: 'fullscreen',
},
tags: ['autodocs'],
argTypes: {
tabs: {
description: 'Tabs to show in the container.',
table: {
type: { summary: 'ITabView[]' },
defaultValue: { summary: '[]' },
},
},
default: {
description: 'Slot rendering the tab content.',
table: {
type: {
summary: 'Exposed prop',
detail: 'activeTab: current tab object',
},
},
},
},
};

export default meta;
type Story = StoryObj<typeof OeTabContainer>;

// export const Default: Story = {};
export const Default: Story = {
render: () => ({
components: {
OeTabContainer,
},
setup() {
const tabs: ITabView[] = [
{
id: 'algemeen',
label: 'Algemeen',
component: {} as Component,
},
{
id: 'zone',
label: 'Zone',
component: {} as Component,
},
];

return { tabs };
},
template: `
<oe-tab-container :tabs="tabs">
<template #default="{ activeTab }">
<h2>Tab {{ activeTab.label }}</h2>
</template>
</oe-tab-container>
`,
}),
};