-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Properly setup library exports and fix CJS build (#70)
- Loading branch information
Showing
11 changed files
with
66 additions
and
9 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
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
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './formatterUtils'; | ||
export * from './mergeRefs'; | ||
export * from './responsiveUtils'; |
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 @@ | ||
export { mergeRefs } from './mergeRefs'; |
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,19 @@ | ||
import { mergeRefs } from './mergeRefs'; | ||
|
||
describe('mergeRefs util', () => { | ||
it('correctly set value for function refs', () => { | ||
const functionRef = jest.fn(); | ||
const value = 'test'; | ||
const refSetter = mergeRefs([functionRef]); | ||
refSetter(value); | ||
expect(functionRef).toHaveBeenCalledWith(value); | ||
}); | ||
|
||
it('correctly set value for mutable ref object', () => { | ||
const mutableRef = { current: null }; | ||
const value = 'new-value'; | ||
const refSetter = mergeRefs<string | null>([mutableRef]); | ||
refSetter(value); | ||
expect(mutableRef.current).toEqual(value); | ||
}); | ||
}); |
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,18 @@ | ||
import type { LegacyRef, MutableRefObject, RefCallback } from 'react'; | ||
|
||
/** | ||
* Utility to merge multiple React refs, inspired by https://github.com/gregberge/react-merge-refs | ||
*/ | ||
export const mergeRefs = <T = unknown>( | ||
refs: Array<MutableRefObject<T> | LegacyRef<T> | undefined | null>, | ||
): RefCallback<T> => { | ||
return (value) => { | ||
refs.forEach((ref) => { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref != null) { | ||
(ref as MutableRefObject<T | null>).current = value; | ||
} | ||
}); | ||
}; | ||
}; |