@use 'sass:meta';
@use 'sass:math';

/// Helper utility to set both height and weight. Pass a single value to set
/// both height and width to the same value. Unitless values are assumed to
/// be in `rem`s.
///
/// @param {Length-Percentage|string} $width - A length dimension (ex. 20rem or
/// 300px or 10%). Passing 'max' is equivalent to passing 100%.
/// @param {Number} $height [$width] - A length dimension. If no
/// value is entered $height is set equal to $width.
///
/// @group Utilities
@mixin size($width, $height: $width) {
  @if $width == 'max' {
    $width: 100%;
  }

  @if $height == 'max' {
    $height: 100%;
  }

  @if meta.type-of($width) == 'number' and math.is-unitless($width) {
    $width: $width * 1rem;
  }

  @if meta.type-of($height) == 'number' and math.is-unitless($height) {
    $height: $height * 1rem;
  }

  width: #{$width};
  height: #{$height};
}
