From 84b31396ec34b54e3fde7f48df05082fb301c07b Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 9 Jun 2021 20:34:51 +0200 Subject: [PATCH] feat: more flexible carousels and fix homepage alignment Currently the carousels on the front page don't align with any other elements on the page which looks odd. This seems to be due to a limitation where the item size has to be passed in to the carousel. These changes reimplement the carousel, making it more flexible and allowing it to handle any size of items and any spacing. The new carousel is used on the frontpage to lay out the items in a way that aligns with the rest of the content. --- .../app/pages/homepage/_homepage-theme.scss | 16 -- .../src/app/pages/homepage/homepage.html | 36 ++-- .../src/app/pages/homepage/homepage.scss | 80 ++++++-- .../src/app/shared/carousel/carousel.html | 22 ++- .../src/app/shared/carousel/carousel.scss | 15 +- .../src/app/shared/carousel/carousel.spec.ts | 43 +--- .../src/app/shared/carousel/carousel.ts | 187 +++++++----------- 7 files changed, 181 insertions(+), 218 deletions(-) diff --git a/material.angular.io/src/app/pages/homepage/_homepage-theme.scss b/material.angular.io/src/app/pages/homepage/_homepage-theme.scss index d1ac6e13d821..2657931cc0bb 100644 --- a/material.angular.io/src/app/pages/homepage/_homepage-theme.scss +++ b/material.angular.io/src/app/pages/homepage/_homepage-theme.scss @@ -57,21 +57,5 @@ } outline: none; } - - .docs-featured-components-carousel-item:hover { - img { - transform: scale(1.2); - } - - box-shadow:inset 0 0 0 1.5px mat.get-color-from-palette($foreground, divider); - } - - .docs-featured-components-carousel-item:focus { - img { - transform: scale(1.2); - } - - box-shadow:inset 0 0 0 1.5px mat.get-color-from-palette($foreground, disabled); - } } } diff --git a/material.angular.io/src/app/pages/homepage/homepage.html b/material.angular.io/src/app/pages/homepage/homepage.html index ef0b4654e366..128f69a20513 100644 --- a/material.angular.io/src/app/pages/homepage/homepage.html +++ b/material.angular.io/src/app/pages/homepage/homepage.html @@ -43,9 +43,16 @@

Frictionless

+ + + + {{guide.name}} @@ -76,11 +85,6 @@

Guides

- - - View all guides - chevron_right - diff --git a/material.angular.io/src/app/pages/homepage/homepage.scss b/material.angular.io/src/app/pages/homepage/homepage.scss index 323107553c8a..fb6cd7bc5916 100644 --- a/material.angular.io/src/app/pages/homepage/homepage.scss +++ b/material.angular.io/src/app/pages/homepage/homepage.scss @@ -53,6 +53,9 @@ $margin-promotion-sections-small: 15px; display: flex; flex-direction: column; padding: 16px; + width: 75%; + max-width: 1080px; + margin: auto; a { text-decoration: none; @@ -61,7 +64,7 @@ $margin-promotion-sections-small: 15px; h2 { font-size: 25px; font-weight: 400; - margin: 16px 0; + margin: 0 0 16px; padding: 0; } @@ -74,7 +77,7 @@ $margin-promotion-sections-small: 15px; } mat-divider { - width: 75%; + width: 100%; } mat-icon { @@ -82,8 +85,19 @@ $margin-promotion-sections-small: 15px; } } +.carousel-item { + width: 48%; + + & + & { + margin-left: 2%; + } + + @media (min-width: 1020px) { + max-width: 32%; + } +} + .docs-homepage-row { - width: 75%; display: flex; flex-direction: row; margin: $margin-promotion-sections 0; @@ -91,20 +105,32 @@ $margin-promotion-sections-small: 15px; .docs-homepage-carousel-row { margin: $margin-promotion-sections 0; - width: 75%; display: flex; flex-direction: column; + width: 100%; - a.docs-link { - width: 100%; - text-align: right; + h2 { + margin-top: 0; } +} + +.docs-homepage-header { + display: flex; + width: 100%; + align-items: center; + justify-content: space-between; + margin-bottom: 16px; h2 { - margin-top: 0; + margin: 0; } } +.docs-link { + display: inline-flex; + align-items: center; +} + .docs-homepage-guides { .docs-homepage-guides-card-divider { width: 30%; @@ -113,9 +139,18 @@ $margin-promotion-sections-small: 15px; } .docs-homepage-guides-carousel-item { - padding: 15px; display: flex; text-decoration: none; + box-sizing: border-box; + + // We need a slight padding so the box shadow doesn't get cut off by the carousel. + padding: 3px; + + .mat-card { + // Ensures that the cards stretch to the full width of the item. + width: 100%; + min-height: 140px; + } } .docs-homepage-guides-card.mat-card { @@ -131,31 +166,39 @@ $margin-promotion-sections-small: 15px; } } - .docs-homepage-featured-components { .docs-featured-components-carousel-item { - padding: 15px; text-align: center; + box-sizing: border-box; + font-size: 18px; .docs-homepage-img-container { overflow: hidden; - width: 259px; - height: 144px; - margin-bottom: 10px; + margin-bottom: 16px; + max-height: 200px; } img { transition: 0.3s ease-in-out; width: 100%; } + + &:hover, &:focus { + img { + transform: scale(1.1); + } + } } } .docs-homepage-row-column { display: flex; flex-direction: column; - margin: 0 auto; - width: 30%; + width: 32%; + + & + & { + margin-left: 2%; + } } .docs-header-start { @@ -187,6 +230,10 @@ $margin-promotion-sections-small: 15px; .docs-homepage-row-column { width: 100%; + + & + & { + margin-left: 0; + } } } @@ -194,7 +241,6 @@ $margin-promotion-sections-small: 15px; * Rules for when the device is detected to be a small screen. */ @media (max-width: 720px) { - .docs-header-start { margin: $margin-promotion-sections-small 0 0 0; } diff --git a/material.angular.io/src/app/shared/carousel/carousel.html b/material.angular.io/src/app/shared/carousel/carousel.html index b75a21734e4e..c331a1e9847c 100644 --- a/material.angular.io/src/app/shared/carousel/carousel.html +++ b/material.angular.io/src/app/shared/carousel/carousel.html @@ -1,14 +1,16 @@ + +