SafeSqlInput.tsx 629 B

123456789101112131415
  1. import { rawSql, type SafeSqlFragment } from '@supabase/pg-meta'
  2. import type { ChangeEvent, ComponentProps } from 'react'
  3. import { Input } from 'ui-patterns/DataInputs/Input'
  4. type InputProps = ComponentProps<typeof Input>
  5. export type SafeSqlInputProps = Omit<InputProps, 'placeholder' | 'value' | 'onChange'> & {
  6. placeholder?: SafeSqlFragment
  7. value: SafeSqlFragment
  8. onChange?: (event: ChangeEvent<HTMLInputElement>, value: SafeSqlFragment) => void
  9. }
  10. export const SafeSqlInput = ({ onChange, ...props }: SafeSqlInputProps) => (
  11. <Input {...props} onChange={(event) => onChange?.(event, rawSql(event.target.value))} />
  12. )