-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6e9d71
commit 44c3fcc
Showing
3 changed files
with
71 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { createContext, PropsWithChildren } from 'react'; | ||
import { merge } from 'lodash'; | ||
|
||
export type StringFieldI18n = { | ||
required: string; | ||
minLength: (length: number) => string; | ||
maxLength: (length: number) => string; | ||
}; | ||
|
||
export const defaultStringFieldI18n: StringFieldI18n = { | ||
required: 'Field is required', | ||
minLength: (minLength: number) => `String should not include less than ${minLength} character(s)`, | ||
maxLength: (maxLength: number) => `String should not include more than ${maxLength} character(s)`, | ||
}; | ||
|
||
export const StringFieldI18nContext = createContext<StringFieldI18n>(defaultStringFieldI18n); | ||
|
||
export type StringFieldI18nContextProviderProps = PropsWithChildren<{ i18n?: Partial<StringFieldI18n> }>; | ||
|
||
export const StringFieldI18nContextProvider = ({ i18n, children }: StringFieldI18nContextProviderProps) => { | ||
return ( | ||
<StringFieldI18nContext.Provider value={merge(defaultStringFieldI18n, i18n)}> | ||
{children} | ||
</StringFieldI18nContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters