Skip to content

Commit

Permalink
Added a subtle gradient effect when code tabs overflow. Gradient can …
Browse files Browse the repository at this point in the history
…be increased or arrows can be added to content of pseudo elements to make overflow more obvious if necessary
  • Loading branch information
cmhhelgeson committed Jan 10, 2024
1 parent bbe65e9 commit dd6d8e2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
39 changes: 38 additions & 1 deletion src/components/SampleLayout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
max-width: 600px;
}


nav.sourceFileNav {
position: relative;
}

nav.sourceFileNav ul {
box-sizing: border-box;
Expand All @@ -27,6 +29,41 @@ 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;
Expand Down
22 changes: 20 additions & 2 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,8 +229,25 @@ const SampleLayout: React.FunctionComponent<
<canvas ref={canvasRef}></canvas>
</div>
<div>
<nav className={styles.sourceFileNav}>
<div className={styles.sourceFileScrollContainer}>
<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 (
Expand Down

0 comments on commit dd6d8e2

Please sign in to comment.