import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode, Fragment as _Fragment } from "vue"; // Styles import "./VListItem.css"; // Components import { VListItemSubtitle } from "./VListItemSubtitle.mjs"; import { VListItemTitle } from "./VListItemTitle.mjs"; import { VAvatar } from "../VAvatar/index.mjs"; import { VDefaultsProvider } from "../VDefaultsProvider/index.mjs"; import { VIcon } from "../VIcon/index.mjs"; // Composables import { useList } from "./list.mjs"; import { makeBorderProps, useBorder } from "../../composables/border.mjs"; import { makeComponentProps } from "../../composables/component.mjs"; import { makeDensityProps, useDensity } from "../../composables/density.mjs"; import { makeDimensionProps, useDimension } from "../../composables/dimensions.mjs"; import { makeElevationProps, useElevation } from "../../composables/elevation.mjs"; import { IconValue } from "../../composables/icons.mjs"; import { useNestedItem } from "../../composables/nested/nested.mjs"; import { makeRoundedProps, useRounded } from "../../composables/rounded.mjs"; import { makeRouterProps, useLink } from "../../composables/router.mjs"; import { makeTagProps } from "../../composables/tag.mjs"; import { makeThemeProps, provideTheme } from "../../composables/theme.mjs"; import { genOverlays, makeVariantProps, useVariant } from "../../composables/variant.mjs"; // Directives import { Ripple } from "../../directives/ripple/index.mjs"; // Utilities import { computed, watch } from 'vue'; import { deprecate, EventProp, genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types export const makeVListItemProps = propsFactory({ active: { type: Boolean, default: undefined }, activeClass: String, /* @deprecated */ activeColor: String, appendAvatar: String, appendIcon: IconValue, baseColor: String, disabled: Boolean, lines: String, link: { type: Boolean, default: undefined }, nav: Boolean, prependAvatar: String, prependIcon: IconValue, ripple: { type: [Boolean, Object], default: true }, subtitle: [String, Number, Boolean], title: [String, Number, Boolean], value: null, onClick: EventProp(), onClickOnce: EventProp(), ...makeBorderProps(), ...makeComponentProps(), ...makeDensityProps(), ...makeDimensionProps(), ...makeElevationProps(), ...makeRoundedProps(), ...makeRouterProps(), ...makeTagProps(), ...makeThemeProps(), ...makeVariantProps({ variant: 'text' }) }, 'VListItem'); export const VListItem = genericComponent()({ name: 'VListItem', directives: { Ripple }, props: makeVListItemProps(), emits: { click: e => true }, setup(props, _ref) { let { attrs, slots, emit } = _ref; const link = useLink(props, attrs); const id = computed(() => props.value === undefined ? link.href.value : props.value); const { select, isSelected, isIndeterminate, isGroupActivator, root, parent, openOnSelect } = useNestedItem(id, false); const list = useList(); const isActive = computed(() => props.active !== false && (props.active || link.isActive?.value || isSelected.value)); const isLink = computed(() => props.link !== false && link.isLink.value); const isClickable = computed(() => !props.disabled && props.link !== false && (props.link || link.isClickable.value || props.value != null && !!list)); const roundedProps = computed(() => props.rounded || props.nav); const color = computed(() => props.color ?? props.activeColor); const variantProps = computed(() => ({ color: isActive.value ? color.value ?? props.baseColor : props.baseColor, variant: props.variant })); watch(() => link.isActive?.value, val => { if (val && parent.value != null) { root.open(parent.value, true); } if (val) { openOnSelect(val); } }, { immediate: true }); const { themeClasses } = provideTheme(props); const { borderClasses } = useBorder(props); const { colorClasses, colorStyles, variantClasses } = useVariant(variantProps); const { densityClasses } = useDensity(props); const { dimensionStyles } = useDimension(props); const { elevationClasses } = useElevation(props); const { roundedClasses } = useRounded(roundedProps); const lineClasses = computed(() => props.lines ? `v-list-item--${props.lines}-line` : undefined); const slotProps = computed(() => ({ isActive: isActive.value, select, isSelected: isSelected.value, isIndeterminate: isIndeterminate.value })); function onClick(e) { emit('click', e); if (isGroupActivator || !isClickable.value) return; link.navigate?.(e); props.value != null && select(!isSelected.value, e); } function onKeyDown(e) { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick(e); } } useRender(() => { const Tag = isLink.value ? 'a' : props.tag; const hasTitle = slots.title || props.title; const hasSubtitle = slots.subtitle || props.subtitle; const hasAppendMedia = !!(props.appendAvatar || props.appendIcon); const hasAppend = !!(hasAppendMedia || slots.append); const hasPrependMedia = !!(props.prependAvatar || props.prependIcon); const hasPrepend = !!(hasPrependMedia || slots.prepend); list?.updateHasPrepend(hasPrepend); if (props.activeColor) { deprecate('active-color', ['color', 'base-color']); } return _withDirectives(_createVNode(Tag, { "class": ['v-list-item', { 'v-list-item--active': isActive.value, 'v-list-item--disabled': props.disabled, 'v-list-item--link': isClickable.value, 'v-list-item--nav': props.nav, 'v-list-item--prepend': !hasPrepend && list?.hasPrepend.value, [`${props.activeClass}`]: props.activeClass && isActive.value }, themeClasses.value, borderClasses.value, colorClasses.value, densityClasses.value, elevationClasses.value, lineClasses.value, roundedClasses.value, variantClasses.value, props.class], "style": [colorStyles.value, dimensionStyles.value, props.style], "href": link.href.value, "tabindex": isClickable.value ? list ? -2 : 0 : undefined, "onClick": onClick, "onKeydown": isClickable.value && !isLink.value && onKeyDown }, { default: () => [genOverlays(isClickable.value || isActive.value, 'v-list-item'), hasPrepend && _createVNode("div", { "key": "prepend", "class": "v-list-item__prepend" }, [!slots.prepend ? _createVNode(_Fragment, null, [props.prependAvatar && _createVNode(VAvatar, { "key": "prepend-avatar", "density": props.density, "image": props.prependAvatar }, null), props.prependIcon && _createVNode(VIcon, { "key": "prepend-icon", "density": props.density, "icon": props.prependIcon }, null)]) : _createVNode(VDefaultsProvider, { "key": "prepend-defaults", "disabled": !hasPrependMedia, "defaults": { VAvatar: { density: props.density, image: props.prependAvatar }, VIcon: { density: props.density, icon: props.prependIcon }, VListItemAction: { start: true } } }, { default: () => [slots.prepend?.(slotProps.value)] })]), _createVNode("div", { "class": "v-list-item__content", "data-no-activator": "" }, [hasTitle && _createVNode(VListItemTitle, { "key": "title" }, { default: () => [slots.title?.({ title: props.title }) ?? props.title] }), hasSubtitle && _createVNode(VListItemSubtitle, { "key": "subtitle" }, { default: () => [slots.subtitle?.({ subtitle: props.subtitle }) ?? props.subtitle] }), slots.default?.(slotProps.value)]), hasAppend && _createVNode("div", { "key": "append", "class": "v-list-item__append" }, [!slots.append ? _createVNode(_Fragment, null, [props.appendIcon && _createVNode(VIcon, { "key": "append-icon", "density": props.density, "icon": props.appendIcon }, null), props.appendAvatar && _createVNode(VAvatar, { "key": "append-avatar", "density": props.density, "image": props.appendAvatar }, null)]) : _createVNode(VDefaultsProvider, { "key": "append-defaults", "disabled": !hasAppendMedia, "defaults": { VAvatar: { density: props.density, image: props.appendAvatar }, VIcon: { density: props.density, icon: props.appendIcon }, VListItemAction: { end: true } } }, { default: () => [slots.append?.(slotProps.value)] })])] }), [[_resolveDirective("ripple"), isClickable.value && props.ripple]]); }); return {}; } }); //# sourceMappingURL=VListItem.mjs.map