Skip to content

Commit

Permalink
fix(anchors) Use scroll-padding for headings anchoring
Browse files Browse the repository at this point in the history
  • Loading branch information
makishvili committed Jul 25, 2023
1 parent 2ece8dc commit 6d38fc8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
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;
}
4 changes: 2 additions & 2 deletions styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}

@mixin fixAnchorPosition($offset: 0px) {
padding-top: calc(var(--dc-header-height, #{$headerHeight}));
margin-top: calc(#{$offset} - var(--dc-header-height, #{$headerHeight}));
// Works with scroll-padding-top (see /styles/default.css)
padding-top: calc(var(--dc-header-height, #{$headerHeight}) - #{$offset});
}

@mixin reset-link-style() {
Expand Down
30 changes: 22 additions & 8 deletions styles/yfm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@
@include fixAnchorPosition(calc(#{$headerMarginTopMedium} - #{$blockMarginBottomMedium}));
}

h1 + h2,
h2 + h3,
h3 + h4,
h4 + h5,
h5 + h6 {
@include fixAnchorPosition();
}

// Use 0px for the top offset of the header if it is the first child element,
// because it is located after the page title
h1,
Expand All @@ -142,6 +134,28 @@
}
}

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

table {
h1,
h2,
h3,
h4,
h5,
h6 {
// Непонятно, как нормально переопределить селектор с &:first-child
/* stylelint-disable-next-line declaration-no-important */
padding-top: 0 !important;
margin-bottom: 0;
}
}

.yfm-page__delimeter {
height: 4px;
border-radius: 2px;
Expand Down

0 comments on commit 6d38fc8

Please sign in to comment.