VTEX Modal

Description

The VTEX Modal is the block to use when you want to display another block in a VTEX app.

It renders a button and when you click it, it opens the modal with its children component rendered.

📢 Disclaimer: Don't fork this project; use, contribute, or open issue with your feature request

Table of Contents

Usage

This app uses our store builder with the blocks architecture. To know more about Store Builder click here.

To use this app or override the default CSS you need import it in your dependencies on manifest.json file.

  "dependencies": {
    "vtex.modal": "0.x"
  }

Then, use the modal block in your blocks.json like:

"modal": {
    "children": ["rich-text"],
    "props": { 
	   "centered": true,
	   "blockClass": "home-modal",
	   "buttonClass": "t-heading-5",
	   "showCloseIcon": false
	}
  }

Blocks API

When implementing this app as a block, various inner blocks may be available. The following interface lists the available blocks within modal and describes if they are required or optional.

{
  "modal": {
    "allowed": "*",
    "component": "index",
    "composition": "children"
  }
}

For now this block does not have any required or optional blocks. It allows you to render any block as its children.

Configuration

Through the Storefront, you can change the modal's behavior and interface. However, you also can make in your theme app, as Store theme does.

Prop nameTypeDescription
centeredBooleanSet to true if component should be centered on screen. Default: false
closeOnEscBooleanSet to true if modal should close when esc key is pressed. Default: true
closeOnOverlayClickBooleanSet to true if modal should close when pressing on outside area. Default: true
showCloseIconBooleanSet to true if modal should display close icon. Default: true
buttonLabelStringSet the label displayed on button to open modal Default: ""
buttonClassStringPass extra tachyon classes to button container. Default: null
blockClassStringUnique class name to be appended to block classes. Default: null

Styles API

This app provides some CSS classes as an API for style customization.

To use this CSS API, you must add the styles builder and create an app styling CSS file.

  1. Add the styles builder to your manifest.json:
  "builders": {
    "styles": "1.x"
  }
  1. Create a file called vtex.rich-text.css inside the styles/css folder. Add your custom styles:
.container {
  margin-top: 10px;
}

CSS Namespaces

Below, we describe the namespaces that are defined in the modal.

Token nameComponentDescription
containerindexThe container that encloses the whole <Modal> component
childrenContainerindexIt represents the view that encloses the children rendered inside the container
buttonindexIt is inserted in the view that encloses the button used to open the modal

Troubleshooting

You can check if others are passing through similar issues here. Also feel free to open issues or contribute with pull requests.

Tests

To execute our tests go to react/ folder and run yarn test

Travis CI

Build Status
Coverage Status