All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.lib.components.VRating.VRating.mjs.map Maven / Gradle / Ivy

{"version":3,"file":"VRating.mjs","names":["VBtn","makeComponentProps","makeDensityProps","IconValue","useLocale","useProxiedModel","makeSizeProps","makeTagProps","makeThemeProps","provideTheme","computed","shallowRef","clamp","createRange","genericComponent","getUid","propsFactory","useRender","makeVRatingProps","name","String","itemAriaLabel","type","default","activeColor","color","clearable","Boolean","disabled","emptyIcon","fullIcon","halfIncrements","hover","length","Number","readonly","modelValue","itemLabels","Array","itemLabelPosition","validator","v","includes","ripple","VRating","props","emits","value","setup","_ref","slots","t","themeClasses","rating","normalizedValue","parseFloat","range","increments","flatMap","hoverIndex","itemState","map","isHovering","isFilled","isHovered","isFullIcon","icon","eventState","onMouseenter","onMouseleave","onClick","undefined","VRatingItem","_ref2","index","showStar","id","replace","btnProps","density","size","variant","_createVNode","_Fragment","item","_mergeProps","createLabel","labelProps","label","_createTextVNode","hasLabels","tag","class","style","i"],"sources":["../../../src/components/VRating/VRating.tsx"],"sourcesContent":["// Styles\nimport './VRating.sass'\n\n// Components\nimport { VBtn } from '@/components/VBtn'\n\n// Composables\nimport { makeComponentProps } from '@/composables/component'\nimport { makeDensityProps } from '@/composables/density'\nimport { IconValue } from '@/composables/icons'\nimport { useLocale } from '@/composables/locale'\nimport { useProxiedModel } from '@/composables/proxiedModel'\nimport { makeSizeProps } from '@/composables/size'\nimport { makeTagProps } from '@/composables/tag'\nimport { makeThemeProps, provideTheme } from '@/composables/theme'\n\n// Utilities\nimport { computed, shallowRef } from 'vue'\nimport { clamp, createRange, genericComponent, getUid, propsFactory, useRender } from '@/util'\n\n// Types\nimport type { Prop } from 'vue'\nimport type { Variant } from '@/composables/variant'\n\ntype VRatingItemSlot = {\n  value: number\n  index: number\n  isFilled: boolean\n  isHovered: boolean\n  icon: IconValue\n  color?: string\n  props: Record\n  rating: number\n}\n\ntype VRatingItemLabelSlot = {\n  value: number\n  index: number\n  label?: string\n}\n\ntype VRatingSlots = {\n  item: VRatingItemSlot\n  'item-label': VRatingItemLabelSlot\n}\n\nexport const makeVRatingProps = propsFactory({\n  name: String,\n  itemAriaLabel: {\n    type: String,\n    default: '$vuetify.rating.ariaLabel.item',\n  },\n  activeColor: String,\n  color: String,\n  clearable: Boolean,\n  disabled: Boolean,\n  emptyIcon: {\n    type: IconValue,\n    default: '$ratingEmpty',\n  },\n  fullIcon: {\n    type: IconValue,\n    default: '$ratingFull',\n  },\n  halfIncrements: Boolean,\n  hover: Boolean,\n  length: {\n    type: [Number, String],\n    default: 5,\n  },\n  readonly: Boolean,\n  modelValue: {\n    type: [Number, String],\n    default: 0,\n  },\n  itemLabels: Array as Prop,\n  itemLabelPosition: {\n    type: String,\n    default: 'top',\n    validator: (v: any) => ['top', 'bottom'].includes(v),\n  },\n  ripple: Boolean,\n\n  ...makeComponentProps(),\n  ...makeDensityProps(),\n  ...makeSizeProps(),\n  ...makeTagProps(),\n  ...makeThemeProps(),\n}, 'VRating')\n\nexport const VRating = genericComponent()({\n  name: 'VRating',\n\n  props: makeVRatingProps(),\n\n  emits: {\n    'update:modelValue': (value: number | string) => true,\n  },\n\n  setup (props, { slots }) {\n    const { t } = useLocale()\n    const { themeClasses } = provideTheme(props)\n    const rating = useProxiedModel(props, 'modelValue')\n    const normalizedValue = computed(() => clamp(parseFloat(rating.value), 0, +props.length))\n\n    const range = computed(() => createRange(Number(props.length), 1))\n    const increments = computed(() => range.value.flatMap(v => props.halfIncrements ? [v - 0.5, v] : [v]))\n    const hoverIndex = shallowRef(-1)\n\n    const itemState = computed(() => increments.value.map(value => {\n      const isHovering = props.hover && hoverIndex.value > -1\n      const isFilled = normalizedValue.value >= value\n      const isHovered = hoverIndex.value >= value\n      const isFullIcon = isHovering ? isHovered : isFilled\n      const icon = isFullIcon ? props.fullIcon : props.emptyIcon\n      const activeColor = props.activeColor ?? props.color\n      const color = (isFilled || isHovered) ? activeColor : props.color\n\n      return { isFilled, isHovered, icon, color }\n    }))\n\n    const eventState = computed(() => [0, ...increments.value].map(value => {\n      function onMouseenter () {\n        hoverIndex.value = value\n      }\n\n      function onMouseleave () {\n        hoverIndex.value = -1\n      }\n\n      function onClick () {\n        if (props.disabled || props.readonly) return\n        rating.value = normalizedValue.value === value && props.clearable ? 0 : value\n      }\n\n      return {\n        onMouseenter: props.hover ? onMouseenter : undefined,\n        onMouseleave: props.hover ? onMouseleave : undefined,\n        onClick,\n      }\n    }))\n\n    const name = computed(() => props.name ?? `v-rating-${getUid()}`)\n\n    function VRatingItem ({ value, index, showStar = true }: { value: number, index: number, showStar?: boolean }) {\n      const { onMouseenter, onMouseleave, onClick } = eventState.value[index + 1]\n      const id = `${name.value}-${String(value).replace('.', '-')}`\n      const btnProps = {\n        color: itemState.value[index]?.color,\n        density: props.density,\n        disabled: props.disabled,\n        icon: itemState.value[index]?.icon,\n        ripple: props.ripple,\n        size: props.size,\n        variant: 'plain' as Variant,\n      }\n\n      return (\n        <>\n           0,\n              'v-rating__item--full': props.halfIncrements && value % 1 === 0,\n            }}\n            onMouseenter={ onMouseenter }\n            onMouseleave={ onMouseleave }\n            onClick={ onClick }\n          >\n            { t(props.itemAriaLabel, value, props.length) }\n            {\n              !showStar ? undefined\n              : slots.item ? slots.item({\n                ...itemState.value[index],\n                props: btnProps,\n                value,\n                index,\n                rating: normalizedValue.value,\n              })\n              : (\n                \n              )\n            }\n          \n\n          \n        \n      )\n    }\n\n    function createLabel (labelProps: { value: number, index: number, label?: string }) {\n      if (slots['item-label']) return slots['item-label'](labelProps)\n\n      if (labelProps.label) return { labelProps.label }\n\n      return  \n    }\n\n    useRender(() => {\n      const hasLabels = !!props.itemLabels?.length || slots['item-label']\n\n      return (\n        \n          \n\n          { range.value.map((value, i) => (\n            
\n {\n hasLabels && props.itemLabelPosition === 'top'\n ? createLabel({ value, index: i, label: props.itemLabels?.[i] })\n : undefined\n }\n
\n { props.halfIncrements ? (\n <>\n \n \n \n ) : (\n \n )}\n
\n {\n hasLabels && props.itemLabelPosition === 'bottom'\n ? createLabel({ value, index: i, label: props.itemLabels?.[i] })\n : undefined\n }\n
\n ))}\n \n )\n })\n\n return {}\n },\n})\n\nexport type VRating = InstanceType\n"],"mappings":";AAAA;AACA;;AAEA;AAAA,SACSA,IAAI,6BAEb;AAAA,SACSC,kBAAkB;AAAA,SAClBC,gBAAgB;AAAA,SAChBC,SAAS;AAAA,SACTC,SAAS;AAAA,SACTC,eAAe;AAAA,SACfC,aAAa;AAAA,SACbC,YAAY;AAAA,SACZC,cAAc,EAAEC,YAAY,uCAErC;AACA,SAASC,QAAQ,EAAEC,UAAU,QAAQ,KAAK;AAAA,SACjCC,KAAK,EAAEC,WAAW,EAAEC,gBAAgB,EAAEC,MAAM,EAAEC,YAAY,EAAEC,SAAS,gCAE9E;AA0BA,OAAO,MAAMC,gBAAgB,GAAGF,YAAY,CAAC;EAC3CG,IAAI,EAAEC,MAAM;EACZC,aAAa,EAAE;IACbC,IAAI,EAAEF,MAAM;IACZG,OAAO,EAAE;EACX,CAAC;EACDC,WAAW,EAAEJ,MAAM;EACnBK,KAAK,EAAEL,MAAM;EACbM,SAAS,EAAEC,OAAO;EAClBC,QAAQ,EAAED,OAAO;EACjBE,SAAS,EAAE;IACTP,IAAI,EAAEnB,SAAS;IACfoB,OAAO,EAAE;EACX,CAAC;EACDO,QAAQ,EAAE;IACRR,IAAI,EAAEnB,SAAS;IACfoB,OAAO,EAAE;EACX,CAAC;EACDQ,cAAc,EAAEJ,OAAO;EACvBK,KAAK,EAAEL,OAAO;EACdM,MAAM,EAAE;IACNX,IAAI,EAAE,CAACY,MAAM,EAAEd,MAAM,CAAC;IACtBG,OAAO,EAAE;EACX,CAAC;EACDY,QAAQ,EAAER,OAAO;EACjBS,UAAU,EAAE;IACVd,IAAI,EAAE,CAACY,MAAM,EAAEd,MAAM,CAAC;IACtBG,OAAO,EAAE;EACX,CAAC;EACDc,UAAU,EAAEC,KAAuB;EACnCC,iBAAiB,EAAE;IACjBjB,IAAI,EAAEF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