Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / new-forms / plugins / PluginsContext.tsx
Size: Mime:
/**
 * @todo @name InputPluginsContext
 */
import { createContext } from 'react'
import { ComponentClass } from 'react'
import {
  Value,
  AnyObj,
  SerializerFunction,
  ValidatorFunction,
} from '../typings'

export interface InputPluginIsSatisfiedByArg {
  [key: string]: any
  type: string
}

export interface DefaultStateReturn<Props = AnyObj> {
  serializer?: SerializerFunction
  validator?: ValidatorFunction
  type?: string
  attributes?: Props
  formState?: any
  propertyName?: string
  label?: string
  value?: Value
  identifier?: string
  isActive?: boolean
  isSelected?: boolean
  // anything else would end up in .attributes
  [key: string]: any
}

// @todo type...
export type DefaultStateFunction = <InputState = any>(
  inputState: InputState
) => DefaultStateReturn

export interface InputPluginStaticTypes {
  // or defaultState keyof InputState
  defaultState?: DefaultStateReturn | DefaultStateFunction
  isSatisfiedByProps: (props: InputPluginIsSatisfiedByArg) => boolean
}
export type InputPluginType<Type = any> = ComponentClass<Type> &
  InputPluginStaticTypes

// @todo InputPlugin[]
export type PluginsContextValue = InputPluginType[]
export const PluginsContext = createContext<PluginsContextValue>(
  undefined as any
)
export const { Provider, Consumer } = PluginsContext