react-buildkit
Version:
React BuildKit - A comprehensive TypeScript utility library for React applications with Capacitor integration for cross-platform mobile development. Provides helper functions, hooks, form validation, storage utilities, and more.
577 lines (543 loc) • 19.7 kB
TypeScript
export { default as ZClassNames } from 'classnames';
import { FormikHelpers, FormikState, FormikErrors } from 'formik';
export { FieldArray as ZFieldArray, Formik as ZFormik, Form as ZFormikForm, useFormikContext as useZFormikContext } from 'formik';
export { default as ZDropzone, Accept as ZDropzoneAccept, useDropzone as useZDropzone } from 'react-dropzone';
import React, { CSSProperties } from 'react';
import { JSX } from 'react/jsx-runtime';
import * as _capacitor_geolocation from '@capacitor/geolocation';
import * as _capacitor_clipboard from '@capacitor/clipboard';
declare const configureZRTK: (options: {}) => void;
declare enum ToastDurationEnum {
long = "long",
short = "short"
}
declare enum ToastPositionEnum {
top = "top",
bottom = "bottom",
center = "center"
}
declare enum ResponseCodeEnum {
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NO_CONTENT = 204,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
CONFLICT = 409,
UNPROCESSABLE_ENTITY = 422,
TOO_MANY_REQUESTS = 429,
INTERNAL_SERVER_ERROR = 500,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504
}
declare enum ResponseStatusEnum {
SUCCESS = "success",
ERROR = "error",
WARNING = "warning",
INFO = "info"
}
declare enum LinkTargetEnum {
BLANK = "_blank",
SELF = "_self",
PARENT = "_parent",
TOP = "_top"
}
declare enum SearchParamKeysEnum {
PAGE = "page",
LIMIT = "limit",
SEARCH = "search",
SORT = "sort",
ORDER = "order",
FILTER = "filter",
FROM = "from",
TO = "to",
STATUS = "status",
TYPE = "type",
CATEGORY = "category",
TAB = "tab",
VIEW = "view",
MODE = "mode",
ID = "id",
QUERY = "q",
encryptedDataSearchParam = "data"
}
declare const ztkMessages: {
general: {
loading: string;
error: string;
success: string;
warning: string;
info: string;
confirm: string;
cancel: string;
yes: string;
no: string;
ok: string;
close: string;
save: string;
delete: string;
edit: string;
add: string;
remove: string;
submit: string;
reset: string;
back: string;
next: string;
previous: string;
finish: string;
};
errors: {
required: string;
invalid: string;
network: string;
server: string;
notFound: string;
unauthorized: string;
forbidden: string;
validation: string;
unknown: string;
};
validation: {
email: string;
phone: string;
url: string;
password: string;
confirmPassword: string;
min: string;
max: string;
minLength: string;
maxLength: string;
pattern: string;
};
};
declare enum zValidationRuleE {
string = "string",
username = "username",
email = "email",
password = "password",
confirm_password = "confirm_password",
url = "url",
phoneNumber = "phoneNumber",
otp = "otp",
accountId = "accountId",
subject = "subject",
message = "message",
linkTitle = "linkTitle"
}
declare enum CONTAINS {
number = "number",
letter = "letter",
specialSymbol = "specialSymbol",
minCharacter = "minCharacter"
}
declare enum ReactToastifyTypeEnum {
info = "info",
success = "success",
warning = "warning",
error = "error",
default = "default"
}
declare enum TableIdsEnum {
id = "tableIdCol",
title = "tableTitleCol",
description = "tableDescriptionCol",
image = "tableImageCol",
status = "tableStatusCol",
amount = "tableAmountCol",
actions = "tableActionsCol",
createdAt = "tableCreatedAtCol",
transferMethod = "tableTransferMethodCol",
receptScreenshot = "tableReceptScreenshotCol",
name = "tableNameCol",
email = "tableEmailCol",
phoneNumber = "tablePhoneNumberCol",
city = "tableCityCol",
role = "tableRoleCol",
country = "tableCountryCol",
referralCode = "tableReferralCodeCol",
withdrawOptions = "tableWithdrawOptionsCol",
isBlocked = "tableIsBlockedCol",
maxPlayersAllowed = "tableMaxPlayersAllowedCol",
minPlayersToStartGame = "tableMinPlayersToStartGameCol",
feePerPlayer = "tableFeePerPlayerCol",
serviceCharges = "tableServiceChargesCol",
engagerServiceCharges = "tableEngagerServiceChargesCol",
roomCode = "tableRoomCodeCol",
gameTitle = "tableGameTitleCol",
private = "tablePrivateCol",
visibility = "tableVisibilityCol",
playersCount = "tablePlayersCountCol",
willStartAt = "tableWillStartAtCol",
capacity = "capacity",
poolValue = "poolValue",
sendTo = "tableSendToCol",
sendAt = "tableSendAtCol",
agentRemarks = "tableAgentRemarksCol",
playerData = "tablePlayerDataCol",
requestAt = "tableRequestAtCol",
playerPhoneNumber = "tablePlayerPhoneNumberCol",
transferAt = "tableTransferAtCol",
requestedAt = "tableRequestedAtCol",
playerEmail = "tablePlayerEmailCol",
roleIdentifier = "roleIdentifier",
isDefault = "isDefault",
gameType = "tableGameTypeCol"
}
type ZFormikHelpers<Value> = FormikHelpers<Value>;
type zSetFieldErrorType = (field: string, message: string | undefined) => void;
type zSetFieldValueType = (field: string, value: unknown, shouldValidate?: boolean | undefined) => Promise<void | FormikErrors<unknown>>;
type zResetFormType<T> = (nextState?: Partial<FormikState<T>> | undefined) => void;
interface ZReactStarsProps {
className?: string;
edit?: boolean;
value?: number;
count?: number;
size?: number;
color1?: string;
color2?: string;
hoverColor?: string;
onChange?: (value: number) => void;
disabled?: boolean;
}
interface IStar {
active: boolean;
hover: boolean;
}
declare const parentStyles: CSSProperties;
declare const defaultStyles: CSSProperties;
declare const disabledStyles: CSSProperties;
declare const StarIcon: ({ fill, size, }: {
fill: string;
size: number;
}) => JSX.Element;
declare const ZReactStars: React.FC<ZReactStarsProps>;
interface IApiResponseResult<T> {
data?: T;
authToken?: string;
dataList?: T;
}
interface IApiResponse<T> {
errors: Record<string, string> | null;
result: IApiResponseResult<T> | null;
message: string;
success: boolean;
status: ResponseStatusEnum;
code: ResponseCodeEnum;
}
interface useZMediaQueryScaleReturnInterface {
is2XlScale: boolean;
isBelowXlScale: boolean;
isBelow2XlScale: boolean;
isXlScale: boolean;
isLgScale: boolean;
isBelowLgScale: boolean;
isMdScale: boolean;
is768Scale: boolean;
isBelow768Scale: boolean;
isBelowMdScale: boolean;
isSmScale: boolean;
isBelowSmScale: boolean;
isXsScale: boolean;
isBelowXsScale: boolean;
is1300pxScale: boolean;
is1200pxScale: boolean;
is1250pxScale: boolean;
is1150pxScale: boolean;
is1100pxScale: boolean;
is900pxScale: boolean;
isBelow900pxScale: boolean;
}
interface ZFilterOptions {
search?: string;
showAll?: string;
itemPerPage: number;
currentPage: number;
keyValueFilter?: Record<string, any>;
}
interface ZPaginationInfoI {
from?: number;
to?: number;
range?: Array<string | number>;
currentPage: number;
canGoPrevious: boolean;
canGoNext: boolean;
pages?: number;
}
interface IUser {
id: string;
name?: string;
email?: string;
createdAt?: string;
updatedAt?: string;
}
declare const isCapAndroid: boolean;
declare const isCapIOS: boolean;
declare const isCapWeb: boolean;
declare const isCapMobileApp: boolean;
declare const isHybrid: boolean;
declare const LOCALSTORAGE_KEYS: {
readonly userData: "8f3j3ff-f-3ff3f";
readonly userAuthToken: "d7fgf33--3-3--3";
readonly resetPassword: "rtogorg4--de-3-02";
};
declare const APP_ROUTES: {
readonly wildCard: "*";
readonly rootRoute: "/";
readonly home: "/home";
readonly register: "/register";
readonly login: "/login";
readonly myAccount: "/my-account";
readonly resetPassword: "/forget-password";
};
declare const API_URLS: {
readonly register: "/register";
readonly login: "/login";
readonly logout: "/logout";
readonly getUserData: "/getUserData";
readonly updateUserData: "/updateUserData";
readonly updateUserStatus: "/updateUserStatus";
};
declare const developerDetails: {
readonly portfolioWebsite: "https://aoneahsan.com";
readonly updatedResume: "https://aoneahsan.com/resume";
readonly updatedCV: "https://aoneahsan.com/cv";
readonly linkedinProfile: "https://linkedin.com/in/aoneahsan";
readonly githubProfile: "https://github.com/aoneahsan";
};
declare const defaultValues: {
minCharacter: number;
};
declare const mediaScales: {
readonly brackpoint_2xl: "1550px";
readonly brackpoint_xl: "1439px";
readonly brackpoint_lg: "1100px";
readonly brackpoint_md: "668px";
readonly brackpoint_sm: "500px";
readonly brackpoint_xs: "350px";
};
declare const fiveMinutesInMileSeconds: number;
declare const reactQueryOptions: {
readonly staleTime: {
readonly fiveMinutes: typeof fiveMinutesInMileSeconds;
};
};
declare const showToast: (message?: string, options?: {
duration?: ToastDurationEnum;
position?: ToastPositionEnum;
[key: string]: any;
}) => Promise<void>;
declare const BROWSER: {
open: (url: string, options?: {
target?: LinkTargetEnum;
windowName?: string;
toolbarColor?: string;
presentationStyle?: "fullscreen" | "popover";
width?: number;
height?: number;
[key: string]: any;
}) => Promise<void>;
};
interface StorageOptions {
encrypt?: boolean;
group?: string;
}
declare const STORAGE: {
get: (key: string, options?: StorageOptions) => Promise<any | null>;
set: (key: string, data: unknown, options?: StorageOptions) => Promise<void>;
remove: (key: string, options?: StorageOptions) => Promise<void>;
clear: (options?: StorageOptions) => Promise<void>;
};
interface ZAlertOptions {
title?: string;
message?: string;
buttonTitle?: string;
[key: string]: any;
}
declare const showZAlert: (options?: ZAlertOptions) => Promise<void>;
interface ZConfirmOptions {
title?: string;
message?: string;
okButtonTitle?: string;
cancelButtonTitle?: string;
[key: string]: any;
}
declare const showZConfirm: (options?: ZConfirmOptions) => Promise<{
value: boolean;
}>;
interface ZPromptOptions {
title?: string;
message?: string;
okButtonTitle?: string;
cancelButtonTitle?: string;
inputPlaceholder?: string;
inputText?: string;
[key: string]: any;
}
declare const showZPrompt: (options?: ZPromptOptions) => Promise<{
value: string;
cancelled: boolean;
}>;
interface ZClipboardWriteOptions {
string?: string;
image?: string;
url?: string;
label?: string;
[key: string]: any;
}
declare const zWriteToClipboard: (value?: string | ZClipboardWriteOptions) => Promise<void>;
declare const zCheckClipboard: () => Promise<_capacitor_clipboard.ReadResult>;
interface ZGeolocationOptions {
enableHighAccuracy?: boolean;
timeout?: number;
maximumAge?: number;
[key: string]: any;
}
declare const zGetCurrentPosition: (options?: ZGeolocationOptions) => Promise<_capacitor_geolocation.Position>;
declare const zCheckPermissions: () => Promise<_capacitor_geolocation.PermissionStatus>;
declare const formatFormErrorsFromApiResponse: (errors: Record<string, string> | null) => Record<string, string> | null;
declare const checkIfContains: (val: string, contains?: CONTAINS, minCharacter?: number) => boolean;
interface ValidateFieldOptions {
messages?: {
required?: string;
email?: string;
password?: {
minLength?: string;
needsNumber?: string;
needsLetter?: string;
needsSpecialChar?: string;
};
url?: string;
phoneNumber?: string;
otp?: string;
};
minCharacter?: number;
customValidator?: (value: string) => string | undefined;
}
declare const validateField: (fieldKey: string, values: Record<string, unknown>, errorsObj: Record<string, unknown>, validationRule?: zValidationRuleE, options?: ValidateFieldOptions) => void;
declare const validateFields: (fieldKeys: string[], values: Record<string, unknown>, errorsObj: Record<string, unknown>, validationRules: zValidationRuleE[], options?: ValidateFieldOptions) => void;
declare const truncateText: (str?: string, length?: number) => string;
declare const getRandomId: () => string;
declare const toTitleCase: (str: string) => string;
interface ZPaginateOptions {
delta?: number;
dotsString?: string;
showBoundaries?: boolean;
}
declare const ZPaginate: (current: number, total: number, options?: ZPaginateOptions) => {
range: number[];
rangeWithDots: Array<string | number>;
};
declare const ZFilterData: <T>({ data, filters, searchKey, caseSensitive, }: {
data: T;
filters: Partial<ZFilterOptions>;
searchKey?: string | string[];
caseSensitive?: boolean;
}) => Array<(T & unknown[])[number]>;
declare const ZFilterAndPaginateData: <T>({ data, filters, searchKey, }: {
data: T;
filters: ZFilterOptions;
searchKey?: string | string[];
}) => {
_data: Array<(T & unknown[])[number]> | null;
_paginationInfo: ZPaginationInfoI;
};
declare const clearAuthDataFromLocalStorage: () => Promise<void>;
declare const setAuthDataInLocalStorage: ({ userData, authToken, }: {
userData?: IUser;
authToken?: string;
}) => Promise<void>;
declare const getAuthTokenFromLocalStorage: () => Promise<string | null>;
declare const getAuthDataFromLocalStorage: () => Promise<{
userData: IUser | null;
authToken: string | null;
} | null>;
interface SetSearchParamsOptions {
encrypt?: boolean;
paramKey?: string;
}
declare const setSearchParamsData: (data: unknown, setSearchParams: (nextInit?: any, navigateOpts?: undefined) => void, options?: SetSearchParamsOptions) => void;
interface GetSearchParamsOptions {
encrypt?: boolean;
paramKey?: string;
}
declare const getSearchParamsData: <T>(searchParams: URLSearchParams, options?: GetSearchParamsOptions) => T | null;
declare const addQueryParamsInUrl: (url: string, queryParams: Record<string, string> | null) => string;
declare const formatRoutesMatchResult: (routesMatch: string[] | undefined) => {
isLoginRoute: boolean;
isRegisterRoute: boolean;
isHomeRoute: boolean;
isMyAccountRoute: boolean;
} | {
isLoginRoute?: undefined;
isRegisterRoute?: undefined;
isHomeRoute?: undefined;
isMyAccountRoute?: undefined;
};
declare const getTestingAttribute: (selector: string, listItemSelector?: string) => Record<string, string>;
interface MediaQueryScaleOptions {
breakpoints?: {
brackpoint_2xl?: string;
brackpoint_xl?: string;
brackpoint_lg?: string;
brackpoint_md?: string;
brackpoint_sm?: string;
brackpoint_xs?: string;
};
customBreakpoints?: Record<string, string>;
queryOptions?: {
orientation?: 'portrait' | 'landscape';
scan?: 'progressive' | 'interlace';
aspectRatio?: string;
deviceAspectRatio?: string;
[key: string]: any;
};
}
declare const useZMediaQueryScale: (options?: MediaQueryScaleOptions) => useZMediaQueryScaleReturnInterface & Record<string, boolean>;
declare const backendApi: {
readonly invalidUserData: "invalid user data";
};
declare const formValidations: {
readonly urlIncorrectFormate: "Please enter a valid URL! like (https://yourlink.com) or (http://yourlink.com).";
readonly phoneNumberRequired: "Phone number is require.";
readonly passwordNotMatch: "Password does not match. please try again!";
readonly currency: "currency is required.";
readonly resendCodeLimitExceeded: "Attempt limit exceeded, please try after some time.";
readonly resendCodeSuccess: "Confirmation code resent successfully.";
readonly urlNotValid: "Should be a valid URL";
};
declare const generic: {
readonly registerSuccessfully: "Register successfully :)";
readonly loginSuccessfully: "Login successfully :)";
readonly copied: "Copied";
};
declare const user: {
readonly deletedSuccessfully: "User deleted successfully.";
readonly blockSuccessfully: "User block successfully.";
readonly updatedSuccessfully: "User updated successfully.";
readonly createdSuccessfully: "User created successfully.";
readonly unBlockSuccessfully: "User unblock successfully.";
readonly notFound: "User not found.";
readonly noIdProvided: "No user id provided!";
};
declare const zrtkMessages: {
readonly formValidations: typeof formValidations;
readonly generic: typeof generic;
readonly backendApi: typeof backendApi;
readonly user: typeof user;
};
declare const reportError: (error: unknown, message?: string, showInConsole?: boolean) => void;
declare function encryptData(data: any, secretKey?: string): string;
declare function decryptData(encryptedData: string, secretKey?: string, parseJSON?: boolean): any;
declare function hashData(data: string): string;
declare function generateSecretKey(length?: number): string;
declare function checkForDuplicateEnumValues(enumObj: Record<string, any>, enumName: string): void;
declare function convertToTitleCase(str: string): string;
declare function validateEmail(email: string): boolean;
declare function validatePhoneNumber(phoneNumber: string): boolean;
declare function validateURL(url: string): boolean;
declare function ZTotalPages(totalCount: number, pageSize: number): number;
export { API_URLS, APP_ROUTES, BROWSER, CONTAINS, type GetSearchParamsOptions, type IApiResponse, type IApiResponseResult, type IStar, type IUser, LOCALSTORAGE_KEYS, LinkTargetEnum, type MediaQueryScaleOptions, ReactToastifyTypeEnum, ResponseCodeEnum, ResponseStatusEnum, STORAGE, SearchParamKeysEnum, type SetSearchParamsOptions, StarIcon, type StorageOptions, TableIdsEnum, ToastDurationEnum, ToastPositionEnum, type ValidateFieldOptions, type ZAlertOptions, type ZClipboardWriteOptions, type ZConfirmOptions, ZFilterAndPaginateData, ZFilterData, type ZFilterOptions, type ZFormikHelpers, type ZGeolocationOptions, ZPaginate, type ZPaginateOptions, type ZPaginationInfoI, type ZPromptOptions, ZReactStars, type ZReactStarsProps, ZTotalPages, addQueryParamsInUrl, checkForDuplicateEnumValues, checkIfContains, clearAuthDataFromLocalStorage, configureZRTK, convertToTitleCase, decryptData, defaultStyles, defaultValues, developerDetails, disabledStyles, encryptData, formatFormErrorsFromApiResponse, formatRoutesMatchResult, generateSecretKey, getAuthDataFromLocalStorage, getAuthTokenFromLocalStorage, getRandomId, getSearchParamsData, getTestingAttribute, hashData, isCapAndroid, isCapIOS, isCapMobileApp, isCapWeb, isHybrid, mediaScales, parentStyles, reactQueryOptions, reportError, setAuthDataInLocalStorage, setSearchParamsData, showToast, showZAlert, showZConfirm, showZPrompt, toTitleCase, truncateText, useZMediaQueryScale, type useZMediaQueryScaleReturnInterface, validateEmail, validateField, validateFields, validatePhoneNumber, validateURL, zCheckClipboard, zCheckPermissions, zGetCurrentPosition, type zResetFormType, type zSetFieldErrorType, type zSetFieldValueType, zValidationRuleE, zWriteToClipboard, zrtkMessages, ztkMessages };