Skip to content

Commit

Permalink
Revert "updates the expandable component" (#5556)
Browse files Browse the repository at this point in the history
the expandables aren't appearing correctly on the live site so this
reverts this pr

https://docs.getdbt.com/docs/collaborate/dbt-explorer-faqs

Reverts #5531
![Screenshot 2024-05-23 at 15 40
45](https://github.com/dbt-labs/docs.getdbt.com/assets/89008547/c429f589-4163-49f4-a2df-ad406c6f6546)
  • Loading branch information
mirnawong1 authored May 23, 2024
2 parents 9c72237 + f70f39a commit 468a962
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 132 deletions.
89 changes: 26 additions & 63 deletions website/src/components/expandable/index.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,51 @@
/* 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) => {
event.preventDefault();
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 (
<div id={anchorId} className={`${styles.expandableContainer} `}>
<div className={styles.header} onClick={handleToggleClick}>
<div id={anchorId} className={`${styles.expandableContainer} ${styles.local} expandable-anchor anchor`}>
<a
href={`#${anchorId}`}
className={styles.link}
onClick={handleToggleClick}
role="button"
tabIndex="0"
>
<span className={`${styles.toggle} ${isOn ? styles.toggleDown : styles.toggleRight}`}></span>
&nbsp;
<span className={styles.headerText}>
{alt_header}
</span>
<span onClick={handleCopyClick} className={styles.copyIcon}></span>
</div>
<div style={{ display: isOn ? 'block' : 'none' }} className={styles.body}>
<span className={styles.headerText}>{alt_header}</span>
</a>
<div
style={{ display: isOn ? 'block' : 'none' }}
className={styles.body}
>
{children}
</div>
</div>
);
}

export default Expandable;
export default expandable;
74 changes: 8 additions & 66 deletions website/src/components/expandable/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,14 @@
text-decoration: none;
transition: text-decoration 0.3s; /* Smooth transition */
font-weight: 600;
margin-bottom: 10px;
margin-bottom: 20px;
}

:local(.header) {
display: flex;
align-items: center;
:local(.link:hover) :local(.headerText),
:local(.link:focus) :local(.headerText) {
text-decoration: underline;
cursor: pointer;
color: rgba(18, 12, 12, 0.862);
font-weight: 550;
margin-bottom: 10px;
text-decoration: none;
}


:local(.copyIcon) {
width: 12px;
height: 12px;
background-image: url('/img/copy.png');
background-size: contain;
background-repeat: no-repeat;
opacity: 0;
transition: opacity 0.3s ease-in-out;
margin-left: 4px;
vertical-align: middle;
cursor: pointer;
}

:local(.header:hover) :local(.copyIcon) {
opacity: 1;
}

.copy-popup {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #047377;
color: rgb(236, 236, 236);
padding: 10px;
border-radius: 5px;
z-index: 9999;
}

}

:local(.toggle)::before {
content: '';
Expand Down Expand Up @@ -81,29 +46,10 @@
border-color: rgb(253, 153, 83);
}

:local(.copyPopup) {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #000;
color: #fff;
padding: 10px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 1000;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}

:local(.copyPopup.show) {
opacity: 1;
}

.expandableContainer :local(.body) {
margin-top: 2px;
margin-top: 10px;
margin-left: .5em;
padding: 5px;
padding: 10px;
background-color: transparent;
}

Expand All @@ -112,10 +58,6 @@
color: rgba(255, 255, 255, 0.801); /* White text in dark mode */
}

:local(html[data-theme='dark'] details .headerText) {
color: rgba(18, 12, 12, 0.862); /* this adds black text inside details in dark mode */
}

:local(.body > p:last-child) {
margin-bottom: 0px;

Expand All @@ -139,6 +81,6 @@
}

.expandableContainer {
margin-bottom: 5px; /* Adjust this value as needed to create space */
margin-bottom: 10px; /* Adjust this value as needed to create space */
}

4 changes: 2 additions & 2 deletions website/src/theme/MDXComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import dbtEditor from '@site/src/components/dbt-editor';
import Icon from '@site/src/components/icon';
import Lifecycle from '@site/src/components/lifeCycle';
import detailsToggle from '@site/src/components/detailsToggle';
import Expandable from '@site/src/components/expandable';
import expandable from '@site/src/components/expandable';
import ConfettiTrigger from '@site/src/components/confetti/';

const MDXComponents = {
Expand Down Expand Up @@ -96,7 +96,7 @@ const MDXComponents = {
Icon: Icon,
Lifecycle: Lifecycle,
detailsToggle: detailsToggle,
Expandable: Expandable,
expandable: expandable,
ConfettiTrigger: ConfettiTrigger,
};
export default MDXComponents;
2 changes: 1 addition & 1 deletion website/static/js/headerLinkCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ window.addEventListener("load", copyHeader);

// separating function from eventlistener to understand they are two separate things
function copyHeader () {
const headers = document.querySelectorAll("h2.anchor, h3.anchor, h4.anchor");
const headers = document.querySelectorAll("h2.anchor, h3.anchor, .expandable-anchor.anchor");

headers.forEach((header) => {
header.style.cursor = "pointer";
Expand Down

0 comments on commit 468a962

Please sign in to comment.