Add Color swatches to #Brooklyn theme. Use hexadecimal values or images.
We want to go from this:
... to that:
Note: The name of the product option label does not need to be Color nor Finish. This tutorial can work with any product option.
Upload to your theme assets an image that will illustrate the option. Write down the filename next to the option name in your text file. Repeat for all options.
Time to write some CSS! Open your theme.scss.liquid stylesheet in the online code editor. At the very bottom of the file, define your options, following this very strict format:
$options: (
'Finish-Walnut' 'swatch_walnut.png',
'Finish-Gold' 'swatch_gold.png',
'Finish-Graphite' 'swatch_graphite.png'
);
Notes
map
object, which would have made our code more succinct.<Option Name>-<Option Value>
. Use the same case as in your Admin. Except replace white space with a dash. So if you have a 'Finish' option, and one of its values is 'Marbled Green', use 'Finish-Marbled-Green', not 'Finish Marbled Green' nor 'finish-Marbled-green'. Accents are allowed.$url_prefix: '{{ '*' | asset_url | split: '*' | first }}';
$url_suffix: '{{ '*' | asset_url | split: '*' | last }}';
@each $option in $options {
$optionName: nth($option, 1);
$bgImage: nth($option, 2);
#ProductSelect-option-#{$optionName} + label {
background-image: url( $url_prefix + $bgImage + $url_suffix );
background-size: cover;
color: transparent;
width: 50px;
height: 50px;
overflow: hidden;
border-radius: 25px;
margin: 5px;
text-indent: 100%;
white-space: nowrap;
}
#ProductSelect-option-#{$optionName}:checked + label {
border-color: #555;
border-width: 3px;
}
}
That's it!
We want to go from this:
... to that:
Note
The name of the product option does not need to be Color. This tutorial can work with any product option.
Find the proper hexadecimal value for each color. Use this tool: http://www.color-hex.com/ Add the hex value next to each color in your text file.
Time to write some CSS! Open your theme.scss.liquid stylesheet in the online code editor. At the very bottom of the file, define your colors, following this very strict format:
$colors: (
'Color-Hot-Pink' #FE4365,
'Color-Vieux-Rose' #FC9D9A,
'Color-Old-Paper' #F9CDAD,
'Color-Faded-Green' #C8C8A9,
'Color-Green' #83AF9B
);
Notes
map
object, which would have made our code more succinct.<Option Name>-<Option Value>
. Use the same case as in your Admin. Except replace white space with a dash. So if you have a 'Color' option, and one of its values is 'Faded Green', use 'Color-Faded-Green', not 'Color Faded Green' nor 'color-Faded-green'. Accents are allowed.@each $color in $colors {
$colorName: nth($color, 1);
$bgColor: nth($color, 2);
#ProductSelect-option-#{$colorName} + label {
background-color: $bgColor;
color: $bgColor;
width: 50px;
height: 50px;
overflow: hidden;
border-radius: 25px;
margin: 5px;
text-indent: 100%;
white-space: nowrap;
}
#ProductSelect-option-#{$colorName}:checked + label {
border-color: #555;
border-width: 3px;
}
}
That's it!