reka-ui
Version:
Vue port for Radix UI Primitives.
1 lines • 4.7 kB
Source Map (JSON)
{"version":3,"file":"RadioGroupRoot.cjs","sources":["../../src/RadioGroup/RadioGroupRoot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { Ref } from 'vue'\nimport type { PrimitiveProps } from '@/Primitive'\nimport type { AcceptableValue, DataOrientation, Direction, FormFieldProps } from '@/shared/types'\nimport { createContext, useDirection, useFormControl, useForwardExpose } from '@/shared'\n\nexport interface RadioGroupRootProps extends PrimitiveProps, FormFieldProps {\n /** The controlled value of the radio item to check. Can be binded as `v-model`. */\n modelValue?: AcceptableValue\n /**\n * The value of the radio item that should be checked when initially rendered.\n *\n * Use when you do not need to control the state of the radio items.\n */\n defaultValue?: AcceptableValue\n /** When `true`, prevents the user from interacting with radio items. */\n disabled?: boolean\n /** The orientation of the component. */\n orientation?: DataOrientation\n /** The reading direction of the combobox when applicable. <br> If omitted, inherits globally from `ConfigProvider` or assumes LTR (left-to-right) reading mode. */\n dir?: Direction\n /** When `true`, keyboard navigation will loop from last item to first, and vice versa. */\n loop?: boolean\n}\nexport type RadioGroupRootEmits = {\n /** Event handler called when the radio group value changes */\n 'update:modelValue': [payload: string]\n}\n\ninterface RadioGroupRootContext {\n modelValue?: Readonly<Ref<AcceptableValue | undefined>>\n changeModelValue: (value?: AcceptableValue) => void\n disabled: Ref<boolean>\n loop: Ref<boolean>\n orientation: Ref<DataOrientation | undefined>\n name?: string\n required: Ref<boolean>\n}\n\nexport const [injectRadioGroupRootContext, provideRadioGroupRootContext]\n = createContext<RadioGroupRootContext>('RadioGroupRoot')\n</script>\n\n<script setup lang=\"ts\">\nimport { toRefs } from 'vue'\nimport { useVModel } from '@vueuse/core'\nimport { Primitive } from '@/Primitive'\nimport { RovingFocusGroup } from '@/RovingFocus'\nimport { VisuallyHiddenInput } from '@/VisuallyHidden'\n\nconst props = withDefaults(defineProps<RadioGroupRootProps>(), {\n disabled: false,\n required: false,\n orientation: undefined,\n loop: true,\n})\n\nconst emits = defineEmits<RadioGroupRootEmits>()\n\ndefineSlots<{\n default: (props: {\n /** Current input values */\n modelValue: typeof modelValue.value\n }) => any\n}>()\n\nconst { forwardRef, currentElement } = useForwardExpose()\nconst modelValue = useVModel(props, 'modelValue', emits, {\n defaultValue: props.defaultValue,\n passive: (props.modelValue === undefined) as false,\n})\n\nconst { disabled, loop, orientation, name, required, dir: propDir } = toRefs(props)\nconst dir = useDirection(propDir)\nconst isFormControl = useFormControl(currentElement)\n\nprovideRadioGroupRootContext({\n modelValue,\n changeModelValue: (value) => {\n modelValue.value = value\n },\n disabled,\n loop,\n orientation,\n name: name?.value,\n required,\n})\n</script>\n\n<template>\n <RovingFocusGroup\n as-child\n :orientation=\"orientation\"\n :dir=\"dir\"\n :loop=\"loop\"\n >\n <Primitive\n :ref=\"forwardRef\"\n role=\"radiogroup\"\n :data-disabled=\"disabled ? '' : undefined\"\n :as-child=\"asChild\"\n :as=\"as\"\n :aria-orientation=\"orientation\"\n :aria-required=\"required\"\n :dir=\"dir\"\n >\n <slot :model-value=\"modelValue\" />\n\n <VisuallyHiddenInput\n v-if=\"isFormControl && name\"\n :required=\"required\"\n :disabled=\"disabled\"\n :value=\"modelValue\"\n :name=\"name\"\n />\n </Primitive>\n </RovingFocusGroup>\n</template>\n"],"names":["createContext","useForwardExpose","useVModel","toRefs","useDirection","useFormControl"],"mappings":";;;;;;;;;;;;AAuCO,MAAM,CAAC,2BAAA,EAA6B,4BAA4B,CAAA,GACnEA,mCAAqC,gBAAgB;;;;;;;;;;;;;;;;;AAUzD,IAAA,MAAM,KAAQ,GAAA,OAAA;AAOd,IAAA,MAAM,KAAQ,GAAA,MAAA;AASd,IAAA,MAAM,EAAE,UAAA,EAAY,cAAe,EAAA,GAAIC,wCAAiB,EAAA;AACxD,IAAA,MAAM,UAAa,GAAAC,cAAA,CAAU,KAAO,EAAA,YAAA,EAAc,KAAO,EAAA;AAAA,MACvD,cAAc,KAAM,CAAA,YAAA;AAAA,MACpB,OAAA,EAAU,MAAM,UAAe,KAAA;AAAA,KAChC,CAAA;AAED,IAAM,MAAA,EAAE,QAAU,EAAA,IAAA,EAAM,WAAa,EAAA,IAAA,EAAM,UAAU,GAAK,EAAA,OAAA,EAAY,GAAAC,UAAA,CAAO,KAAK,CAAA;AAClF,IAAM,MAAA,GAAA,GAAMC,iCAAa,OAAO,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgBC,qCAAe,cAAc,CAAA;AAEnD,IAA6B,4BAAA,CAAA;AAAA,MAC3B,UAAA;AAAA,MACA,gBAAA,EAAkB,CAAC,KAAU,KAAA;AAC3B,QAAA,UAAA,CAAW,KAAQ,GAAA,KAAA;AAAA,OACrB;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,WAAA;AAAA,MACA,MAAM,IAAM,EAAA,KAAA;AAAA,MACZ;AAAA,KACD,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}