Skip to content

Commit

Permalink
refactor: ♻️ update all units to be one time in global-variables file
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton225 committed May 25, 2024
1 parent ec00196 commit 6c5b32d
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 397 deletions.
83 changes: 83 additions & 0 deletions src/abstract/_global-variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@charset "UTF-8";

// @access public

// @version 1.0.0

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/ZexLabs/sass-pire

// @namespace abstract

// @module abstract/global-variables

// stylelint-disable scss/dollar-variable-empty-line-before

$all-units: (
cm,
mm,
in,
px,
pt,
pc,
"%",
em,
ex,
ch,
rem,
vw,
vh,
vmin,
vmax,
dpi,
dpcm,
dppx,
vw,
svw,
lvw,
dvw,
vh,
lvh,
dvh,
vi,
svi,
lvi,
vmin,
svmin,
lvmin,
dvmin,
vmax,
svmax,
lvmax,
dvmax,
vb,
lvb,
dvb) !default;

$data-types: (
number,
string,
bool,
list,
color,
map,
null) !default;

$angle-units: (
deg,
turn,
rad,
grad) !default;

$main-units: (
#{"%"},
rem,
px,
em) !default;

$time-units: (
ms,
s) !default;
6 changes: 6 additions & 0 deletions src/abstract/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
// @see variables
@forward "variables";

// * forwarded global-variables.
// * This module forwards the variables defined in the "global-variables" module.
// * It allows you to use these variables in other files.
// @see global-variables
@forward "global-variables";

// * forwarded config.
// * This module forwards the configuration defined for library.
// * It allows you to use these configurations in other files.
Expand Down
10 changes: 0 additions & 10 deletions src/abstract/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@

// stylelint-disable scss/dollar-variable-empty-line-before

// * Units.

$all-data-types: (number, string, bool, list, color, map, null) !default;

$angle-units: (deg, turn, rad, grad) !default;

$main-units: (#{"%"}, rem, px, em) !default;

$time-units: (ms, s) !default;

// * Grid.

$column-gap-props: (-webkit-column-gap, -moz-column-gap, column-gap) !default;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/type-checks/_is-angle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
// @example
// * .example {
// * content: is-angle(12deg);
// * };
// * }

// @output
// * .example {
// * content: true;
// * };
// * }

// @returns {boolean} - True if it has one of the angle units,
// * false if not.

@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../../abstract/variables" as var;
@use "../../abstract/global-variables" as var;
@use "../../development-utils/toggle-error-message" as Error;

@function is-angle($value) {
Expand Down
6 changes: 3 additions & 3 deletions src/functions/type-checks/_is-time.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
// @example
// * .example {
// * content: is-time(12s);
// * };
// * }

// @output
// * .example {
// * content: true;
// * };
// * }

// @returns {boolean} - True if it's a time type, false if not.

@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../../abstract/variables" as var;
@use "../../abstract/global-variables" as var;
@use "../../development-utils/toggle-error-message" as Error;

@function is-time($value) {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/general/_box-shadow.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// @dependencies:
// * - meta.type-of (SASS function).
// * - $main-units (variable).
// * - var.$main-units (variable).
// * - pref.prefixing-web (mixin).

// @param {List} $val
Expand Down Expand Up @@ -72,7 +72,7 @@
@use "sass:list";
@use "sass:math";
@use "../vendor-prefixes/prefix" as pref;
@use "../../abstract" as var;
@use "../../abstract/global-variables" as var;

@mixin shadow($val...) {
$box-shadow-values: (inherit, initial, revert, revert-layer, unset, none) !default;
Expand Down
48 changes: 4 additions & 44 deletions src/mixins/general/_circle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// * - meta.type-of (SASS function).
// * - math.unit (SASS function).
// * - list.index (SASS function).
// * - var.$all-units (variable).
// * - Error.toggle (function).

// @param {Number} $side
Expand All @@ -49,6 +50,7 @@
@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../../abstract/global-variables" as var;
@use "../../development-utils/toggle-error-message" as Error;

@mixin circle($one-side: 0) {
Expand All @@ -58,54 +60,12 @@
$get-unit: math.unit($one-side);

@if $get-unit != "" {
$all-units: (
cm,
mm,
in,
px,
pt,
pc,
"%",
em,
ex,
ch,
rem,
vw,
vh,
vmin,
vmax,
dpi,
dpcm,
dppx,
vw,
svw,
lvw,
dvw,
vh,
lvh,
dvh,
vi,
svi,
lvi,
vmin,
svmin,
lvmin,
dvmin,
vmax,
svmax,
lvmax,
dvmax,
vb,
lvb,
dvb
) !default;

@if list.index($all-units, $get-unit) {
@if list.index(var.$all-units, $get-unit) {
width: #{$one-side};
height: #{$one-side};
border-radius: 50%;
} @else {
content: Error.toggle("The parameter of circle mixin must be one of these values: (#{$all-units}).");
content: Error.toggle("The parameter of circle mixin must be one of these values: (#{var.$all-units}).");
}
} @else {
content: Error.toggle("The parameter of circle mixin must have a unit.");
Expand Down
50 changes: 5 additions & 45 deletions src/mixins/general/_square.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
// @dependencies:
// * - meta.type-of (SASS function).
// * - math.unit (SASS function).
// * - is-in-list (function).
// * - toggle (function).
// * - var.$all-units (variable).
// * - func.is-in-list (function).
// * - Error.toggle (function).

// @param {Number} $one-side
// * The length of one side of the square.
Expand All @@ -48,55 +49,14 @@
@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../../abstract/global-variables" as var;
@use "../../functions/global/is-in-list" as func;
@use "../../development-utils/toggle-error-message" as Error;

@mixin square($one-side: 1px) {
$all-units: (
cm,
mm,
in,
px,
pt,
pc,
"%",
em,
ex,
ch,
rem,
vw,
vh,
vmin,
vmax,
dpi,
dpcm,
dppx,
vw,
svw,
lvw,
dvw,
vh,
lvh,
dvh,
vi,
svi,
lvi,
vmin,
svmin,
lvmin,
dvmin,
vmax,
svmax,
lvmax,
dvmax,
vb,
lvb,
dvb
) !default;

@if meta.type-of($one-side) == number {
@if not unitless($one-side) {
@if func.is-in-list($all-units, math.unit($one-side)) {
@if func.is-in-list(var.$all-units, math.unit($one-side)) {
width: $one-side;
height: $one-side;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/general/_transition.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// @module general/transition

// @dependencies:
// * - $time-units (variable).
// * - var.$time-units (variable).
// * - meta.type-of (SASS function).
// * - prefix.prefixing-all (mixin).
// * - is-in-list (function).
Expand Down Expand Up @@ -58,7 +58,7 @@
@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../../abstract/variables" as var;
@use "../../abstract/global-variables" as var;
@use "../vendor-prefixes/prefix" as pref;
@use "../../functions" as func;

Expand Down
Loading

0 comments on commit 6c5b32d

Please sign in to comment.