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

Feat/create divider component #229

Merged
merged 12 commits into from
Nov 6, 2023
8 changes: 8 additions & 0 deletions packages/components/divider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withInstall } from '@puik/utils'

import Divider from './src/divider.vue'

export const PuikDivider = withInstall(Divider)
export default PuikDivider

export * from './src/divider'
31 changes: 31 additions & 0 deletions packages/components/divider/src/divider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { buildProps } from '@puik/utils'
import type { ExtractPropTypes, PropType } from 'vue'
import type Divider from './divider.vue'

export enum PuikDividerOrientation {
HORIZONTAL = 'horizontal',
VERTICAL = 'vertical',
}

export const dividerOrientations = ['horizontal', 'vertical'] as const
export type PuikDividerOrientationString = (typeof dividerOrientations)[number]

export const dividerProps = buildProps({
orientation: {
type: [
String as PropType<PuikDividerOrientation>,
String as PropType<PuikDividerOrientationString>,
],
required: false,
default: PuikDividerOrientation.HORIZONTAL,
},
dataTest: {
type: String,
required: false,
default: undefined,
},
} as const)

export type DividerProps = ExtractPropTypes<typeof dividerProps>

export type DividerInstance = InstanceType<typeof Divider>
22 changes: 22 additions & 0 deletions packages/components/divider/src/divider.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<hr
v-if="props.orientation === PuikDividerOrientation.HORIZONTAL"
class="puik-divider puik-divider--horizontal"
:data-test="dataTest"
/>
<div
v-if="props.orientation === PuikDividerOrientation.VERTICAL"
class="puik-divider puik-divider--vertical"
:data-test="dataTest"
></div>
</template>

<script setup lang="ts">
import { dividerProps, PuikDividerOrientation } from './divider'

defineOptions({
name: 'PuikDivider',
})

const props = defineProps(dividerProps)
</script>
147 changes: 147 additions & 0 deletions packages/components/divider/stories/divider.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { dividerOrientations } from '../src/divider'
import PuikDivider from './../src/divider.vue'
import type { Meta, StoryFn, Args } from '@storybook/vue3'

const dividerOrientationsSummary = dividerOrientations.join('|')

export default {
title: 'Components/Divider',
component: PuikDivider,
argTypes: {
orientation: {
description:
'define the horizontal or vertical orientation of the divider component',
control: 'select',
options: dividerOrientations,
table: {
type: {
summary: 'string',
},
defaultValue: {
summary: 'horizontal',
},
},
},
dataTest: {
description: 'set data-test attribute for e2e tests purpose',
control: 'text',
table: {
type: {
summary: 'string',
},
defaultValue: {
summary: 'undefined',
},
},
},
},
args: {},
} as Meta

const DefaultTemplate: StoryFn = (args: Args) => ({
components: {
PuikDivider,
},
setup() {
return { args }
},
template: `<puik-divider v-bind="args"/>`,
})

const OrientationTemplate: StoryFn = (args: Args) => ({
components: {
PuikDivider,
},
setup() {
return { args }
},
template: `
<div style="display: flex; flex-direction: column; gap: 8px;">
<puik-divider orientation="horizontal"/>
<div style="min-height: 96px; display: flex">
<puik-divider orientation="vertical"/>
</div>
</div>
`,
})

const DataTestTemplate: StoryFn = (args: Args) => ({
components: {
PuikDivider,
},
setup() {
return { args }
},
template: `
<div style="display: flex; flex-direction: column; gap: 8px;">
<puik-divider orientation="horizontal" dataTest="test"/>
<div style="min-height: 96px; display: flex">
<puik-divider orientation="vertical" dataTest="test"/>
</div>
</div>
`,
})

export const Default = {
render: DefaultTemplate,
args: {},
parameters: {
docs: {
source: {
code: `
<!-- VueJS Snippet -->
<puik-divider />

<!-- HTML/CSS Snippet -->
<hr class="puik-divider puik-divider--horizontal">
`,
language: 'html',
},
},
},
}

export const Orientation = {
render: OrientationTemplate,
args: {},
parameters: {
docs: {
source: {
code: `
<!-- VueJS Snippet -->
<!-- $orientations: ${dividerOrientationsSummary} -->
<puik-divider orientation="{$size}"/>

<!-- HTML/CSS Snippet -->
<!-- $size = 'horizontal' -->
<hr class="puik-divider puik-divider--horizontal">
<!-- $size = 'vertical' -->
<div class="puik-divider puik-divider--vertical"></div>
`,
language: 'html',
},
},
},
}

export const DataTest = {
render: DataTestTemplate,
args: {},
parameters: {
docs: {
source: {
code: `
<!-- VueJS Snippet -->
<puik-divider orientation="{$size}" data-test="{$test}"/>

<!-- HTML/CSS Snippet -->
<!-- $size = 'horizontal' -->
<hr class="puik-divider puik-divider--horizontal" data-test="horizontal-{$test}">
<!-- $size = 'vertical' -->
<div class="puik-divider puik-divider--vertical" data-test="vertical-{$test}"></div>
`,
language: 'html',
},
},
},
}
2 changes: 2 additions & 0 deletions packages/components/divider/style/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@puik/components/base/style/css'
import '@puik/theme/puik-divider.css'
2 changes: 2 additions & 0 deletions packages/components/divider/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '@puik/components/base/style'
import '@puik/theme/src/divider.scss'
34 changes: 34 additions & 0 deletions packages/components/divider/test/divider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { mount } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
import PuikDivider from '../src/divider.vue'
import type { MountingOptions, VueWrapper } from '@vue/test-utils'

describe('Divider tests', () => {
let wrapper: VueWrapper<any>
const findDivider = () => wrapper.find('.puik-divider')
const factory = (
propsData: Record<string, any> = {},
options: MountingOptions<any> = {}
) => {
wrapper = mount(PuikDivider, {
props: {
...propsData,
},
...options,
})
}
it('should be a vue instance', () => {
factory()
expect(wrapper).toBeTruthy()
})

it('should be a vertical divider', () => {
factory({ orientation: 'vertical' })
expect(findDivider().classes()).toContain('puik-divider--vertical')
})

it('the value of the data-test attribute should be "test"', () => {
factory({ orientation: 'vertical', dataTest: 'test' })
expect(findDivider().attributes('data-test')).toBe('test')
})
})
1 change: 1 addition & 0 deletions packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * from './tab-navigation'
export * from './progress-stepper'
export * from './chip'
export * from './tag'
export * from './divider'
2 changes: 2 additions & 0 deletions packages/puik/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PuikDivider } from '@puik/components/divider'
import { PuikTag } from '@puik/components/tag'
import { PuikChip } from '@puik/components/chip'
import {
Expand Down Expand Up @@ -50,6 +51,7 @@ import type { Plugin } from 'vue'

// prettier-ignore
export default [
PuikDivider,
PuikTag,
PuikChip,
PuikTabNavigationGroupPanels,
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/src/divider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.puik-divider--horizontal {
@apply text-primary-400;
cnavarro-prestashop marked this conversation as resolved.
Show resolved Hide resolved
}
.puik-divider--vertical {
@apply bg-primary-400 w-[1px] min-h-full;
}
1 change: 1 addition & 0 deletions packages/theme/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
@use 'progress-stepper-step';
@use 'chip';
@use 'tag';
@use 'divider';
1 change: 1 addition & 0 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// GlobalComponents for Volar
declare module '@vue/runtime-core' {
export interface GlobalComponents {
PuikDivider: typeof import('@prestashopcorp/puik')['PuikDivider']
PuikTag: typeof import('@prestashopcorp/puik')['PuikTag']
PuikTabNavigationGroupPanels: typeof import('@prestashopcorp/puik')['PuikTabNavigationGroupPanels']
PuikTabNavigationTitle: typeof import('@prestashopcorp/puik')['PuikTabNavigationTitle']
Expand Down
Loading