summaryrefslogtreecommitdiffhomepage
path: root/packages/ui/src/components/inline-input.tsx
blob: d0a603ee39488552d8579d44888501dc994ae98f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import type { ComponentProps } from "solid-js"
import { splitProps } from "solid-js"

export type InlineInputProps = ComponentProps<"input"> & {
  width?: string
}

export function InlineInput(props: InlineInputProps) {
  const [local, others] = splitProps(props, ["class", "width", "style"])

  const style = () => {
    if (!local.style) return { width: local.width }
    if (typeof local.style === "string") {
      if (!local.width) return local.style
      return `${local.style};width:${local.width}`
    }
    if (!local.width) return local.style
    return { ...local.style, width: local.width }
  }

  return <input data-component="inline-input" class={local.class} style={style()} {...others} />
}