Rename init dir to mixins.

This commit is contained in:
Fredrik Jonsson 2023-01-25 09:54:08 +01:00
commit 48099a734b
8 changed files with 75 additions and 49 deletions

View file

@ -8,15 +8,12 @@
// Colours and variables.
@import 'colors';
@import 'variables';
@import 'extra';
// Add typey to manage font sizes and margins.
@import 'typey';
// Custom mixins used on this site.
@import 'init/breakpoint/respond-to';
@import 'init/clearfix/clearfix';
@import 'init/rtl/rtl';
@import 'init/visually-hidden/visually-hidden';
// Custom functions used on this site.
@import 'init/image-url/image-url';
// Mixins and functions.
@import 'mixins/breakpoint/respond-to';
@import 'mixins/clearfix/clearfix';
@import 'mixins/flex-calc/flex-calc';
@import 'mixins/image-url/image-url';
@import 'mixins/rtl/rtl';
@import 'mixins/spacing/spacing';

View file

@ -1,38 +0,0 @@
// stylelint-disable declaration-no-important
// visually-hidden()
//
// Make an element visually hidden, but accessible to screen readers, etc.
// @see http://snook.ca/archives/html_and_css/hiding-content-for-accessibility
@mixin visually-hidden {
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
word-wrap: normal;
}
// visually-hidden--off()
//
// Turns off the visually-hidden effect.
@mixin visually-hidden--off {
position: static !important;
clip: auto;
height: auto;
width: auto;
overflow: visible;
}
// visually-hidden--focusable()
//
// Makes an element visually hidden by default, but visible when receiving
// focus.
@mixin visually-hidden--focusable {
@include visually-hidden;
&:active,
&:focus {
@include visually-hidden--off;
}
}

View file

@ -0,0 +1,14 @@
@mixin respond-to($breakpoint) {
// If the key exists in the map
@if map-has-key($breakpoints, $breakpoint) {
// Prints a media query based on the value
@media (min-width: map-get($breakpoints, $breakpoint)) {
@content;
}
}
@else {
@media (min-width: $breakpoint) {
@content;
}
}
}

View file

@ -0,0 +1,19 @@
// clearfix()
//
// Allows the bottom of an element to extend to the bottom of all floated
// children elements. @see http://nicolasgallagher.com/micro-clearfix-hack/
//
// We use the micro-clearfix, optimized for use in `@extend` where fewer `&` is
// better.
@mixin clearfix() {
&::before {
content: '';
display: table;
}
&::after {
content: '';
display: table;
clear: both;
}
}

View file

@ -0,0 +1,4 @@
@mixin flex($c, $x) {
flex-basis: calc(100% / #{$c} - #{$x * $base-line-height + 'rem'});
flex-grow: 0;
}

View file

@ -0,0 +1,50 @@
// stylelint-disable function-url-quotes
// The relative path from the css directory to the sass directory.
$image-url-path-to-source: '../sass' !default;
// The relative path from the root sass directory to where your components usually lie.
$image-url-subdirectory: 'components' !default;
// image-url()
//
// If you include your images next to your component Sass files, you need to
// specify a url() to point from the generated CSS to the Sass source like this:
//
// ```css
// content: url(../sass/components/is-quite/long.svg);
// ```
//
// With the `image-url()` function the path to all your components is assumed to
// start with `../sass/components/` and you just need to give it the last, short
// bit of the path in your Sass code like this:
//
// ```scss
// content: image-url(is-quite/short.svg);
// ```
//
// If you want to point at an image that is not in the components sub-directory
// of your sass directory, you can override the default $subdirectory by
// passing it in as the first parameter of `image-url()` like this:
//
// ```scss
// content: image-url(base, grouping/blockquote.svg);
// ```
//
// which would output `url(../sass/base/grouping/blockquote.svg)`.
//
// $subdirectory = $image-url-subdirectory - Optional. The relative path from
// the root of your Sass source to the sub-directory where
// components usually lie.
// $path - Required. The path to the image relative to the
// `$subdirectory`.
// $path-to-source = $image-url-path-to-source - Optional. The relative path
// from the css build directory to the sass source directory.
@function image-url($subdirectory, $path: null, $path-to-source: $image-url-path-to-source) {
// If only 1 parameter is given, its value is intended for the $path.
@if type-of($path) == 'null' {
$path: $subdirectory;
$subdirectory: $image-url-subdirectory;
}
@return url(unquote($path-to-source + '/' + $subdirectory + '/' + $path));
}

View file

@ -0,0 +1,28 @@
// stylelint-disable scss/at-if-closing-brace-newline-after, scss/at-if-closing-brace-space-after
$include-rtl: true !default;
// rtl()
//
// Includes Right-To-Left language support by adding a parent selector of
// `[dir="rtl"]`. Since the dir attribute is usually defined on the html element
// of a page, using this mixin on a ruleset that matches the html element won't
// work.
//
// Can be turned off globally by setting `$include-rtl: false;`.
//
// $selector = '[dir="rtl"]' - The RTL parent selector.
@mixin rtl($selector: '[dir="rtl"]') {
@if $include-rtl {
@if & {
#{$selector} & {
@content;
}
}
@else {
#{$selector} {
@content;
}
}
}
}

View file

@ -0,0 +1,58 @@
@mixin spacing($property, $spacing) {
$converted-list: ();
@each $x in $spacing {
$spacing: #{$x * $base-line-height + 'rem'};
$converted-list: join($converted-list, $spacing, $separator: space);
}
#{$property}: $converted-list;
}
@mixin gap($x) {
@include spacing(gap, $x);
}
@mixin margin($x) {
@include spacing(margin, $x);
}
@mixin margin-inline($x) {
@include spacing(margin-inline, $x);
}
@mixin margin-block($x) {
@include spacing(margin-block, $x);
}
@mixin margin-top($x) {
@include spacing(margin-top, $x);
}
@mixin margin-bottom($x) {
@include spacing(margin-bottom, $x);
}
@mixin margin-left($x) {
@include spacing(margin-left, $x);
}
@mixin margin-right($x) {
@include spacing(margin-right, $x);
}
@mixin padding($x) {
@include spacing(padding, $x);
}
@mixin padding-inline($x) {
@include spacing(padding-inline, $x);
}
@mixin padding-block($x) {
@include spacing(padding-block, $x);
}
@mixin padding-top($x) {
@include spacing(padding-top, $x);
}
@mixin padding-bottom($x) {
@include spacing(padding-bottom, $x);
}
@mixin padding-left($x) {
@include spacing(padding-left, $x);
}
@mixin padding-right($x) {
@include spacing(padding-right, $x);
}