-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor overflow utils and logic
- Loading branch information
1 parent
ef2d05e
commit c2c6b6f
Showing
6 changed files
with
62 additions
and
60 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
36 changes: 0 additions & 36 deletions
36
packages/ibm-products/src/components/PageHeader/hooks/useOverflow.ts
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
packages/ibm-products/src/global/js/utils/replaceWithOverflow.ts
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,47 @@ | ||
// | ||
// Copyright IBM Corp. 2024, 2024 | ||
// | ||
// This source code is licensed under the Apache-2.0 license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
|
||
import { RefObject } from 'react'; | ||
|
||
/** | ||
* These functions are used to calculate if the content of an area is overflowing it's parent. | ||
* Ideally used to replace an element with another if it's overflowing and vice versa. | ||
* Check PageHeader.tsx and PageHeaderTitle.js for example usage. | ||
*/ | ||
|
||
type Props = { | ||
/** | ||
* the ref for the element not overflowing | ||
*/ | ||
ref: RefObject<HTMLElement>; | ||
/** | ||
* the ref for the element that is overflowing | ||
*/ | ||
overflowRef: RefObject<HTMLElement>; | ||
}; | ||
|
||
export const replaceOverflowWidth = ({ ref, overflowRef }: Props): boolean => { | ||
if (ref.current) { | ||
return ref.current?.offsetWidth < ref.current?.scrollWidth; | ||
} | ||
if (overflowRef.current) { | ||
return overflowRef.current?.offsetWidth < overflowRef.current?.scrollWidth; | ||
} | ||
return false; | ||
}; | ||
|
||
export const replaceOverflowHeight = ({ ref, overflowRef }: Props): boolean => { | ||
if (ref.current) { | ||
return ref.current?.offsetHeight < ref.current?.scrollHeight; | ||
} | ||
if (overflowRef.current) { | ||
return ( | ||
overflowRef.current?.offsetHeight < overflowRef.current?.scrollHeight | ||
); | ||
} | ||
return false; | ||
}; |