Skip to content

Array/Lists for variables #7

Open

Description

@thomasdigby

A way of storing an array of values in a variable and accessing them through the $var[2] syntax.

e.g.

$colors: red, blue, green; // or (red, blue, green)

.red {
  color: $colors[2];
}

to output:

.red {
  color: green;
}

Activity

  1. marcustisater commented on Jul 16, 2016

    @marcustisater
    Member

    I like the idea but what would be a good use case scenario for this? Why would you prefer creating an array over multipel variables.

  2. thomasdigby commented on Jul 16, 2016

    @thomasdigby
    Author

    Mainly for groups of related styles e.g. type setting. Perhaps a poor example, but something similar to this?

    $font-large: 32, 48, 400, 'Arial'; // size, line-height, weight, family
    
    @mixin font-large() {
      font-size: $font-large[0];
      font-family: $font-large[3];
      font-weight: $font-large[2];
      line-height: $font-large[1];
    }
    
    .text-large {
      @include font-large();
    }
    .module-title {
      @include font-large();
    }

    font-large() is a useful mixin as it collates each necessary part of the type style without having to declare each value individually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions