@toptal/picasso-utils 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-ca4ef823d.4082 → 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-25389459e.4083
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.
- package/dist-package/tsconfig.tsbuildinfo +1 -0
- package/package.json +5 -9
- package/src/index.ts +1 -0
- package/src/utils/Breakpoints/story/Breakpoints.example.tsx +49 -0
- package/src/utils/Breakpoints/story/MediaQueries.example.tsx +18 -0
- package/src/utils/Breakpoints/story/index.jsx +60 -0
- package/src/utils/Breakpoints/story/useBreakpoint.example.tsx +17 -0
- package/src/utils/Breakpoints/story/useScreens.example.tsx +60 -0
- package/src/utils/Colors/index.ts +2 -0
- package/src/utils/Colors/story/Default.example.tsx +59 -0
- package/src/utils/Colors/story/HowToUse.example.tsx +14 -0
- package/src/utils/Colors/story/index.jsx +21 -0
- package/src/utils/Formatters/format-amount.ts +34 -0
- package/src/utils/Formatters/index.ts +3 -0
- package/src/utils/Formatters/story/amount.example.tsx +63 -0
- package/src/utils/Formatters/story/index.jsx +16 -0
- package/src/utils/Formatters/test.ts +102 -0
- package/src/utils/Gradients/index.ts +2 -0
- package/src/utils/Gradients/story/Default.example.tsx +30 -0
- package/src/utils/Gradients/story/HowToUse.example.tsx +26 -0
- package/src/utils/Gradients/story/index.jsx +26 -0
- package/src/utils/Modal/__snapshots__/test.tsx.snap +209 -0
- package/src/utils/Modal/index.ts +2 -0
- package/src/utils/Modal/modal-manager.ts +27 -0
- package/src/utils/Modal/test.tsx +86 -0
- package/src/utils/Modal/use-modal.tsx +17 -0
- package/src/utils/Shadows/story/Default.example.tsx +45 -0
- package/src/utils/Shadows/story/HowToUse.example.tsx +19 -0
- package/src/utils/Shadows/story/index.jsx +19 -0
- package/src/utils/Transitions/Rotate180/Rotate180.tsx +44 -0
- package/src/utils/Transitions/Rotate180/__snapshots__/test.tsx.snap +29 -0
- package/src/utils/Transitions/Rotate180/index.ts +4 -0
- package/src/utils/Transitions/Rotate180/story/Default.example.tsx +22 -0
- package/src/utils/Transitions/Rotate180/styles.ts +11 -0
- package/src/utils/Transitions/Rotate180/test.tsx +26 -0
- package/src/utils/Transitions/index.ts +2 -0
- package/src/utils/Transitions/story/index.jsx +13 -0
- package/src/utils/Utils/story/Browser.example.tsx +28 -0
- package/src/utils/Utils/story/Colors.example.tsx +29 -0
- package/src/utils/Utils/story/Generic.example.tsx +30 -0
- package/src/utils/Utils/story/React.example.tsx +32 -0
- package/src/utils/Utils/story/Strings.example.tsx +33 -0
- package/src/utils/__tests__/use-page-scroll-lock.test.tsx +117 -0
- package/src/utils/capitalize.ts +1 -0
- package/src/utils/constants.ts +1 -0
- package/src/utils/disable-unsupported-props.ts +45 -0
- package/src/utils/forward-ref.ts +38 -0
- package/src/utils/get-name-initials.ts +15 -0
- package/src/utils/get-react-node-text-content.ts +36 -0
- package/src/utils/index.ts +92 -0
- package/src/utils/is-boolean.ts +3 -0
- package/src/utils/is-number.ts +3 -0
- package/src/utils/is-overflown.ts +20 -0
- package/src/utils/is-pointer-device.ts +9 -0
- package/src/utils/is-string.ts +3 -0
- package/src/utils/is-substring.ts +4 -0
- package/src/utils/kebab-to-camel-case.ts +7 -0
- package/src/utils/loader-palette.ts +9 -0
- package/src/utils/monads.ts +1 -0
- package/src/utils/noop.ts +1 -0
- package/src/utils/sum.ts +4 -0
- package/src/utils/test.tsx +372 -0
- package/src/utils/to-title-case.ts +14 -0
- package/src/utils/unsafe-error-log.ts +5 -0
- package/src/utils/use-combined-refs.ts +26 -0
- package/src/utils/use-deprecation-warnings.ts +56 -0
- package/src/utils/use-multiple-forward-refs.ts +37 -0
- package/src/utils/use-page-scroll-lock.ts +64 -0
- package/src/utils/use-safe-state.ts +25 -0
- package/src/utils/use-width-of.ts +26 -0
- package/src/utils/useBoolean/index.ts +1 -0
- package/src/utils/useBoolean/test.tsx +25 -0
- package/src/utils/useBoolean/use-boolean.ts +30 -0
- package/src/utils/useInterval/index.ts +1 -0
- package/src/utils/useInterval/test.ts +61 -0
- package/src/utils/useInterval/use-interval.ts +46 -0
- package/src/utils/useMouseEnter/index.ts +1 -0
- package/src/utils/useMouseEnter/test.ts +51 -0
- package/src/utils/useMouseEnter/use-mouse-enter.ts +30 -0
- package/src/utils/useOnScreen/index.ts +1 -0
- package/src/utils/useOnScreen/use-on-screen.ts +50 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Table } from '@toptal/picasso'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
const data = {
|
|
5
|
+
forwardRef: `Wrapper around React.forwardRef that preserves genericity of the passed component`,
|
|
6
|
+
useSafeState: `Wrapper around React.useState that ignores state updates when the component is unmounted`,
|
|
7
|
+
useCombinedRefs: `Combines multiple refs into one`,
|
|
8
|
+
useWidthOf: `Calculates width of an element`,
|
|
9
|
+
disableUnsupportedProps: `Removes props that are not supported for passed props values`,
|
|
10
|
+
ClickAwayListener: `Listen for click events that occur somewhere in the document, outside of the element itself`,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const Example = () => (
|
|
14
|
+
<Table>
|
|
15
|
+
<Table.Head>
|
|
16
|
+
<Table.Row>
|
|
17
|
+
<Table.Cell>Name</Table.Cell>
|
|
18
|
+
<Table.Cell>Description</Table.Cell>
|
|
19
|
+
</Table.Row>
|
|
20
|
+
</Table.Head>
|
|
21
|
+
<Table.Body>
|
|
22
|
+
{Object.entries(data).map(([name, description]) => (
|
|
23
|
+
<Table.Row key={name}>
|
|
24
|
+
<Table.Cell>{name}</Table.Cell>
|
|
25
|
+
<Table.Cell>{description}</Table.Cell>
|
|
26
|
+
</Table.Row>
|
|
27
|
+
))}
|
|
28
|
+
</Table.Body>
|
|
29
|
+
</Table>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
export default Example
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Table } from '@toptal/picasso'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
const data = {
|
|
5
|
+
capitalize: `e.g. capitalize('a test string') === 'A test string'`,
|
|
6
|
+
toTitleCase: `e.g. toTitleCase('a test string') === 'A Test String'`,
|
|
7
|
+
kebabToCamelCase: `e.g. kebabToCamelCase('a-test-string') === 'aTestString'`,
|
|
8
|
+
getNameInitials: `e.g. getNameInitials('John Doe') === 'JD'`,
|
|
9
|
+
isSubstring: `e.g. isSubstring('test', 'a test string') === true`,
|
|
10
|
+
generateRandomString: `e.g. 'qw8vd8'`,
|
|
11
|
+
generateRandomStringOrGetEmptyInTest: ``,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Example = () => (
|
|
15
|
+
<Table>
|
|
16
|
+
<Table.Head>
|
|
17
|
+
<Table.Row>
|
|
18
|
+
<Table.Cell>Name</Table.Cell>
|
|
19
|
+
<Table.Cell>Description</Table.Cell>
|
|
20
|
+
</Table.Row>
|
|
21
|
+
</Table.Head>
|
|
22
|
+
<Table.Body>
|
|
23
|
+
{Object.entries(data).map(([name, description]) => (
|
|
24
|
+
<Table.Row key={name}>
|
|
25
|
+
<Table.Cell>{name}</Table.Cell>
|
|
26
|
+
<Table.Cell>{description}</Table.Cell>
|
|
27
|
+
</Table.Row>
|
|
28
|
+
))}
|
|
29
|
+
</Table.Body>
|
|
30
|
+
</Table>
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export default Example
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks'
|
|
2
|
+
|
|
3
|
+
import { usePageScrollLock } from '../use-page-scroll-lock'
|
|
4
|
+
|
|
5
|
+
let defaultBodyOverflow: string
|
|
6
|
+
|
|
7
|
+
const getHtmlElement = (document: Document) => {
|
|
8
|
+
return document.getElementsByTagName('html')[0]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('usePageScrollLock', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
defaultBodyOverflow = getHtmlElement(document).style.overflow
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
getHtmlElement(document).style.overflow = defaultBodyOverflow
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('single usage', () => {
|
|
21
|
+
it('drops scroll lock when mounted with true', () => {
|
|
22
|
+
renderHook(() => usePageScrollLock(true))
|
|
23
|
+
|
|
24
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('lifts scroll lock', () => {
|
|
28
|
+
it('when unmounted', () => {
|
|
29
|
+
const { unmount } = renderHook(() => usePageScrollLock(true))
|
|
30
|
+
|
|
31
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
32
|
+
|
|
33
|
+
unmount()
|
|
34
|
+
|
|
35
|
+
expect(getHtmlElement(document).style.overflow).toBe('')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('when isLocked switches into false', () => {
|
|
39
|
+
const { rerender } = renderHook(
|
|
40
|
+
isLocked => usePageScrollLock(isLocked),
|
|
41
|
+
{ initialProps: true }
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
45
|
+
|
|
46
|
+
rerender(false)
|
|
47
|
+
|
|
48
|
+
expect(getHtmlElement(document).style.overflow).toBe('')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('restores prev page overflow', () => {
|
|
52
|
+
getHtmlElement(document).style.overflow = 'grid'
|
|
53
|
+
|
|
54
|
+
const { unmount } = renderHook(() => usePageScrollLock(true))
|
|
55
|
+
|
|
56
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
57
|
+
|
|
58
|
+
unmount()
|
|
59
|
+
|
|
60
|
+
expect(getHtmlElement(document).style.overflow).toBe('grid')
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('multiple instances usage', () => {
|
|
66
|
+
it('drops scroll lock once any hook gets isLocked=true', () => {
|
|
67
|
+
const hook1 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
68
|
+
initialProps: false,
|
|
69
|
+
})
|
|
70
|
+
const hook2 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
71
|
+
initialProps: false,
|
|
72
|
+
})
|
|
73
|
+
const hook3 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
74
|
+
initialProps: false,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
expect(getHtmlElement(document).style.overflow).toBe('')
|
|
78
|
+
|
|
79
|
+
hook1.rerender(true)
|
|
80
|
+
|
|
81
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
82
|
+
|
|
83
|
+
hook2.rerender(true)
|
|
84
|
+
hook3.rerender(true)
|
|
85
|
+
|
|
86
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('lifts scroll lock once no hook with isLocked=true left mounted', () => {
|
|
90
|
+
getHtmlElement(document).style.overflow = 'block'
|
|
91
|
+
|
|
92
|
+
const hook1 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
93
|
+
initialProps: true,
|
|
94
|
+
})
|
|
95
|
+
const hook2 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
96
|
+
initialProps: true,
|
|
97
|
+
})
|
|
98
|
+
const hook3 = renderHook(isLocked => usePageScrollLock(isLocked), {
|
|
99
|
+
initialProps: true,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
103
|
+
|
|
104
|
+
hook3.unmount()
|
|
105
|
+
|
|
106
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
107
|
+
|
|
108
|
+
hook2.rerender(false)
|
|
109
|
+
|
|
110
|
+
expect(getHtmlElement(document).style.overflow).toBe('hidden')
|
|
111
|
+
|
|
112
|
+
hook1.rerender(false)
|
|
113
|
+
|
|
114
|
+
expect(getHtmlElement(document).style.overflow).toBe('block')
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as capitalize } from '@material-ui/core/utils/capitalize'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const AVATAR_INITIALS_LIMIT = 3
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import unsafeErrorLog from './unsafe-error-log'
|
|
2
|
+
|
|
3
|
+
type PIndex = { [index: string]: unknown }
|
|
4
|
+
|
|
5
|
+
export type FeatureOptions<P extends object> = {
|
|
6
|
+
featureProps: Partial<P>
|
|
7
|
+
unsupportedProps: Partial<P>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default <P extends object>(
|
|
11
|
+
componentName: string,
|
|
12
|
+
props: P,
|
|
13
|
+
options: FeatureOptions<P>
|
|
14
|
+
) => {
|
|
15
|
+
const { featureProps, unsupportedProps } = options
|
|
16
|
+
|
|
17
|
+
const featurePropNames = Object.keys(featureProps)
|
|
18
|
+
|
|
19
|
+
// Check if in props there are props with same value as feature props, if
|
|
20
|
+
// so it will mean we need to check further for unsupported props and reset them
|
|
21
|
+
if (
|
|
22
|
+
featurePropNames.every(
|
|
23
|
+
propName =>
|
|
24
|
+
(props as PIndex)[propName] !== (featureProps as PIndex)[propName]
|
|
25
|
+
)
|
|
26
|
+
) {
|
|
27
|
+
return props
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const unsupportedPropNames = Object.keys(unsupportedProps)
|
|
31
|
+
|
|
32
|
+
// Check for unsupported props if there are props that are enabled, if so
|
|
33
|
+
// warn developer in console and reset props to turn off unsupported props
|
|
34
|
+
if (unsupportedPropNames.some(propName => (props as PIndex)[propName])) {
|
|
35
|
+
unsafeErrorLog(
|
|
36
|
+
`${componentName} doesn't support: ${unsupportedPropNames.join(
|
|
37
|
+
', '
|
|
38
|
+
)} props when used with ${JSON.stringify(featureProps)}`
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return { ...props, ...unsupportedProps }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return props
|
|
45
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export type Component<T, P> = T & {
|
|
4
|
+
defaultProps?: Partial<P>
|
|
5
|
+
displayName?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wraps the exotic generic functional component type returned by the `forwardRef`.
|
|
10
|
+
* This function adopts the type of the exotic component to take `defaultProps` and
|
|
11
|
+
* `displayName`.
|
|
12
|
+
*
|
|
13
|
+
* @see forwardRef
|
|
14
|
+
*
|
|
15
|
+
* @param component exotic component returned by `forwardRef`
|
|
16
|
+
*/
|
|
17
|
+
export const documentable = <T, P>(component: T): Component<T, P> => component as Component<T, P>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wrapper around React.forwardRef that preserves genericity of the passed `Component`.
|
|
21
|
+
* @note If you need to set `defaultProps` and `displayName` properties, you need to wrap
|
|
22
|
+
* result of this function into `documentable`,
|
|
23
|
+
*
|
|
24
|
+
* @see documentable
|
|
25
|
+
*
|
|
26
|
+
* @warning ⚠️ Use it only when you need to preserve genericity of the component as it
|
|
27
|
+
* omits some type checks on the prop type of the component and IT DOESN'T ADD ref
|
|
28
|
+
* property type to the list of props — you have to do it on your own. If you don't
|
|
29
|
+
* care about genericity use React.forwardRef directly.
|
|
30
|
+
*
|
|
31
|
+
* @param component React component conforming to forwardRef type constraints
|
|
32
|
+
*/
|
|
33
|
+
export const forwardRef = <P, T>(
|
|
34
|
+
component: (props: P, ref: React.Ref<T>) => React.ReactElement | null
|
|
35
|
+
) =>
|
|
36
|
+
React.forwardRef(component) as unknown as (
|
|
37
|
+
props: P & { ref?: React.Ref<T> }
|
|
38
|
+
) => React.ReactElement | null
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AVATAR_INITIALS_LIMIT } from './constants'
|
|
2
|
+
|
|
3
|
+
export default (fullName: string) => {
|
|
4
|
+
return fullName
|
|
5
|
+
.split(' ')
|
|
6
|
+
.map(word => {
|
|
7
|
+
if (word === '' || word.length <= 1) {
|
|
8
|
+
return ''
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return word[0]
|
|
12
|
+
})
|
|
13
|
+
.join('')
|
|
14
|
+
.slice(0, AVATAR_INITIALS_LIMIT)
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extracts only the text contents of a ReactNode *recursively*.
|
|
5
|
+
*
|
|
6
|
+
* Be aware that depending on the size of the node element tree this function
|
|
7
|
+
* can ve very slow and actually throw a StackOverflow error. Shouldn't be a
|
|
8
|
+
* problem for elements that you expect a shallow or raw text input.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Results on `Foo Bar`
|
|
12
|
+
* getReactNodeTextContent(<div>Foo <span>Bar</span></div>)
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://stackoverflow.com/a/60564620/4595583} for the inspiration
|
|
15
|
+
*/
|
|
16
|
+
export const getReactNodeTextContent = (node: ReactNode): string => {
|
|
17
|
+
switch (typeof node) {
|
|
18
|
+
case 'number':
|
|
19
|
+
case 'string':
|
|
20
|
+
return String(node).trim()
|
|
21
|
+
|
|
22
|
+
case 'object':
|
|
23
|
+
if (Array.isArray(node)) {
|
|
24
|
+
return node.map(getReactNodeTextContent).filter(Boolean).join(' ')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (node != null && 'props' in node) {
|
|
28
|
+
return getReactNodeTextContent(node.props.children)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// All other cases are ignored (booleans, null, undefined and non-elements)
|
|
32
|
+
// Fall through
|
|
33
|
+
default:
|
|
34
|
+
return ''
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { alpha, lighten, darken } from '@toptal/picasso-shared'
|
|
2
|
+
|
|
3
|
+
import * as TransitionUtils from './Transitions'
|
|
4
|
+
|
|
5
|
+
const colorUtils = {
|
|
6
|
+
alpha,
|
|
7
|
+
lighten,
|
|
8
|
+
darken,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { colorUtils }
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
breakpointsList as breakpoints,
|
|
15
|
+
screens,
|
|
16
|
+
isScreenSize,
|
|
17
|
+
useBreakpoint,
|
|
18
|
+
useScreens,
|
|
19
|
+
shadows,
|
|
20
|
+
colors as palette,
|
|
21
|
+
gradients,
|
|
22
|
+
generateRandomString,
|
|
23
|
+
generateRandomStringOrGetEmptyInTest,
|
|
24
|
+
sizes,
|
|
25
|
+
} from '@toptal/picasso-provider'
|
|
26
|
+
export type { BreakpointKeys } from '@toptal/picasso-provider'
|
|
27
|
+
export { useIsomorphicLayoutEffect, isBrowser } from '@toptal/picasso-shared'
|
|
28
|
+
|
|
29
|
+
export { default as ClickAwayListener } from '@material-ui/core/ClickAwayListener'
|
|
30
|
+
|
|
31
|
+
export { capitalize } from './capitalize'
|
|
32
|
+
export { default as disableUnsupportedProps } from './disable-unsupported-props'
|
|
33
|
+
export { type FeatureOptions } from './disable-unsupported-props'
|
|
34
|
+
export { forwardRef, documentable } from './forward-ref'
|
|
35
|
+
export type { Component } from './forward-ref'
|
|
36
|
+
export { default as getNameInitials } from './get-name-initials'
|
|
37
|
+
export { default as isBoolean } from './is-boolean'
|
|
38
|
+
export { default as isNumber } from './is-number'
|
|
39
|
+
export { default as isOverflown } from './is-overflown'
|
|
40
|
+
export { default as isPointerDevice } from './is-pointer-device'
|
|
41
|
+
export { default as isString } from './is-string'
|
|
42
|
+
export { default as isSubstring } from './is-substring'
|
|
43
|
+
export { default as kebabToCamelCase } from './kebab-to-camel-case'
|
|
44
|
+
export type { Maybe } from './monads'
|
|
45
|
+
export { default as noop } from './noop'
|
|
46
|
+
export { default as toTitleCase } from './to-title-case'
|
|
47
|
+
export { default as useCombinedRefs } from './use-combined-refs'
|
|
48
|
+
export { default as useSafeState } from './use-safe-state'
|
|
49
|
+
export { default as useWidthOf } from './use-width-of'
|
|
50
|
+
export { default as loaderPalette } from './loader-palette'
|
|
51
|
+
export { default as unsafeErrorLog } from './unsafe-error-log'
|
|
52
|
+
export { default as useBoolean } from './useBoolean/use-boolean'
|
|
53
|
+
export { default as useInterval } from './useInterval'
|
|
54
|
+
export { default as useOnScreen } from './useOnScreen'
|
|
55
|
+
export { default as useMouseEnter } from './useMouseEnter'
|
|
56
|
+
export { default as sum } from './sum'
|
|
57
|
+
export type { ReferenceObject } from './use-width-of'
|
|
58
|
+
export { default as useMultipleForwardRefs } from './use-multiple-forward-refs'
|
|
59
|
+
export { usePageScrollLock } from './use-page-scroll-lock'
|
|
60
|
+
export { AVATAR_INITIALS_LIMIT } from './constants'
|
|
61
|
+
|
|
62
|
+
export const Transitions = TransitionUtils
|
|
63
|
+
|
|
64
|
+
export { useModal } from './Modal'
|
|
65
|
+
export * from './Modal'
|
|
66
|
+
|
|
67
|
+
export { formatAmount, DEFAULT_CURRENCY, DEFAULT_LOCALE } from './Formatters'
|
|
68
|
+
|
|
69
|
+
export type { FormatAmount } from './Formatters'
|
|
70
|
+
export * from './get-react-node-text-content'
|
|
71
|
+
|
|
72
|
+
export * from './Colors'
|
|
73
|
+
export * from './Formatters'
|
|
74
|
+
export * from './Gradients'
|
|
75
|
+
export * from './Modal'
|
|
76
|
+
export * from './Transitions'
|
|
77
|
+
|
|
78
|
+
export { SPACING_0 } from '@toptal/picasso-provider'
|
|
79
|
+
export { SPACING_1 } from '@toptal/picasso-provider'
|
|
80
|
+
export { SPACING_2 } from '@toptal/picasso-provider'
|
|
81
|
+
export { SPACING_3 } from '@toptal/picasso-provider'
|
|
82
|
+
export { SPACING_4 } from '@toptal/picasso-provider'
|
|
83
|
+
export { SPACING_6 } from '@toptal/picasso-provider'
|
|
84
|
+
export { SPACING_8 } from '@toptal/picasso-provider'
|
|
85
|
+
export { SPACING_10 } from '@toptal/picasso-provider'
|
|
86
|
+
export { SPACING_12 } from '@toptal/picasso-provider'
|
|
87
|
+
export { spacingToRem } from '@toptal/picasso-provider'
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
useDeprecationWarning,
|
|
91
|
+
usePropDeprecationWarning,
|
|
92
|
+
} from './use-deprecation-warnings'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pixel value of font render space correction.
|
|
3
|
+
* It's individual for different fonts, so it won't work for 100% cases,
|
|
4
|
+
* but it allows us to be much closer to actual overflow detection while calculating.
|
|
5
|
+
* Tolerance of the render could be 0-2px depending on the font that is used,
|
|
6
|
+
* and also affected by the right-padding added at Ellipsis component.
|
|
7
|
+
*/
|
|
8
|
+
const FONT_RENDER_CORRECTION = 0.475
|
|
9
|
+
|
|
10
|
+
const isOverflown = (element: HTMLElement) => {
|
|
11
|
+
const { scrollWidth, scrollHeight } = element
|
|
12
|
+
const { width, height } = element.getBoundingClientRect()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
scrollWidth > width + FONT_RENDER_CORRECTION ||
|
|
16
|
+
scrollHeight > height + FONT_RENDER_CORRECTION
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default isOverflown
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Maybe<T> = T | null | undefined
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default () => {}
|
package/src/utils/sum.ts
ADDED