Skip to content

Commit

Permalink
Convert docs anchor links to @emotion/css
Browse files Browse the repository at this point in the history
- instead of using `ClassNames` render prop
  • Loading branch information
cee-chen committed Oct 4, 2022
1 parent bc1be72 commit 3399bdf
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src-docs/src/services/routing/heading_anchor_links.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState, useMemo } from 'react';
import { createPortal } from 'react-dom';
import { useLocation } from 'react-router-dom';
import { ClassNames } from '@emotion/react';
import { css } from '@emotion/css';

import { EuiButtonIcon, useEuiTheme, logicalCSS } from '../../../../src';

Expand Down Expand Up @@ -33,43 +33,39 @@ export const useHeadingAnchorLinks = () => {
// to quickly get/copy the heading anchor link
const anchorLinks = useMemo(
() => (
<ClassNames>
{({ css }) => (
<>
{headingNodes.map((heading) => {
const headingCss = css`
&:hover [data-anchor-link] {
opacity: 1;
}
`;
const linkCss = css`
opacity: 0;
${logicalCSS('margin-left', euiTheme.size.s)}
<>
{headingNodes.map((heading) => {
const headingCss = css`
&:hover [data-anchor-link] {
opacity: 1;
}
`;
const linkCss = css`
opacity: 0;
${logicalCSS('margin-left', euiTheme.size.s)}
&:hover,
&:hover,
&:focus {
opacity: 1;
}
`;
opacity: 1;
}
`;

heading.classList.add(headingCss);
heading.classList.add(headingCss);

return createPortal(
<EuiButtonIcon
data-anchor-link
iconType="link"
color="text"
size="xs"
css={linkCss}
aria-label="Go to heading anchor link"
href={`#${pathname}#${heading.id}`}
/>,
heading
);
})}
</>
)}
</ClassNames>
return createPortal(
<EuiButtonIcon
data-anchor-link
iconType="link"
color="text"
size="xs"
className={linkCss}
aria-label="Go to heading anchor link"
href={`#${pathname}#${heading.id}`}
/>,
heading
);
})}
</>
),
[headingNodes] // eslint-disable-line react-hooks/exhaustive-deps
);
Expand Down

0 comments on commit 3399bdf

Please sign in to comment.