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 responsive design to the components in components/layouts #124

Merged
merged 4 commits into from
Oct 28, 2024
Merged
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
3 changes: 3 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
extends: ['stylelint-config-standard-scss', 'stylelint-config-recess-order'],
rules: {
'scss/no-global-function-names': null,
},
};
6 changes: 3 additions & 3 deletions src/components/layouts/Article/Article.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
width: 100%;
min-width: 200px;
max-width: 980px;
padding: 45px;
padding: $size-article-padding-small;
margin: 0 auto;

@media (width <= 767px) {
padding: 15px;
@include screen(lg) {
padding: $size-article-padding-large;
}
}
6 changes: 3 additions & 3 deletions src/components/layouts/Aside/Aside.module.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.aside {
@include selector-scrollbar(2px);
@include selector-scrollbar($size-2);

position: sticky;
top: $size-header-height;
height: calc(100vh - $size-header-height);
background-color: var(--color-bg-default);
border-right: 1px solid var(--color-border-default);
border-right: $border-default;

> ul:not(:last-child) {
margin: 16px 0;
border-bottom: 1px solid var(--color-border-default);
border-bottom: $border-default;
}
}
13 changes: 12 additions & 1 deletion src/components/layouts/Body/Body.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@

> aside {
grid-area: 2 / 1 / 3 / 2;
transform: translateX(-100%); // TODO: Move to `Aside` component.
}

> main {
grid-area: 2 / 2 / 3 / 3;
grid-area: 2 / 1 / 3 / 3;
}

@include screen(xl) {
> aside {
transform: translateX(0); // TODO: Move to `Aside` component.
}

> main {
grid-area: 2 / 2 / 3 / 3;
}
}
}
4 changes: 1 addition & 3 deletions src/components/layouts/Header/Header.module.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
.header {
@include props-flex-center;

position: sticky;
top: 0;
z-index: 1;
display: grid;
grid-template-columns: $size-sidebar-width 1fr 64px;
background-color: inherit;
border-bottom: 1px solid var(--color-border-default);
border-bottom: $border-default;

> div:first-child {
grid-area: 1 / 1 / 2 / 2;
Expand Down
14 changes: 13 additions & 1 deletion src/components/layouts/Main/Main.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
.main {
display: grid;
grid-template-columns: 1fr $size-nav-width;
contain: paint; // `overflow: hidden` prevent children's `position: sticky` from working. So I used it instead.

> article {
grid-area: 1 / 1 / 2 / 2;
grid-area: 1 / 1 / 2 / 3;
}

> nav {
grid-area: 1 / 2 / 2 / 3;
transform: translateX(100%); // TODO: Move to `Nav` component.
}

@include screen(md) {
> article {
grid-area: 1 / 1 / 2 / 2;
}

> nav {
transform: translateX(0); // TODO: Move to `Nav` component.
}
}
}
17 changes: 15 additions & 2 deletions src/components/layouts/Nav/Nav.module.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
.nav {
@include selector-scrollbar($size-2);

position: sticky;
top: $size-header-height;
box-sizing: border-box;
height: calc(100vh - $size-header-height);
padding: 45px 24px 0 0;
padding: $size-article-padding-small;
background-color: var(--color-bg-inset);
border-left: $border-default;

> div {
padding: 4px 8px;
background-color: var(--color-bg-default);
border: 1px solid var(--color-border-default);
border: $border-default;
border-radius: $size-border-radius;
}

@include screen(md) {
background-color: inherit;
border-left: none;
}

@include screen(lg) {
padding: $size-article-padding-large 24px 0 0;
}
}
2 changes: 1 addition & 1 deletion src/components/layouts/Section/Section.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.section {
margin: 50px 0;
margin: 32px 0;
}
9 changes: 8 additions & 1 deletion src/styles/utils/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
}

@mixin selector-scrollbar($width: 4px) {
@mixin selector-scrollbar($width: $size-4) {
overflow: hidden auto;

// Global usage: `*::webkit-scrollbar`.
Expand All @@ -76,3 +76,10 @@
}
}
}

/* media */
@mixin screen($breakpoint) {
@media (min-width: map-get($breakpoints, $breakpoint)) {
@content;
}
}
19 changes: 17 additions & 2 deletions src/styles/utils/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$config-base-not-pseudo-class-selector: '.markdown-body *';

/* size */
$size-2: 0.125rem;
$size-4: 0.25rem;
$size-8: 0.5rem;
$size-16: 1rem;
Expand All @@ -10,15 +11,20 @@ $size-40: 2.5rem;
$size-border-radius: 6px;
$size-header-height: 64px;
$size-sidebar-width: 256px;
$size-article-padding-large: 45px;
$size-article-padding-small: 16px;
$size-nav-width: $size-sidebar-width;

/* text-weight */
$text-weight-normal: 400;
$text-weight-medium: 500;
$text-weight-semibold: 600;

/* list */
$border-default: 1px solid var(--color-border-default);

/* font */
$font-stack-system: // For general usage
$font-stack-system:
-apple-system,
blinkmacsystemfont,
segoe ui,
Expand All @@ -28,11 +34,20 @@ $font-stack-system: // For general usage
sans-serif,
apple color emoji,
segoe ui emoji;
$font-stack-monospace: // For markdown content
$font-stack-monospace:
ui-monospace,
sfmono-regular,
sf mono,
menlo,
consolas,
liberation mono,
monospace;

/* breakpoints */
$breakpoints: (
sm: 640px,
md: 768px,
lg: 1024px,
xl: 1280px,
2xl: 1536px,
);