Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add AnchorNavigation component #1396

Merged
merged 65 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7805086
feat: Setup new TOC component
Jul 12, 2023
ff01d38
chore: Initial explorations
Jul 12, 2023
a2e5ae3
feat: Setup styling
Jul 12, 2023
b2dd1f3
chore: Update styles and demo page
Jul 17, 2023
5c9b54a
Add TextSample component
Jul 25, 2023
20b3a21
chore: Update styling and add scrollspy
Jul 25, 2023
b557f0f
scroll spy working on load, not intesecting afterwards but logic seem…
Jul 26, 2023
00a711b
Improve scroll spy
Jul 26, 2023
dc05449
wip
Jul 28, 2023
6ccd216
chore: Wip
Jul 31, 2023
474d632
chore: Expand interfaces
Aug 1, 2023
e6ae72b
Add TextSample to page
Aug 1, 2023
8f54e79
Comment out experiences on scroll spy
Aug 1, 2023
88eaa76
chore: Add custom scroll handling
Aug 1, 2023
442a8e0
fix eslint
Aug 2, 2023
a4b513e
Rename to anchor navigation
Aug 3, 2023
d02f58f
Fix border styles
Aug 7, 2023
4699a75
Refactor and clean up interface
Aug 8, 2023
9780a41
scroll el into view
Aug 14, 2023
5216aaa
WIP
Sep 4, 2023
4d51d1d
Merge branch 'main' into rucarva-toc
Sep 4, 2023
90738dd
chore: Add info slot
Sep 4, 2023
b906157
chore: Use pseudo elements instead of border
Sep 4, 2023
cada289
Cleaned up styling
Sep 4, 2023
5bf9801
chore: Update styling
Sep 5, 2023
aa99e36
chore: Refactor class names
Sep 5, 2023
03c4e19
chore: Add test utils
Sep 5, 2023
d1e389e
chore: Update test utils
Sep 5, 2023
c61b8a6
chore: Clean up scroll spy code
Sep 5, 2023
efb2c39
Merge branch 'main' into rucarva-toc
Sep 5, 2023
6eb73bc
chore: Fix tests
Sep 6, 2023
cf6c313
Merge branch 'main' into rucarva-toc
Sep 6, 2023
deec329
chore: Make component extend base component props
Sep 6, 2023
a27a191
chore: Revert unrelated changes
Sep 6, 2023
486f455
chore: Remove redundant page
Sep 7, 2023
bc32ae5
chore: Remove unused code
Sep 7, 2023
36ad9b1
chore: Update documenter and activeHref
Sep 7, 2023
72289bf
chore: Fix useBaseProps
Sep 7, 2023
d79422f
chore: Fix props destructuring
Sep 7, 2023
f97e4a5
chore: Improve scroll spy logic for the scrolled to bottom
Sep 8, 2023
63078eb
chore: Update API and clean up pages
Sep 8, 2023
c709048
chore: Clean up naming
Sep 8, 2023
0004d15
chore: Simplify and optimise useScrollSpy
Sep 8, 2023
58afb43
Merge branch 'main' into rucarva-toc
Sep 8, 2023
91a41dd
chore: Fix tests
Sep 8, 2023
38d2e90
chore: Update interfaces
Sep 10, 2023
eb4cb75
chore: Update documenter snapshot
Sep 10, 2023
11ee01c
chore: Use Math.ceil on window.scrollY
Sep 11, 2023
7e9c637
chore: Update bottom detection logic
Sep 11, 2023
b561dc8
chore: Update pages, interface
Sep 11, 2023
52cfaee
chore: Update interface and refactor useeffect
Sep 12, 2023
ca0b42b
chore: Simplify code
Sep 13, 2023
68dd6d3
chore: Round scrollY
Sep 14, 2023
5042fef
chore: Use test util classes
Sep 19, 2023
96b6935
chore: Use test util classes
Sep 19, 2023
c0581b4
chore: Add unit tests
Sep 19, 2023
8c19819
chore: Add more unit tests
Sep 19, 2023
8ae012b
chore: Adding tests
Sep 19, 2023
157b9dd
chore: Add more tests
Sep 19, 2023
d367207
chore: Update documenter and add test
Sep 19, 2023
d3a0893
chore: Make it 1 based index
Sep 19, 2023
d36a5e0
chore: Make consisent class names and expand coverage
Sep 20, 2023
ec8ade6
chore: Clean up comments
Sep 20, 2023
da8988c
chore: Address feedback
Sep 20, 2023
78fa994
chore: Update documenter snapshot
Sep 20, 2023
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
70 changes: 70 additions & 0 deletions pages/anchor-navigation/basic.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import AnchorNavigation from '~components/anchor-navigation';
import { TextSample, navigateToItem } from './utils';
import SpaceBetween from '~components/space-between';
import Header from '~components/header';
import ScreenshotArea from '../utils/screenshot-area';
import styles from './styles.scss';

const TextContent = () => {
return (
<SpaceBetween size="l">
<div style={{ padding: '40px' }}>
<h2 id="section-1">Section 1</h2>
<TextSample />
<h3 id="section-1-1">Section 1.1</h3>
<TextSample />
<h4 id="section-1-1-1">Section 1.1.1</h4>
<TextSample />
<h4 id="section-1-1-2">Section 1.1.2</h4>
<TextSample />
<h3 id="section-1-2">Section 1.2</h3>
<TextSample />
<h4 id="section-1-2-1">Section 1.2.1</h4>
Small text
<h5 id="section-1-2-1-1">Section 1.2.1.1</h5>
Small text
</div>
</SpaceBetween>
);
};

export default function BasicAnchorNavigation() {
return (
<article>
<h1>Anchor navigation</h1>
<ScreenshotArea>
<SpaceBetween size="l">
<div className={styles['content-grid']}>
<TextContent />
<div>
<div className={styles['anchor-navigation']}>
<Header id="anchor-nav-heading" variant="h3">
On this page
</Header>
<AnchorNavigation
ariaLabelledby="anchor-nav-heading"
onFollow={e => {
e.preventDefault();
navigateToItem(e.detail.href);
}}
anchors={[
{ href: '#section-1', text: 'Section 1', level: 1 },
{ href: '#section-1-1', text: 'Section 1.1', level: 2, info: 'Updated' },
{ href: '#section-1-1-1', text: 'Section 1.1.1', level: 3 },
{ href: '#section-1-1-2', text: 'Section 1.1.2', level: 3 },
{ href: '#section-1-2', text: 'Section 1.2', level: 2, info: 'New' },
{ href: '#section-1-2-1', text: 'Section 1.2.1', level: 3 },
{ href: '#section-1-2-1-1', text: 'Section 1.2.1.1', level: 4 },
]}
/>
</div>
</div>
</div>
</SpaceBetween>
</ScreenshotArea>
</article>
);
}
69 changes: 69 additions & 0 deletions pages/anchor-navigation/expandable.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import AnchorNavigation from '~components/anchor-navigation';
import { TextSample, navigateToItem } from './utils';
import SpaceBetween from '~components/space-between';
import ScreenshotArea from '../utils/screenshot-area';
import styles from './styles.scss';
import { ExpandableSection } from '~components';

const TextContent = () => {
return (
<SpaceBetween size="l">
<div style={{ padding: '40px' }}>
<h2 id="section-1">Section 1</h2>
<TextSample />
<h3 id="section-1-1">Section 1.1</h3>
<TextSample />
<h4 id="section-1-1-1">Section 1.1.1</h4>
<TextSample />
<h4 id="section-1-1-2">Section 1.1.2</h4>
<TextSample />
<h3 id="section-1-2">Section 1.2</h3>
<TextSample />
<h4 id="section-1-2-1">Section 1.2.1</h4>
<TextSample />
<h5 id="section-1-2-1-1">Section 1.2.1.1</h5>
<TextSample />
</div>
</SpaceBetween>
);
};

export default function ExpandableAnchorNavigation() {
return (
<article>
<h1>Anchor navigation in expandable section</h1>
<ScreenshotArea>
<SpaceBetween size="l">
<div className={styles['content-grid']}>
<TextContent />
<div>
<div className={styles['anchor-navigation']}>
<ExpandableSection variant="footer" headerText="On this page">
<AnchorNavigation
ariaLabelledby="anchor-nav-heading"
onFollow={e => {
e.preventDefault();
navigateToItem(e.detail.href);
}}
anchors={[
rubencarvalho marked this conversation as resolved.
Show resolved Hide resolved
{ href: '#section-1', text: 'Section 1', level: 1 },
{ href: '#section-1-1', text: 'Section 1.1', level: 2 },
{ href: '#section-1-1-1', text: 'Section 1.1.1', level: 3 },
{ href: '#section-1-1-2', text: 'Section 1.1.2', level: 3 },
{ href: '#section-1-2', text: 'Section 1.2', level: 2 },
{ href: '#section-1-2-1', text: 'Section 1.2.1', level: 3 },
{ href: '#section-1-2-1-1', text: 'Section 1.2.1.1', level: 4 },
]}
/>
</ExpandableSection>
</div>
</div>
</div>
</SpaceBetween>
</ScreenshotArea>
</article>
);
}
13 changes: 13 additions & 0 deletions pages/anchor-navigation/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
.content-grid {
display: grid;
grid-template-columns: 1fr 300px;
}

.anchor-navigation {
position: sticky;
top: 40px;
}
Loading
Loading