This tutorial shows you how to build a counter widget, where you can increment and decrement a number. Through this simple widget we will walk through everything that you can do with Wix Blocks.

We recommend that you build this widget from scratch, but if you get stuck, you can view a template of the widget in Blocks and edit it under your Wix account.
Create an empty Blocks app. Start with a blank canvas.
A flexbox is a container that allows responsiveness. It will keep the other elements organized. To add a flexbox:


1. Click Settings.
2. Select Text only from the drop down list.
3. Change the button's text or icon to "+".
4. Click the Design
icon in the Inspector panel
and select Text.
5. Click Themes and select Heading 6 from the drop down list.
6. Drag and drop another square button to the left section.
7. Change the text to "-".


icon in the bottom right of the screen. 
Now it's time to make the widget do what it's supposed to do: count up and down when the buttons are clicked.
1. Go to the bottom part of your screen to add code to your widget.

2. Add the following code before your onReady() function.
3. Add the following code in your onReady() function.
4. Click the Preview button to see your widget in action.
Blocks lets you define an API for your widget, so that the user (a site owner who installs the widget) can customize it to their needs. The API can contain properties, events and exported functions.
Let's say that you want a user to be able to decide what the "step" of the count is. Perhaps they want the step to be 2, so that the count is 0,2,4,6 etc.
To do that, let's define a property in the widget API named step.
step Property
icon to open the Widget API panel.
icon that appears).

Change your code so that when the buttons are clicked, addToCount is called with the step from the properties rather than with the default value of 1.
Use $widget.props to access your properties (notice the autocomplete Velo suggestions).

3. Change the step to a different number and see how your widget works.

The widget API allows you to add an event that is fired whenever you decide.
Add an event that is fired when the "count" variable changes:
icon to open the Widget API panel.
icon that appears). 
4. Add this line to your addToCount() function, to fire the event when the count changes.
5. Now, your addToCount() function should look like this:
You'll need to catch your event in the site editor once you have installed your widget in your website (this will be describe in Step 8).
Create and export a reset() function, so that site owners can easily set the count to 0.
icon to open the Widget API panel.
icon that appears). 
4. Paste the following code instead of the function default code:
5. Update the JSDoc. You must keep the function's annotation in this format.
The Configuration tab within the Editor Experience Panel
allows you to determine the behavior of the widget and its elements when a site owner edits it in the editor. Try out a few options in the Configuration tab.

Set a display name for your widget elements:
panel.
Prevent the text element from being selectable in the editor:
panel to remove the blue checkmark. 
Blocks allows you to create various variations for your widget's design and layout, through design presets. To create another design preset:
panel .
.
to rename your preset (you can also duplicate or delete it). 
4. Make some visible changes in your widget, like changing the color of the middle section.

Move back and forth between presets to see the differences.
Note that some design and layout changes impact only your current preset, while others impact all (learn more).
Go to your site editor to catch the event from your app. First you need to register an Event Handler for the change event:
icon.
Now write the function. It gets the `count` as a parameter and resets the count when it gets to whatever number you decide (in our example: 30). Your function should look like this:
Preview or publish to see your site in action.