Options
All
  • Public
  • Public/Protected
  • All
Menu

PlaceHires react-component-library utilities

Index

Type aliases

ErrorCode: string

Placeholder type for error codes. Override with enum for better type safety

ErrorToFieldName: { [ errorCodeOrStatus in ErrorCode | number]?: string | { customErrorMessage: string; fieldName: string } }

Maps error code (or status) to field name

Styles<Params, RuleNameSubsetReferencableInNestedSelectors, RuleName>: Record<RuleNameSubsetReferencableInNestedSelectors | RuleName, CSSObject> | ((theme: Theme, params: Params, classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName, CSSObject>)

Styles (that makesStyles takes) as specified in tss-react

Type parameters

  • Params

  • RuleNameSubsetReferencableInNestedSelectors: string

  • RuleName: string

Variables

alertError: DebouncedFuncLeading<(message?: any) => void> = ...

Renders error alert (debounced to limit errors on screen)

Functions

  • alertAction(message: string): void
  • Renders action alert - info alert with appropriate title and position

    Parameters

    • message: string

    Returns void

  • alertInfo(message: string, title?: string): void
  • Renders info alert

    Parameters

    • message: string
    • Optional title: string

    Returns void

  • alertSuccess(message: string): void
  • Renders success alert

    Parameters

    • message: string

    Returns void

  • alertWarning(message: string): void
  • Renders warning alert

    Parameters

    • message: string

    Returns void

  • createNotification(options: Partial<iNotification>): void
  • Creates a new notification on screen

    Parameters

    • options: Partial<iNotification>

    Returns void

  • displayFieldError<Values>(err: unknown, formikHelpers: FormikHelpers<Values>, errorsToFieldName: ErrorToFieldName): err is ApolloError
  • Displays formik field error message if error has matching code/status with errorsToFieldName Returns true if there was a match - error was displayed, false otherwise.

    Type parameters

    • Values

    Parameters

    • err: unknown
    • formikHelpers: FormikHelpers<Values>
    • errorsToFieldName: ErrorToFieldName

    Returns err is ApolloError

  • displayFieldErrorOnMatchingError<R, Values>(mutationPromise: Promise<R>, formikHelpers: FormikHelpers<Values>, fieldName: keyof Values, ...errorCodes: (string | ErrorHandlingObject)[]): Promise<R>
  • Sets appropriate error for fieldName in Formik form if mutationPromise throws error that matches one of graphql errorCodes provided.

    The promise is passed through (i.e. return promise succeeds if original promise succeeds, fails if original promise fails)

    Type parameters

    • R

    • Values

    Parameters

    • mutationPromise: Promise<R>
    • formikHelpers: FormikHelpers<Values>
    • fieldName: keyof Values
    • Rest ...errorCodes: (string | ErrorHandlingObject)[]

    Returns Promise<R>

  • download(filename: string, text: string): void
  • Downloads a file with given filename an text content

    Parameters

    • filename: string
    • text: string

    Returns void

  • enumToSelectOptions<T>(enumObj: Record<string, T>, getLabel: (value: T) => string, options?: { noEmptyValue?: boolean }): SelectOption[]
  • Converts enum to list of select options

    Type parameters

    • T: string | number

    Parameters

    • enumObj: Record<string, T>
    • getLabel: (value: T) => string
        • (value: T): string
        • Parameters

          • value: T

          Returns string

    • Optional options: { noEmptyValue?: boolean }
      • Optional noEmptyValue?: boolean

    Returns SelectOption[]

  • findLabel(options: SelectOption[], value: string | number): string
  • Finds correct label from given select options based on given value

    Parameters

    Returns string

  • findSelectedOption<I, O, K>(selectedIdentifier: undefined | I, options: O[], optIdentifierKey: K): Record<string | number, O>[I]
  • Same as findSelectedOptions, but for a single object

    Type parameters

    • I: string | number

    • O: { [ k in string]: I }

    • K: string

    Parameters

    • selectedIdentifier: undefined | I
    • options: O[]
    • optIdentifierKey: K

    Returns Record<string | number, O>[I]

  • findSelectedOptions<I, O, K>(selectedIdentifiers: undefined | I[], options: O[], optIdentifierKey: K): Record<string | number, O>[I][]
  • Find selected options based on their identifiers. Useful to get initial options for Autocomplete

    Type parameters

    • I: string | number

    • O: { [ k in string]: I }

    • K: string

    Parameters

    • selectedIdentifiers: undefined | I[]
    • options: O[]
    • optIdentifierKey: K

    Returns Record<string | number, O>[I][]

  • getClassName(className: string, condition: boolean): string
  • Returns classname string

    Parameters

    • className: string
    • condition: boolean

    Returns string

  • getErrorMessage(err: unknown): undefined | string
  • Gets message of error

    Parameters

    • err: unknown

    Returns undefined | string

  • getInitialValues<Values>(emptyValues: Values, filledValues: undefined | Partial<Values>): Values
  • Gets initial values to pass to formik without extra fields

    Type parameters

    • Values: Record<string, unknown>

    Parameters

    • emptyValues: Values

      Values used by empty form

    • filledValues: undefined | Partial<Values>

      Values used by none-empty form. Extra fields (that don't appear in emptyValues) are removed.

    Returns Values

  • inBrowser(): boolean
  • Checks if currently in browser

    Returns boolean

  • isApolloErrorWithOneOfCodes(err: unknown, ...codes: string[]): err is ApolloError
  • Checks if error is Apollo Error, and checks if error codes match

    Parameters

    • err: unknown
    • Rest ...codes: string[]

    Returns err is ApolloError

  • isApolloNetworkErrorWithOneOfStatusCodes(err: unknown, ...statusCodes: number[]): err is ApolloError & { networkError: ServerParseError | ServerError }
  • Checks if error is Apollo Network Error and checks if status code matches any of provided

    Parameters

    • err: unknown
    • Rest ...statusCodes: number[]

    Returns err is ApolloError & { networkError: ServerParseError | ServerError }

  • isApolloNetworkErrorWithStatusCode(err: unknown): err is ApolloError & { networkError: ServerParseError | ServerError }
  • Checks if error is Apollo Network Error with a status code

    Parameters

    • err: unknown

    Returns err is ApolloError & { networkError: ServerParseError | ServerError }

  • isError(obj: unknown): obj is Error
  • Checks if object is an error

    Parameters

    • obj: unknown

    Returns obj is Error

  • keyInObject<X, Y>(obj: X, prop: Y): obj is X & Record<Y, unknown>
  • Checks if key is in object

    Type parameters

    • X

    • Y: PropertyKey

    Parameters

    • obj: X
    • prop: Y

    Returns obj is X & Record<Y, unknown>

  • listToSelectOptions<T>(values: T[], getLabel: (value: T) => string, options?: { noEmptyValue?: boolean }): SelectOption[]
  • Converts list of values to list of SelectOptions

    Type parameters

    • T: string | number

    Parameters

    • values: T[]
    • getLabel: (value: T) => string
        • (value: T): string
        • Parameters

          • value: T

          Returns string

    • Optional options: { noEmptyValue?: boolean }
      • Optional noEmptyValue?: boolean

    Returns SelectOption[]

  • logPassThrough<P>(logItem: P): P
  • Logs an item

    Type parameters

    • P

    Parameters

    • logItem: P

    Returns P

  • makeStyles<Params, RuleNameSubsetReferencableInNestedSelectors>(params?: { name?: string | Record<string, unknown>; uniqId?: string }): <RuleName_2>(cssObjectByRuleNameOrGetCssObjectByRuleName: Record<RuleName_2, CSSObject> | ((theme: Theme, params: Params, classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName_2, CSSObject>)) => (params: Params, styleOverrides?: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }) => { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }
  • Type parameters

    • Params = void

    • RuleNameSubsetReferencableInNestedSelectors: string = never

    Parameters

    • Optional params: { name?: string | Record<string, unknown>; uniqId?: string }
      • Optional name?: string | Record<string, unknown>
      • Optional uniqId?: string

    Returns <RuleName_2>(cssObjectByRuleNameOrGetCssObjectByRuleName: Record<RuleName_2, CSSObject> | ((theme: Theme, params: Params, classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName_2, CSSObject>)) => (params: Params, styleOverrides?: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }) => { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }

      • <RuleName_2>(cssObjectByRuleNameOrGetCssObjectByRuleName: Record<RuleName_2, CSSObject> | ((theme: Theme, params: Params, classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName_2, CSSObject>)): (params: Params, styleOverrides?: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }) => { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }
      • Type parameters

        • RuleName_2: string

        Parameters

        • cssObjectByRuleNameOrGetCssObjectByRuleName: Record<RuleName_2, CSSObject> | ((theme: Theme, params: Params, classes: Record<RuleNameSubsetReferencableInNestedSelectors, string>) => Record<RuleNameSubsetReferencableInNestedSelectors | RuleName_2, CSSObject>)

        Returns (params: Params, styleOverrides?: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }) => { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }

          • (params: Params, styleOverrides?: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }): { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }
          • Parameters

            • params: Params
            • Optional styleOverrides: { ownerState?: Record<string, unknown>; props: { classes?: Record<string, string> } & Record<string, unknown> }
              • Optional ownerState?: Record<string, unknown>
              • props: { classes?: Record<string, string> } & Record<string, unknown>

            Returns { classes: Record<RuleName_2, string>; css: Css; cx: Cx; theme: Theme }

            • classes: Record<RuleName_2, string>
            • css: Css
            • cx: Cx
            • theme: Theme
  • mergeStyles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>(baseStyle: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>, ...mergeStyles: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>[]): Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>
  • (Deep) Merges 2 Styles into one.

    Type parameters

    • Props: Record<string, unknown>

    • RuleNameSubsetReferencableInNestedSelectors: string

    • RuleName: string

    Parameters

    • baseStyle: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>
    • Rest ...mergeStyles: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>[]

    Returns Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>

  • mergeStylesConditionally<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>(commonStyle: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>, ...conditionalStyles: ConditionalStyles<Props, RuleNameSubsetReferencableInNestedSelectors, string>[]): Styles<Props, RuleNameSubsetReferencableInNestedSelectors, string | RuleName>
  • (Deep) Merges styles conditionally into commonStyle if their given conditions are satisfied. Conditional styles also take in optional mediaQueryGenerator, that would add media query generated by it to the respective styles.

    Type parameters

    • Props: Record<string, unknown>

    • RuleNameSubsetReferencableInNestedSelectors: string

    • RuleName: string

    Parameters

    • commonStyle: Styles<Props, RuleNameSubsetReferencableInNestedSelectors, RuleName>
    • Rest ...conditionalStyles: ConditionalStyles<Props, RuleNameSubsetReferencableInNestedSelectors, string>[]

    Returns Styles<Props, RuleNameSubsetReferencableInNestedSelectors, string | RuleName>

  • mergeTwoConditionalStylesResponsively<K, Props, R1, R2, R3>(commonStyle: Styles<Props, string, R1>, conditionalStylesWithoutMediaQuery1: Omit<ConditionalStyles<Props, string, R2>, "mediaQueryGenerator">, conditionalStylesWithoutMediaQuery2: Omit<ConditionalStyles<Props, string, R3>, "mediaQueryGenerator">, propNameForBreakpoint: K): Styles<Props, string, R1 | R2 | R3>
  • (Deep) Merges 2 styles conditionally into ${commonStyle} if their conditions are satisfied. Additionally, when styles' prop with key ${propNameForBreakpoint} is non null key (a breakpoint or a number referring to screen width), then both styles will be displayed - the first style displayed for screens with width smaller than the given breakpoint/screen width; the second style will be applied for screens with width bigger than the given breakpoint/screen width.

    Type parameters

    • K: string

    • Props: { [ k in string]?: number | Breakpoint }

    • R1: string

    • R2: string

    • R3: string

    Parameters

    • commonStyle: Styles<Props, string, R1>
    • conditionalStylesWithoutMediaQuery1: Omit<ConditionalStyles<Props, string, R2>, "mediaQueryGenerator">
    • conditionalStylesWithoutMediaQuery2: Omit<ConditionalStyles<Props, string, R3>, "mediaQueryGenerator">
    • propNameForBreakpoint: K

    Returns Styles<Props, string, R1 | R2 | R3>

  • navigateOut(url: string): void
  • Navigates to url

    Parameters

    • url: string

    Returns void

  • openNewTab(url: string): void
  • Opens a url in a new tab

    Parameters

    • url: string

    Returns void

  • Removes empty placeholder option (Returns new array)

    Parameters

    Returns SelectOption[]

  • removeOptions<I, O, K>(removeIdentifiers: undefined | I[], options: O[], optIdentifierKey: K): O[]
  • Removes options from options that match identifiers from removeIdentifiers Useful to remove some options from Autocomplete options

    Type parameters

    • I: string | number

    • O: { [ k in string]: I }

    • K: string

    Parameters

    • removeIdentifiers: undefined | I[]
    • options: O[]
    • optIdentifierKey: K

    Returns O[]

  • Generates option nodes for native Select input

    Parameters

    Returns Element[]

  • updateCacheAfterAdd<ObjKey, V, Result, Variables>(apolloCache: DataProxy, query: TypedDocumentNode<Result, Variables>, createdObject: V, options?: { queryVariables?: Variables; toUpdateListName?: ObjKey; unshift?: boolean }): void
  • Updates cache of a query by adding createdObject to the query. Used after mutation that creates/adds a new object.

    Type parameters

    • ObjKey: string

    • V

    • Result: CacheResultValues<ObjKey, V>

    • Variables

    Parameters

    • apolloCache: DataProxy

      Can be found in mutation update method parameter

    • query: TypedDocumentNode<Result, Variables>

      The query result cache which needs to be updated. This query should return a List of objects or if toUpdateListName is specified, query should return with object with toUpdateListName that has array value

    • createdObject: V

      Created object to add to query result

    • Optional options: { queryVariables?: Variables; toUpdateListName?: ObjKey; unshift?: boolean }

      Optional config options

      • Optional queryVariables?: Variables

        Query variables used on the query

      • Optional toUpdateListName?: ObjKey

        If the cache array we want to update is nested inside query data

      • Optional unshift?: boolean

        Moves createdObject to the begging of the query result instead of the end

    Returns void

  • updateCacheAfterRemove<ObjKey, V, Result, Variables>(apolloCache: DataProxy, query: TypedDocumentNode<Result, Variables>, deleteId: string, options?: { queryVariables?: Variables; toUpdateListName?: ObjKey }): void
  • Updates cache of a query by deleting object with deleteId from the query. Used after mutation that deletes/removes an object.

    Type parameters

    • ObjKey: string

    • V: { _id: string }

    • Result: CacheResultValues<ObjKey, V>

    • Variables

    Parameters

    • apolloCache: DataProxy

      Can be found in mutation update method parameter

    • query: TypedDocumentNode<Result, Variables>

      The query result cache which needs to be updated. This query should return a List of objects or if toUpdateListName is specified, query should return with object with toUpdateListName that has array value

    • deleteId: string

      Id of deleted object to remove from query result

    • Optional options: { queryVariables?: Variables; toUpdateListName?: ObjKey }

      Optional config options

      • Optional queryVariables?: Variables

        Query variables used on the query

      • Optional toUpdateListName?: ObjKey

        If the cache array we want to update is nested inside query data

    Returns void

  • withStyles<C, Props, CssObjectByRuleName>(Component: C, cssObjectByRuleNameOrGetCssObjectByRuleName: (CssObjectByRuleName & {}) | ((theme: Theme, props: Props, classes: Record<Exclude<keyof CssObjectByRuleName, `@media${string}`>, string>) => CssObjectByRuleName), params?: { name?: string | Record<string, unknown>; uniqId?: string }): C extends keyof ReactHTML ? ReactHTML[C] : C
  • Type parameters

    • C: keyof ReactHTML | ReactComponent<any>

    • Props: any

    • CssObjectByRuleName: ({ root: CSSObject } & {}) | ({} & {})

    Parameters

    • Component: C
    • cssObjectByRuleNameOrGetCssObjectByRuleName: (CssObjectByRuleName & {}) | ((theme: Theme, props: Props, classes: Record<Exclude<keyof CssObjectByRuleName, `@media${string}`>, string>) => CssObjectByRuleName)
    • Optional params: { name?: string | Record<string, unknown>; uniqId?: string }
      • Optional name?: string | Record<string, unknown>
      • Optional uniqId?: string

    Returns C extends keyof ReactHTML ? ReactHTML[C] : C

Generated using TypeDoc