A small framework for turning a series of SVG files into a clickable prototype.
Check out the full kitchen sink on CodePen or this example prototype of a copy machine interface to see what this library is capable of. Hint: the access code is 1505
- Supports going between multiple SVG "screens"
- Converts rectangles that are named with a special token into HTML input fields
- Collection of helper functions that make coding somewhat less repetitive
The following instructions are optimized for Adobe Illustrator, but you can use any program that edits SVG
Basically: follow the instructions from the excellent article How designers can create interactive prototypes with Illustrator -- See the heading Preparing your Illustrator document
- Everything you want to add functionality to later will need a valid CSS Class Name.
- Overlay everything on top of each other.
See this CodePen for all examples
- Rectangles named with
HTMLINPUT-TEXT-[input-id]
turn into a<input type="text">
with the idinput-id
- Create hotspots above all the (fill: white, no stroke)
- Name these hotspots with a valid CSS Class Name
- Suggestion: Create a new layer containing all the hotspots that floats above all your other visual elements, to ensure that they are all the top-most layer.
The following is a screenshot of what I have in Illustrator for the copy machine example given: The Layers of my Adobe Illustrator file.
Choose Save a Copy -> Save as type SVG -> I use these settings
See the example
folder for the source code (CoffeeScript) for the copy machine prototype.
- Import
prototype.js
andprototype.css
from thedist
folder into your project. - Call
new Prototype(setup)
in your code. The optional parametersetup
is an object containing two keys:initialState
andstates
(see Configuration, below).
Protoype-with-svg provides a naive implementation of a state machine, so that it can support transitioning between one SVG and another. Each object in states
can have the following keys:
The name of the SVG file representing the current state's view
Example: "Copy Machine Export-01.svg"
All the IDs of elements to hide when the state is loaded.
Example: [ 'text-error-msg' ]
All the IDs of elements containing text to clear when the state is loaded
Example: [ 'text-code' ]
This holds all of the tooltips. This should be an object where the keys are the IDs of elements, and the values are the corresponding tooltip text to be displayed.
Example: 'numpad': 'Pssst! The access code is 1505'
This holds all of the click events of your prototype. This should be an object where the keys are the IDs of the elements, and the values are the functions that should be called when the element is clicked:
Example: 'numpad_0': function () { inputCode('0'); }
this will call inputCode('0')
when numpad_0
is clicked
This to be written about later, but here is a list of them so you can at least see what they are in prototype.coffee|js
- setText
- clearText
- hide
- show
- gotoState
- mask
- unmask
You will need some sort of HTTP server to see your prototype in action. I personally use npm's http-server
, but many other options abound, such as python -m SimpleHTTPServer
It's written in CoffeeScript, but you can refer to the Javascript output as well.
- Clipping paths generally will not give you the result you want, unfortunately, unless you add the Rasterize Appearance (Effect -> Rasterize) to the object. Alternatively, you can try performing a Crop in the Pathfinder, or Expanding the object.
- Illustrator (CS5) sometimes increments the ID numerically, appending
_1_
etc., without apparent reason, which is annoying. This is resolved in code, so please do not include the pattern_#_
in your mockup. - Can sometimes click on something that is not meant to be displayed. I think this is because there are still events attached that should not be there.
- It would be nice if there were some "headless" Javascript library that can automatically do some databinding.
- Can't yet clear the text of what shows up in Illustrator as "multi-line" text fields, the ones that are a
<g>
wrapped around a<rect>
and a<text>
.- Workaround: You are better off just hiding the entire
<g>
rather than trying to clear it
- Workaround: You are better off just hiding the entire
- Illustrator (CS5) does not export the text-anchor attribute. That means text that will change in length at runtime will usually have to be left-aligned to look good.
- Well, fix some of those known issues. They really suck.
- Consideration of integrating other Javascript libraries (d3? angular? react? rivets?, snap.js?) into the mix for greater leverage and expressability.
- Add unit testing
- Improve deployment and dependencies (Yeoman? bower? jQuery plugin? requirejs?)
- Make the examples and documentation prettier and more complete.
- Let me know what functionality should be added!
Based on Tom Germeau's article that opened my mind about prototyping using Adobe Illustrator (or any SVG editor): How designers can create interactive prototypes with Illustrator
Typeface used in example is Norwester by Jamie Wilson