🔥 Huge style refactoring by using SvelteKit built-in style tag

It's been tricky but got there finally! Hello `:global`
- Avoid using one global CSS file containing everything
- Import the component SCSS file in a script tag from the component file to allow style scoping and including it only when used
This commit is contained in:
2022-06-22 23:25:08 +02:00
parent 4f81640b61
commit cdabe6935b
89 changed files with 1779 additions and 1735 deletions

View File

@@ -1,5 +1,5 @@
// Photos Page
.photos {
.photos-page {
// Intro Section
&__intro {
margin-bottom: clamp(32px, 7.5vw, 96px);
@@ -7,7 +7,7 @@
text-align: center;
// Title
h1 {
:global(h1) {
margin: -20px 0 48px;
color: $color-secondary;
line-height: 1;
@@ -17,7 +17,7 @@
}
}
// Text
p {
& > :global(p) {
max-width: 456px;
margin: 20px auto 56px;
@@ -35,219 +35,11 @@
}
}
// Filter
.filter {
position: relative;
max-width: 982px;
margin: 0 auto;
padding: 0 16px;
@include bp (sm) {
padding: 0 32px;
}
// Span
&__label {
display: block;
color: rgba($color-tertiary, 0.7);
@include bp (sm) {
position: absolute;
left: 64px;
top: 52%;
transform: translateY(-50%);
margin-bottom: 0;
}
}
&__bar {
display: flex;
justify-content: center;
align-items: center;
min-height: 64px;
margin-top: 20px;
padding: 0 12px;
background: $color-primary-darker;
border-radius: 50vh;
@include bp (mob-lg) {
padding: 0 16px;
}
@include bp (sm) {
height: 72px;
margin-top: 0;
padding: 28px 32px;
}
ul {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
li {
display: block;
margin: 8px 2px;
font-size: rem(14px);
color: #fff;
@include bp (sm) {
margin: 0 2px;
font-size: rem(16px);
}
}
.icon {
display: block;
width: 20px;
height: 20px;
overflow: hidden;
margin-right: 12px;
color: #fff;
border-radius: 100%;
transition: color 0.3s;
@include bp (sm) {
width: 26px;
height: 26px;
}
img {
display: block;
width: 100%;
height: 100%;
}
}
.select {
position: relative;
display: flex;
align-items: center;
padding: 8px 12px 8px 8px;
font-weight: 900;
border-radius: 100vh;
transition: background-color 0.2s;
@include bp (sm) {
padding: 8px 16px;
}
select {
opacity: 0;
position: absolute;
top: 0;
left: 8px;
width: 100%;
height: 100%;
cursor: pointer;
}
}
// Hover
li:hover {
.icon {
color: $color-secondary-light;
}
.select {
background-color: $color-primary-tertiary20;
}
}
}
// Actions
&__actions {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20px;
@include bp (sm) {
position: absolute;
top: 50%;
right: 56px;
transform: translateY(-50%);
margin-top: 0;
}
a {
display: block;
text-decoration: none;
color: rgba(#fff, 0.6);
font-size: rem(14px);
font-weight: 900;
line-height: 1;
img {
display: block;
}
}
// Reset link
.reset {
margin-right: 16px;
padding: 0;
color: rgba($color-tertiary, 0.6);
font-weight: 900;
font-size: rem(14px);
transition: color 0.3s;
&:hover {
color: $color-tertiary;
}
}
// Shuffle button
.shuffle {
display: flex;
align-items: center;
justify-content: center;
height: 32px;
background-color: $color-tertiary;
padding: 0 16px;
border-radius: 50vh;
}
}
/*
** States
*/
// Fixed when scrolled pass intro
&.is-over {
--top: 24px;
transform: translate3d(0, calc(-100% - var(--top)), 0);
pointer-events: none;
.filter__bar {
pointer-events: auto;
box-shadow: 0 10px 20px rgba(#000, 0.1);
}
@include bp (sm) {
position: fixed;
z-index: 10;
top: var(--top);
left: 0;
right: 0;
}
}
// Visible when scrolling back up
&.is-visible {
transform: translate3d(0,0,0);
pointer-events: auto;
}
// Apply transition
&.is-transitioning {
transition: transform 1.0s var(--ease-quart);
}
}
// Content Block
&__content {
--corners: 8px;
position: relative;
padding: 20px 0;
padding: 20px;
background-color: $color-tertiary;
@include bp (sm) {
@@ -286,6 +78,16 @@
transform: translate3d(var(--margin-sides), 0, 0);
}
}
// Modules
:global(.grid-modules) {
grid-column: span var(--columns);
margin-bottom: 0;
@include bp (sd) {
grid-column: 2 / span 22;
}
}
}
// Photo Grid
@@ -310,22 +112,16 @@
}
// Photo
.photo {
:global(.photo) {
position: relative;
opacity: 0;
transform: translate3d(0, 96px, 0);
transition: opacity 1.2s var(--ease-quart), transform 1.2s var(--ease-quart);
// Hidden state
&.is-visible {
opacity: 1;
transform: translate3d(0,0,0);
}
a {
:global(a) {
display: block;
}
figcaption {
:global(figcaption) {
position: absolute;
top: 0;
left: 0;
@@ -397,9 +193,19 @@
}
}
// Show postcard on hover
&:hover {
:global(.postcard) {
opacity: 1;
transform: translate3d(3%, 3%, 0) rotate(2deg);
}
:global(.postcard--small) {
transform: translate3d(0,0,0);
}
}
// Postcard
.postcard {
:global(.postcard) {
position: absolute;
bottom: 0;
right: 0;
@@ -408,27 +214,19 @@
opacity: 0;
transform: translate3d(6%, 12%, 0) rotate(-1deg);
transition: opacity 0.5s var(--ease-quart), transform 0.9s var(--ease-quart);
&--small {
border-radius: 6px 6px 0 0;
transform: translate3d(6%, 12%, 0) rotate(-3deg);
}
}
// Show postcard on hover
&:hover {
.postcard {
opacity: 1;
transform: translate3d(3%, 3%, 0) rotate(2deg);
&--small {
transform: translate3d(0,0,0);
}
}
:global(.postcard--small) {
border-radius: 6px 6px 0 0;
transform: translate3d(6%, 12%, 0) rotate(-3deg);
}
}
}
// Visible photo state
:global(.is-visible) {
opacity: 1;
transform: translate3d(0,0,0);
}
}
// Message
&__message {
@@ -441,108 +239,297 @@
grid-column: 3 / span 20;
}
}
}
/**
* Controls
*/
.controls {
grid-column: span var(--columns);
display: grid;
margin: 48px auto;
align-items: center;
/*
** Filters
*/
.filters {
position: relative;
max-width: 982px;
margin: 0 auto;
padding: 0 16px;
@include bp (sm) {
padding: 0 32px;
}
// Bar
&__bar {
display: flex;
justify-content: center;
align-items: center;
min-height: 64px;
margin-top: 20px;
padding: 0 12px;
background: $color-primary-darker;
border-radius: 50vh;
@include bp (mob-lg) {
padding: 0 16px;
}
@include bp (sm) {
justify-content: space-between;
margin: clamp(56px, 4.5vw, 80px) 0;
}
@include bp (sd) {
--columns: 22;
grid-column: 2 / span var(--columns);
height: 72px;
margin-top: 0;
padding: 28px 32px;
}
// Updated Date
&__date {
grid-column: span var(--columns);
grid-row: 2;
font-size: rem(18px);
color: rgba($color-gray, 0.6);
font-weight: 300;
text-align: center;
margin: 24px 0 48px;
line-height: 1.35;
ul {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
li {
display: block;
margin: 8px 2px;
font-size: rem(14px);
color: #fff;
@include bp (sm) {
grid-column: span 5;
grid-row: 1;
text-align: left;
margin: 0;
margin: 0 2px;
font-size: rem(16px);
}
}
:global(.icon) {
display: block;
width: 20px;
height: 20px;
overflow: hidden;
margin-right: 12px;
color: #fff;
border-radius: 100%;
transition: color 0.3s;
@include bp (sm) {
width: 26px;
height: 26px;
}
time {
:global(img) {
display: block;
@include bp (sd) {
display: inline;
}
width: 100%;
height: 100%;
}
}
// See More Photos
.button {
grid-column: span var(--columns);
grid-row: 1;
margin: 0 auto;
:global(.select) {
position: relative;
display: flex;
align-items: center;
padding: 8px 12px 8px 8px;
font-weight: 900;
border-radius: 100vh;
transition: background-color 0.2s;
@include bp (sm) {
grid-column: 7 / span 12;
padding: 8px 16px;
}
@include bp (sd) {
grid-column-start: 6;
:global(select) {
opacity: 0;
position: absolute;
top: 0;
left: 8px;
width: 100%;
height: 100%;
cursor: pointer;
}
}
// Photo Count
&__count {
grid-column: span var(--columns);
grid-row: 3;
text-align: center;
color: rgba($color-text, 0.3);
font-family: $font-serif;
font-size: rem(64px);
font-weight: 200;
line-height: 1;
letter-spacing: -0.05em;
@include bp (sm) {
grid-column: 18 / span 7;
grid-row: 1;
margin-left: auto;
text-align: right;
// Hover
li:hover {
:global(.icon) {
color: $color-secondary-light;
}
@include bp (sd) {
grid-column-start: 16;
}
span {
display: inline-block;
margin: 0 -6px;
&:last-child {
margin-right: 0;
}
:global(.select) {
background-color: $color-primary-tertiary20;
}
}
}
// Modules
.grid-modules {
grid-column: span var(--columns);
margin-bottom: 0;
// Span
&__label {
display: block;
color: rgba($color-tertiary, 0.7);
@include bp (sm) {
position: absolute;
left: 64px;
top: 52%;
transform: translateY(-50%);
margin-bottom: 0;
}
}
// Actions
&__actions {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20px;
@include bp (sm) {
position: absolute;
top: 50%;
right: 56px;
transform: translateY(-50%);
margin-top: 0;
}
// Reset link
.reset {
margin-right: 16px;
padding: 0;
color: rgba($color-tertiary, 0.6);
font-weight: 900;
font-size: rem(14px);
transition: color 0.3s;
&:hover {
color: $color-tertiary;
}
}
// Shuffle button
// .shuffle {
// display: flex;
// align-items: center;
// justify-content: center;
// height: 32px;
// background-color: $color-tertiary;
// padding: 0 16px;
// border-radius: 50vh;
// }
}
/*
** States
*/
// Fixed when scrolled pass intro
&.is-over {
--top: 24px;
transform: translate3d(0, calc(-100% - var(--top)), 0);
pointer-events: none;
.filters__bar {
pointer-events: auto;
box-shadow: 0 10px 20px rgba(#000, 0.1);
}
@include bp (sm) {
position: fixed;
z-index: 10;
top: var(--top);
left: 0;
right: 0;
}
}
// Visible when scrolling back up
&.is-visible {
transform: translate3d(0,0,0);
pointer-events: auto;
}
// Apply transition
&.is-transitioning {
transition: transform 1.0s var(--ease-quart);
}
}
/**
* Controls
*/
.controls {
grid-column: span var(--columns);
display: grid;
margin: 48px auto;
align-items: center;
justify-content: center;
@include bp (sm) {
justify-content: space-between;
margin: clamp(56px, 4.5vw, 80px) 0;
}
@include bp (sd) {
--columns: 22;
grid-column: 2 / span var(--columns);
}
// Updated Date
&__date {
grid-column: span var(--columns);
grid-row: 2;
font-size: rem(18px);
color: rgba($color-gray, 0.6);
font-weight: 300;
text-align: center;
margin: 24px 0 48px;
line-height: 1.35;
@include bp (sm) {
grid-column: span 5;
grid-row: 1;
text-align: left;
margin: 0;
}
time {
display: block;
@include bp (sd) {
display: inline;
}
}
}
// See More Photos
:global(.button) {
grid-column: span var(--columns);
grid-row: 1;
margin: 0 auto;
@include bp (sm) {
grid-column: 7 / span 12;
}
@include bp (sd) {
grid-column: 2 / span 22;
grid-column-start: 6;
}
}
// Photo Count
&__count {
grid-column: span var(--columns);
grid-row: 3;
text-align: center;
color: rgba($color-text, 0.3);
font-family: $font-serif;
font-size: rem(64px);
font-weight: 200;
line-height: 1;
letter-spacing: -0.05em;
@include bp (sm) {
grid-column: 18 / span 7;
grid-row: 1;
margin-left: auto;
text-align: right;
}
@include bp (sd) {
grid-column-start: 16;
}
span {
display: inline-block;
margin: 0 -6px;
&:last-child {
margin-right: 0;
}
}
}
}