Почему каждый мой цикл не работает, когда я помещаю его под миксин? - PullRequest
0 голосов
/ 02 июня 2019

Мой каждый цикл, который повторяет карту цветов кнопок, не выполняет то, что я хочу.Когда я включаю миксин в класс ниже, ничего не работает.

Вот пример моего scss:

 //BUTTONS

$button-colors :(
  default:$base-blue,
  success:$base-green,
  error:$base-red,
  warning:$base-orange,
  info:$base-purple
);

@mixin button-styles {
  display: block;
  width: 100%;
  border: none;
  color: $base-white;
  text-transform: uppercase;
  font-weight: bold;
  margin-bottom: 15px;
  padding: 10px;
}

@mixin button-colors {
  @each $button, $color in $button-colors {
    .btn--#{$button} {
      background-color: #{$color};
    }
  }
}

[class^=btn] {
  @include button-styles;
  @include button-colors;
}

Вот мой HTML

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Circles UI Kit</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="css/styles.css">
  <link rel="stylesheet" href="css/normalize.css">
</head>
<!-- 
    List of classes used

    Grid:
    .container
    .grid__row
    .grid__col--1 *NOT USED HERE
    .grid__col--2 *
    .grid__col--3
    .grid__col--4
    .grid__col--5
    .grid__col--6
    .grid__col--7
    .grid__col--8
    .grid__col--9
    .grid__col--10 *
    .grid__col--11 *
    .grid__col--12
    .card
    .centered
    .theme__colors
    (.grid__col--1, .grid__col--2, .grid__col--10, and .grid__col--11 are not used here in the HTML but would be good to include in the Sass)

    Typography:
    .container
    .link
    .blockquote
    .headline--primary
    .headline--secondary

    Image:
    .img--logo
    .img--frame
    .img--avatar

    Navigation:
    .nav
    .nav__item

    Buttons:
    .btn--default
    .btn--success
    .btn--error
    .btn--warning
    .btn--info
    .theme__colors

    Forms:
    .form
    .form__label--hidden
    .form__input

  -->

<body class="container">
  <div class="grid__row">
    <div class="grid__col--3">
      <a class="link" href="/">
        <img class="img--logo" alt="circles logo" src="images/logo.png">
      </a>
    </div>
    <div class="grid__col--9">
      <nav role="navigation">
        <ul class="nav">
          <li class="nav__item"><a href="#type">Typography</a></li>
          <li class="nav__item"><a href="#buttons">Buttons</a></li>
          <li class="nav__item"><a href="#forms">Form</a></li>
          <li class="nav__item"><a href="#images">Images</a></li>
          <li class="nav__item"><a href="#grid">Grid</a></li>
        </ul>
      </nav>
    </div>
  </div>

  <div class="grid__row">
    <div class="grid__col--12">
      <div class="card">
        <p>This is what the navigation menu looks like when the screen is at 769px or higher. When the screen is less
          than 769px,
          the menu will be displayed vertically.</p>
      </div>
    </div>
  </div>

  <div class="grid__row">
    <div class="grid__col--8">
      <div class="card">
        <h4 id="type" class="headline--secondary">Typography</h4>
        <h1 class="headline--primary">Take a look at this amazing headline</h1>
        <p>This is a typical paragraph for the UI Kit. <a href="#" class="link">Here is what a link might look like</a>.
          The
          typical font family for this kit is Helvetica Neue. This kit is intended for clean and refreshing web layouts.
          No jazz hands here, just the essentials to make dreams come true, with minimal clean web design. The kit comes
          fully equipped with everything from full responsive media styling to buttons to form fields. <em>I enjoy using
            italics as well from time to time</em>.
          Fell free to create the most amazing designs ever with this kit. I truly hope you enjoy not only the kit but
          this
          amazing paragraph as well. :)</p>
        <blockquote class="blockquote">You know what really gets me going? A really nice set of block quotes. That's
          right, block quotes that say, "Hey,
          I'm an article you want to read and nurture."</blockquote>
      </div>
    </div>
    <div class="grid__col--4">
      <form class="form">
        <legend id="forms" class="headline--secondary">Form Elements</legend>
        <img class="img--avatar" src="images/avatar.png" alt="Avatar">
        <label class="form__label--hidden" for="username">Username:</label>
        <input class="form__input" type="text" id="username" placeholder="Username">
        <label class="form__label--hidden" for="password">Password:</label>
        <input class="form__input" type="password" id="password" placeholder="Password">
        <button class="btn--default theme__colors" type="submit" value="Login">Login</button>
      </form>
    </div>
  </div>

  <h4 id="images" class="headline--secondary">Images</h4>

  <div class="grid__row">
    <div class="grid__col--6">
      <img class="img--frame" src="images/image.png" alt="sample image">
    </div>
    <div class="grid__col--6">
      <img class="img--avatar" src="images/avatar.png" alt="Avatar">
    </div>
  </div>

  <h4 id="buttons" class="headline--secondary">Buttons</h4>

  <div class="grid__row">
    <div class="grid__col--12">
      <button class="btn--default theme__colors">default</button>
      <button class="btn--success theme__colors">success</button>
      <button class="btn--error theme__colors">error</button>
      <button class="btn--warning theme__colors">warning</button>
      <button class="btn--info theme__colors">info</button>
    </div>
  </div>

  <h4 id="grid" class="headline--secondary">Grid System</h4>

  <div class="grid__row">
    <div class="grid__col--12 theme__colors">.grid__col--12</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--6 theme__colors">.grid__col--6</div>
    <div class="grid__col--6 theme__colors">.grid__col--6</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--4 theme__colors">.grid__col--4</div>
    <div class="grid__col--4 theme__colors">.grid__col--4</div>
    <div class="grid__col--4 theme__colors">.grid__col--4</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--3 theme__colors">.grid__col--3</div>
    <div class="grid__col--3 theme__colors">.grid__col--3</div>
    <div class="grid__col--3 theme__colors">.grid__col--3</div>
    <div class="grid__col--3 theme__colors">.grid__col--3</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--5 theme__colors">.grid__col--5</div>
    <div class="grid__col--7 theme__colors">.grid__col--7</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--8 theme__colors">.grid__col--8</div>
    <div class="grid__col--4 theme__colors">.grid__col--4</div>
  </div>
  <div class="grid__row">
    <div class="grid__col--7 theme__colors centered">.centered .grid__col--7</div>
  </div>

</body>

</html>

Isесть проблема с самим миксином?Я пытаюсь понять, где я ошибся в своем подходе?Вы обычно должны писать циклы под mixins в scss, верно?

...