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

fix(anchors) Use scroll-padding for headings anchoring #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/demo/Components/DocPage/page-ru.json

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/demo/reset-storybook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
}
}

body.yc-root {
--dc-header-height: 64px;
}

.yc-root .Header {
display: flex;
justify-content: flex-end;
Expand Down
6 changes: 5 additions & 1 deletion styles/default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body {
padding: 0;
box-sizing: border-box;

--dc-header-height: 0;
--dc-header-height: 64px;
--dc-subheader-height: 40px;

--dc-error-image-403: url('data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=');
Expand All @@ -33,6 +33,10 @@ body {
}
}

html {
scroll-padding-top: var(--dc-header-height);
}

#root {
min-height: 100vh;
}
5 changes: 2 additions & 3 deletions styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
list-style: none;
}

@mixin fixAnchorPosition($offset: 0px) {
padding-top: calc(var(--dc-header-height, #{$headerHeight}));
margin-top: calc(#{$offset} - var(--dc-header-height, #{$headerHeight}));
@mixin setHeadingPadding($offset: 0px) {
padding-top: calc(var(--dc-header-height, #{$headerHeight}) - #{$offset});
}

@mixin reset-link-style() {
Expand Down
37 changes: 25 additions & 12 deletions styles/yfm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,15 @@
// The margin is summed up. So, we need to take 15px away from the header margin-top
h1,
h2 {
@include fixAnchorPosition(calc(#{$headerMarginTopLarge} - #{$blockMarginBottomMedium}));
@include setHeadingPadding(calc(#{$headerMarginTopLarge} - #{$blockMarginBottomMedium}));
margin-bottom: $blockMarginBottomLarge;
}

h3,
h4,
h5,
h6 {
@include fixAnchorPosition(calc(#{$headerMarginTopMedium} - #{$blockMarginBottomMedium}));
}

h1 + h2,
h2 + h3,
h3 + h4,
h4 + h5,
h5 + h6 {
@include fixAnchorPosition();
@include setHeadingPadding(calc(#{$headerMarginTopMedium} - #{$blockMarginBottomMedium}));
}

// Use 0px for the top offset of the header if it is the first child element,
Expand All @@ -138,7 +130,28 @@
h5,
h6 {
&:first-child {
@include fixAnchorPosition();
@include setHeadingPadding();
}
}

h1 + h2,
h2 + h3,
h3 + h4,
h4 + h5,
h5 + h6 {
padding-top: 0;
}

table {
h1,
h2,
h3,
h4,
h5,
h6 {
/* stylelint-disable-next-line declaration-no-important */
padding-top: 0 !important;
margin-bottom: 0;
}
}

Expand All @@ -155,7 +168,7 @@
& + h4,
& + h5,
& + h6 {
@include fixAnchorPosition(#{$headerMarginTopLarge});
@include setHeadingPadding(#{$headerMarginTopLarge});
}
}

Expand Down