Skip to content

Commit

Permalink
feat(utils): implement responsive layout system
Browse files Browse the repository at this point in the history
  • Loading branch information
JoomFX committed Jul 16, 2024
1 parent 6dad9aa commit 7c23143
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 58 deletions.
24 changes: 24 additions & 0 deletions packages/utils/scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,28 @@
}
}
}
}


// Responsive Layout Breakpoints
@mixin kendo-breakpoint-up( $breakpoint, $media: all ) {
@media only #{$media} and (min-width: k-map-get( $kendo-breakpoints, #{$breakpoint} )) {
@content;
}
}

@mixin kendo-breakpoint-down( $breakpoint, $media: all ) {
@media only #{$media} and (max-width: ( k-map-get( $kendo-breakpoints, #{$breakpoint} ) - .02 )) {
@content;
}
}

@mixin kendo-breakpoint-only( $breakpoint, $media: all ) {
$breakpoint-index: k-list-index( k-map-keys($kendo-breakpoints), $breakpoint );
$next-breakpoint-index: $breakpoint-index + 1;

$next-breakpoint: k-list-nth( k-map-keys($kendo-breakpoints), $next-breakpoint-index );
@media only #{$media} and (min-width: k-map-get( $kendo-breakpoints, #{$breakpoint} )) and (max-width: ( k-map-get( $kendo-breakpoints, #{$next-breakpoint} ) - .02)) {
@content;
}
}
93 changes: 41 additions & 52 deletions packages/utils/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,47 @@ $kendo-sizing: () !default;

$kendo-border-radii: () !default;

$_default-kendo-fraction-classes: (
'91-6': 91.6666%,
'83-3': 83.3333%,
'66-6': 66.6666%,
'58-3': 58.3333%,
'41-6': 41.6666%,
'33-3': 33.3333%,
'16-7': 16.6666%,
'14-3': 14.2857%,
'12-5': 12.5%,
'11-1': 11.1111%,
'9-1': 9.0909%,
'8-3': 8.3333%
);

$kendo-fraction-classes: $_default-kendo-fraction-classes !default;
$kendo-fraction-classes: k-map-merge($_default-kendo-fraction-classes, $kendo-fraction-classes);

$_default-kendo-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px
) !default;

$kendo-breakpoints: $_default-kendo-breakpoints !default;
$kendo-breakpoints: k-map-merge($_default-kendo-breakpoints, $kendo-breakpoints);

$_default-kendo-container-max-widths: (
sm: 540px,
md: 720px,
lg: 960px,
xl: 1140px,
xxl: 1320px
) !default;

$kendo-container-max-widths: $_default-kendo-container-max-widths !default;
$kendo-container-max-widths: k-map-merge($_default-kendo-container-max-widths, $kendo-container-max-widths);

$kendo-utils: (

// Accessibility
Expand Down Expand Up @@ -273,19 +314,6 @@ $kendo-utils: (
11: 11,
12: 12,
13: 13,
-1: -1,
-2: -2,
-3: -3,
-4: -4,
-5: -5,
-6: -6,
-7: -7,
-8: -8,
-9: -9,
-10: -10,
-11: -11,
-12: -12,
-13: -13,
auto: auto
),
"grid-column-end": (
Expand All @@ -302,19 +330,6 @@ $kendo-utils: (
11: 11,
12: 12,
13: 13,
-1: -1,
-2: -2,
-3: -3,
-4: -4,
-5: -5,
-6: -6,
-7: -7,
-8: -8,
-9: -9,
-10: -10,
-11: -11,
-12: -12,
-13: -13,
auto: auto
),
"grid-column-span": (
Expand Down Expand Up @@ -347,19 +362,6 @@ $kendo-utils: (
11: 11,
12: 12,
13: 13,
-1: -1,
-2: -2,
-3: -3,
-4: -4,
-5: -5,
-6: -6,
-7: -7,
-8: -8,
-9: -9,
-10: -10,
-11: -11,
-12: -12,
-13: -13,
auto: auto
),
"grid-row-end": (
Expand All @@ -376,19 +378,6 @@ $kendo-utils: (
11: 11,
12: 12,
13: 13,
-1: -1,
-2: -2,
-3: -3,
-4: -4,
-5: -5,
-6: -6,
-7: -7,
-8: -8,
-9: -9,
-10: -10,
-11: -11,
-12: -12,
-13: -13,
auto: auto
),
"grid-row-span": (
Expand Down
10 changes: 10 additions & 0 deletions packages/utils/scss/flex-grid/_gap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,13 @@
@include generate-utils( gap-y, row-gap, $kendo-utils-gap, $css-var: "spacing" );

}

@mixin kendo-utils--flex-grid--gap--responsive($key) {

// Gap responsive utility classes
$kendo-utils-gap: k-map-get( $kendo-utils, "gap" ) !default;
@include generate-utils( gap-#{$key}, gap, $kendo-utils-gap, $css-var: "spacing", $important: false );
@include generate-utils( gap-x-#{$key}, column-gap, $kendo-utils-gap, $css-var: "spacing", $important: false );
@include generate-utils( gap-y-#{$key}, row-gap, $kendo-utils-gap, $css-var: "spacing", $important: false );

}
26 changes: 20 additions & 6 deletions packages/utils/scss/flex-grid/_grid-column-start-end.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,38 @@

@mixin kendo-utils--flex-grid--grid-column-start-end() {

// Grid column span utility classes
$kendo-utils-grid-column-span: k-map-get( $kendo-utils, "grid-column-span" ) !default;
@include generate-utils( col-span, grid-column, $kendo-utils-grid-column-span );

// Grid column start utility classes
$kendo-utils-grid-column-start: k-map-get( $kendo-utils, "grid-column-start" ) !default;
@include generate-utils( col-start, grid-column-start, $kendo-utils-grid-column-start );


// Grid column end utility classes
$kendo-utils-grid-column-end: k-map-get( $kendo-utils, "grid-column-end" ) !default;
@include generate-utils( col-end, grid-column-end, $kendo-utils-grid-column-end );


// Grid column span utility classes
$kendo-utils-grid-column-span: k-map-get( $kendo-utils, "grid-column-span" ) !default;
@include generate-utils( col-span, grid-column, $kendo-utils-grid-column-span );


// Legacy aliases
@include generate-utils( colspan, grid-column, $kendo-utils-grid-column-span );
.#{$kendo-prefix}colspan-all { @extend .#{$kendo-prefix}colspan-full !optional; }
.\!#{$kendo-prefix}colspan-all { @extend .\!#{$kendo-prefix}colspan-full !optional; }

}

@mixin kendo-utils--flex-grid--grid-column-start-end--responsive($key) {

// Grid column span responsive utility classes
$kendo-utils-grid-column-span: k-map-get( $kendo-utils, "grid-column-span" ) !default;
@include generate-utils( col-span-#{$key}, grid-column, $kendo-utils-grid-column-span, $important: false );

// Grid column start responsive utility classes
$kendo-utils-grid-column-start: k-map-get( $kendo-utils, "grid-column-start" ) !default;
@include generate-utils( col-start-#{$key}, grid-column-start, $kendo-utils-grid-column-start, $important: false );

// Grid column end responsive utility classes
$kendo-utils-grid-column-end: k-map-get( $kendo-utils, "grid-column-end" ) !default;
@include generate-utils( col-end-#{$key}, grid-column-end, $kendo-utils-grid-column-end, $important: false );

}
8 changes: 8 additions & 0 deletions packages/utils/scss/flex-grid/_grid-template-columns.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@
@include generate-utils( grid-cols, grid-template-columns, $kendo-utils-grid-template-columns );

}

@mixin kendo-utils--flex-grid--grid-template-columns--responsive($key) {

// Grid template columns responsive utility classes
$kendo-utils-grid-template-columns: k-map-get( $kendo-utils, "grid-template-columns" ) !default;
@include generate-utils( grid-cols-#{$key}, grid-template-columns, $kendo-utils-grid-template-columns, $important: false );

}
6 changes: 6 additions & 0 deletions packages/utils/scss/flex-grid/index.import.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@
@include kendo-utils--flex-grid--place-items();
@include kendo-utils--flex-grid--place-self();
}

@mixin kendo-utils--flex-grid--responsive($key) {
@include kendo-utils--flex-grid--gap--responsive($key);
@include kendo-utils--flex-grid--grid-column-start-end--responsive($key);
@include kendo-utils--flex-grid--grid-template-columns--responsive($key);
}
11 changes: 11 additions & 0 deletions packages/utils/scss/index.import.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@import "./accessibility/index.import.scss";
@import "./layout/index.import.scss";
@import "./responsive-layout/index.import.scss";
@import "./flex-grid/index.import.scss";
@import "./spacing/index.import.scss";
@import "./sizing/index.import.scss";
Expand All @@ -25,6 +26,7 @@
@mixin kendo-utils() {
@include kendo-utils--accessibility();
@include kendo-utils--layout();
@include kendo-utils--responsive-layout();
@include kendo-utils--flex-grid();
@include kendo-utils--spacing();
@include kendo-utils--sizing();
Expand All @@ -39,4 +41,13 @@
@include kendo-utils--svg();

@include kendo-utils--elevation();

// Responsive utils
@each $key, $val in $kendo-breakpoints {
@include kendo-breakpoint-up($key) {
@include kendo-utils--layout--responsive($key);
@include kendo-utils--flex-grid--responsive($key);
@include kendo-utils--spacing--responsive($key);
}
}
}
8 changes: 8 additions & 0 deletions packages/utils/scss/layout/_display.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@
.\!#{$kendo-prefix}d-flex-col { @extend .\!#{$kendo-prefix}d-flex, .\!#{$kendo-prefix}flex-row !optional; }

}

@mixin kendo-utils--layout--display--responsive($key) {

// Display responsive utility classes
$kendo-utils-display: k-map-get( $kendo-utils, "display" ) !default;
@include generate-utils( d-#{$key}, display, $kendo-utils-display, $important: false );

}
4 changes: 4 additions & 0 deletions packages/utils/scss/layout/index.import.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
@include kendo-utils--layout--visibility();
@include kendo-utils--layout--zindex();
}

@mixin kendo-utils--layout--responsive($key) {
@include kendo-utils--layout--display--responsive($key);
}
48 changes: 48 additions & 0 deletions packages/utils/scss/responsive-layout/_col.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@mixin kendo-utils--responsive-layout--col() {

// Column
.k-col {
flex: 1 0 0%;
}

// Column Sizes
@for $i from 1 through 100 {
.k-col-size-#{$i} {
flex: 0 0 auto;
width: $i * 1%;
}
}

@each $i, $n in $kendo-fraction-classes {
.k-col-size-#{$i} {
flex: 0 0 auto;
width: $n;
}
}

}

@mixin kendo-utils--responsive-layout--col--responsive($key) {

// Column responsive
.k-col-#{$key} {
flex: 1 0 0%;
}

// Column Sizes responsive
@for $i from 1 through 100 {
.k-col-#{$key}-size-#{$i} {
flex: 0 0 auto;
width: $i * 1%;
}
}

@each $i, $n in $kendo-fraction-classes {
.k-col-#{$key}-size-#{$i} {
flex: 0 0 auto;
width: $n;
}
}
}


22 changes: 22 additions & 0 deletions packages/utils/scss/responsive-layout/_container.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@mixin kendo-utils--responsive-layout--container() {

// Page Container
.k-container,
.k-container-fluid {
margin: 0 auto;
width: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
}

}

@mixin kendo-utils--responsive-layout--container--responsive($key, $val) {

// Page Container responsive
.k-container {
max-width: var(--kendo-container-#{$key}-max-width, #{$val});
}

}
15 changes: 15 additions & 0 deletions packages/utils/scss/responsive-layout/_row.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@mixin kendo-utils--responsive-layout--row() {

// Row
.k-row {
display: flex;
flex-flow: row wrap;
box-sizing: border-box;

> * {
width: 100%;
box-sizing: border-box;
}
}

}
22 changes: 22 additions & 0 deletions packages/utils/scss/responsive-layout/index.import.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@import "./_container.scss";
@import "./_row.scss";
@import "./_col.scss";


@mixin kendo-utils--responsive-layout() {
@include kendo-utils--responsive-layout--container();
@include kendo-utils--responsive-layout--row();
@include kendo-utils--responsive-layout--col();

@each $key, $val in $kendo-breakpoints {
@include kendo-breakpoint-up($key) {
@include kendo-utils--responsive-layout--col--responsive($key);
}
}

@each $key, $val in $kendo-container-max-widths {
@include kendo-breakpoint-up($key) {
@include kendo-utils--responsive-layout--container--responsive($key, $val);
}
}
}
Loading

0 comments on commit 7c23143

Please sign in to comment.