Skip to content

Commit

Permalink
[form-builder] Fix value typing for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent 41767ae commit f3fc5fc
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import ArrayFunctions from 'part:@sanity/form-builder/input/array/functions'
import {map} from 'rxjs/operators'
import {isPlainObject, get} from 'lodash'
import {FOCUS_TERMINATOR, startsWith} from '@sanity/util/paths'
import Button from 'part:@sanity/components/buttons/default'
import Fieldset from 'part:@sanity/components/fieldsets/default'
import formBuilderConfig from 'config:@sanity/form-builder'
import ArrayFunctions from 'part:@sanity/form-builder/input/array/functions'
import DefaultButton from 'part:@sanity/components/buttons/default'
import Button from 'part:@sanity/components/buttons/default'
import Fieldset from 'part:@sanity/components/fieldsets/default'
import {ResolvedUploader, Uploader} from '../../sanity/uploads/typedefs'
import {Marker, Type} from '../../typedefs'
import {Path} from '../../typedefs/path'
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/form-builder/src/inputs/BooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './BooleanInput.css'
import {Props} from './types'

const BooleanInput = React.forwardRef(
(props: Props, ref: React.MutableRefObject<HTMLDivElement>) => {
(props: Props<boolean>, ref: React.MutableRefObject<HTMLDivElement>) => {
const inputRef = useRef<any>(null)
const handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
props.onChange(PatchEvent.from(set(event.currentTarget.checked)))
Expand Down
5 changes: 3 additions & 2 deletions packages/@sanity/form-builder/src/inputs/EmailInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import {uniqueId} from 'lodash'
import TextInput from 'part:@sanity/components/textinputs/default'
import FormField from 'part:@sanity/components/formfields/default'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'
export default class EmailInput extends React.Component<Props, {}> {

export default class EmailInput extends React.Component<Props<string>> {
_input: TextInput | null
_inputId = uniqueId('EmailInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/@sanity/form-builder/src/inputs/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import {uniqueId} from 'lodash'
import TextInput from 'part:@sanity/components/textinputs/default'
import FormField from 'part:@sanity/components/formfields/default'
import {getValidationRule} from '../utils/getValidationRule'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'
export default class NumberInput extends React.Component<Props, {}> {

export default class NumberInput extends React.Component<Props<number>> {
_input: TextInput | null
_inputId = uniqueId('NumberInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/form-builder/src/inputs/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function toSelectItem(option) {
return {title: capitalize(option), value: option}
}

export default class SelectInput extends React.Component<Props> {
export default class SelectInput extends React.Component<Props<string | number>> {
_input: (RadioSelect | Select) | null
name = uniqueId('RadioName')
static defaultProps = {
Expand Down
5 changes: 3 additions & 2 deletions packages/@sanity/form-builder/src/inputs/StringInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import {uniqueId} from 'lodash'
import TextInput from 'part:@sanity/components/textinputs/default'
import FormField from 'part:@sanity/components/formfields/default'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'
export default class StringInput extends React.Component<Props> {

export default class StringInput extends React.Component<Props<string>> {
_input: TextInput | null
_inputId = uniqueId('StringInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/form-builder/src/inputs/TagsArrayInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import {uniqueId} from 'lodash'
import FormField from 'part:@sanity/components/formfields/default'
import TagInput from 'part:@sanity/components/tags/textfield'
import PatchEvent, {set, unset} from '../../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'

export default class TagsArrayInput extends React.PureComponent<Props> {
export default class TagsArrayInput extends React.PureComponent<Props<string[]>> {
_input: TagInput
_inputId = uniqueId('TagsArrayInput')
set(nextValue: string[]) {
Expand Down
5 changes: 3 additions & 2 deletions packages/@sanity/form-builder/src/inputs/TelephoneInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import {uniqueId} from 'lodash'
import TextInput from 'part:@sanity/components/textinputs/default'
import FormField from 'part:@sanity/components/formfields/default'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'
export default class TelephoneInput extends React.Component<Props> {

export default class TelephoneInput extends React.Component<Props<string>> {
_input: TextInput | null
_inputId = uniqueId('TelephoneInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/form-builder/src/inputs/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import {uniqueId} from 'lodash'
import FormField from 'part:@sanity/components/formfields/default'
import TextArea from 'part:@sanity/components/textareas/default'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
import {uniqueId} from 'lodash'

export default class TextInput extends React.Component<Props> {
export default class TextInput extends React.Component<Props<string>> {
_input: TextArea | null
_inputId = uniqueId('TextInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/form-builder/src/inputs/UrlInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import FormField from 'part:@sanity/components/formfields/default'
import {getValidationRule} from '../utils/getValidationRule'
import PatchEvent, {set, unset} from '../PatchEvent'
import {Props} from './types'
export default class UrlInput extends React.Component<Props> {

export default class UrlInput extends React.Component<Props<string>> {
_input: TextInput | null
_inputId = uniqueId('UrlInput')
handleChange = (event: React.SyntheticEvent<HTMLInputElement>) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/@sanity/form-builder/src/inputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {FormFieldPresence} from '@sanity/base/presence'
import {Type, Marker} from '../typedefs'
import PatchEvent from '../PatchEvent'

export type Props = {
export type Props<T> = {
type: Type
level: number
value: string | null
value: T | null | undefined
readOnly: boolean | null
onChange: (arg0: PatchEvent) => void
onChange: (patchEvent: PatchEvent) => void
onFocus: () => void
onBlur?: () => void
markers: Array<Marker>
markers: Marker[]
presence: FormFieldPresence[]
}

0 comments on commit f3fc5fc

Please sign in to comment.