# State Machine: The State Switcher

> State Machine is a Sketch plugin. Installing it will allow you to use ⌃⌘S to switch an active tab on a tab bar you’re designing, an active navigation section in a menu, or a page number in a pagination control.

- Date: 2015-08-06T00:00:00.000Z
- Authors: Roman Shamin
- Categories: Design, DX, Developer Products
- URL: https://evilmartians.com/chronicles/state-machine-the-state-switcher

---

State Machine is a Sketch plugin. Installing it will allow you to use ⌃⌘S to switch an active tab on a tab bar you’re designing, an active navigation section in a menu, or a page number in a pagination control.

*Image: ⌘R, change ID, ⌃⌘S*

## How does it work

The designer uses the component title to point to the element he wants to switch to and hits ⌃⌘S. The plugin finds the layer needed, the neighboring layer with the style that differs from it and swaps their styles.

*Image: Examples.sketch*

To understand State Machine better and play with examples a little bit, get [Examples.sketch](https://cdn.rawgit.com/romashamin/statemachine-sketch/master/Examples.sketch) right now

The more elements a component contains, the more useful State Machine is. It may be excruciating to add a symbol for each state of a ten-page indicator by using _Insert → Symbol_ for that each time. Here’s how it works with State Machine:

1. Copy the component.
2. ⌘R, change its ID.
3. ⌃⌘S.

## Organizing a component

For State Machine to work, you need to organize a component properly. What does a properly organized component consist of, exactly?

1. A group of layers, with one of the layers having a distinctive style (the _active_ one).
2. A key `::` and an ID in layer names (see the example).
3. A key `::` and an ID of one of the layers in the group name (see the example).

*Image: A component example: key and active layer ID in group name, layers include keys and ID each*

Please note:

* State Machine ignores other groups inside the component, and it ignores layers without a key.
* State Machine won’t do anything if there are less than three layers in a component.
* State Machine assumes that a layer ID is a part of the string that follows the key name.

*Image: A key `::` and an ID*

The amount of time you invest in creating a proper structure and correctly formed names will pay for itself by the ability to automate further work with components — and the neatness of your Sketch design.

> Try Also: [RenameIt](https://github.com/rodi01/RenameIt) plugin in tow with State Machine

## Suitable components

The plugin will work with interface components consisting of a collection of similar elements, with one of them considered _active_.

*Image: No need to switch anything manually anymore*

## Be careful with disabled styles

If State Machine becomes buggy or will seem like it does not do anything, check if some of the component’s layers have some of their styles disabled. For instance, if you take some similar layers, add a _Fill_ to one of them and turn it off afterward, Sketch will add the disabled fill parameters into the layer style anyway. This layer will look exactly like its neighbors, but technically, it will have a unique style, so State Machine will consider it an _active_ element of the group.

---

State Machine enables the designer to address the component he’s working with as a whole. Design in once and treat it as a single unit later. Control the component by assigning layer IDs in component names instead of going under the hood every time something needs to be changed.

> [Download and Install State Machine](https://github.com/romashamin/statemachine-sketch)

State Machine is a free and open source project [hosted on GitHub](https://github.com/romashamin/statemachine-sketch). Use [Issues](https://github.com/romashamin/statemachine-sketch/issues) to report any bugs you find, and feel free to fork the repository if there is any additional functionality you would like to implement.

---

This article was written by [Evil Martians](https://evilmartians.com), a product development consultancy trusted by teams from early-stage startups to public companies. If you're working through a hard problem, [we can help](https://evilmartians.com/contact-us)
