@skbkontur/react-ui 4.5.3 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/cjs/components/CurrencyInput/CurrencyHelper.js +1 -1
  3. package/cjs/components/CurrencyInput/CurrencyHelper.js.map +1 -1
  4. package/cjs/components/CurrencyInput/constants.d.ts +3 -0
  5. package/cjs/components/CurrencyInput/constants.js +6 -2
  6. package/cjs/components/CurrencyInput/constants.js.map +1 -1
  7. package/cjs/components/CurrencyLabel/CurrencyLabel.d.ts +3 -1
  8. package/cjs/components/CurrencyLabel/CurrencyLabel.js +6 -3
  9. package/cjs/components/CurrencyLabel/CurrencyLabel.js.map +1 -1
  10. package/cjs/components/CurrencyLabel/CurrencyLabel.md +6 -0
  11. package/cjs/components/DropdownMenu/DropdownMenu.md +38 -0
  12. package/cjs/components/Input/Input.js +6 -1
  13. package/cjs/components/Input/Input.js.map +1 -1
  14. package/cjs/components/MenuItem/MenuItem.d.ts +6 -0
  15. package/cjs/components/MenuItem/MenuItem.js +12 -2
  16. package/cjs/components/MenuItem/MenuItem.js.map +1 -1
  17. package/cjs/components/SidePage/SidePage.d.ts +5 -0
  18. package/cjs/components/SidePage/SidePage.js +9 -1
  19. package/cjs/components/SidePage/SidePage.js.map +1 -1
  20. package/cjs/components/SidePage/SidePageBody.d.ts +1 -0
  21. package/cjs/components/SidePage/SidePageBody.js +11 -6
  22. package/cjs/components/SidePage/SidePageBody.js.map +1 -1
  23. package/cjs/internal/InternalMenu/InternalMenu.d.ts +1 -0
  24. package/cjs/internal/InternalMenu/InternalMenu.js +24 -8
  25. package/cjs/internal/InternalMenu/InternalMenu.js.map +1 -1
  26. package/cjs/internal/InternalMenu/InternalMenu.styles.d.ts +5 -4
  27. package/cjs/internal/InternalMenu/InternalMenu.styles.js +14 -18
  28. package/cjs/internal/InternalMenu/InternalMenu.styles.js.map +1 -1
  29. package/cjs/lib/utils.d.ts +1 -1
  30. package/cjs/lib/utils.js +2 -3
  31. package/cjs/lib/utils.js.map +1 -1
  32. package/components/CurrencyInput/CurrencyHelper/CurrencyHelper.js +3 -3
  33. package/components/CurrencyInput/CurrencyHelper/CurrencyHelper.js.map +1 -1
  34. package/components/CurrencyInput/constants/constants.js +4 -1
  35. package/components/CurrencyInput/constants/constants.js.map +1 -1
  36. package/components/CurrencyInput/constants.d.ts +3 -0
  37. package/components/CurrencyLabel/CurrencyLabel/CurrencyLabel.js +5 -2
  38. package/components/CurrencyLabel/CurrencyLabel/CurrencyLabel.js.map +1 -1
  39. package/components/CurrencyLabel/CurrencyLabel.d.ts +3 -1
  40. package/components/CurrencyLabel/CurrencyLabel.md +6 -0
  41. package/components/DropdownMenu/DropdownMenu.md +38 -0
  42. package/components/Input/Input/Input.js +18 -5
  43. package/components/Input/Input/Input.js.map +1 -1
  44. package/components/MenuItem/MenuItem/MenuItem.js +7 -2
  45. package/components/MenuItem/MenuItem/MenuItem.js.map +1 -1
  46. package/components/MenuItem/MenuItem.d.ts +6 -0
  47. package/components/SidePage/SidePage/SidePage.js +10 -6
  48. package/components/SidePage/SidePage/SidePage.js.map +1 -1
  49. package/components/SidePage/SidePage.d.ts +5 -0
  50. package/components/SidePage/SidePageBody/SidePageBody.js +9 -1
  51. package/components/SidePage/SidePageBody/SidePageBody.js.map +1 -1
  52. package/components/SidePage/SidePageBody.d.ts +1 -0
  53. package/internal/InternalMenu/InternalMenu/InternalMenu.js +24 -6
  54. package/internal/InternalMenu/InternalMenu/InternalMenu.js.map +1 -1
  55. package/internal/InternalMenu/InternalMenu.d.ts +1 -0
  56. package/internal/InternalMenu/InternalMenu.styles/InternalMenu.styles.js +13 -10
  57. package/internal/InternalMenu/InternalMenu.styles/InternalMenu.styles.js.map +1 -1
  58. package/internal/InternalMenu/InternalMenu.styles.d.ts +5 -4
  59. package/lib/utils/utils.js +0 -1
  60. package/lib/utils/utils.js.map +1 -1
  61. package/lib/utils.d.ts +1 -1
  62. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["utils.ts"],"names":["React","isForwardRef","isBrowser","delay","ms","Promise","resolve","setTimeout","emptyHandler","CancelationError","code","Error","taskWithDelay","task","cancelationToken","reject","then","isFunction","x","isFunctionalComponent","Component","Boolean","prototype","isReactComponent","isClassComponent","isIntrinsicElement","element","type","isRefableElement","escapeRegExpSpecChars","s","replace","getRandomID","Math","random","toString","slice","isExternalLink","link","RegExp","window","location","host","test","isReactUINode","componentName","node","isValidElement","Object","hasOwnProperty","call","__KONTUR_REACT_UI__","KB","UNITS","calculateDecimals","decimals","formatBytes","bytes","calculatedDecimals","i","floor","log2","formattedBytes","parseFloat","pow","toFixed","isNonNullable","value","undefined","isNullable","isReactUIComponent","name","child","mergeRefs","refs","forEach","ref","current","extractDataProps","props","dataProps","restWithoutDataProps","entries","map","startsWith","startsWithOneOf","searchKeys","inputString","keyIndex","findIndex","key"],"mappings":";AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,YAAT,QAA6B,UAA7B;;AAEA,SAASC,SAAT,QAA0B,UAA1B;;AAEA;;;;;;;;;;;;;AAaA,OAAO,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAACC,EAAD,UAAgB,IAAIC,OAAJ,CAAY,UAACC,OAAD,UAAaC,UAAU,CAACD,OAAD,EAAUF,EAAV,CAAvB,EAAZ,CAAhB,EAAd;;AAEP,OAAO,IAAMI,YAAY,GAAG,SAAfA,YAAe,GAAM;AAChC;AACD,CAFM;;AAIP,WAAaC,gBAAb;AACSC,IAAAA,IADT,GACgB,kBADhB,wEAAsCC,KAAtC;;;AAIA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAAyCT,EAAzC,EAAqD;AAC1D,MAAIU,gBAA4B,GAAG,oCAAM,IAAN,EAAnC;;AAEA,MAAIT,OAAJ,CAAY,UAACC,OAAD,EAAUS,MAAV,EAAqB;AAC/BD,IAAAA,gBAAgB,GAAGC,MAAnB;AAC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,GAAD,CAAjB,EAAwB;AAC7B,eAASA,GAAD,CAA0CC,OAA1C,GAAoDV,KAA5D;AACD;AACF,KAND;AAOD,GARD;AASD;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMW,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAIC,KAAJ,EAAiB;AAC/C,MAAMC,SAA8B,GAAG,EAAvC;AACA,MAAMC,oBAAyC,GAAG,EAAlD;;AAEAjC,EAAAA,MAAM,CAACkC,OAAP,CAAeH,KAAf,EAAsBI,GAAtB,CAA0B,gBAAmB,KAAjBZ,IAAiB,WAAXJ,KAAW;AAC3C,QAAII,IAAI,CAACa,UAAL,CAAgB,OAAhB,CAAJ,EAA8B;AAC5B,aAAQJ,SAAS,CAACT,IAAD,CAAT,GAAkBJ,KAA1B;AACD;;AAED,WAAQc,oBAAoB,CAACV,IAAD,CAApB,GAA6BJ,KAArC;AACD,GAND;;AAQA,SAAO,EAAEa,SAAS,EAATA,SAAF,EAAaC,oBAAoB,EAApBA,oBAAb,EAAP;AACD,CAbM;;AAeP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMI,eAAe,GAAG,SAAlBA,eAAkB,CAACC,UAAD,EAAuBC,WAAvB,EAA+C;AAC5E,MAAMC,QAAQ,GAAGF,UAAU,CAACG,SAAX,CAAqB,UAACC,GAAD,EAAS;AAC7C,WAAOH,WAAW,CAACH,UAAZ,CAAuBM,GAAvB,CAAP;AACD,GAFgB,CAAjB;;AAIA,SAAOF,QAAQ,IAAI,CAAnB;AACD,CANM","sourcesContent":["import { ReactComponentLike } from 'prop-types';\nimport React from 'react';\nimport { isForwardRef } from 'react-is';\n\nimport { isBrowser } from './client';\n\n// NOTE: Copy-paste from @types/react\nexport type Defaultize<P, D> = P extends any\n ? string extends keyof P\n ? P\n : Pick<P, Exclude<keyof P, keyof D>> &\n Partial<Pick<P, Extract<keyof P, keyof D>>> &\n Partial<Pick<D, Exclude<keyof D, keyof P>>>\n : never;\n\nexport type DefaultizeProps<C, P> = C extends { defaultProps: infer D } ? Defaultize<P, D> : P;\n\nexport type AnyObject = Record<string, unknown>;\n\nexport const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nexport const emptyHandler = () => {\n /* noop */\n};\n\nexport class CancelationError extends Error {\n public code = 'CancelationError';\n}\n\nexport function taskWithDelay(task: () => void, ms: number) {\n let cancelationToken: () => void = () => null;\n\n new Promise((resolve, reject) => {\n cancelationToken = reject;\n setTimeout(resolve, ms);\n })\n .then(task)\n .catch(() => null);\n\n return cancelationToken;\n}\n\nexport type FunctionWithParams<R = any> = (...args: any[]) => R;\nexport function isFunction<T>(x: T | FunctionWithParams): x is FunctionWithParams {\n return typeof x === 'function';\n}\n\nexport function isFunctionalComponent(Component: ReactComponentLike): boolean {\n return Boolean(typeof Component === 'function' && !(Component.prototype && Component.prototype.isReactComponent));\n}\n\nexport function isClassComponent(Component: ReactComponentLike): boolean {\n return Boolean(typeof Component === 'function' && Component.prototype && Component.prototype.isReactComponent);\n}\n\nexport function isIntrinsicElement(element: React.ReactElement): boolean {\n return typeof element.type === 'string';\n}\n\nexport function isRefableElement(element: React.ReactElement): boolean {\n return Boolean(isIntrinsicElement(element) || isClassComponent(element.type) || isForwardRef(element));\n}\n\nexport function escapeRegExpSpecChars(s: string): string {\n return s.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n\nexport const getRandomID = (): string => Math.random().toString(16).slice(2);\n\nexport const isExternalLink = (link: string): boolean => {\n return new RegExp(`^(https?:)?//${isBrowser ? `(?!${window.location.host})` : ``}\\\\S+`, 'gi').test(link);\n};\n\n/**\n * Check if the given ReactNode is an element of the specified ReactUI component\n */\nexport const isReactUINode = (componentName: string, node: React.ReactNode): boolean => {\n if (React.isValidElement(node)) {\n return (\n Object.prototype.hasOwnProperty.call(node.type, '__KONTUR_REACT_UI__') &&\n // @ts-expect-error: React doesn't know about existence of __KONTUR_REACT_UI__.\n node.type.__KONTUR_REACT_UI__ === componentName\n );\n }\n\n return false;\n};\n\nconst KB = 1024;\nconst UNITS = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\nconst calculateDecimals = (decimals: number) => {\n if (decimals < 0) {\n return 0;\n }\n\n return 0;\n};\n\nexport const formatBytes = (bytes: number, decimals = 2): string | null => {\n if (bytes === 0) {\n return '0 Bytes';\n }\n\n if (!bytes) {\n return null;\n }\n\n const calculatedDecimals = calculateDecimals(decimals);\n\n const i = Math.floor(Math.log2(bytes) / Math.log2(KB));\n const formattedBytes = parseFloat((bytes / Math.pow(KB, i)).toFixed(calculatedDecimals));\n\n return `${formattedBytes} ${UNITS[i]}`;\n};\n\n/**\n * Проверяет, не является ли переданный аргумент null или undefined и исключает типы null и undefined из типа аргумента\n *\n * @param value Значение, которое нужно проверить и исключить из него типы\n * @returns Возвращает true, если переданный аргумент не является null или undefined иначе false\n */\nexport const isNonNullable = <T>(value: T): value is NonNullable<T> => {\n return value !== null && value !== undefined;\n};\n\n/**\n * Checks if the value `null` or `undefined`.\n *\n * @param value Value to check for `null` and `undefined`.\n * @returns Returns `true` if `value` is `null` or `undefined`, else `false`.\n */\n// @ts-expect-error: TypeScript doesn't consider the check inside of the function.\nexport const isNullable = <T>(value: T): value is null | undefined => {\n return value === null || value === undefined;\n};\n\n/**\n * Creates a function that checks if the given `child`\n * is an instance of some component specified by `name`.\n *\n * @param name Component name for which function will be created.\n * @returns A function that checks if the given `child` is an instance of the component specified by `name`.\n */\nexport const isReactUIComponent = <P = any>(name: string) => {\n return (child: React.ReactNode): child is React.ReactElement<P> => {\n // @ts-expect-error: Property `type` doesn't exist on type `React.ReactNode`, but exists on type `React.ReactElement` meanwhile `React.ReactElement` is not compatible with `React` `children` type.\n return child?.type?.__KONTUR_REACT_UI__ === name;\n };\n};\n\n/**\n * Merges two or more refs into one.\n *\n * @param refs Array of refs.\n * @returns A single ref composing all the refs passed.\n *\n * @example\n * const SomeComponent = forwardRef((props, ref) => {\n * const localRef = useRef();\n *\n * return <div ref={mergeRefs([localRef, ref])} />;\n * });\n */\nexport function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (isNonNullable(ref)) {\n return ((ref as React.MutableRefObject<T | null>).current = value);\n }\n });\n };\n}\n\n/**\n * Extracts all data attributes from props and returns them as well as props.\n *\n * @param props Props object to extract data attributes from.\n * @returns Separated data attributes and all other props.\n */\nexport const extractDataProps = <T>(props: T) => {\n const dataProps: Record<string, any> = {};\n const restWithoutDataProps: Record<string, any> = {};\n\n Object.entries(props).map(([name, value]) => {\n if (name.startsWith('data-')) {\n return (dataProps[name] = value);\n }\n\n return (restWithoutDataProps[name] = value);\n });\n\n return { dataProps, restWithoutDataProps };\n};\n\n/**\n * Basically `.startsWith` for arrays.\n *\n * @param searchKeys Array of strings to test against `inputString`.\n * @param inputString String on which search will be performed.\n * @returns `true` if `inputString` starts with one of keys, else `false`.\n */\nexport const startsWithOneOf = (searchKeys: string[], inputString: string) => {\n const keyIndex = searchKeys.findIndex((key) => {\n return inputString.startsWith(key);\n });\n\n return keyIndex >= 0;\n};\n"]}
1
+ {"version":3,"sources":["utils.ts"],"names":["React","isForwardRef","isBrowser","delay","ms","Promise","resolve","setTimeout","emptyHandler","CancelationError","code","Error","taskWithDelay","task","cancelationToken","reject","then","isFunction","x","isFunctionalComponent","Component","Boolean","prototype","isReactComponent","isClassComponent","isIntrinsicElement","element","type","isRefableElement","escapeRegExpSpecChars","s","replace","getRandomID","Math","random","toString","slice","isExternalLink","link","RegExp","window","location","host","test","isReactUINode","componentName","node","isValidElement","Object","hasOwnProperty","call","__KONTUR_REACT_UI__","KB","UNITS","calculateDecimals","decimals","formatBytes","bytes","calculatedDecimals","i","floor","log2","formattedBytes","parseFloat","pow","toFixed","isNonNullable","value","undefined","isNullable","isReactUIComponent","name","child","mergeRefs","refs","forEach","ref","current","extractDataProps","props","dataProps","restWithoutDataProps","entries","map","startsWith","startsWithOneOf","searchKeys","inputString","keyIndex","findIndex","key"],"mappings":";AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,YAAT,QAA6B,UAA7B;;AAEA,SAASC,SAAT,QAA0B,UAA1B;;AAEA;;;;;;;;;;;;;AAaA,OAAO,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAACC,EAAD,UAAgB,IAAIC,OAAJ,CAAY,UAACC,OAAD,UAAaC,UAAU,CAACD,OAAD,EAAUF,EAAV,CAAvB,EAAZ,CAAhB,EAAd;;AAEP,OAAO,IAAMI,YAAY,GAAG,SAAfA,YAAe,GAAM;AAChC;AACD,CAFM;;AAIP,WAAaC,gBAAb;AACSC,IAAAA,IADT,GACgB,kBADhB,wEAAsCC,KAAtC;;;AAIA,OAAO,SAASC,aAAT,CAAuBC,IAAvB,EAAyCT,EAAzC,EAAqD;AAC1D,MAAIU,gBAA4B,GAAG,oCAAM,IAAN,EAAnC;;AAEA,MAAIT,OAAJ,CAAY,UAACC,OAAD,EAAUS,MAAV,EAAqB;AAC/BD,IAAAA,gBAAgB,GAAGC,MAAnB;AACAR,IAAAA,UAAU,CAACD,OAAD,EAAUF,EAAV,CAAV;AACD,GAHD;AAIGY,EAAAA,IAJH,CAIQH,IAJR;AAKS,sBAAM,IAAN,EALT;;AAOA,SAAOC,gBAAP;AACD;;;AAGD,OAAO,SAASG,UAAT,CAAuBC,CAAvB,EAA2E;AAChF,SAAO,OAAOA,CAAP,KAAa,UAApB;AACD;;AAED,OAAO,SAASC,qBAAT,CAA+BC,SAA/B,EAAuE;AAC5E,SAAOC,OAAO,CAAC,OAAOD,SAAP,KAAqB,UAArB,IAAmC,EAAEA,SAAS,CAACE,SAAV,IAAuBF,SAAS,CAACE,SAAV,CAAoBC,gBAA7C,CAApC,CAAd;AACD;;AAED,OAAO,SAASC,gBAAT,CAA0BJ,SAA1B,EAAkE;AACvE,SAAOC,OAAO,CA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AAED,WAAQc,oBAAoB,CAACV,IAAD,CAApB,GAA6BJ,KAArC;AACD,GAND;;AAQA,SAAO,EAAEa,SAAS,EAATA,SAAF,EAAaC,oBAAoB,EAApBA,oBAAb,EAAP;AACD,CAbM;;AAeP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMI,eAAe,GAAG,SAAlBA,eAAkB,CAACC,UAAD,EAAuBC,WAAvB,EAA+C;AAC5E,MAAMC,QAAQ,GAAGF,UAAU,CAACG,SAAX,CAAqB,UAACC,GAAD,EAAS;AAC7C,WAAOH,WAAW,CAACH,UAAZ,CAAuBM,GAAvB,CAAP;AACD,GAFgB,CAAjB;;AAIA,SAAOF,QAAQ,IAAI,CAAnB;AACD,CANM","sourcesContent":["import { ReactComponentLike } from 'prop-types';\nimport React from 'react';\nimport { isForwardRef } from 'react-is';\n\nimport { isBrowser } from './client';\n\n// NOTE: Copy-paste from @types/react\nexport type Defaultize<P, D> = P extends any\n ? string extends keyof P\n ? P\n : Pick<P, Exclude<keyof P, keyof D>> &\n Partial<Pick<P, Extract<keyof P, keyof D>>> &\n Partial<Pick<D, Exclude<keyof D, keyof P>>>\n : never;\n\nexport type DefaultizeProps<C, P> = C extends { defaultProps: infer D } ? Defaultize<P, D> : P;\n\nexport type AnyObject = Record<string, unknown>;\n\nexport const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nexport const emptyHandler = () => {\n /* noop */\n};\n\nexport class CancelationError extends Error {\n public code = 'CancelationError';\n}\n\nexport function taskWithDelay(task: () => void, ms: number) {\n let cancelationToken: () => void = () => null;\n\n new Promise((resolve, reject) => {\n cancelationToken = reject;\n setTimeout(resolve, ms);\n })\n .then(task)\n .catch(() => null);\n\n return cancelationToken;\n}\n\nexport type FunctionWithParams<R = any> = (...args: any[]) => R;\nexport function isFunction<T>(x: T | FunctionWithParams): x is FunctionWithParams {\n return typeof x === 'function';\n}\n\nexport function isFunctionalComponent(Component: ReactComponentLike): boolean {\n return Boolean(typeof Component === 'function' && !(Component.prototype && Component.prototype.isReactComponent));\n}\n\nexport function isClassComponent(Component: ReactComponentLike): boolean {\n return Boolean(typeof Component === 'function' && Component.prototype && Component.prototype.isReactComponent);\n}\n\nexport function isIntrinsicElement(element: React.ReactElement): boolean {\n return typeof element.type === 'string';\n}\n\nexport function isRefableElement(element: React.ReactElement): boolean {\n return Boolean(isIntrinsicElement(element) || isClassComponent(element.type) || isForwardRef(element));\n}\n\nexport function escapeRegExpSpecChars(s: string): string {\n return s.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n}\n\nexport const getRandomID = (): string => Math.random().toString(16).slice(2);\n\nexport const isExternalLink = (link: string): boolean => {\n return new RegExp(`^(https?:)?//${isBrowser ? `(?!${window.location.host})` : ``}\\\\S+`, 'gi').test(link);\n};\n\n/**\n * Check if the given ReactNode is an element of the specified ReactUI component\n */\nexport const isReactUINode = (componentName: string, node: React.ReactNode): boolean => {\n if (React.isValidElement(node)) {\n return (\n Object.prototype.hasOwnProperty.call(node.type, '__KONTUR_REACT_UI__') &&\n // @ts-expect-error: React doesn't know about existence of __KONTUR_REACT_UI__.\n node.type.__KONTUR_REACT_UI__ === componentName\n );\n }\n\n return false;\n};\n\nconst KB = 1024;\nconst UNITS = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\nconst calculateDecimals = (decimals: number) => {\n if (decimals < 0) {\n return 0;\n }\n\n return 0;\n};\n\nexport const formatBytes = (bytes: number, decimals = 2): string | null => {\n if (bytes === 0) {\n return '0 Bytes';\n }\n\n if (!bytes) {\n return null;\n }\n\n const calculatedDecimals = calculateDecimals(decimals);\n\n const i = Math.floor(Math.log2(bytes) / Math.log2(KB));\n const formattedBytes = parseFloat((bytes / Math.pow(KB, i)).toFixed(calculatedDecimals));\n\n return `${formattedBytes} ${UNITS[i]}`;\n};\n\n/**\n * Проверяет, не является ли переданный аргумент null или undefined и исключает типы null и undefined из типа аргумента\n *\n * @param value Значение, которое нужно проверить и исключить из него типы\n * @returns Возвращает true, если переданный аргумент не является null или undefined иначе false\n */\nexport const isNonNullable = <T>(value: T): value is NonNullable<T> => {\n return value !== null && value !== undefined;\n};\n\n/**\n * Checks if the value `null` or `undefined`.\n *\n * @param value Value to check for `null` and `undefined`.\n * @returns Returns `true` if `value` is `null` or `undefined`, else `false`.\n */\nexport const isNullable = (value: unknown): value is null | undefined => {\n return value === null || value === undefined;\n};\n\n/**\n * Creates a function that checks if the given `child`\n * is an instance of some component specified by `name`.\n *\n * @param name Component name for which function will be created.\n * @returns A function that checks if the given `child` is an instance of the component specified by `name`.\n */\nexport const isReactUIComponent = <P = any>(name: string) => {\n return (child: React.ReactNode): child is React.ReactElement<P> => {\n // @ts-expect-error: Property `type` doesn't exist on type `React.ReactNode`, but exists on type `React.ReactElement` meanwhile `React.ReactElement` is not compatible with `React` `children` type.\n return child?.type?.__KONTUR_REACT_UI__ === name;\n };\n};\n\n/**\n * Merges two or more refs into one.\n *\n * @param refs Array of refs.\n * @returns A single ref composing all the refs passed.\n *\n * @example\n * const SomeComponent = forwardRef((props, ref) => {\n * const localRef = useRef();\n *\n * return <div ref={mergeRefs([localRef, ref])} />;\n * });\n */\nexport function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n return ref(value);\n } else if (isNonNullable(ref)) {\n return ((ref as React.MutableRefObject<T | null>).current = value);\n }\n });\n };\n}\n\n/**\n * Extracts all data attributes from props and returns them as well as props.\n *\n * @param props Props object to extract data attributes from.\n * @returns Separated data attributes and all other props.\n */\nexport const extractDataProps = <T>(props: T) => {\n const dataProps: Record<string, any> = {};\n const restWithoutDataProps: Record<string, any> = {};\n\n Object.entries(props).map(([name, value]) => {\n if (name.startsWith('data-')) {\n return (dataProps[name] = value);\n }\n\n return (restWithoutDataProps[name] = value);\n });\n\n return { dataProps, restWithoutDataProps };\n};\n\n/**\n * Basically `.startsWith` for arrays.\n *\n * @param searchKeys Array of strings to test against `inputString`.\n * @param inputString String on which search will be performed.\n * @returns `true` if `inputString` starts with one of keys, else `false`.\n */\nexport const startsWithOneOf = (searchKeys: string[], inputString: string) => {\n const keyIndex = searchKeys.findIndex((key) => {\n return inputString.startsWith(key);\n });\n\n return keyIndex >= 0;\n};\n"]}
package/lib/utils.d.ts CHANGED
@@ -38,7 +38,7 @@ export declare const isNonNullable: <T>(value: T) => value is NonNullable<T>;
38
38
  * @param value Value to check for `null` and `undefined`.
39
39
  * @returns Returns `true` if `value` is `null` or `undefined`, else `false`.
40
40
  */
41
- export declare const isNullable: <T>(value: T) => value is null | undefined;
41
+ export declare const isNullable: (value: unknown) => value is null | undefined;
42
42
  /**
43
43
  * Creates a function that checks if the given `child`
44
44
  * is an instance of some component specified by `name`.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui",
3
- "version": "4.5.3",
3
+ "version": "4.6.0",
4
4
  "description": "UI Components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "index.js",
7
7
  "sideEffects": false,
8
- "homepage": "https://tech.skbkontur.ru/react-ui/4.5.3/",
8
+ "homepage": "https://tech.skbkontur.ru/react-ui/4.6.0/",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git@github.com:skbkontur/retail-ui.git"