Skip to content

Commit

Permalink
:danielrage: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dbox committed Jul 19, 2023
1 parent 314f7d6 commit df20810
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 377 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"modules": true
}
},
"extends": ["eslint:recommended"],
"ignorePatterns": ["!.*", "**/node_modules/**/*"],
"plugins": ["unused-imports"],
"rules": {
Expand Down
83 changes: 5 additions & 78 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# KNI SCSS

Note: 2.0 is a very breaking change and should NOT be upgraded. Only use it for a fresh build.

Our css starter pack and folder structure. The purpose of this repo is to have a single source of truth for all css used across, react, wordpress, static, or any future sites. When spinning up a new repo, please make sure it's using the latest version of this `scss` folder..

### Install
Expand Down Expand Up @@ -40,7 +42,7 @@ body {
padding: 0 5%;

@media (min-width: #{$tp}px) {
padding: 0 15vw;
padding: 0 15pxv;
}
}
```
Expand All @@ -54,83 +56,8 @@ Designs will have both portrait (mobile) designs and (desktop) designs delivered

### Scale Everything

We're introducing a new `vw()` function which takes these sizes into account.

Input:

```scss
div {
width: vw(320px);
}
```

Output:

```scss
div {
width: 2.34375vw;
}
```

The output becomes a flexible vw unit that changes as browser resizes. At `$siteBasis--mobile`(375px) and `siteBasis--desktop`(1280px) it should match up exactly to the comp.

Use the pixel sizes you see in Figma and wrap them in this function everywhere. The exception is if you want to use actual pixels, then use `px` or `rem(px)` and it will output fixed pixel sizes.

Many times you'll only need `vw()` for desktop applications (then mobile gets something like 100%), but because mobile and desktop use different `siteBasis` vars, mobile usages will need the optional mobile argument:

Input:

```scss
div {
width: vw(30px, mobile);

@media (min-width: #{$tl}px) {
width:vw(30px);
}
```

Output:

```scss
div {
width: 2.34375vw;

@media (min-width: #{$tl}px) {
width: 2.34375vw;
}
```
pxv writeup here

### Fluid Typography

We have 2 mixins to help with Fluid Typography.

#### fluidType()

Base mixin:

```scss
.item {
@include fluidType($minFontSize, $maxFontSize, $minWidth, $maxWidth);
}
```

#### setType()

This is superset of fluidType that should be used in most cases, and is great for Figma matching. Use this for fully responsive type automation. In most cases you only need to provide 2 arguments: The mobile size and the desktop size. **Note** these values are not the same as `fluidType`.

```scss
h1 {
@include setType(32, 48);
}
```

Sometimes for smaller fonts you want to override the smallest size that it can go. In this case pass in the `$minClamp` argument which is the percentage the minimum font size should be compared to default size. Set it to `100%` to have it not scale any smaller than default size.

```scss
p {
@include setType(14, 16, $minClamp: 94%);
}
.eyebrow {
@include setType(11, 13, 100%);
}
```
new responsive type writeup here
39 changes: 33 additions & 6 deletions scss/01-config/01-variables/_01-breakpoints.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,36 @@ $minContentWidth: $ms !default;
$maxContentWidth: $ds !default;
$maxFormWidth: $tm !default;
$maxReaderWidth: $tm !default;
$siteMin: $ms !default;
$siteMin--desktop: $tl !default;
$siteBasis--mobile: $mm !default;
$siteBasis--desktop: $dm !default;
$siteMax--mobile: $tm !default;
$siteMax--desktop: $dl !default;

// Default breakpoint. Can add more per project!
* {
--emBase: 16;
--mobileMin: #{$ms};
--mobile: #{$mm};
--mobileMax: #{$ts};
--desktopMin: #{$tl};
--desktop: #{$dm};
--desktopMax: #{$dxl};
--siteMin: var(--mobileMin);
--siteBasis: var(--mobile);
--siteMax: var(--mobileMax);

@media (min-width: #{$tl}px) {
--siteMin: var(--desktopMin);
--siteBasis: var(--desktop);
--siteMax: var(--desktopMax);
}
}

// MQ shortcuts
@mixin desktop {
@media (min-width: #{$tl}px) {
@content;
}
}

@mixin tablet {
@media (min-width: #{$ml + 1}px) and (max-width: #{$tl}px) {
@content;
}
}
31 changes: 1 addition & 30 deletions scss/01-config/02-functions/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,4 @@
@return #{$em * $emBase}px;
}

@function vw($px, $range: desktop) {
$basis: 0;
$max: 0;

@if $range == desktop {
$basis: $siteBasis--desktop;
$max: $siteMax--desktop;
} @else if $range == mobile {
$basis: $siteBasis--mobile;
$max: $siteMax--mobile;
}

@if $basis != 0 and $max != 0 and $px > 0 {
@return clamp(
1px,
#{removeUnit($px) * math.div(100, $basis)}vw,
#{math.div((removeUnit($px) * $max), $basis)}px
);

// reverse clamp for negative numbers
} @else if $basis != 0 and $max != 0 and $px < 0 {
@return clamp(
#{math.div((removeUnit($px) * $max), $basis)}px,
#{removeUnit($px) * math.div(100, $basis)}vw,
-1px
);
} @else {
@error 'Error in vw: $basis and $max must not be equal to zero. $basis: #{$basis}, $max: #{$max}';
}
}
// rip vw()
191 changes: 2 additions & 189 deletions scss/01-config/03-mixins/_01-type.scss
Original file line number Diff line number Diff line change
@@ -1,189 +1,2 @@
@use 'sass:math';

@mixin fluidType(
$minFontSize: $baseMinFontSize,
$maxFontSize: $baseMaxFontSize,
$minWidth: $minContentWidth,
$maxWidth: $maxContentWidth,
$minBreakpoint: true,
$midBreakpoint: true,
$maxBreakpoint: true
) {
@if $midBreakpoint {
font-size: calc(
#{rem($minFontSize)} +
(#{$maxFontSize} - #{$minFontSize}) *
((100vw - #{$minWidth}px) / (#{$maxWidth} - #{$minWidth}))
);
}

@if $minBreakpoint {
@media (max-width: #{$minWidth}px) {
font-size: rem($minFontSize);
}
}

@if $maxBreakpoint {
@media (min-width: #{$maxWidth}px) {
font-size: rem($maxFontSize);
}
}
}

@mixin setType($fontSize--mobile, $fontSize--desktop, $minClamp: false) {
$fontSize--mobile-small: math.div(
($fontSize--mobile * $siteMin),
$siteBasis--mobile
);
$fontSize--mobile-large: math.div(
($fontSize--mobile * $siteMax--mobile),
$siteBasis--mobile
);
$fontSize--desktop-small: math.div(
($fontSize--desktop * $siteMin--desktop),
$siteBasis--desktop
);
$fontSize--desktop-large: math.div(
($fontSize--desktop * $siteMax--desktop),
$siteBasis--desktop
);
$minMobileClamp: $fontSize--mobile-small;
$minDesktopClamp: $fontSize--desktop-small;

@if $minClamp {
$minMobileClamp: $fontSize--mobile * math.div($minClamp, 100%);
$minDesktopClamp: $fontSize--desktop * math.div($minClamp, 100%);
}

// $siteMin to $siteMax--mobile
@include fluidType(
$minFontSize: $fontSize--mobile-small,
$maxFontSize: $fontSize--mobile-large,
$minWidth: $siteMin,
$maxWidth: $siteMax--mobile,
$maxBreakpoint: false
);

// below $siteMin
@media (min-width: 1px) and (max-width: #{($siteMin)}px) {
font-size: rem($minMobileClamp);
}

// minClamp rules
@if $minClamp {
font-size: rem($minMobileClamp);

@media (min-width: #{$siteBasis--mobile + 1}px) and (max-width: #{($siteMax--mobile - 1)}px) {
@include fluidType(
$minFontSize: $minMobileClamp,
$maxFontSize: $fontSize--mobile-large,
$minWidth: $siteBasis--mobile,
$maxWidth: $siteMax--mobile,
$maxBreakpoint: false
);
}
}

// lock size at $siteMax--mobile (tablet) until $siteMin--desktop
@media (min-width: #{$siteMax--mobile}px) {
font-size: rem($minDesktopClamp);
}

// $siteMin--desktop to $siteMax--desktop
@media (min-width: #{$siteMin--desktop}px) {
@include fluidType(
$minFontSize: $fontSize--desktop-small,
$maxFontSize: $fontSize--desktop-large,
$minWidth: $siteMin--desktop,
$maxWidth: $siteMax--desktop,
$minBreakpoint: false,
$maxBreakpoint: false
);
}

// Desktop minClamp rules
@if $minClamp {
// $siteMin--desktop to $siteBasis--desktop
@media (min-width: #{$siteMin--desktop}px) and (max-width: #{$siteBasis--desktop - 1}px) {
@include fluidType(
$minFontSize: $minDesktopClamp,
$maxFontSize: $fontSize--desktop,
$minWidth: $siteMin--desktop,
$maxWidth: $siteBasis--desktop,
$minBreakpoint: false,
$maxBreakpoint: false
);
}
}

// $siteMax--desktop and above
@include fluidType(
$minFontSize: $minDesktopClamp,
$maxFontSize: $fontSize--desktop-large,
$minWidth: $siteMin--desktop,
$maxWidth: $siteMax--desktop,
$minBreakpoint: false,
$midBreakpoint: false
);
}

@mixin h {
font-family: $headingFontStack;
font-weight: $headingFont-bold;
color: $black;
line-height: 1.1em;
}

@mixin h1 {
@include setType(32, 48);
}

@mixin h2 {
@include setType(26, 40);
}

@mixin h3 {
@include setType(22, 33);
}

@mixin h4 {
@include setType(20, 27);
}

@mixin h5 {
@include setType(18, 23);
}

@mixin h6 {
@include setType(16, 20);
}

@mixin p--xxs {
@include setType(10, 10, 100%);
}

@mixin p--xs {
@include setType(10, 12, 100%);
}

@mixin p--sm {
@include setType(12, 14, 100%);
}

@mixin p {
color: $gray-200;
line-height: 1.4;
@include setType(14, 16, 95%);
}

@mixin p--lg {
@include setType(16, 18, 100%);
}

@mixin p--xl {
@include setType(18, 20, 100%);
}

@mixin p--xxl {
@include setType(20, 22, 100%);
}
// nothing to see here.
// Fluid Type and setType are now deprecated. See 02-base/type
Loading

0 comments on commit df20810

Please sign in to comment.