Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Modify Spire CSS widget styles

Describes how to modify the styles of an existing widget in Spire.

This example shows how to modify the styles of the ProductPrice component. This component is used across the site.

  • This will involve the use of style extension objects in Spire.
  • This will involve the use of styled-components to specify CSS rules.
  • This solution is ideal if you need to customize the style of a widget and:
    • The Mobius component does not provide a prop to modify that style or
    • The CSS rules are complex.

This example will use the VS Code IDE for modifying the widget styles.


Spire CSS styles

Spire allows for CSS styles to be passed down to specific child widgets. This capability is the result of adding a React Context Provider and Hook to additionalStyles.tsx.

The widgets with this ability include Banner, Button, Image, Link, LinkList, Logo, NavigationList, Quick Order, Rich Content, Slideshow, SocialLinks, Subscribe, SecondaryNavigation, HeaderLinkList, HeaderSearchInput, Header/MainNavigation, HeaderSignIn, HeaderShipToAddress, CurrencyMenu, and LanguageMenu.



You have created a custom blueprint.

  1. Open your IDE.

  2. In your IDE, open the ~/src/FrontEnd directory from the InsiteCommerce repository.

  3. Find the WidgetExtensions directory in your custom blueprint directory (such as ~/FrontEnd/modules/blueprints/myCustomBlueprint/src/WidgetExtensions).

  4. In the WidgetExtensions directory, create a new file named CommonComponentsExtensions.ts. The name does not matter. This file will be used for components that are used across the Storefront.

  5. Add the following code to the CommonComponentsExtensions.ts file.

    import {productPriceStyles} from "@insite/content-library/Components/ProductPrice";
    import {css} from "styled-components";
    import mergeToNew from "@insite/client-framework/Common/mergeToNew";
    /* Note: Modifying the styles this way will affect all instances of the widget across the Storefront.
       Each component and widget in Spire exports a base style exensions object.
       You can import this object and modify the properties on it. This will affect
       all instances of the component or widget across the Storefront. In this example,
       the style extensions object is named "productPriceStyles".
       The `mergeToNew` function uses lodash's `_.merge()` behind the scenes
       to make deep merging two objects easier. You can also do this manually
       using the JavaScript spread (...) operator.
       /* This is using the `css` utility function provided by styled-components.
          You should extend the base widget or component CSS rules when you add new CSS rules.
          Note: You should NOT use CSS selectors to apply CSS rules. 
          Each of the Mobius components used by widgets in Spire makes use of 
          the style extension objects. This allows you to target a specific element within a widget 
          to apply styles.
        css: css`
            text-align: right;`,});
  6. Save the file.

  7. Run Spire using your custom blueprint. Below is an example of starting Spire from the terminal. You may also do this from your IDE. Spire includes some default VS Code launch configurations.
    npm run start myCustomBlueprint 3000

  8. Go to the Storefront. The Storefront URL is <http://localhost:3000>. Use the port number used to run Spire.

  9. Go to a Product Detail page and the Product List page.

The resulting Product Detail page:

The text is moved to the right.

The text is moved to the right.

The resulting Product List page:

The text is moved to the right.

The text is moved to the right.