I want to make a navigation bar like this:
Toast ui homepage
I try to replicate as much as possible to achieve this.
I get the following message:
I want something like this (these were made with image editing):
Option 1: Center alignment
Option 2: Left alignment
I want the position of the linked list to be dynamic, depending on the position of the link group that contains it. All I did was align it left.
That is, I want the link list to be directly below the link group that contains it for better UI.
Can you tell me how to get this by editing my code and box?
P粉6902008562024-04-02 16:13:07
Set the paddingLeft of link-list
and the x coordinate of link-group
export const useGetElementById = (id) => {
const [element, setElement] = useState(null);
useEffect(() => {
setElement(document.getElementById(id));
}, [id]);
return element;
};
link-list
into a component and receive linkGroupId as props.
And set the paddingLeft of link-list
and the x coordinate of
link-groupinterface Props { linkGroupId: string; pages: AppPage[]; } export const LinkList = ({ linkGroupId, pages }: Props) => { const [linkGroupX, setLinkGroupX] = useState(0); const linkGroupEl = useGetElementById(linkGroupId); useEffect(() => { if (!linkGroupEl) return; const linkGroupRect = linkGroupEl.getBoundingClientRect(); setLinkGroupX(linkGroupRect.left); }, [linkGroupEl]); return ( {pages.map((page) => (
); };- {page.title}
))}
of link-group
...
{pagesKeys.map((key) => {
const pages = PAGES.get(key) || [];
return (
-
{key}
);
})}
...
option2.