Skip to content

Commit

Permalink
Merge branch 'main' into EB-1111-data-test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgoud authored Nov 12, 2023
2 parents e685da6 + c3af2d4 commit fb04eeb
Show file tree
Hide file tree
Showing 17 changed files with 273 additions and 30 deletions.
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'
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type { ExtractPropTypes } from 'vue'
import type TabNavigationTitle from './tab-navigation-title.vue'

export const tabNavigationTitleProps = buildProps({
position: {
type: Number,
required: true,
},
disabled: {
type: Boolean,
required: false,
default: false,
},
position: {
type: Number,
required: true,
},
} as const)

export type TabNavigationTitleProps = ExtractPropTypes<
Expand Down
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
12 changes: 4 additions & 8 deletions packages/theme/src/accordion-group.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
.puik-accordion-group {
.puik-accordion {
@apply mb-4;
}
@apply flex flex-col gap-4 w-full;

&--contained {
@apply gap-0;

.puik-accordion {
@apply mb-0 border-t-0 border-b;
@apply border-t-0;
}

& > .puik-accordion:first-of-type {
@apply border-t;
}

& > .puik-accordion:last-of-type {
@apply border-t-0 border-b;
}
}
}
2 changes: 1 addition & 1 deletion packages/theme/src/accordion.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use './common/typography.scss';

.puik-accordion {
@apply border border-primary-400 mb-4;
@apply border border-primary-400;

&__header {
@apply px-6 py-4 flex w-full items-center;
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;
}
.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';
2 changes: 1 addition & 1 deletion packages/theme/src/tab-navigation-group-titles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.puik-tab-navigation__group-titles {
@apply flex min-h-[48px] overflow-x-auto;
@apply flex flex-col min-h-[48px] sm:flex-row sm:flex-wrap;
}
22 changes: 6 additions & 16 deletions packages/theme/src/tab-navigation-title.scss
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
@use './common/typography.scss';

.puik-tab-navigation__title {
@apply relative min-h-full p-2 flex items-center cursor-pointer puik-body-default-bold;
flex: 0 1 135px;
gap: 8px;
white-space: nowrap;
border-bottom: 1px solid #dce1e3;
@apply relative p-2 flex gap-2 whitespace-nowrap border-b border-b-primary-400 items-center cursor-pointer puik-body-default-bold sm:w-[135px];

&:focus:not(:hover) {
@apply bg-primary-400;
outline: none;
@apply bg-primary-400 outline-none;
}

&:hover {
@apply bg-primary-300;
}

&--selected {
&::before {
@apply bg-black;
content: '';
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 3px;
border-radius: 4px 4px 0 0;
@apply bg-primary content-[''] block absolute bottom-0 left-0 w-full h-[3px] rounded-t-[4px];
}
}
&--disabled {
Expand Down
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

0 comments on commit fb04eeb

Please sign in to comment.