AndreiAnton / store-framework

https://lab.github.com/vtex-trainings/store-framework
0 stars 0 forks source link

CSS Handles and the power of customizing blocks #6

Open github-learning-lab[bot] opened 4 years ago

github-learning-lab[bot] commented 4 years ago

CSS Handles and the power of customizing blocks

:sparkles: Branch: csshandles

Introduction

Taking a quick look at your online store, you'll notice that components have similar styles, even without applying any customization.

All of them, including the recently configured Info Card, share pre-established values for font, background color, main color, button format, etc.

This is due to the style.json, the file responsible for declaring generic customization values for every Store Framework store.

style

To create a unique identity for your store's components, you can overwrite these values using CSS customizations.

Analyzing the recipe employed to customize stores using CSS, we can notice that several steps will be needed in order to apply your own style, such as:

  1. Create a new file in the CSS folder, naming it vtex.{AppName}.css

  2. Use the CSS Handle of the component that will be customized in this file in the following format:

    .{CSSHandle} {
        {PropriedadeDeCSS}: {ValorDesejado};
        {PropriedadeDeCSS}: {ValorDesejado};
    }
  3. Lacking CSS Handles, apply permitted CSS Selectors, such as :global(vtex-{componentName}).

  4. To apply CSS to a specific block and not to every block of that type, use the blockClass resource, which appears next to the CSS Handles when inspecting your code. The blockClass must be declared as a prop in the block in question, and thus be referenced in the style file as shown below:

    .{CSSHandle}--{blockClass} {
        {PropriedadeDeCSS}: {ValorDesejado};
        {PropriedadeDeCSS}: {ValorDesejado};
    }

Customizing the Info Card

To uncover a component's CSS Handles, such as the Info Card, simply access your documentation's Customization section.

According to the description of CSS Handles and to the store customization recipe using CSS, we can implement a customized Info Card example, editing its title and call-to-action button configurations by adding the following code to the vtex.store-components.css file, found in /styles/css:

.infoCardHeadline {
    font-family: serif;
    font-size: 2.25rem;
    font-weight: normal;
    color: gray;
    border: 2px solid black;
    padding: 24px;
}

.infoCardCallActionContainer :global(.vtex-button) {
    color: white;
    background-color: gray;
    border: transparent;
}

.infoCardCallActionContainer :global(.vtex-button):hover {
    color: gray;
    background-color: blue;
    border: transparent;
}

You can check the effect of these changes by running the vtex link command.

image

Next, we'll add a specific style to the vintage info card. To begin, add the blockClassprop to info-card#button-right, as shown below:

"info-card#button-right": {
  "props": {
    "isFullModeStyle": false,
    "textPosition": "right",
    "imageUrl": "https://appliancetheme.vteximg.com.br/arquivos/cozinha-rosa-min.png",
    "headline": "Vintage Pink",
    "subhead": "Give your kitchen a boho style adding vintage apparels.<br>Available until January 2020.",
    "callToActionMode": "button",
    "callToActionText": "Explore",
    "callToActionUrl": "/sale/d",
    "textAlignment": "center",
    "blockClass": "vintage"     //  <------------
  }
}

Thereafter, declare a background-color for this specific info card in your CSS file:

.infoCardContainer--vintage {
  background-color: #EDCFD1
}

Check out the result by linking your app.

image

Activity

  1. In the vtex.store-components.css file, copy the above-mentioned code and use it in your theme's CSS file, according to the recipe on store customizations using CSS;
  2. Based on the Info Card Handles, define a maximum width (max-width) of 1260px for all info cards, a margin of 0 auto and a padding of 0.
  3. Change the component's title color to black;
  4. Put the title in bold;
  5. Change the background color during hover to white.
  6. In parallel to the vintage blockClass, apply a new block class called metal to the info card info-card#button-left and apply the #e1e1e1 background color to it.

image


If you're still unsure as to how to send your answers, click here to go through that step again.

vtex-course-hub[bot] commented 4 years ago

Oopsie, something went wrong :crying_cat_face:

Results

:white_check_mark::white_check_mark::x::x::x::white_check_mark::white_check_mark::x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :x: You haven't declared .infoCardContainer classes for the image :x: You haven't declared the attributes correctly for the image - .infoCardContainer :x: You haven't declared the attributes values correctly for the image - .infoCardContainer :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :x: You haven't declared the attributes values correctly for the text - .infoCardHeadline :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :x: You haven't declared the attributes values correctly for the button hover - .infoCardCallActionContainer :global(.vtex-button):hover

Try again :grin:

vtex-course-hub[bot] commented 4 years ago

Oopsie, something went wrong :crying_cat_face:

Results

:white_check_mark::white_check_mark::x::x::x::white_check_mark::white_check_mark::x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :x: You haven't declared .infoCardContainer classes for the image :x: You haven't declared the attributes correctly for the image - .infoCardContainer :x: You haven't declared the attributes values correctly for the image - .infoCardContainer :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :x: You haven't declared the attributes values correctly for the text - .infoCardHeadline :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :x: You haven't declared the attributes values correctly for the button hover - .infoCardCallActionContainer :global(.vtex-button):hover

Try again :grin:

vtex-course-hub[bot] commented 4 years ago

Oopsie, something went wrong :crying_cat_face:

Results

:white_check_mark::white_check_mark::x::x::x::white_check_mark::white_check_mark::x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :x: You haven't declared .infoCardContainer classes for the image :x: You haven't declared the attributes correctly for the image - .infoCardContainer :x: You haven't declared the attributes values correctly for the image - .infoCardContainer :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :x: You haven't declared the attributes values correctly for the text - .infoCardHeadline :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :x: You haven't declared the attributes values correctly for the button hover - .infoCardCallActionContainer :global(.vtex-button):hover

Try again :grin:

vtex-course-hub[bot] commented 4 years ago

Oopsie, something went wrong :crying_cat_face:

Results

:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :white_check_mark: Check Css Classes - Image :white_check_mark: Check Css Attributes - Image :white_check_mark: Check Css Attributes values - Image :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :x: You haven't declared the attributes values correctly for the text - .infoCardHeadline :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :x: You haven't declared the attributes values correctly for the button hover - .infoCardCallActionContainer :global(.vtex-button):hover

Try again :grin:

vtex-course-hub[bot] commented 4 years ago

Oopsie, something went wrong :crying_cat_face:

Results

:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :white_check_mark: Check Css Classes - Image :white_check_mark: Check Css Attributes - Image :white_check_mark: Check Css Attributes values - Image :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :white_check_mark: Check Css Attributes values - Text :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :x: You haven't declared the attributes values correctly for the button hover - .infoCardCallActionContainer :global(.vtex-button):hover

Try again :grin:

vtex-course-hub[bot] commented 4 years ago

You did great! :grin:

Results

:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:

Tests

:white_check_mark: Getting the file :white_check_mark: First test - Code compilation :white_check_mark: Check Css Classes - Image :white_check_mark: Check Css Attributes - Image :white_check_mark: Check Css Attributes values - Image :white_check_mark: Check Css Classes - Text :white_check_mark: Check Css Attributes - Text :white_check_mark: Check Css Attributes values - Text :white_check_mark: Check Css Classes - Button :white_check_mark: Check Css Attributes - Button :white_check_mark: Check Css Classes and Metal blockClass :white_check_mark: Check Css Attribute Values - Metal blockclass :white_check_mark: Check Css Classes and Vintage blockClass :white_check_mark: Check Css Attribute Values - Vintage :white_check_mark: Check Css Attributes values - Button :white_check_mark: Check Css Classes - Button Hover :white_check_mark: Check Css Attributes - Button Hover :white_check_mark: Check Css Attributes values - Button Hover

github-learning-lab[bot] commented 4 years ago

You have successfully completed this step!

Go to the next step!