Metacomponent

What this is

A component that displays a bunch of colored squares to show off a CSS theme's flair.

Designed by WoedenazWoedenaz and componentised by CroquemboucheCroquembouche.

This component is designed to be used for CSS themes, but it can be used on almost any page, if you really want.

Usage

On any wiki:

[[include :scp-wiki:component:theme-squares -=-
| color1-name=My Favourite Colour
| color1-variable=--fav-color
| color1-info=(191, 144, 0)
]]

Note the "-=-" after the component name. You do need to include that — otherwise all this text explaining how to use the component will appear on your page.

For this component, there are three parameters per color. Replace N with the number of the color.

colorN-name The name of the color. Pick whatever you want!
colorN-variable The name of the CSS variable that contains this color.
The variable should hold three comma-separated numbers representing the RGB values of the color. This is consistent with BHL-style variables.
If your variables hold something else (e.g. a full RGB/RGBA or hex color), you will need to override the background color of each theme square manually with CSS.
colorN-info Some info about the colour. Displaying the RGB values is typical. Keep it short.
If you don't want any text, add @@ @@ instead.
colorN-has-light-text
Optional. Default: 0
Either 0 or 1. Determines the font color on the square. Useful to make sure there is enough contrast between the background color and the text color.
If 1, the value of --swatch-text-light is used, or white (255, 255, 255) if it is not defined. Otherwise --swatch-text-dark, or black (0, 0, 0). Like all BHL-style CSS color variables, three numbers representing RGB values are expected.

A color can only be used if it's exposed as a CSS variable. All colors in a Black Highlighter theme have a corresponding CSS variable by default, so for BHL themes, this component should work out of the box. However, sigma9 does not use CSS variables, so the only CSS variables that are available will be any that you have defined in your theme.

This component can hold a maximum of 6 primary colors and 12 secondary colors. I recommend two primary colors and no more than six secondary colors.

To add a primary color, just add the top three of the above parameters to the include, as shown in the example.

To add a secondary color, it's the same, but replace 'color' with 'subcolor'.

Example

Here's a longer example, taken from the Black Highlighter theme:

[[include :scp-wiki:component:theme-squares -=-
| color1-name=Payne's Grey
| color1-variable=--gray-monochrome
| color1-info=(66, 66, 72)
| color1-has-light-text=1
| color2-name=Rosewood
| color2-variable=--bright-accent
| color2-info=(133, 0, 5)
| color2-has-light-text=1
| subcolor1-name=Alto
| subcolor1-variable=--very-light-gray-monochrome
| subcolor1-info=(215, 215, 215)
| subcolor2-name=White Smoke
| subcolor2-variable=--pale-gray-monochrome
| subcolor2-info=(244, 244, 244)
| subcolor3-name=Bastille
| subcolor3-variable=--dark-gray-monochrome
| subcolor3-info=(48, 48, 52)
| subcolor3-has-light-text=1
| subcolor4-name=Buccaneer
| subcolor4-variable=--medium-accent
| subcolor4-info=(100, 46, 44)
| subcolor4-has-light-text=1
| subcolor5-name=Maroon
| subcolor5-variable=--dark-accent
| subcolor5-info=(100, 3, 15)
| subcolor5-has-light-text=1
| subcolor6-name=Mango Tango
| subcolor6-variable=--newpage-color
| subcolor6-info=(221, 102, 17)
]]

This produces the following colored squares:

bhl-squares.png

Tweaking

You can adjust the appearance of the component with CSS.

The whole component has the .colors-container class, and any CSS that targets it should included that class to ensure that nothing else on the page is affected. Every colored square has class .color. The primary colors have a .colors parent and the secondary colors have a .subcolors parent.

You'll need to use !important to override a square's background.

For example, the Laughter and Knives theme adds a gradient background to the 9th secondary color like so:

.colors-container .subcolors .color:nth-of-type(9) {
    background: var(--pastel-rainbow) !important;
}

Tool to convert existing syntax to arguments for this component

.colors-container {
  width: 98%;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  font-weight: 700;
  font-family: var(--title-font, Verdana);
  color: black;
}
 
.colors-container .colors, .colors-container .subcolors {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
}
 
.colors-container .color {
  flex-grow: 2;
  padding: 0.5rem;
  margin: 0.5rem;
  color: rgb(var(--swatch-text-dark, 0, 0, 0));
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
 
.colors-container .colors .color {
  height: 7rem;
  min-width: 4rem;
  flex-basis: calc((100% / 2) - 2rem);
}
 
.colors-container .subcolors .color {
  height: 4rem;
  min-width: 4rem;
  font-size: 75%;
  text-align: center;
  flex-basis: calc((100% / 6) - 2rem);
}
 
.colors-container .css-variable {
  font-size: 75%;
  letter-spacing: 0.1em;
  font-family: var(--body-font, Verdana);
}
 
/* Hide a colour that's not been provided by seeing if the variable starts with "{$" */
.colors-container [data-variable^=\{\$] {
  display: none;
}
 
.colors-container [data-has-light-text="1"] {
  color: white;
  color: rgb(var(--swatch-text-light, 255, 255, 255));
}
{$color1-name}{$color1-variable}{$color1-info}
{$color2-name}{$color2-variable}{$color2-info}
{$color3-name}{$color3-variable}{$color3-info}
{$color4-name}{$color4-variable}{$color4-info}
{$color5-name}{$color5-variable}{$color5-info}
{$color6-name}{$color6-variable}{$color6-info}
{$subcolor1-name}{$subcolor1-variable}{$subcolor1-info}
{$subcolor2-name}{$subcolor2-variable}{$subcolor2-info}
{$subcolor3-name}{$subcolor3-variable}{$subcolor3-info}
{$subcolor4-name}{$subcolor4-variable}{$subcolor4-info}
{$subcolor5-name}{$subcolor5-variable}{$subcolor5-info}
{$subcolor6-name}{$subcolor6-variable}{$subcolor6-info}
{$subcolor7-name}{$subcolor7-variable}{$subcolor7-info}
{$subcolor8-name}{$subcolor8-variable}{$subcolor8-info}
{$subcolor9-name}{$subcolor9-variable}{$subcolor9-info}
{$subcolor10-name}{$subcolor10-variable}{$subcolor10-info}
{$subcolor11-name}{$subcolor11-variable}{$subcolor11-info}
{$subcolor12-name}{$subcolor12-variable}{$subcolor12-info}