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

Add media query & debug on homepage #184

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions apps/front/src/pages/homePage/HomePage.module.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
@use "../../styles/reference" as *;

.root {
background: salmon;

@include desktop {
background: red;
}

@include desktop-portrait {
background: green;
}

@include mobile-landscape {
background: blue;
}
}

.fontSize {
@include absoluteCenter();
font-size: 40rem;
}
24 changes: 23 additions & 1 deletion apps/front/src/pages/homePage/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import css from "./HomePage.module.scss"
import React, { ForwardedRef, forwardRef, Suspense, useEffect, useRef } from "react"
import React, {
ForwardedRef,
forwardRef,
Suspense,
useEffect,
useRef,
useState
} from "react"
import { useStack } from "@cher-ami/router"
import debug from "@cher-ami/debug"
import { MetasManager, TMetaTags } from "~/libs/dom/MetaManager"
import { listen } from "@cher-ami/utils"
const TestComponent = React.lazy(() => import("./LazyTest"))

interface IProps {
Expand All @@ -19,8 +27,21 @@ const log = debug(`front:${componentName}`)
* @name HomePage
*/
function HomePage(props: IProps, handleRef: ForwardedRef<any>) {
//--------------------------------------------------------------------- REFS
const rootRef = useRef<HTMLDivElement>(null)

//--------------------------------------------------------------------- STATE
const [fontSize, setFontSize] = useState<string>("0")

//--------------------------------------------------------------------- EFFECTS

useEffect(() => {
setFontSize(window.getComputedStyle(document.body).getPropertyValue("font-size"))
return listen(window, "resize", () =>
setFontSize(window.getComputedStyle(document.body).getPropertyValue("font-size"))
)
}, [])

/**
* Client meta
*/
Expand Down Expand Up @@ -53,6 +74,7 @@ function HomePage(props: IProps, handleRef: ForwardedRef<any>) {
<TestComponent />
</Suspense>
{componentName}
<div className={css.fontSize}>{fontSize}</div>
<br />
<br />
<div>data from getStaticProps: </div>
Expand Down
1 change: 1 addition & 0 deletions apps/front/src/styles/_breakpoints.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// breakpoints
// need both for scss and css
$breakpoint-mobile: 320px;
$breakpoint-mobile-horizontal: 500px;
$breakpoint-tablet: 768px;
$breakpoint-laptop: 1024px;
$breakpoint-bigLaptop: 1440px;
Expand Down
52 changes: 39 additions & 13 deletions apps/front/src/styles/_ratio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,34 @@
}
}

/// Mixin pour manipuler les propriétés des vues en fonction des breakpoints.
/// @param {string} $property - La propriété CSS à manipuler.
/// @param {any} $value1 - La première valeur pour cette propriété.
/// @param {any} [$value2=$value1] - La deuxième valeur pour cette propriété (par défaut égale à $value1).
/// @param {string} [$breakpoint=breakpoints.$breakpoint-tablet] - Le point de rupture (breakpoint) pour les médias queries (par défaut égal à breakpoints.$breakpoint-tablet).
/// @param {boolean} [$cap=false] - Indique si les valeurs doivent être plafonnées (par défaut false).
@mixin propertyViewport(
$property,
$value1,
$value2: $value1,
$breakpoint: breakpoints.$breakpoint-tablet,
$cap: false
) {
//Mobile
@include propertyVW($property, $value1);
@media (min-width: $breakpoint) {
@include propertyVH($property, $value2);
}

@media (min-width: breakpoints.$breakpoint-tablet) and (orientation: portrait) {
@include propertyVW($property, $value2, viewport.$viewport-reference-tablet-width);
//Horizontal Desktop & Tablet
@include desktop($breakpoint) {
@include propertyVH($property, $value2, $ratioVW: 0);
}

@media (min-width: breakpoints.$breakpoint-laptop) and (orientation: landscape) {
@include propertyVH(
$property,
$value2,
viewport.$viewport-reference-desktop-height,
0
);
//Portrait Desktop & Tablet
@include desktop-portrait {
@include propertyVW($property, $value2, viewport.$viewport-reference-tablet-width);
}

@media (max-width: #{breakpoints.$breakpoint-laptop - 1}) and (orientation: landscape) {
//Horizontal mobile
@include mobile-landscape {
@include propertyVH($property, $value2, viewport.$viewport-reference-width, 0);
}

Expand All @@ -119,3 +121,27 @@
}
}
}

/// Desktop media query.
/// @param {string} [$breakpoint=breakpoints.$breakpoint-tablet] - Le point de rupture pour les médias queries (par défaut égal à breakpoints.$breakpoint-tablet).
@mixin desktop($breakpoint: breakpoints.$breakpoint-tablet) {
cherami-tech marked this conversation as resolved.
Show resolved Hide resolved
@media (min-width: $breakpoint) and (orientation: landscape) and (min-height: breakpoints.$breakpoint-mobile-horizontal) {
cherami-tech marked this conversation as resolved.
Show resolved Hide resolved
@content;
}
}

/// Desktop & Tablet portrait media query
/// @param {string} [$breakpoint=breakpoints.$breakpoint-tablet] - Le point de rupture pour les médias queries (par défaut égal à breakpoints.$breakpoint-tablet).
@mixin desktop-portrait($breakpoint: breakpoints.$breakpoint-tablet) {
@media (min-width: $breakpoint) and (orientation: portrait) {
@content;
}
}

/// Mobile landscape media query.
/// @param {string} [$breakpoint=breakpoints.$breakpoint-laptop] - Le point de rupture pour les médias queries (par défaut égal à breakpoints.$breakpoint-laptop).
@mixin mobile-landscape($breakpoint: breakpoints.$breakpoint-laptop) {
@media (max-width: #{$breakpoint - 1}) and (orientation: landscape) {
@content;
}
}
1 change: 1 addition & 0 deletions apps/front/src/styles/breakpoints-inline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

:root {
--breakpoint-mobile: #{$breakpoint-mobile};
--breakpoint-mobile-horizontal: #{$breakpoint-mobile-horizontal};
--breakpoint-tablet: #{$breakpoint-tablet};
--breakpoint-laptop: #{$breakpoint-laptop};
--breakpoint-bigLaptop: #{$breakpoint-bigLaptop};
Expand Down
Loading