A platform for community discussion. Free, open, simple.
Add container queries library (#41876)
Manuel Kostka6db0f1eaeaac
diff --git a/app/assets/stylesheets/lib/breakpoints.import.scss b/app/assets/stylesheets/lib/breakpoints.import.scssnew file mode 100644index 00000000000..5b9479d52f9--- /dev/null+++ b/app/assets/stylesheets/lib/breakpoints.import.scss@@ -0,0 +1 @@+@error "lib/breakpoints should be accessed via @use not @import";diff --git a/app/assets/stylesheets/lib/breakpoints.scss b/app/assets/stylesheets/lib/breakpoints.scssnew file mode 100644index 00000000000..dc3887270c0--- /dev/null+++ b/app/assets/stylesheets/lib/breakpoints.scss@@ -0,0 +1,19 @@+@use "sass:map";++// Shared breakpoint scale used by the viewport and container libraries+$breakpoints: (+ xs: 20rem,+ sm: 40rem,+ md: 48rem,+ lg: 64rem,+ xl: 80rem,+ 2xl: 96rem,+);++@function get($bp) {+ @if not map.has-key($breakpoints, $bp) {+ @error "Invalid breakpoint: #{$bp}";+ }++ @return map.get($breakpoints, $bp);+}diff --git a/app/assets/stylesheets/lib/container.import.scss b/app/assets/stylesheets/lib/container.import.scssnew file mode 100644index 00000000000..cf1ad692137--- /dev/null+++ b/app/assets/stylesheets/lib/container.import.scss@@ -0,0 +1 @@+@error "lib/container should be accessed via @use not @import";diff --git a/app/assets/stylesheets/lib/container.scss b/app/assets/stylesheets/lib/container.scssnew file mode 100644index 00000000000..d3ab81ef805--- /dev/null+++ b/app/assets/stylesheets/lib/container.scss@@ -0,0 +1,29 @@+@use "breakpoints";++$breakpoints: breakpoints.$breakpoints;++@function _container-name($name) {+ @if $name {+ @return "#{$name} ";+ }++ @return "";+}++@mixin from($bp, $name: null) {+ @container #{_container-name($name)}(width >= #{breakpoints.get($bp)}) {+ @content;+ }+}++@mixin until($bp, $name: null) {+ @container #{_container-name($name)}(width < #{breakpoints.get($bp)}) {+ @content;+ }+}++@mixin between($from, $until, $name: null) {+ @container #{_container-name($name)}(#{breakpoints.get($from)} <= width < #{breakpoints.get($until)}) {+ @content;+ }+}diff --git a/app/assets/stylesheets/lib/viewport.scss b/app/assets/stylesheets/lib/viewport.scssindex aea427a9457..f7127893f72 100644--- a/app/assets/stylesheets/lib/viewport.scss+++ b/app/assets/stylesheets/lib/viewport.scss@@ -1,35 +1,21 @@-@use "sass:map";+@use "breakpoints";-$breakpoints: (- sm: 40rem,- md: 48rem,- lg: 64rem,- xl: 80rem,- 2xl: 96rem,-);--@function _get-breakpoint($bp) {- @if not map.has-key($breakpoints, $bp) {- @error "Invalid breakpoint: #{$bp}";- }-- @return map.get($breakpoints, $bp);-}+$breakpoints: breakpoints.$breakpoints;@mixin from($bp) {- @media (width >= #{_get-breakpoint($bp)}) {+ @media (width >= #{breakpoints.get($bp)}) {@content;}}@mixin until($bp) {- @media (width < #{_get-breakpoint($bp)}) {+ @media (width < #{breakpoints.get($bp)}) {@content;}}@mixin between($from, $until) {- @media (#{_get-breakpoint($from)} <= width < #{_get-breakpoint($until)}) {+ @media (#{breakpoints.get($from)} <= width < #{breakpoints.get($until)}) {@content;}}