From 2f9c253b97ecbc9813c97757ab5ecdc9b2d74596 Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Thu, 19 Oct 2023 18:24:53 +0200 Subject: [PATCH 01/16] feat: create avatar component (wip) --- packages/components/avatar/index.ts | 8 ++ packages/components/avatar/src/avatar.ts | 78 ++++++++++++++++++ packages/components/avatar/src/avatar.vue | 45 +++++++++++ .../avatar/stories/avatar.stories.ts | 34 ++++++++ packages/components/avatar/style/css.ts | 2 + packages/components/avatar/style/index.ts | 2 + .../components/avatar/test/avatar.spec.ts | 23 ++++++ packages/components/index.ts | 1 + packages/puik/component.ts | 2 + packages/theme/src/avatar.scss | 80 +++++++++++++++++++ packages/theme/src/index.scss | 1 + typings/global.d.ts | 1 + 12 files changed, 277 insertions(+) create mode 100644 packages/components/avatar/index.ts create mode 100644 packages/components/avatar/src/avatar.ts create mode 100644 packages/components/avatar/src/avatar.vue create mode 100644 packages/components/avatar/stories/avatar.stories.ts create mode 100644 packages/components/avatar/style/css.ts create mode 100644 packages/components/avatar/style/index.ts create mode 100644 packages/components/avatar/test/avatar.spec.ts create mode 100644 packages/theme/src/avatar.scss diff --git a/packages/components/avatar/index.ts b/packages/components/avatar/index.ts new file mode 100644 index 00000000..8e96fb3c --- /dev/null +++ b/packages/components/avatar/index.ts @@ -0,0 +1,8 @@ +import { withInstall } from '@puik/utils' + +import Avatar from './src/avatar.vue' + +export const PuikAvatar = withInstall(Avatar) +export default PuikAvatar + +export * from './src/avatar' diff --git a/packages/components/avatar/src/avatar.ts b/packages/components/avatar/src/avatar.ts new file mode 100644 index 00000000..a7e77338 --- /dev/null +++ b/packages/components/avatar/src/avatar.ts @@ -0,0 +1,78 @@ +import { buildProps } from '@puik/utils' +import type { ExtractPropTypes, PropType } from 'vue' +import type Avatar from './avatar.vue' + +export const avatarColorVariants = [ + 'neutral', + 'blue', + 'yellow', + 'green', + 'purple', +] as const +export type PuikAvatarBgColor = (typeof avatarColorVariants)[number] + +export const avatarModes = ['primary', 'reverse'] as const +export type PuikAvatarMode = (typeof avatarModes)[number] + +export const avatarSizes = ['small', 'medium', 'large', 'jumbo'] as const +export type PuikAvatarSize = (typeof avatarSizes)[number] + +export const avatarTypes = ['photo', 'icon', 'initials'] as const +export type PuikAvatarType = (typeof avatarTypes)[number] + +export const avatarProps = buildProps({ + id: { + type: String, + required: false, + default: undefined, + }, + colorVariant: { + type: String as PropType, + required: false, + default: 'neutral', + }, + size: { + type: String as PropType, + required: false, + default: 'medium', + }, + type: { + type: String as PropType, + required: false, + default: 'initials', + }, + mode: { + type: String as PropType, + required: false, + default: 'primary', + }, + src: { + type: String, + required: false, + default: '', + }, + alt: { + type: String, + required: false, + default: '', + }, + icon: { + type: String, + required: false, + default: '', + }, + firstname: { + type: String, + required: false, + default: '', + }, + lastname: { + type: String, + required: false, + default: '', + }, +} as const) + +export type AvatarProps = ExtractPropTypes + +export type AvatarInstance = InstanceType diff --git a/packages/components/avatar/src/avatar.vue b/packages/components/avatar/src/avatar.vue new file mode 100644 index 00000000..2aab2c8b --- /dev/null +++ b/packages/components/avatar/src/avatar.vue @@ -0,0 +1,45 @@ + + + diff --git a/packages/components/avatar/stories/avatar.stories.ts b/packages/components/avatar/stories/avatar.stories.ts new file mode 100644 index 00000000..92ee5478 --- /dev/null +++ b/packages/components/avatar/stories/avatar.stories.ts @@ -0,0 +1,34 @@ +import PuikAvatar from './../src/avatar.vue' +import type { Meta, StoryFn, Args } from '@storybook/vue3' + +export default { + title: 'Components/Avatar', + component: PuikAvatar, +} as Meta + +const Template: StoryFn = (args: Args) => ({ + components: { + PuikAvatar, + }, + setup() { + return { args } + }, + template: ``, +}) + +export const Default = { + render: Template, + args: {}, + parameters: { + docs: { + source: { + code: ` + + + + `, + language: 'html', + }, + }, + }, +} diff --git a/packages/components/avatar/style/css.ts b/packages/components/avatar/style/css.ts new file mode 100644 index 00000000..baf5bacb --- /dev/null +++ b/packages/components/avatar/style/css.ts @@ -0,0 +1,2 @@ +import '@puik/components/base/style/css' +import '@puik/theme/puik-avatar.css' diff --git a/packages/components/avatar/style/index.ts b/packages/components/avatar/style/index.ts new file mode 100644 index 00000000..22f633c6 --- /dev/null +++ b/packages/components/avatar/style/index.ts @@ -0,0 +1,2 @@ +import '@puik/components/base/style' +import '@puik/theme/src/avatar.scss' diff --git a/packages/components/avatar/test/avatar.spec.ts b/packages/components/avatar/test/avatar.spec.ts new file mode 100644 index 00000000..099d67e0 --- /dev/null +++ b/packages/components/avatar/test/avatar.spec.ts @@ -0,0 +1,23 @@ +import { mount } from '@vue/test-utils' +import { describe, it, expect } from 'vitest' +import PuikAvatar from '../src/avatar.vue' +import type { MountingOptions, VueWrapper } from '@vue/test-utils' + +describe('Avatar tests', () => { + let wrapper: VueWrapper + const factory = ( + propsData: Record = {}, + options: MountingOptions = {} + ) => { + wrapper = mount(PuikAvatar, { + props: { + ...propsData, + }, + ...options, + }) + } + it('should be a vue instance', () => { + factory() + expect(wrapper).toBeTruthy() + }) +}) diff --git a/packages/components/index.ts b/packages/components/index.ts index d0a24516..1e283aff 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 './avatar' diff --git a/packages/puik/component.ts b/packages/puik/component.ts index 4bc52ab5..8e556d5b 100644 --- a/packages/puik/component.ts +++ b/packages/puik/component.ts @@ -1,3 +1,4 @@ +import { PuikAvatar } from '@puik/components/avatar' 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 [ + PuikAvatar, PuikTag, PuikChip, PuikTabNavigationGroupPanels, diff --git a/packages/theme/src/avatar.scss b/packages/theme/src/avatar.scss new file mode 100644 index 00000000..8cf32458 --- /dev/null +++ b/packages/theme/src/avatar.scss @@ -0,0 +1,80 @@ +@use './common/typography.scss'; + +.puik-avatar { + @apply flex justify-center items-center rounded-full overflow-hidden; +} +.puik-avatar--small { + @apply w-6 h-6; +} +.puik-avatar--medium { + @apply w-8 h-8; +} +.puik-avatar--large { + @apply w-12 h-12; +} +.puik-avatar--jumbo { + @apply w-14 h-14; +} +.puik-avatar--primary { + @apply border border-transparent; + .puik-avatar_initials { + @apply text-white; + } +} +.puik-avatar--reverse { + @apply border border-primary-300; + .puik-avatar_initials { + @apply text-primary-800; + } +} +.puik-avatar--photo { + @apply border-none; + img { + object-fit: cover; + } +} +.puik-avatar--neutral { + @apply bg-primary-800; +} +.puik-avatar--blue { + @apply bg-ocean-blue; +} +.puik-avatar--yellow { + @apply bg-amber; +} +.puik-avatar--green { + @apply bg-green-400; +} +.puik-avatar--purple { + @apply bg-purple; +} +.puik-avatar--reverse.puik-avatar--neutral { + @apply bg-white; +} +.puik-avatar--reverse.puik-avatar--blue { + @apply bg-ocean-blue-50; +} +.puik-avatar--reverse.puik-avatar--yellow { + @apply bg-amber-100; +} +.puik-avatar--reverse.puik-avatar--green { + @apply bg-green-50; +} +.puik-avatar--reverse.puik-avatar--purple { + @apply bg-purple-50; +} +.puik-avatar_initials { + @apply font-bold; + &--small { + @apply text-xs/none; + } + &--medium { + @apply text-sm/none; + } + &--large { + @apply text-base/none; + } + &--jumbo { + @apply text-2xl/none; + } +} diff --git a/packages/theme/src/index.scss b/packages/theme/src/index.scss index d888a495..81d1eb8c 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 'avatar'; diff --git a/typings/global.d.ts b/typings/global.d.ts index df474081..c403a209 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 { + PuikAvatar: typeof import('@prestashopcorp/puik')['PuikAvatar'] PuikTag: typeof import('@prestashopcorp/puik')['PuikTag'] PuikTabNavigationGroupPanels: typeof import('@prestashopcorp/puik')['PuikTabNavigationGroupPanels'] PuikTabNavigationTitle: typeof import('@prestashopcorp/puik')['PuikTabNavigationTitle'] From 77ab4da25fe202ba6a4ab426257882e91a5a012f Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Fri, 20 Oct 2023 17:59:37 +0200 Subject: [PATCH 02/16] docs: storybook docs (wip) --- packages/components/avatar/src/avatar.ts | 22 +- packages/components/avatar/src/avatar.vue | 2 +- .../avatar/stories/avatar.stories.ts | 286 +++++++++++++++++- 3 files changed, 292 insertions(+), 18 deletions(-) diff --git a/packages/components/avatar/src/avatar.ts b/packages/components/avatar/src/avatar.ts index a7e77338..29b053eb 100644 --- a/packages/components/avatar/src/avatar.ts +++ b/packages/components/avatar/src/avatar.ts @@ -2,14 +2,14 @@ import { buildProps } from '@puik/utils' import type { ExtractPropTypes, PropType } from 'vue' import type Avatar from './avatar.vue' -export const avatarColorVariants = [ +export const avatarColors = [ 'neutral', 'blue', 'yellow', 'green', 'purple', ] as const -export type PuikAvatarBgColor = (typeof avatarColorVariants)[number] +export type PuikAvatarBgColor = (typeof avatarColors)[number] export const avatarModes = ['primary', 'reverse'] as const export type PuikAvatarMode = (typeof avatarModes)[number] @@ -26,11 +26,16 @@ export const avatarProps = buildProps({ required: false, default: undefined, }, - colorVariant: { + color: { type: String as PropType, required: false, default: 'neutral', }, + mode: { + type: String as PropType, + required: false, + default: 'primary', + }, size: { type: String as PropType, required: false, @@ -41,22 +46,17 @@ export const avatarProps = buildProps({ required: false, default: 'initials', }, - mode: { - type: String as PropType, - required: false, - default: 'primary', - }, - src: { + icon: { type: String, required: false, default: '', }, - alt: { + src: { type: String, required: false, default: '', }, - icon: { + alt: { type: String, required: false, default: '', diff --git a/packages/components/avatar/src/avatar.vue b/packages/components/avatar/src/avatar.vue index 2aab2c8b..61fe1b81 100644 --- a/packages/components/avatar/src/avatar.vue +++ b/packages/components/avatar/src/avatar.vue @@ -1,7 +1,7 @@