Skip to content

Commit

Permalink
Merge pull request #204 from PrestaShopCorp/feat/chip-component
Browse files Browse the repository at this point in the history
Feat/chip component
  • Loading branch information
mattgoud authored Oct 11, 2023
2 parents 7b79976 + b9d6e84 commit ce06783
Show file tree
Hide file tree
Showing 21 changed files with 1,272 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/components/chip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withInstall } from '@puik/utils'

import Chip from './src/chip.vue'

export const PuikChip = withInstall(Chip)
export default PuikChip

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

export const chipSizeVariants = ['default', 'small'] as const

export type PuikChipSizeVariant = (typeof chipSizeVariants)[number]

export const chipProps = buildProps({
id: {
type: String,
required: true,
default: undefined,
},
content: {
type: String,
required: true,
default: undefined,
},
size: {
type: String,
required: false,
default: 'default',
},
icon: {
type: String,
default: '',
required: false,
},
disabled: {
type: Boolean,
required: false,
default: false,
},
tooltipPosition: {
type: String as PropType<PuikTooltipPosition>,
Required: false,
default: 'bottom',
},
} as const)

export type ChipProps = ExtractPropTypes<typeof chipProps>

export type ChipInstance = InstanceType<typeof Chip>
44 changes: 44 additions & 0 deletions packages/components/chip/src/chip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div
:id="id"
:class="[
`puik-chip puik-chip--${size as PuikChipSizeVariant}`,
{ 'puik-chip--disabled': disabled },
]"
>
<PuikIcon v-if="icon && icon != ''" :icon="icon" class="puik-chip__icon" />
<div class="puik-chip__content">
<puik-tooltip
v-if="content?.length >= 30"
:position="(tooltipPosition as PuikTooltipPosition)"
:description="content"
>
<template #description>{{ content }}</template>
{{ content }}
</puik-tooltip>
{{ content }}
</div>
<PuikIcon
icon="close"
class="puik-chip__close"
@click="disabled ? '' : handleCloseEvent()"
/>
</div>
</template>

<script setup lang="ts">
import { PuikIcon } from '@puik/components/icon'
import { PuikTooltip } from '@puik/components/tooltip'
import { chipProps, type PuikChipSizeVariant } from './chip'
import type { PuikTooltipPosition } from '@puik/components/tooltip'
defineOptions({
name: 'PuikChip',
})
const props = defineProps(chipProps)
const emit = defineEmits(['close'])
const handleCloseEvent = () => {
emit('close')
}
</script>
Loading

0 comments on commit ce06783

Please sign in to comment.