Skip to content

Commit

Permalink
feat(VList): add prependSpacer prop
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwu9145 committed Oct 25, 2024
1 parent 8c5a2b9 commit 359a115
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/api-generator/src/locale/en/VList.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"inactive": "If set, the list tile will not be rendered as a link even if it has to/href prop or @click handler.",
"lines": "Designates a **minimum-height** for all children `v-list-item` components. This prop uses [line-clamp](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp) and is not supported in all browsers.",
"link": "Applies `v-list-item` hover styles. Useful when using the item is an _activator_.",
"prependSpacer": "Defines the gap between the prepend element and the element that follows it.",
"nav": "An alternative styling that reduces `v-list-item` width and rounds the corners. Typically used with **[v-navigation-drawer](/components/navigation-drawers)**.",
"subheader": "Removes the top padding from `v-list-subheader` components. When used as a **String**, renders a subheader for you.",
"slim": "Reduces horizontal spacing for badges, icons, tooltips, and avatars within slim list items to create a more compact visual representation.",
Expand Down
13 changes: 11 additions & 2 deletions packages/vuetify/src/components/VList/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { makeThemeProps, provideTheme } from '@/composables/theme'
import { makeVariantProps } from '@/composables/variant'

// Utilities
import { computed, ref, shallowRef, toRef } from 'vue'
import { EventProp, focusChild, genericComponent, getPropertyFromItem, omit, propsFactory, useRender } from '@/util'
import { computed, ref, shallowRef, toRef, watch } from 'vue'
import { convertToUnit, EventProp, focusChild, genericComponent, getPropertyFromItem, omit, propsFactory, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -92,6 +92,7 @@ export const makeVListProps = propsFactory({
type: [Boolean, String] as PropType<'one' | 'two' | 'three' | false>,
default: 'one',
},
prependSpacer: [Number, String],
slim: Boolean,
nav: Boolean,

Expand Down Expand Up @@ -239,6 +240,14 @@ export const VList = genericComponent<new <
}
}

watch([contentRef, () => props.prependSpacer], () => {
if (contentRef.value && props.prependSpacer) {
const width = convertToUnit(props.prependSpacer)

if (width) contentRef.value.style.setProperty('--v-list-prepend-spacer-width', width)
}
}, { immediate: true })

useRender(() => {
return (
<props.tag
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VList/VListItem.sass
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
> .v-icon,
> .v-tooltip
~ .v-list-item__spacer
width: $list-item-icon-margin-start
width: var(--v-list-prepend-spacer-width, $list-item-icon-margin-start)

> .v-avatar ~ .v-list-item__spacer
width: $list-item-avatar-margin-start
Expand Down

0 comments on commit 359a115

Please sign in to comment.