Skip to content

Add anchor for section titles for quick sharing of sections #408

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

Merged
merged 25 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
36fb1ff
[r96943502] chore: started adding anchor to titles
marinaaisa Aug 3, 2022
988aea7
[r96943502] feat: create SectionTitle component
marinaaisa Aug 5, 2022
a288046
[r96943502] feat: add SectionTitle to more headings
marinaaisa Aug 8, 2022
94b47b3
[r96943502] chore: make anchor optional for those that already have a…
marinaaisa Aug 9, 2022
a69286b
[r96943502] test: fix current tests
marinaaisa Aug 9, 2022
21c50ce
[r96943502] test: add tests for SectionTitle component
marinaaisa Aug 9, 2022
2d7bfad
[r96943502] fix: TopicsTable component
marinaaisa Aug 9, 2022
336bfb1
[r96943502] test: fix failing test
marinaaisa Aug 10, 2022
3895e95
[r96943502] fix: address feedback
marinaaisa Aug 11, 2022
1f3cfd4
[r96943502] chore: it does not render anchor if target ide is true
marinaaisa Aug 13, 2022
93f8da3
[r96943502] test: add new tests for scrollToElement
marinaaisa Aug 13, 2022
08be7cc
[r96943502] fix: address feedback
marinaaisa Aug 30, 2022
3237783
[r96943502] fix: prevent jumping issues
marinaaisa Aug 31, 2022
32c52a8
[r96943502] fix: address feedback
marinaaisa Aug 31, 2022
f5c1b7f
[r96943502] chore: delete extra anchors to avoid duplication of ids
marinaaisa Sep 1, 2022
d6b730e
[r96943502] styles: [WIP] update UI
marinaaisa Sep 2, 2022
f4877b6
[r96943502] styles: [WIP] update UI with link icon
marinaaisa Sep 2, 2022
23fd3c7
[r96943502] fix: address feedback
marinaaisa Sep 6, 2022
711f557
[r96943502] fix: adding padding right to header anchor so icon does n…
marinaaisa Sep 8, 2022
e4b5f40
[r96943502] chore: add aria label for AX
marinaaisa Sep 8, 2022
ae6fd00
Merge branch 'main' into r96943502/anchor-titles
Sep 12, 2022
2b73297
[r94221573] chore: address design feedback + refactor vars
marinaaisa Sep 13, 2022
fa59672
Merge branch 'main' into r96943502/anchor-titles
marinaaisa Sep 13, 2022
acd16a5
[r94150776] fix: address feedback
marinaaisa Sep 15, 2022
8c87dea
Merge branch 'main' into r96943502/anchor-titles
marinaaisa Sep 15, 2022
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
16 changes: 8 additions & 8 deletions src/components/ContentNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script>
import Aside from './ContentNode/Aside.vue';
import CodeListing from './ContentNode/CodeListing.vue';
import LinkableHeading from './ContentNode/LinkableHeading.vue';
import CodeVoice from './ContentNode/CodeVoice.vue';
import DictionaryExample from './ContentNode/DictionaryExample.vue';
import EndpointExample from './ContentNode/EndpointExample.vue';
Expand Down Expand Up @@ -230,14 +231,13 @@ function renderNode(createElement, references) {
};
return createElement(EndpointExample, { props }, renderChildren(node.summary || []));
}
case BlockType.heading:
return createElement(`h${node.level}`, {
attrs: {
id: node.anchor,
},
}, (
node.text
));
case BlockType.heading: {
const props = {
anchor: node.anchor,
level: node.level,
};
return createElement(LinkableHeading, { props }, node.text);
}
case BlockType.orderedList:
return createElement('ol', {
attrs: {
Expand Down
84 changes: 84 additions & 0 deletions src/components/ContentNode/LinkableHeading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--
This source file is part of the Swift.org open source project

Copyright (c) 2022 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->

<template>
<component
:id="anchor"
:is="`h${level}`"
>
<router-link
v-if="anchor && !isTargetIDE"
:to="{ hash: `#${anchor}` }"
class="header-anchor"
aria-label="Scroll to section"
@click="handleFocusAndScroll(anchor)"
>
<slot />
<LinkIcon class="icon" aria-hidden="true"/>
</router-link>
<template v-else>
<slot />
</template>
</component>
</template>

<script>
import scrollToElement from 'docc-render/mixins/scrollToElement';
import LinkIcon from 'theme/components/Icons/LinkIcon.vue';

export default {
name: 'LinkableHeading',
mixins: [scrollToElement],
components: {
LinkIcon,
},
props: {
anchor: {
type: String,
required: false,
},
level: {
type: Number,
default: () => 2,
validator: v => v >= 1 && v <= 6,
},
},
inject: {
isTargetIDE: {
default: () => false,
},
},
};
</script>

<style scoped lang="scss">
@import 'docc-render/styles/_core.scss';
$icon-margin: 7px;

.header-anchor {
color: inherit;
text-decoration: none;
position: relative;
padding-right: $icon-size-default + $icon-margin;
display: inline-block;

.icon {
position: absolute;
bottom: .2em;
display: none;
height: $icon-size-default;
margin-left: $icon-margin;
}

&:hover .icon {
display: inline;
}
}
</style>
5 changes: 3 additions & 2 deletions src/components/DocumentationTopic/ContentTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
:title="title"
>
<div class="container">
<h2 class="title">{{title}}</h2>
<LinkableHeading class="title" :anchor="anchor">{{ title }}</LinkableHeading>
<slot />
</div>
</OnThisPageSection>
</template>

<script>
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
import OnThisPageSection from './OnThisPageSection.vue';

export default {
name: 'ContentTable',
components: { OnThisPageSection },
components: { OnThisPageSection, LinkableHeading },
props: {
anchor: {
type: String,
Expand Down
17 changes: 16 additions & 1 deletion src/components/DocumentationTopic/ContentTableSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<div class="contenttable-section">
<div class="section-title">
<slot name="title">
<h3 class="title">{{ title }}</h3>
<LinkableHeading
:level="3"
class="title"
:anchor="anchorComputed"
>{{ title }}</LinkableHeading>
</slot>
</div>
<div class="section-content">
Expand All @@ -24,13 +28,24 @@
</template>

<script>
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
import { anchorize } from 'docc-render/utils/strings';

export default {
name: 'ContentTableSection',
components: { LinkableHeading },
props: {
title: {
type: String,
required: true,
},
anchor: {
type: String,
default: null,
},
},
computed: {
anchorComputed: ({ title, anchor }) => anchor || anchorize(title),
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DocumentationTopic/OnThisPageSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->

<template>
<section :id="anchor"><slot /></section>
<section><slot /></section>
</template>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class="declaration"
title="Declaration"
>
<h2>Declaration</h2>
<LinkableHeading anchor="declaration">Declaration</LinkableHeading>
<template v-if="hasModifiedChanges">
<DeclarationDiff
:class="[changeClasses, multipleLinesClass]"
Expand Down Expand Up @@ -48,6 +48,7 @@
<script>
import ConditionalConstraints from 'docc-render/components/DocumentationTopic/ConditionalConstraints.vue';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

import DeclarationGroup from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
import DeclarationDiff
Expand All @@ -65,6 +66,7 @@ export default {
DeclarationSourceLink,
ConditionalConstraints,
OnThisPageSection,
LinkableHeading,
},
constants: { ChangeTypes, multipleLinesClass },
inject: ['identifier', 'store'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class="parameters"
title="Parameters"
>
<h2>Parameters</h2>
<LinkableHeading anchor="parameters">Parameters</LinkableHeading>
<dl>
<template v-for="param in parameters">
<dt class="param-name" :key="`${param.name}:name`">
Expand All @@ -31,12 +31,14 @@
<script>
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

export default {
name: 'Parameters',
components: {
ContentNode,
OnThisPageSection,
LinkableHeading,
},
props: {
parameters: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<template>
<OnThisPageSection anchor="possibleValues" title="PossibleValues">
<h2>Possible Values</h2>
<LinkableHeading anchor="possibleValues">Possible Values</LinkableHeading>
<dl class="datalist">
<template v-for="value in values">
<dt class="param-name" :key="`${value.name}:name`">
Expand All @@ -28,10 +28,16 @@
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import ContentNode from 'docc-render/components/ContentNode.vue';
import WordBreak from 'docc-render/components/WordBreak.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

export default {
name: 'PossibleValues',
components: { ContentNode, OnThisPageSection, WordBreak },
components: {
ContentNode,
OnThisPageSection,
LinkableHeading,
WordBreak,
},
props: {
values: {
type: Array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class="details"
title="Details"
>
<h2>Details</h2>
<LinkableHeading anchor="details">Details</LinkableHeading>
<dl>
<template v-if="isSymbol">
<dt class="detail-type" :key="`${details.name}:name`">
Expand Down Expand Up @@ -45,12 +45,14 @@
<script>
import PropertyListKeyType from 'docc-render/components/DocumentationTopic/PrimaryContent/PropertyListKeyType.vue';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

export default {
name: 'PropertyListKeyDetails',
components: {
PropertyListKeyType,
OnThisPageSection,
LinkableHeading,
},
props: {
details: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<template>
<OnThisPageSection :anchor="anchor" :title="title">
<h2>{{ title }}</h2>
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
<ParametersTable :parameters="properties" :changes="propertyChanges" class="property-table">
<template slot="symbol" slot-scope="{ name, type, content, changes, deprecated }">
<div class="property-name" :class="{ deprecated: deprecated }">
Expand Down Expand Up @@ -60,6 +60,7 @@

<script>
import { anchorize } from 'docc-render/utils/strings';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
import WordBreak from 'docc-render/components/WordBreak.vue';
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';

Expand All @@ -83,6 +84,7 @@ export default {
ContentNode,
OnThisPageSection,
ParametersTable,
LinkableHeading,
},
props: {
title: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<template>
<OnThisPageSection :anchor="anchor" :title="title">
<h2>{{ title }}</h2>
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
<ParametersTable :parameters="[bodyParam]" :changes="bodyChanges" keyBy="key">
<template slot="symbol" slot-scope="{ type, content, changes, name }">
<PossiblyChangedType
Expand Down Expand Up @@ -84,6 +84,7 @@
import { anchorize } from 'docc-render/utils/strings';
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

import WordBreak from 'docc-render/components/WordBreak.vue';
import apiChangesProvider from 'docc-render/mixins/apiChangesProvider';
Expand All @@ -107,6 +108,7 @@ export default {
ContentNode,
OnThisPageSection,
ParametersTable,
LinkableHeading,
},
constants: { ChangesKey },
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

<template>
<OnThisPageSection :anchor="anchor" :title="title">
<h2>{{ title }}</h2>
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
<DeclarationSource :tokens="tokens" />
</OnThisPageSection>
</template>

<script>
import { anchorize } from 'docc-render/utils/strings';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
import DeclarationSource
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationSource.vue';

Expand All @@ -29,6 +30,7 @@ export default {
components: {
DeclarationSource,
OnThisPageSection,
LinkableHeading,
},
props: {
title: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<template>
<OnThisPageSection :anchor="anchor" :title="title">
<h2>{{ title }}</h2>
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
<ParametersTable :parameters="parameters" :changes="parameterChanges">
<template slot="symbol" slot-scope="{ name, type, content, changes, deprecated }">
<div class="param-name" :class="{ deprecated: deprecated }">
Expand Down Expand Up @@ -55,6 +55,7 @@
import { anchorize } from 'docc-render/utils/strings';
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';

import WordBreak from 'docc-render/components/WordBreak.vue';
import apiChangesProvider from 'docc-render/mixins/apiChangesProvider';
Expand All @@ -76,6 +77,7 @@ export default {
ContentNode,
OnThisPageSection,
ParametersTable,
LinkableHeading,
},
props: {
title: {
Expand Down
Loading