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

Add sizes for tags #1065

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions demo/sections/components/Tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
title="Tags"
:demos="[
{ title: 'Basic' },
{ title: 'Size XS' },
{ title: 'Using Slot' },
{ title: 'Multiple' },
{ title: 'Using p-tag-wrapper' },
Expand All @@ -17,6 +18,14 @@
</div>
</template>

<template #size-xs>
<div class="tags__list">
<p-tag v-for="index in 3" :key="index" size="xs">
{{ index }}
</p-tag>
</div>
</template>

<template #using-slot>
<div class="tags__list">
<p-tag v-for="item in classes" :key="item.name" :class="item.className" class="tag" icon="TagIcon">
Expand Down
23 changes: 17 additions & 6 deletions src/components/Tag/PTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
import { Icon } from '@/types/icon'
import { TagValue, normalize } from '@/types/tag'

const props = defineProps<{
const props = withDefaults(defineProps<{
icon?: Icon,
label?: string,
value?: string | TagValue,
dismissible?: boolean,
}>()
size?: 'xs' | 'sm',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be a little more semantically prescriptive, maybe the terms here would be better suited as 'sm' | 'default'? Or, like buttons, we ended up refactoring to just the default and a bool prop called small.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm like 98.6% sure we'll never add a large for tags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will shoot for consistency. size -> small?: boolean

}>(), { icon: undefined, label: undefined, value: undefined, size: 'sm' })

const emits = defineEmits<{
(event: 'dismiss', value: TagValue): void,
Expand All @@ -41,6 +42,7 @@
const classes = computed(() => ({
root: {
'p-tag--dismissible': props.dismissible,
[`p-tag--${props.size}`]: true,
},
}))
</script>
Expand All @@ -50,10 +52,7 @@
gap-1
inline-flex
items-center
rounded-default
px-2.5
py-0.5
text-sm;
rounded-default;
background-color: var(--p-color-tag-bg);
border-color: var(--p-color-tag-border);
color: var(--p-color-tag-text);
Expand All @@ -66,4 +65,16 @@
.p-tag__dismiss {
color: var(--p-color-tag-text);
}

.p-tag--sm { @apply
text-sm
px-2.5
py-0.5
}

.p-tag--xs { @apply
text-xs
px-1.5
py-0.5
}
</style>
4 changes: 3 additions & 1 deletion src/components/Tags/PTags.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="p-tags">
<PTag v-for="tag in tags" :key="tag.label">
<PTag v-for="tag in tags" :key="tag.label" :dismissible="dismissible" :size="size">
<slot :tag="tag">
{{ tag.label }}
</slot>
Expand All @@ -15,6 +15,8 @@

const props = defineProps<{
tags: (string | TagValue)[],
dismissible?: boolean,
size?: 'xs' | 'sm',
}>()

const tags = computed(() => props.tags.map(normalize))
Expand Down
Loading