Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/components/SampleLayout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
max-width: 600px;
}

nav.sourceFileNav {
position: relative;
}

nav.sourceFileNav ul {
box-sizing: border-box;
list-style-type: none;
padding: 0;
margin: 0;
Expand All @@ -24,6 +29,68 @@ nav.sourceFileNav li {
transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

nav.sourceFileNav::before {
content: '';
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
width: 30px;
height: 37px;
top: 15px;
left: 0px;
pointer-events: none;
}

nav.sourceFileNav[data-left=true]::before {
background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), transparent);
}

nav.sourceFileNav::after {
content: '';
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 30px;
height: 37px;
top: 15px;
right: 0px;
pointer-events: none;
}

nav.sourceFileNav[data-right=true]::after {
background: linear-gradient(270deg, rgba(0, 0, 0, 0.35), transparent);
}

nav.sourceFileNav div.sourceFileScrollContainer {
white-space: nowrap;
overflow-x: auto;
scrollbar-width: thin;
}

nav.sourceFileNav div.sourceFileScrollContainer::-webkit-scrollbar {
display: inline;
margin-top: 10px;
margin-bottom: 10px;
height: 11px;
width: 10px;
}

nav.sourceFileNav div.sourceFileScrollContainer::-webkit-scrollbar-thumb {
background: rgb(200, 200, 200);
height: 4px;
border-radius: 20px;
-webkit-box-shadow: inset 0px 0px 10px rgb(45, 33, 33);
border: 0.5px solid transparent;
background-clip: content-box;
}

nav.sourceFileNav div.sourceFileScrollContainer::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0);
}

nav.sourceFileNav li a {
display: block;
margin: 0;
Expand Down
56 changes: 38 additions & 18 deletions src/components/SampleLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const SampleLayout: React.FunctionComponent<
}>
> = (props) => {
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const navRef = useRef<HTMLDivElement | null>(null);
const sources = useMemo(
() =>
props.sources.map(({ name, contents }) => {
Expand Down Expand Up @@ -228,24 +229,43 @@ const SampleLayout: React.FunctionComponent<
<canvas ref={canvasRef}></canvas>
</div>
<div>
<nav className={styles.sourceFileNav}>
<ul>
{sources.map((src, i) => {
return (
<li key={i}>
<a
href={`#${src.name}`}
data-active={activeHash == src.name}
onClick={() => {
setActiveHash(src.name);
}}
>
{src.name}
</a>
</li>
);
})}
</ul>
<nav className={styles.sourceFileNav} ref={navRef}>
<div
className={styles.sourceFileScrollContainer}
onScroll={(event) => {
const element = event.currentTarget;
const scrollRight =
element.scrollWidth - element.clientWidth - element.scrollLeft;
if (element.scrollLeft > 25) {
navRef.current.setAttribute('data-left', 'true');
} else {
navRef.current.setAttribute('data-left', 'false');
}
if (scrollRight > 25) {
navRef.current.setAttribute('data-right', 'true');
} else {
navRef.current.setAttribute('data-right', 'false');
}
}}
>
<ul>
{sources.map((src, i) => {
return (
<li key={i}>
<a
href={`#${src.name}`}
data-active={activeHash == src.name}
onClick={() => {
setActiveHash(src.name);
}}
>
{src.name}
</a>
</li>
);
})}
</ul>
</div>
</nav>
{sources.map((src, i) => {
return (
Expand Down