1 |
- {"version":3,"file":"VSelectionControl.mjs","names":["VIcon","VLabel","makeSelectionControlGroupProps","VSelectionControlGroupSymbol","useTextColor","makeComponentProps","useDensity","useProxiedModel","Ripple","computed","inject","nextTick","ref","shallowRef","filterInputAttrs","genericComponent","getUid","matchesSelector","propsFactory","useRender","wrapInArray","makeVSelectionControlProps","label","String","trueValue","falseValue","value","useSelectionControl","props","group","undefined","densityClasses","modelValue","isMultiple","multiple","Array","isArray","model","get","val","some","v","valueComparator","set","readonly","currentValue","newVal","filter","item","textColorClasses","textColorStyles","error","disabled","color","icon","trueIcon","falseIcon","VSelectionControl","name","directives","inheritAttrs","emits","setup","_ref","attrs","slots","uid","id","isFocused","isFocusVisible","input","onForceUpdate","checked","onFocus","e","target","onBlur","onInput","forceUpdate","for","rootAttrs","inputAttrs","_createVNode","_mergeProps","inline","class","style","default","_withDirectives","type","_resolveDirective","ripple"],"sources":["../../../src/components/VSelectionControl/VSelectionControl.tsx"],"sourcesContent":["// Styles\nimport './VSelectionControl.sass'\n\n// Components\nimport { VIcon } from '@/components/VIcon'\nimport { VLabel } from '@/components/VLabel'\nimport { makeSelectionControlGroupProps, VSelectionControlGroupSymbol } from '@/components/VSelectionControlGroup/VSelectionControlGroup'\n\n// Composables\nimport { useTextColor } from '@/composables/color'\nimport { makeComponentProps } from '@/composables/component'\nimport { useDensity } from '@/composables/density'\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Directives\nimport { Ripple } from '@/directives/ripple'\n\n// Utilities\nimport { computed, inject, nextTick, ref, shallowRef } from 'vue'\nimport {\n filterInputAttrs,\n genericComponent,\n getUid,\n matchesSelector,\n propsFactory,\n useRender,\n wrapInArray,\n} from '@/util'\n\n// Types\nimport type { CSSProperties, ExtractPropTypes, Ref, WritableComputedRef } from 'vue'\nimport type { GenericProps } from '@/util'\n\nexport type SelectionControlSlot = {\n model: WritableComputedRef<any>\n textColorClasses: Ref<string[]>\n textColorStyles: Ref<CSSProperties>\n props: {\n onBlur: (e: Event) => void\n onFocus: (e: FocusEvent) => void\n id: string\n }\n}\n\nexport type VSelectionControlSlots = {\n default: never\n label: { label: string | undefined, props: Record<string, unknown> }\n input: SelectionControlSlot\n}\n\nexport const makeVSelectionControlProps = propsFactory({\n label: String,\n trueValue: null,\n falseValue: null,\n value: null,\n\n ...makeComponentProps(),\n ...makeSelectionControlGroupProps(),\n}, 'VSelectionControl')\n\nexport function useSelectionControl (\n props: ExtractPropTypes<ReturnType<typeof makeVSelectionControlProps>> & {\n 'onUpdate:modelValue': ((val: any) => void) | undefined\n }\n) {\n const group = inject(VSelectionControlGroupSymbol, undefined)\n const { densityClasses } = useDensity(props)\n const modelValue = useProxiedModel(props, 'modelValue')\n const trueValue = computed(() => (\n props.trueValue !== undefined ? props.trueValue\n : props.value !== undefined ? props.value\n : true\n ))\n const falseValue = computed(() => props.falseValue !== undefined ? props.falseValue : false)\n const isMultiple = computed(() => (\n !!props.multiple ||\n (props.multiple == null && Array.isArray(modelValue.value))\n ))\n const model = computed({\n get () {\n const val = group ? group.modelValue.value : modelValue.value\n\n return isMultiple.value\n ? val.some((v: any) => props.valueComparator(v, trueValue.value))\n : props.valueComparator(val, trueValue.value)\n },\n set (val: boolean) {\n if (props.readonly) return\n\n const currentValue = val ? trueValue.value : falseValue.value\n\n let newVal = currentValue\n\n if (isMultiple.value) {\n newVal = val\n ? [...wrapInArray(modelValue.value), currentValue]\n : wrapInArray(modelValue.value).filter((item: any) => !props.valueComparator(item, trueValue.value))\n }\n\n if (group) {\n group.modelValue.value = newVal\n } else {\n modelValue.value = newVal\n }\n },\n })\n const { textColorClasses, textColorStyles } = useTextColor(computed(() => {\n return (\n model.value &&\n !props.error &&\n !props.disabled\n ) ? props.color : undefined\n }))\n const icon = computed(() => model.value ? props.trueIcon : props.falseIcon)\n\n return {\n group,\n densityClasses,\n trueValue,\n falseValue,\n model,\n textColorClasses,\n textColorStyles,\n icon,\n }\n}\n\nexport const VSelectionControl = genericComponent<new <T>(\n props: {\n modelValue?: T\n 'onUpdate:modelValue'?: (val: T) => any\n },\n slots: VSelectionControlSlots,\n) => GenericProps<typeof props, typeof slots>>()({\n name: 'VSelectionControl',\n\n directives: { Ripple },\n\n inheritAttrs: false,\n\n props: makeVSelectionControlProps(),\n\n emits: {\n 'update:modelValue': (val: any) => true,\n },\n\n setup (props, { attrs, slots }) {\n const {\n group,\n densityClasses,\n icon,\n model,\n textColorClasses,\n textColorStyles,\n trueValue,\n } = useSelectionControl(props)\n const uid = getUid()\n const id = computed(() => props.id || `input-${uid}`)\n const isFocused = shallowRef(false)\n const isFocusVisible = shallowRef(false)\n const input = ref<HTMLInputElement>()\n\n group?.onForceUpdate(() => {\n if (input.value) {\n input.value.checked = model.value\n }\n })\n\n function onFocus (e: FocusEvent) {\n isFocused.value = true\n if (matchesSelector(e.target as HTMLElement, ':focus-visible') !== false) {\n isFocusVisible.value = true\n }\n }\n\n function onBlur () {\n isFocused.value = false\n isFocusVisible.value = false\n }\n\n function onInput (e: Event) {\n if (props.readonly && group) {\n nextTick(() => group.forceUpdate())\n }\n model.value = (e.target as HTMLInputElement).checked\n }\n\n useRender(() => {\n const label = slots.label\n ? slots.label({\n label: props.label,\n props: { for: id.value },\n })\n : props.label\n const [rootAttrs, inputAttrs] = filterInputAttrs(attrs)\n\n return (\n <div\n class={[\n 'v-selection-control',\n {\n 'v-selection-control--dirty': model.value,\n 'v-selection-control--disabled': props.disabled,\n 'v-selection-control--error': props.error,\n 'v-selection-control--focused': isFocused.value,\n 'v-selection-control--focus-visible': isFocusVisible.value,\n 'v-selection-control--inline': props.inline,\n },\n densityClasses.value,\n props.class,\n ]}\n { ...rootAttrs }\n style={ props.style }\n >\n <div\n class={[\n 'v-selection-control__wrapper',\n textColorClasses.value,\n ]}\n style={ textColorStyles.value }\n >\n { slots.default?.() }\n\n <div\n class={[\n 'v-selection-control__input',\n ]}\n v-ripple={ props.ripple && [\n !props.disabled && !props.readonly,\n null,\n ['center', 'circle'],\n ]}\n >\n { icon.value && <VIcon key=\"icon\" icon={ icon.value } /> }\n\n <input\n ref={ input }\n checked={ model.value }\n disabled={ !!(props.readonly || props.disabled) }\n id={ id.value }\n onBlur={ onBlur }\n onFocus={ onFocus }\n onInput={ onInput }\n aria-disabled={ !!(props.readonly || props.disabled) }\n type={ props.type }\n value={ trueValue.value }\n name={ props.name }\n aria-checked={ props.type === 'checkbox' ? model.value : undefined }\n { ...inputAttrs }\n />\n\n { slots.input?.({\n model,\n textColorClasses,\n textColorStyles,\n props: {\n onFocus,\n onBlur,\n id: id.value,\n },\n } as SelectionControlSlot)}\n </div>\n </div>\n\n { label && (\n <VLabel for={ id.value } clickable>\n { label }\n </VLabel>\n )}\n </div>\n )\n })\n\n return {\n isFocused,\n input,\n }\n },\n})\n\nexport type VSelectionControl = InstanceType<typeof VSelectionControl>\n"],"mappings":";AAAA;AACA;;AAEA;AAAA,SACSA,KAAK;AAAA,SACLC,MAAM;AAAA,SACNC,8BAA8B,EAAEC,4BAA4B,gEAErE;AAAA,SACSC,YAAY;AAAA,SACZC,kBAAkB;AAAA,SAClBC,UAAU;AAAA,SACVC,eAAe,8CAExB;AAAA,SACSC,MAAM,6CAEf;AACA,SAASC,QAAQ,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,UAAU,QAAQ,KAAK;AAAA,SAE/DC,gBAAgB,EAChBC,gBAAgB,EAChBC,MAAM,EACNC,eAAe,EACfC,YAAY,EACZC,SAAS,EACTC,WAAW,gCAGb;AAqBA,OAAO,MAAMC,0BAA0B,GAAGH,YAAY,CAAC;EACrDI,KAAK,EAAEC,MAAM;EACbC,SAAS,EAAE,IAAI;EACfC,UAAU,EAAE,IAAI;EAChBC,KAAK,EAAE,IAAI;EAEX,GAAGrB,kBAAkB,EAAE;EACvB,GAAGH,8BAA8B;AACnC,CAAC,EAAE,mBAAmB,CAAC;AAEvB,OAAO,SAASyB,mBAAmBA,CACjCC,KAEC,EACD;EACA,MAAMC,KAAK,GAAGnB,MAAM,CAACP,4BA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