|
@@ -1,236 +1,231 @@
|
|
|
---
|
|
|
title: Functions
|
|
|
+subtitle: "Utility functions to calculate colors and other values"
|
|
|
layout: documentation
|
|
|
doc-tab: overview
|
|
|
doc-subtab: functions
|
|
|
+breadcrumb:
|
|
|
+- home
|
|
|
+- documentation
|
|
|
+- overview
|
|
|
+- overview-functions
|
|
|
---
|
|
|
|
|
|
-{% include subnav/subnav-overview.html %}
|
|
|
+<div class="content">
|
|
|
+ <p>Bulma uses 3 custom functions to help define the values and colors dynamically:</p>
|
|
|
+ <ul>
|
|
|
+ <li><code>powerNumber($number, $exp)</code>: calculates the value of a number exposed to another one. Returns a number.</li>
|
|
|
+ <li><code>colorLuminance($color)</code>: defines if a color is dark or light. Return a decimal number between 0 and 1 where <= 0.5 is dark and > 0.5 is light.</li>
|
|
|
+ <li><code>findColorInvert($color)</code>: returns either 70% transparent black or 100% opaque white depending on the luminance of the color.</li>
|
|
|
+ </ul>
|
|
|
+</div>
|
|
|
|
|
|
-<section class="section">
|
|
|
- <div class="container">
|
|
|
- <h1 class="title">Functions</h1>
|
|
|
- <h2 class="subtitle">Utility functions to calculate colors and other values</h2>
|
|
|
+{% include anchor.html name="The <code>findColorInvert()</code> function" %}
|
|
|
|
|
|
- <hr>
|
|
|
-
|
|
|
- <div class="content">
|
|
|
- <p>Bulma uses 3 custom functions to help define the values and colors dynamically:</p>
|
|
|
- <ul>
|
|
|
- <li><code>powerNumber($number, $exp)</code>: calculates the value of a number exposed to another one. Returns a number.</li>
|
|
|
- <li><code>colorLuminance($color)</code>: defines if a color is dark or light. Return a decimal number between 0 and 1 where <= 0.5 is dark and > 0.5 is light.</li>
|
|
|
- <li><code>findColorInvert($color)</code>: returns either 70% transparent black or 100% opaque white depending on the luminance of the color.</li>
|
|
|
- </ul>
|
|
|
- </div>
|
|
|
-
|
|
|
- {% include anchor.html name="The <code>findColorInvert()</code> function" %}
|
|
|
-
|
|
|
- <div class="content">
|
|
|
- <p>The <code>findColorInvert($color)</code> function takes a <strong>color</strong> as an input, and outputs either transparent <strong>black</strong> <code>rgba(#000, 0.7)</code> or <strong>white</strong> <code>#fff</code>:</p>
|
|
|
- <ul>
|
|
|
- <li>if <code>colorLuminance($color) > 0.55</code>, it outputs <code>rgba(#000, 0.7)</code></li>
|
|
|
- <li>otherwise, it outputs <code>#fff</code></li>
|
|
|
- </ul>
|
|
|
- <p>Its purpose is to guarantee a <strong>readable</strong> shade for the <em>text</em> when the input color is used as the <em>background</em>.</p>
|
|
|
- <table class="table is-bordered">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>color</th>
|
|
|
- <th>color luminance</th>
|
|
|
- <th>findColorInvert()</th>
|
|
|
- <th>result</th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #00d1b2;"></span>
|
|
|
- <code>#00d1b2</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.52831</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #fff;"></span>
|
|
|
- <code>#fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #00d1b2; border-color: #00d1b2; color: #fff;">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #3273dc;"></span>
|
|
|
- <code>#3273dc</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.23119</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #fff;"></span>
|
|
|
- <code>#fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #3273dc; border-color: #3273dc; color: #fff;">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #23d160;"></span>
|
|
|
- <code>#23d160</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.51067</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #fff;"></span>
|
|
|
- <code>#fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #23d160; border-color: #23d160; color: #fff;">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #ffdd57;"></span>
|
|
|
- <code>#ffdd57</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.76863</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: rgba(0, 0, 0, 0.7);"></span>
|
|
|
- <code>rgba(0, 0, 0, 0.7)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #ffdd57; border-color: #ffdd57; color: rgba(0, 0, 0, 0.7);">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #ff3860;"></span>
|
|
|
- <code>#ff3860</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.27313</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #fff;"></span>
|
|
|
- <code>#fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #ff3860; border-color: #ff3860; color: #fff;">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #ffb3b3;"></span>
|
|
|
- <code>#ffb3b3</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.61796</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
- <code>rgba(0,0,0,0.7)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #ffb3b3; border-color: #ffb3b3; color: rgba(0,0,0,0.7);">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #ffbc6b;"></span>
|
|
|
- <code>#ffbc6b</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.63053</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
- <code>rgba(0,0,0,0.7)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: #ffbc6b; border-color: #ffbc6b; color: rgba(0,0,0,0.7);">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: hsl(294, 71%, 79%);"></span>
|
|
|
- <code>hsl(294, 71%, 79%)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <code>0.5529</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
- <code>rgba(0,0,0,0.7)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: rgba(0,0,0,0.7);">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
- <p>
|
|
|
- For colors that have a luminance close to the <code>0.55</code> threshold, it can be useful to <strong>override</strong> the <code>findColorInvert()</code> function, and rather set the invert color <strong>manually.</strong>
|
|
|
- <br>
|
|
|
- For example, this shade of <span class="bd-color" style="background: hsl(294, 71%, 79%); float: none; height: 16px; width: 16px; margin-right: 0; vertical-align: middle;"></span> purple has a color luminance of <code>0.5529</code>. It can be preferable to set a color invert of white instead of transparent black:
|
|
|
- </p>
|
|
|
- <table class="table is-bordered">
|
|
|
- <tbody>
|
|
|
- <tr>
|
|
|
- <th>
|
|
|
- with <code>findColorInvert()</code>
|
|
|
- </th>
|
|
|
- <td>
|
|
|
- <code>$purple-invert: findColorInvert($purple)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
- <code>rgba(0,0,0,0.7)</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: rgba(0,0,0,0.7);">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <th>
|
|
|
- with manual setting
|
|
|
- </th>
|
|
|
- <td>
|
|
|
- <code>$purple-invert: #fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <span class="bd-color" style="background: #fff;"></span>
|
|
|
- <code>#fff</code>
|
|
|
- </td>
|
|
|
- <td>
|
|
|
- <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: #fff;">
|
|
|
- Button
|
|
|
- </a>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</section>
|
|
|
+<div class="content">
|
|
|
+ <p>The <code>findColorInvert($color)</code> function takes a <strong>color</strong> as an input, and outputs either transparent <strong>black</strong> <code>rgba(#000, 0.7)</code> or <strong>white</strong> <code>#fff</code>:</p>
|
|
|
+ <ul>
|
|
|
+ <li>if <code>colorLuminance($color) > 0.55</code>, it outputs <code>rgba(#000, 0.7)</code></li>
|
|
|
+ <li>otherwise, it outputs <code>#fff</code></li>
|
|
|
+ </ul>
|
|
|
+ <p>Its purpose is to guarantee a <strong>readable</strong> shade for the <em>text</em> when the input color is used as the <em>background</em>.</p>
|
|
|
+ <table class="table is-bordered">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>color</th>
|
|
|
+ <th>color luminance</th>
|
|
|
+ <th>findColorInvert()</th>
|
|
|
+ <th>result</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #00d1b2;"></span>
|
|
|
+ <code>#00d1b2</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.52831</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #fff;"></span>
|
|
|
+ <code>#fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #00d1b2; border-color: #00d1b2; color: #fff;">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #3273dc;"></span>
|
|
|
+ <code>#3273dc</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.23119</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #fff;"></span>
|
|
|
+ <code>#fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #3273dc; border-color: #3273dc; color: #fff;">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #23d160;"></span>
|
|
|
+ <code>#23d160</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.51067</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #fff;"></span>
|
|
|
+ <code>#fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #23d160; border-color: #23d160; color: #fff;">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #ffdd57;"></span>
|
|
|
+ <code>#ffdd57</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.76863</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: rgba(0, 0, 0, 0.7);"></span>
|
|
|
+ <code>rgba(0, 0, 0, 0.7)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #ffdd57; border-color: #ffdd57; color: rgba(0, 0, 0, 0.7);">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #ff3860;"></span>
|
|
|
+ <code>#ff3860</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.27313</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #fff;"></span>
|
|
|
+ <code>#fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #ff3860; border-color: #ff3860; color: #fff;">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #ffb3b3;"></span>
|
|
|
+ <code>#ffb3b3</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.61796</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
+ <code>rgba(0,0,0,0.7)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #ffb3b3; border-color: #ffb3b3; color: rgba(0,0,0,0.7);">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #ffbc6b;"></span>
|
|
|
+ <code>#ffbc6b</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.63053</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
+ <code>rgba(0,0,0,0.7)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: #ffbc6b; border-color: #ffbc6b; color: rgba(0,0,0,0.7);">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: hsl(294, 71%, 79%);"></span>
|
|
|
+ <code>hsl(294, 71%, 79%)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <code>0.5529</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
+ <code>rgba(0,0,0,0.7)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: rgba(0,0,0,0.7);">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <p>
|
|
|
+ For colors that have a luminance close to the <code>0.55</code> threshold, it can be useful to <strong>override</strong> the <code>findColorInvert()</code> function, and rather set the invert color <strong>manually.</strong>
|
|
|
+ <br>
|
|
|
+ For example, this shade of <span class="bd-color" style="background: hsl(294, 71%, 79%); float: none; height: 16px; width: 16px; margin-right: 0; vertical-align: middle;"></span> purple has a color luminance of <code>0.5529</code>. It can be preferable to set a color invert of white instead of transparent black:
|
|
|
+ </p>
|
|
|
+ <table class="table is-bordered">
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <th>
|
|
|
+ with <code>findColorInvert()</code>
|
|
|
+ </th>
|
|
|
+ <td>
|
|
|
+ <code>$purple-invert: findColorInvert($purple)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: rgba(0,0,0,0.7);"></span>
|
|
|
+ <code>rgba(0,0,0,0.7)</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: rgba(0,0,0,0.7);">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th>
|
|
|
+ with manual setting
|
|
|
+ </th>
|
|
|
+ <td>
|
|
|
+ <code>$purple-invert: #fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <span class="bd-color" style="background: #fff;"></span>
|
|
|
+ <code>#fff</code>
|
|
|
+ </td>
|
|
|
+ <td>
|
|
|
+ <a class="button" style="background: hsl(294, 71%, 79%); border-color: hsl(294, 71%, 79%); color: #fff;">
|
|
|
+ Button
|
|
|
+ </a>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+</div>
|