fleet/frontend/hooks/useCheckTruncatedElement.ts
Gabriel Hernandez d7629b08ea
Feat UI idp host details (#27730)
For #27283

This includes the work to add the new users card on host details and
show the new idp information as well as google profiles and other
emails.

This includes:

**new user card on the host details and my device page**


![image](https://github.com/user-attachments/assets/f02badbf-85a2-4198-a30c-ace0e08ac843)


**rework of the grid layout on the host page**

**removal of unneeded device mapping code on host details and my device
page**



I've changed how we are using the grid layout in CSS to better support
dynamic rendering content


<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
- [ ] Added/updated automated tests
- [ ] Manual QA for all new/changed functionality
2025-04-04 15:46:22 +01:00

26 lines
779 B
TypeScript

import { useLayoutEffect, useState } from "react";
/**
* This hook checks if an element is truncated and returns a boolean value.
*/
// eslint-disable-next-line import/prefer-default-export
export const useCheckTruncatedElement = <T extends HTMLElement>(
ref: React.RefObject<T>
) => {
const [isTruncated, setIsTruncated] = useState(false);
useLayoutEffect(() => {
const element = ref.current;
function updateIsTruncated() {
if (element) {
const { scrollWidth, clientWidth } = element;
setIsTruncated(scrollWidth > clientWidth);
}
}
window.addEventListener("resize", updateIsTruncated);
updateIsTruncated();
return () => window.removeEventListener("resize", updateIsTruncated);
}, [ref]);
return isTruncated;
};