Skip to content

Commit

Permalink
feat(VChip): add base-color prop (#20702)
Browse files Browse the repository at this point in the history
resolves #19678
  • Loading branch information
J-Sek authored Dec 2, 2024
1 parent d25b988 commit 1e099f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VChipGroup.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"props": {
"baseColor": "Sets the color of component when not focused. Recommended with `color` or `filter` to properly highlight selected items.",
"centerActive": "Forces the selected chip to be centered.",
"column": "Remove horizontal pagination and wrap items as needed.",
"filter": "Applies an checkmark icon in front of every chip for using it like a filter.",
Expand Down
16 changes: 12 additions & 4 deletions packages/vuetify/src/components/VChip/VChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const makeVChipProps = propsFactory({
activeClass: String,
appendAvatar: String,
appendIcon: IconValue,
baseColor: String,
closable: Boolean,
closeIcon: {
type: IconValue,
Expand Down Expand Up @@ -122,7 +123,6 @@ export const VChip = genericComponent<VChipSlots>()({
setup (props, { attrs, emit, slots }) {
const { t } = useLocale()
const { borderClasses } = useBorder(props)
const { colorClasses, colorStyles, variantClasses } = useVariant(props)
const { densityClasses } = useDensity(props)
const { elevationClasses } = useElevation(props)
const { roundedClasses } = useRounded(props)
Expand Down Expand Up @@ -150,6 +150,15 @@ export const VChip = genericComponent<VChipSlots>()({
},
}))

const variantProps = computed(() => {
const showColor = !group || group.isSelected.value
return ({
color: showColor ? props.color ?? props.baseColor : props.baseColor,
variant: props.variant,
})
})
const { colorClasses, colorStyles, variantClasses } = useVariant(variantProps)

function onClick (e: MouseEvent) {
emit('click', e)

Expand All @@ -174,7 +183,6 @@ export const VChip = genericComponent<VChipSlots>()({
const hasFilter = !!(slots.filter || props.filter) && group
const hasPrependMedia = !!(props.prependIcon || props.prependAvatar)
const hasPrepend = !!(hasPrependMedia || slots.prepend)
const hasColor = !group || group.isSelected.value

return isActive.value && (
<Tag
Expand All @@ -189,7 +197,7 @@ export const VChip = genericComponent<VChipSlots>()({
},
themeClasses.value,
borderClasses.value,
hasColor ? colorClasses.value : undefined,
colorClasses.value,
densityClasses.value,
elevationClasses.value,
roundedClasses.value,
Expand All @@ -199,7 +207,7 @@ export const VChip = genericComponent<VChipSlots>()({
props.class,
]}
style={[
hasColor ? colorStyles.value : undefined,
colorStyles.value,
props.style,
]}
disabled={ props.disabled || undefined }
Expand Down
2 changes: 2 additions & 0 deletions packages/vuetify/src/components/VChipGroup/VChipGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { GenericProps } from '@/util'
export const VChipGroupSymbol = Symbol.for('vuetify:v-chip-group')

export const makeVChipGroupProps = propsFactory({
baseColor: String,
column: Boolean,
filter: Boolean,
valueComparator: {
Expand Down Expand Up @@ -69,6 +70,7 @@ export const VChipGroup = genericComponent<new <T>(

provideDefaults({
VChip: {
baseColor: toRef(props, 'baseColor'),
color: toRef(props, 'color'),
disabled: toRef(props, 'disabled'),
filter: toRef(props, 'filter'),
Expand Down

0 comments on commit 1e099f2

Please sign in to comment.