import React, { useState } from 'react'
import { NumberInput } from '../ValueInput'
import { Label, Row } from '../UI'
import { useDrag } from '../../hooks'
import { RangeGrid } from './StyledNumber'
import { RangeSlider } from './RangeSlider'
import { useInputContext } from '../../context'
import type { NumberProps } from './number-types'
import { multiplyStep } from '../../utils'
import { InnerNumberLabel } from '../ValueInput/StyledInput'
type DraggableLabelProps = {
label: string
step: number
innerLabelTrim: number
onUpdate: (v: any) => void
}
const DraggableLabel = React.memo(({ label, onUpdate, step, innerLabelTrim }: DraggableLabelProps) => {
const [dragging, setDragging] = useState(false)
const bind = useDrag(({ active, delta: [dx], event, memo = 0, first, last, target }) => {
if (first) {
const label = target as HTMLElement
label.requestPointerLock()
}
if (last) {
document.exitPointerLock()
}
setDragging(active)
memo += dx / 2
if (Math.abs(memo) >= 1) {
onUpdate((v: any) => parseFloat(v) + Math.floor(memo) * step * multiplyStep(event))
memo = 0
}
return memo
})
return (
1 ? label : ''} {...bind()}>
{label.slice(0, innerLabelTrim)}
)
})
export function Number({
label,
id,
displayValue,
onUpdate,
onChange,
settings,
innerLabelTrim = 1,
}: Omit & {
id?: string
label: string
innerLabelTrim?: number
}) {
const InnerLabel = innerLabelTrim > 0 && (
)
return (
)
}
export function NumberComponent() {
const props = useInputContext()
const { label, value, onUpdate, settings, id } = props
const { min, max } = settings
const hasRange = max !== Infinity && min !== -Infinity
return (
{hasRange && }
)
}