From c38a5ec6825fc57130638700fc6fda3a8ed89fbb Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Thu, 23 May 2024 15:40:11 +0100 Subject: [PATCH] Revert "updates the expandable component" --- website/src/components/expandable/index.js | 89 ++++++------------- .../components/expandable/styles.module.css | 74 ++------------- website/src/theme/MDXComponents/index.js | 4 +- website/static/js/headerLinkCopy.js | 2 +- 4 files changed, 37 insertions(+), 132 deletions(-) diff --git a/website/src/components/expandable/index.js b/website/src/components/expandable/index.js index 1e971c1e182..eb1dc966ad1 100644 --- a/website/src/components/expandable/index.js +++ b/website/src/components/expandable/index.js @@ -1,22 +1,23 @@ /* eslint-disable */ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import styles from './styles.module.css'; function slugify(text) { return text.toString().toLowerCase() - .normalize('NFD') // normalize to nfd unicode form - .replace(/[\u0300-\u036f]/g, '') // remove diacritics - .replace(/\s+/g, '-') // replace spaces with - - .replace(/[^\w\-]+/g, '') // remove all non-word chars - .replace(/\-\-+/g, '-') // replace multipl - with a single - - .replace(/^-+/, '') // trim - from the start - .replace(/-+$/, ''); // trim - from the end + .normalize('NFD') // Normalize to NFD Unicode form + .replace(/[\u0300-\u036f]/g, '') // Remove diacritics + .replace(/\s+/g, '-') // Replace spaces with - + .replace(/[^\w\-]+/g, '') // Remove all non-word chars + .replace(/\-\-+/g, '-') // Replace multiple - with single - + .replace(/^-+/, '') // Trim - from start + .replace(/-+$/, ''); // Trim - from end } -function Expandable({ children, alt_header = null }) { - if (!alt_header) { return null; } +function expandable({ children, alt_header = null }) { + if(!alt_header) { return null; } const [isOn, setOn] = useState(false); + // generate a slug from the alt_header const anchorId = slugify(alt_header); const handleToggleClick = (event) => { @@ -24,65 +25,27 @@ function Expandable({ children, alt_header = null }) { setOn(current => !current); }; - const handleCopyClick = (event) => { - event.preventDefault(); - event.stopPropagation(); - const url = `${window.location.href.split('#')[0]}#${anchorId}`; - navigator.clipboard.writeText(url).then(() => { - showCopyPopup(); - }); - }; - - const showCopyPopup = () => { - const popup = document.createElement('div'); - popup.classList.add('copy-popup'); - popup.innerText = 'Link copied!'; - - // Add close button ('x') - const closeButton = document.createElement('span'); - closeButton.classList.add('close-button'); - closeButton.innerHTML = ' ×'; // '×' symbol for 'x' - closeButton.addEventListener('click', () => { - if (document.body.contains(popup)) { - document.body.removeChild(popup); - } - }); - popup.appendChild(closeButton); - - document.body.appendChild(popup); - - setTimeout(() => { - if (document.body.contains(popup)) { - document.body.removeChild(popup); - } - }, 3000); -}; - -useEffect(() => { - if (window.location.hash === `#${anchorId}`) { - setOn(true); - const element = document.getElementById(anchorId); - if (element) { - element.scrollIntoView({ behavior: 'smooth' }); - } - } -}, [anchorId]); - return ( -