Skip to content

Commit 3e8c360

Browse files
committed
✨ (card-pattern, proportional-box) adds card pattern, error messages
Bumps version to 0.3.0
1 parent aff0fd8 commit 3e8c360

File tree

7 files changed

+146
-13
lines changed

7 files changed

+146
-13
lines changed

README.md

+63-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ Resources:
1717
yarn add @evanshunt/derekstrap;
1818
```
1919

20+
# Development
21+
22+
If making any javascript changes, a `yarn build` needs to be run before commit. To install the included pre-commit hook, run the following from the project root:
23+
24+
```
25+
cp pre-commit.sh .git/hooks/pre-commit
26+
chmod +x .git/hooks/pre-commit
27+
```
28+
2029
## Usage
2130

2231
### With @import
@@ -55,13 +64,14 @@ Breakpoints.init(breakpointList);
5564

5665
SubModules
5766

58-
* [Breakpoints](#Breakpoints)
67+
* [Breakpoints](#breakpoints)
5968
* [debounce.js](#debounce-js)
60-
* [Proportional Box](#Proportional-Box)
61-
* [Proportional Text](#Proportional--Text)
62-
* [setUserAgent.js](#setUserAgent-js)
63-
* [Spacing](#Spacing)
64-
* [Text Sizing](#Text-Sizing)
69+
* [Proportional Box](#proportional-box)
70+
* [Proportional Text](#proportional-text)
71+
* [setUserAgent.js](#setuseragent-js)
72+
* [Spacing](#spacing)
73+
* [Text Sizing](#text-sizing)
74+
* [Card Pattern](#card-pattern)
6575

6676
JS features
6777

@@ -172,11 +182,12 @@ See [src/Breakpoints.js](src/Breakpoints.js) for another example.
172182

173183
The proportional box module is intended to allow you to define an aspect ratio for an element. Often useful for elements which have a background image. The module consists of 3 mixins, two of which are helper methods for `proportional-box()` which is the one you will most likely use in your project.
174184

175-
The method takes 3 arguments. The `$view-width` and `$offset` arguments are optional and will depend on other styles applied to the element in order to function properly. By default the mixin assumes a full-bleed element. The opional arguments are there to configure an element that is not full bleed.
185+
The method takes 3 arguments. All arguments except `$aspect-ratio` are optional and will depend on other styles applied to the element in order to function properly. By default the mixin assumes a full-bleed element. The opional arguments are there to configure an element that is not full bleed.
186+
187+
All arguments will accept a single value or a breakpoint map. If passing a breakpoint map to more than one argument ensure all breakpoint maps include the exact same breakpoints.
176188

177189
* `$aspect-ratio`: Width / height, probably best written as an expression which evaluates to a number, e.g. `16 / 9` rather than `1.77777`. (required)
178-
* `$view-width`: Defaults to `100vw`. This argument should be the proportion of the viewport widht the element takes up, excluding fixed margins. If the element takes up 100% of the viewport except for a 50px margin on each side, the value here should still be `100vw`. Only pass a different value here if the image is not proportional to the entire viewport. If it should be `50vw` wide (excluding fixed margins) then pass `50vw`. (optional)
179-
* `$offset`: Defaults to `0px`. This is the place to define fixed width margins. The value passed should reflect the margin _on one side_ of the element. It will be multiplied by 2 in the mixin. This logic assumes identical left and right margins. If that is not the case the offset value should be (left margin + right margin) / 2.
190+
* `$view-width`: Defaults to `100vw`. This argument should be the proportion of the viewport widht the element (or it's parent) takes up, excluding fixed margins. If the element takes up 100% of the viewport except for a 50px margin on each side, the value here should still be `100vw`. Only pass a different value here if the image is not proportional to the entire viewport. If it should be `50vw` wide (excluding fixed margins) then pass `50vw`. (optional)
180191

181192
The following background image properties are added to the element using this mixin:
182193

@@ -186,6 +197,7 @@ background-repeat: no-repeat;
186197
background-position: center;
187198
```
188199

200+
<!-- @TODO: add multi-breakpoint examples -->
189201
#### Example usage
190202

191203
```
@@ -273,4 +285,45 @@ Note that when the spacing is applied to only one side the element, the opposite
273285
@include derekstrap.horizontal-spacing($regular-margins, 'left');
274286
@include derekstrap.vertical-spacing($section-spacing, 'top');
275287
}
276-
```
288+
```
289+
290+
### Card Pattern
291+
292+
The card pattern module includes a mixin to quickly generate a common card layout pattern using flexbox. It sets the size and margins of both parent and child elements and allows passing breakpoint maps for arguments to create a responsive layout. If you pass more than one breakpoint map as an argument, ensure they contain the exact same breakpoints and that all included breakpoints have been configured in the $breakpointList variable.
293+
294+
### Example Usage
295+
296+
```
297+
@use '~@evanshunt/derekstrap';
298+
299+
// This will create a 4 column layout with a 2rem gutter and 3rem space between rows
300+
.parent-element {
301+
@include derekstrap.card-pattern('.child-selector', 4, 2rem, 3rem);
302+
}
303+
304+
// This will create a layout with a varying number of columns depending on breakpoint
305+
.parent-element {
306+
@include derekstrap.card-pattern('.child-selector', (
307+
'base': 1,
308+
'tablet': 2,
309+
'desktop': 3
310+
), 2rem, 3rem);
311+
}
312+
313+
// This will create a layout with varying columns and gutter size
314+
.parent-element {
315+
@include derekstrap.card-pattern(
316+
'.child-selector',
317+
(
318+
'base': 1,
319+
'tablet': 2,
320+
'desktop': 3
321+
),
322+
(
323+
'base': 2rem,
324+
'tablet': 1rem,
325+
'desktop': 0.5rem
326+
),
327+
3rem
328+
);
329+
}

_index.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@forward 'breakpoints/index';
2-
@forward 'text-sizing/index';
2+
@forward 'card-pattern/index';
3+
@forward 'proportional-box/index';
34
@forward 'proportional-text/index';
45
@forward 'spacing/index';
5-
@forward 'proportional-box/index';
6+
@forward 'text-sizing/index';

card-pattern/_index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@forward 'mixins';

card-pattern/_mixins.scss

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@use 'sass:meta';
2+
@use 'sass:map';
3+
@use '~breakpoint-sass/stylesheets/breakpoint' as *;
4+
@use '../breakpoints/index' as *;
5+
6+
@mixin card-pattern($child-selector, $columns, $gutter: 0, $row-space: 0) {
7+
@if (meta.type-of($columns) == 'map') {
8+
@include card-pattern-responsive($columns, $child-selector, $columns, $gutter, $row-space);
9+
} @else if (meta.type-of($gutter) == 'map') {
10+
@include card-pattern-responsive($gutter, $child-selector, $columns, $gutter, $row-space);
11+
} @else if (meta.type-of($row-space) == 'map') {
12+
@include card-pattern-responsive($row-space, $child-selector, $columns, $gutter, $row-space);
13+
} @else {
14+
@include card-layout($child-selector, $columns, $gutter, $row-space)
15+
}
16+
}
17+
18+
@mixin card-pattern-responsive($sizes, $child-selector, $columns, $gutter, $row-space) {
19+
@each $breakpoint, $size in $sizes {
20+
$bp-columns: $columns;
21+
@if (meta.type-of($columns) == 'map') {
22+
$bp-columns: map.get($columns, $breakpoint)
23+
}
24+
25+
$bp-gutter: $gutter;
26+
@if (meta.type-of($gutter) == 'map') {
27+
$bp-gutter: map.get($gutter, $breakpoint)
28+
}
29+
30+
$bp-row-space: $row-space;
31+
@if (meta.type-of($row-space) == 'map') {
32+
$bp-row-space: map.get($row-space, $breakpoint)$child-selector,
33+
}
34+
35+
@if $breakpoint == 'base' {
36+
@include card-layout($child-selector, $bp-columns, $bp-gutter, $bp-row-space);
37+
} @else {
38+
@include breakpoint(map-get($breakpointList, $breakpoint)) {
39+
@include card-layout($child-selector, $bp-columns, $bp-gutter, $bp-row-space);
40+
}
41+
}
42+
}
43+
}
44+
45+
@mixin card-layout($child-selector, $columns, $gutter, $row-space) {
46+
@if (meta.type-of($columns) == 'null') {
47+
@error "$columns undefined. Ensure all maps passed as arguments contain the same breakpoints.";
48+
}
49+
@if (meta.type-of($gutter) == 'null') {
50+
@error "$gutter undefined. Ensure all maps passed as arguments contain the same breakpoints.";
51+
}
52+
@if (meta.type-of($row-space) == 'null') {
53+
@error "$row-space undefined. Ensure all maps passed as arguments contain the same breakpoints.";
54+
}
55+
56+
width: calc(100% + #{$gutter}); // possibly unneccessary
57+
padding: 0;
58+
margin: (-1 * $row-space / 2) (-1 * $gutter / 2);
59+
display: flex;
60+
flex-flow: row wrap;
61+
62+
#{$child-selector} {
63+
margin: ($row-space / 2) ($gutter / 2);
64+
width: calc(100% / #{$columns} - #{$gutter});
65+
}
66+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@evanshunt/derekstrap",
3-
"version": "0.2.3",
3+
"version": "0.3.0",
44
"description": "A base layout and styles library by Evans Hunt",
55
"main": "dist/main.js",
66
"sass": "_index.scss",

pre-commit.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn build;
2+
git add dist;

proportional-box/_mixins.scss

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
}
2424

2525
@mixin proportional-height($aspect-ratio, $vw, $offset) {
26+
@if (meta.type-of($aspect-ratio) == 'null') {
27+
@error "$aspect-ratio undefined. Ensure all maps passed as arguments contain the same breakpoints.";
28+
}
29+
@if (meta.type-of($vw) == 'null') {
30+
@error "$vw undefined. Ensure all maps passed as arguments contain the same breakpoints.";
31+
}
32+
@if (meta.type-of($offset) == 'null') {
33+
@error "$offset undefined. Ensure all maps passed as arguments contain the same breakpoints.";
34+
}
35+
2636
height: calc(#{1 / $aspect-ratio} * (#{$vw} - 2 * #{$offset}));
2737
}
2838

0 commit comments

Comments
 (0)