diff --git a/packages/components/divider/index.ts b/packages/components/divider/index.ts new file mode 100644 index 00000000..30fa819e --- /dev/null +++ b/packages/components/divider/index.ts @@ -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' diff --git a/packages/components/divider/src/divider.ts b/packages/components/divider/src/divider.ts new file mode 100644 index 00000000..967a1a8b --- /dev/null +++ b/packages/components/divider/src/divider.ts @@ -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, + String as PropType, + ], + required: false, + default: PuikDividerOrientation.HORIZONTAL, + }, + dataTest: { + type: String, + required: false, + default: undefined, + }, +} as const) + +export type DividerProps = ExtractPropTypes + +export type DividerInstance = InstanceType diff --git a/packages/components/divider/src/divider.vue b/packages/components/divider/src/divider.vue new file mode 100644 index 00000000..420c711d --- /dev/null +++ b/packages/components/divider/src/divider.vue @@ -0,0 +1,22 @@ + + + diff --git a/packages/components/divider/stories/divider.stories.ts b/packages/components/divider/stories/divider.stories.ts new file mode 100644 index 00000000..ea8a2344 --- /dev/null +++ b/packages/components/divider/stories/divider.stories.ts @@ -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: ``, +}) + +const OrientationTemplate: StoryFn = (args: Args) => ({ + components: { + PuikDivider, + }, + setup() { + return { args } + }, + template: ` +
+ +
+ +
+
+ `, +}) + +const DataTestTemplate: StoryFn = (args: Args) => ({ + components: { + PuikDivider, + }, + setup() { + return { args } + }, + template: ` +
+ +
+ +
+
+ `, +}) + +export const Default = { + render: DefaultTemplate, + args: {}, + parameters: { + docs: { + source: { + code: ` + + + + +
+`, + language: 'html', + }, + }, + }, +} + +export const Orientation = { + render: OrientationTemplate, + args: {}, + parameters: { + docs: { + source: { + code: ` + + + + + + +
+ +
+`, + language: 'html', + }, + }, + }, +} + +export const DataTest = { + render: DataTestTemplate, + args: {}, + parameters: { + docs: { + source: { + code: ` + + + + + +
+ +
+`, + language: 'html', + }, + }, + }, +} diff --git a/packages/components/divider/style/css.ts b/packages/components/divider/style/css.ts new file mode 100644 index 00000000..d2c5dbbc --- /dev/null +++ b/packages/components/divider/style/css.ts @@ -0,0 +1,2 @@ +import '@puik/components/base/style/css' +import '@puik/theme/puik-divider.css' diff --git a/packages/components/divider/style/index.ts b/packages/components/divider/style/index.ts new file mode 100644 index 00000000..891b06e6 --- /dev/null +++ b/packages/components/divider/style/index.ts @@ -0,0 +1,2 @@ +import '@puik/components/base/style' +import '@puik/theme/src/divider.scss' diff --git a/packages/components/divider/test/divider.spec.ts b/packages/components/divider/test/divider.spec.ts new file mode 100644 index 00000000..aa7630c8 --- /dev/null +++ b/packages/components/divider/test/divider.spec.ts @@ -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 + const findDivider = () => wrapper.find('.puik-divider') + const factory = ( + propsData: Record = {}, + options: MountingOptions = {} + ) => { + 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') + }) +}) diff --git a/packages/components/index.ts b/packages/components/index.ts index d0a24516..54dbcd54 100644 --- a/packages/components/index.ts +++ b/packages/components/index.ts @@ -29,3 +29,4 @@ export * from './tab-navigation' export * from './progress-stepper' export * from './chip' export * from './tag' +export * from './divider' diff --git a/packages/puik/component.ts b/packages/puik/component.ts index 4bc52ab5..c79653ca 100644 --- a/packages/puik/component.ts +++ b/packages/puik/component.ts @@ -1,3 +1,4 @@ +import { PuikDivider } from '@puik/components/divider' import { PuikTag } from '@puik/components/tag' import { PuikChip } from '@puik/components/chip' import { @@ -50,6 +51,7 @@ import type { Plugin } from 'vue' // prettier-ignore export default [ + PuikDivider, PuikTag, PuikChip, PuikTabNavigationGroupPanels, diff --git a/packages/theme/src/divider.scss b/packages/theme/src/divider.scss new file mode 100644 index 00000000..26c0fa47 --- /dev/null +++ b/packages/theme/src/divider.scss @@ -0,0 +1,6 @@ +.puik-divider--horizontal { + @apply text-primary-400; +} +.puik-divider--vertical { + @apply bg-primary-400 w-[1px] min-h-full; +} diff --git a/packages/theme/src/index.scss b/packages/theme/src/index.scss index d888a495..35ddfef1 100644 --- a/packages/theme/src/index.scss +++ b/packages/theme/src/index.scss @@ -42,3 +42,4 @@ @use 'progress-stepper-step'; @use 'chip'; @use 'tag'; +@use 'divider'; diff --git a/typings/global.d.ts b/typings/global.d.ts index df474081..e188f5ce 100644 --- a/typings/global.d.ts +++ b/typings/global.d.ts @@ -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']