Skip to content

Commit

Permalink
chore: add merge input styles for numberinput
Browse files Browse the repository at this point in the history
  • Loading branch information
joyce-foo committed Dec 16, 2024
1 parent dfe6aa8 commit 6302055
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/camp/src/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { Ref } from 'react'
import { useRef } from 'react'
import {
Box,
chakra,
ComponentWithAs as _,
NumberInputProps as ChakraNumberInputProps,
Divider,
forwardRef,
NumberInputProps as ChakraNumberInputProps,
mergeThemeOverride,
SystemStyleObject,
useFormControlProps,
useMergeRefs,
useMultiStyleConfig,
useNumberInput,
} from '@chakra-ui/react'
import type { Ref } from 'react'
import { useMemo, useRef } from 'react'

import { IconButton } from '~/IconButton'
import { BxMinus, BxPlus } from '~/icons'
Expand All @@ -29,6 +30,8 @@ export interface NumberInputProps extends ChakraNumberInputProps {
* Whether to show the increment and decrement steppers. Defaults to true.
*/
showSteppers?: boolean

inputStyles?: SystemStyleObject
}

export const NumberInput = forwardRef<NumberInputProps, 'input'>(
Expand All @@ -38,6 +41,7 @@ export const NumberInput = forwardRef<NumberInputProps, 'input'>(
clampValueOnBlur = false,
isSuccess,
isPrefilled,
inputStyles,
...props
},
ref,
Expand All @@ -48,6 +52,11 @@ export const NumberInput = forwardRef<NumberInputProps, 'input'>(
isPrefilled,
})

const mergedInputStyles = useMemo(
() => mergeThemeOverride(styles.field, inputStyles),
[inputStyles, styles.field],
)

const stepperWrapperRef = useRef<HTMLDivElement | null>(null)

/**
Expand Down Expand Up @@ -90,6 +99,7 @@ export const NumberInput = forwardRef<NumberInputProps, 'input'>(
// is this input.
ref={inputRef}
__css={styles.field}
sx={mergedInputStyles}
/>
{showSteppers && (
<Box __css={styles.stepperWrapper} ref={stepperWrapperRef}>
Expand Down

0 comments on commit 6302055

Please sign in to comment.