Skip to content

Layout gap value list support #12

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

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions _index.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@forward './src/fxlayout' show class-selectors,
@forward "./src/fxlayout" show class-selectors,
gap-class-selectors,
gap-class-selectors-from-list,
attribute-selectors,
gap-attribute-selectors;
gap-attribute-selectors,
gap-attribute-selectors-from-list;

@forward "./src/lib/mixins" hide layout-gap-attributes,
layout-gap-classes;
@forward "./src/lib/mixins";
31 changes: 28 additions & 3 deletions src/fxlayout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
@use "lib/layout-classes" as layoutC;
@use "lib/layout-align-attributes" as layoutAlignA;
@use "lib/layout-align-classes" as layoutAlignC;
@use "lib/layout-gap-attributes" as layoutGapA;
@use "lib/layout-gap-classes" as layoutGapC;
@use "lib/flex-attributes" as flexA;
@use "lib/flex-classes" as flexC;
@use "lib/mixins" as mix;

/// Adds the css-fx-layout class selectors, e.g. `.fx-layout-row`
///
Expand Down Expand Up @@ -36,7 +37,19 @@
/// @param {bool} $includeSelectorsForMediaSizes [false]
/// Will generate additional selectors for flex layout media sizes
@mixin gap-class-selectors($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: false) {
@include mix.layout-gap-classes($from, $to, $gapUnits, $includeSelectorsForMediaSizes)
@include layoutGapC.layout-gap-classes($from, $to, $gapUnits, $includeSelectorsForMediaSizes)
}

/// Includes selectors for classes based on a list of values which can be used to add a gap to elements in a flex container
///
/// @param {number} $values
/// Will generate selectors for every value in $values list
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin gap-class-selectors-from-list($values: 4 8 16, $gapUnits: px em rem, $includeSelectorsForMediaSizes: false) {
@include layoutGapC.layout-gap-classes-from-list($values, $gapUnits, $includeSelectorsForMediaSizes)
}

/// Adds the css-fx-layout attribute selectors, e.g. `data-layout="row"`
Expand Down Expand Up @@ -67,5 +80,17 @@
/// @param {bool} $includeSelectorsForMediaSizes [false]
/// Will generate additional selectors for flex layout media sizes
@mixin gap-attribute-selectors($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: false) {
@include mix.layout-gap-attributes($from, $to, $gapUnits, $includeSelectorsForMediaSizes)
@include layoutGapA.layout-gap-attributes($from, $to, $gapUnits, $includeSelectorsForMediaSizes)
}

/// Includes selectors for attributes based on a list of values which can be used to add a gap to elements in a flex container
///
/// @param {number} $values
/// Will generate selectors for every value in $values list
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin gap-attribute-selectors-from-list($values: 4 8 16, $gapUnits: px em rem, $includeSelectorsForMediaSizes: false) {
@include layoutGapA.layout-gap-attributes-from-list($values, $gapUnits, $includeSelectorsForMediaSizes)
}
67 changes: 67 additions & 0 deletions src/lib/layout-gap-attributes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@use "sass:list";

@import "mixins";

/// Includes selectors for attributes which can be used to add a specific gap to elements in a flex container
///
/// @param {number} $value
/// Will start generating selectors for $value $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {string} $name
/// Will generate selectors for a specific media size, e.g. xs, sm, md, ...
@mixin layout-gap-attribute($value, $gapUnits, $name: false) {
@each $unit in $gapUnits {
*[data-layout-gap#{if($name, '-' + $name, '')}="#{$value}#{$unit}"] {
gap: #{$value}#{$unit};
}
}
}

/// Includes selectors for attributes which can be used to add a gap to elements in a flex container
///
/// @param {number} $from
/// Will start generating selectors from $from $gapUnits
/// @param {number} $to
/// Will generate selectors until including $to $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-attributes($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@for $i from $from through $to {
@include layout-gap-attribute($i, $gapUnits)
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@for $i from $from through $to {
@include layout-gap-attribute($i, $gapUnits, $name)
}
}
}
}
}

/// Includes selectors for attributes based on a list of values which can be used to add a gap to elements in a flex container
///
/// @param {number} $values
/// Will generate selectors for every value in $values list
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-attributes-from-list($values: 4 8 16, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@each $value in $values {
@include layout-gap-attribute($value, $gapUnits)
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@each $value in $values {
@include layout-gap-attribute($value, $gapUnits, $name)
}
}
}
}
}
67 changes: 67 additions & 0 deletions src/lib/layout-gap-classes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@use "sass:list";

@import "mixins";

/// Includes selectors for classes which can be used to add a specific gap to elements in a flex container
///
/// @param {number} $value
/// Will start generating selectors for $value $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {string} $name
/// Will generate selectors for a specific media size, e.g. xs, sm, md, ...
@mixin layout-gap-class($value, $gapUnits, $name: false) {
@each $unit in $gapUnits {
*.fx-gap--#{$value}#{$unit}#{if($name, '--' + $name, '')} {
gap: #{$value}#{$unit};
}
}
};

/// Includes selectors for classes which can be used to add a gap to elements in a flex container
///
/// @param {number} $from
/// Will start generating selectors from $from $gapUnits
/// @param {number} $to
/// Will generate selectors until including $to $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-classes($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@for $i from $from through $to {
@include layout-gap-class($i, $gapUnits)
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@for $i from $from through $to {
@include layout-gap-class($i, $gapUnits, $name)
}
}
}
}
}

/// Includes selectors for classes based on a list of values which can be used to add a gap to elements in a flex container
///
/// @param {number} $values
/// Will generate selectors for every value in $values list
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-classes-from-list($values: 4 8 16, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@each $value in $values {
@include layout-gap-class($value, $gapUnits)
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@each $value in $values {
@include layout-gap-class($value, $gapUnits, $name)
}
}
}
}
}
67 changes: 0 additions & 67 deletions src/lib/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,70 +186,3 @@ $flex-layout-media-queries: (
}
}

// Gap

/// Includes selectors for classes which can be used to add a gap to elements in a flex container
///
/// @param {number} $from
/// Will start generating selectors from $from $gapUnits
/// @param {number} $to
/// Will generate selectors until including $to $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-classes($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@for $i from $from through $to {
@each $unit in $gapUnits {
*.fx-gap--#{$i}#{$unit} {
gap: #{$i}#{$unit};
}
}
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@for $i from $from through $to {
@each $unit in $gapUnits {
*.fx-gap--#{$i}#{$unit}--#{$name} {
gap: #{$i}#{$unit};
}
}
}
}
}
}
}

/// Includes selectors for attributes which can be used to add a gap to elements in a flex container
///
/// @param {number} $from
/// Will start generating selectors from $from $gapUnits
/// @param {number} $to
/// Will generate selectors until including $to $gapUnits
/// @param {string} $gapUnits
/// Will generate selectors for the units passed in $gapUnits, e.g. px em rem
/// @param {bool} $includeSelectorsForMediaSizes
/// Will generate additional selectors for flex layout media sizes
@mixin layout-gap-attributes($from: 1, $to: 24, $gapUnits: px em rem, $includeSelectorsForMediaSizes: true) {
@for $i from $from through $to {
@each $unit in $gapUnits {
*[data-layout-gap="#{$i}#{$unit}"] {
gap: #{$i}#{$unit};
}
}
}
@if $includeSelectorsForMediaSizes {
@each $name, $_ in $flex-layout-media-queries {
@include flex-layout-media($name) {
@for $i from $from through $to {
@each $unit in $gapUnits {
*[data-layout-gap-#{$name}="#{$i}#{$unit}"] {
gap: #{$i}#{$unit};
}
}
}
}
}
}
}
6 changes: 4 additions & 2 deletions test/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ $includeResponsiveApi: true;

@include fx.attribute-selectors($includeResponsiveApi);
@include fx.class-selectors($includeResponsiveApi);
@include fx.gap-attribute-selectors(1, 16, px em, $includeResponsiveApi);
@include fx.gap-class-selectors(1, 16, px em, $includeResponsiveApi);
@include fx.gap-attribute-selectors(1, 8, px em, $includeResponsiveApi);
@include fx.gap-class-selectors(1, 8, px em, $includeResponsiveApi);
@include fx.gap-attribute-selectors-from-list(16 32 48, px em, $includeResponsiveApi);
@include fx.gap-class-selectors-from-list(16 32 48, px em, $includeResponsiveApi);