GitHub

@@ -8,7 +8,9 @@ import type { ComponentConfig } from '../types/tv'

8899

type InputNumber = ComponentConfig<typeof theme, AppConfig, 'inputNumber'>

101011-

export interface InputNumberProps extends Pick<NumberFieldRootProps, 'modelValue' | 'defaultValue' | 'min' | 'max' | 'step' | 'stepSnapping' | 'disabled' | 'required' | 'id' | 'name' | 'formatOptions' | 'disableWheelChange' | 'invertWheelChange' | 'readonly'> {

11+

type InputNumberValue = number | null

12+13+

export interface InputNumberProps<T extends InputNumberValue = InputNumberValue> extends Pick<NumberFieldRootProps, 'modelValue' | 'defaultValue' | 'min' | 'max' | 'step' | 'stepSnapping' | 'disabled' | 'required' | 'id' | 'name' | 'formatOptions' | 'disableWheelChange' | 'invertWheelChange' | 'readonly'> {

1214

/**

1315

* The element or component this component should render as.

1416

* @defaultValue 'div'

@@ -54,7 +56,7 @@ export interface InputNumberProps extends Pick<NumberFieldRootProps, 'modelValue

5456

decrementDisabled?: boolean

5557

autofocus?: boolean

5658

autofocusDelay?: number

57-

modelModifiers?: Pick<ModelModifiers, 'optional'>

59+

modelModifiers?: Pick<ModelModifiers<T>, 'optional'>

5860

/**

5961

* The locale to use for formatting and parsing numbers.

6062

* @defaultValue UApp.locale.code

@@ -64,8 +66,8 @@ export interface InputNumberProps extends Pick<NumberFieldRootProps, 'modelValue

6466

ui?: InputNumber['slots']

6567

}

666867-

export interface InputNumberEmits {

68-

'update:modelValue': [value: number]

69+

export interface InputNumberEmits<T extends InputNumberValue = InputNumberValue> {

70+

'update:modelValue': [value: T]

6971

'blur': [event: FocusEvent]

7072

'change': [event: Event]

7173

}

@@ -76,7 +78,7 @@ export interface InputNumberSlots {

7678

}

7779

</script>

788079-

<script setup lang="ts">

81+

<script setup lang="ts" generic="T extends InputNumberValue = InputNumberValue">

8082

import { onMounted, ref, computed } from 'vue'

8183

import { NumberFieldRoot, NumberFieldInput, NumberFieldDecrement, NumberFieldIncrement, useForwardPropsEmits } from 'reka-ui'

8284

import { reactivePick, useVModel } from '@vueuse/core'

@@ -89,23 +91,23 @@ import UButton from './Button.vue'

89919092

defineOptions({ inheritAttrs: false })

919392-

const props = withDefaults(defineProps<InputNumberProps>(), {

94+

const props = withDefaults(defineProps<InputNumberProps<T>>(), {

9395

orientation: 'horizontal',

9496

increment: true,

9597

decrement: true

9698

})

97-

const emits = defineEmits<InputNumberEmits>()

99+

const emits = defineEmits<InputNumberEmits<T>>()

98100

defineSlots<InputNumberSlots>()

99101100-

const modelValue = useVModel<InputNumberProps, 'modelValue', 'update:modelValue'>(props, 'modelValue', emits, { defaultValue: props.defaultValue })

102+

const modelValue = useVModel<InputNumberProps<T>, 'modelValue', 'update:modelValue'>(props, 'modelValue', emits, { defaultValue: props.defaultValue })

101103102104

const { t, code: codeLocale } = useLocale()

103105

const appConfig = useAppConfig() as InputNumber['AppConfig']

104106105107

const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'defaultValue', 'min', 'max', 'step', 'stepSnapping', 'formatOptions', 'disableWheelChange', 'invertWheelChange', 'readonly'), emits)

106108107-

const { emitFormBlur, emitFormFocus, emitFormChange, emitFormInput, id, color, size: formGroupSize, name, highlight, disabled, ariaAttrs } = useFormField<InputNumberProps>(props)

108-

const { orientation, size: fieldGroupSize } = useFieldGroup<InputNumberProps>(props)

109+

const { emitFormBlur, emitFormFocus, emitFormChange, emitFormInput, id, color, size: formGroupSize, name, highlight, disabled, ariaAttrs } = useFormField<InputNumberProps<T>>(props)

110+

const { orientation, size: fieldGroupSize } = useFieldGroup<InputNumberProps<T>>(props)

109111110112

const locale = computed(() => props.locale || codeLocale.value)

111113

const inputSize = computed(() => fieldGroupSize.value || formGroupSize.value)

Read the original on github.com ↗