Meetup library of React UI components for the web.
Table of Contents
- Getting started
- Release notes
This checklist can be used as a guide for adding components that are easy to reuse and maintain. The categories come from a talk I saw Elyse Holladay give at Clarity Conf 2017.
Easy to reason about
- It will be clear to other designers or engineers what problem the component solves and when to use it
- All properties, options and variants are documented in Storybook
- Has unit tests
- Provides logical defaults
- If there can be errors, error states are designed and documented
- If the component has become complex, it has been broken into smaller components
- Doesn't rely on a parent component to behave or look correctly
- Doesn't have logic that controls functionality outside of itself e.g.: if there is a button in the component, it should take an event handler via props instead of assuming what the button is going to do
- Works in supported browsers and devices
- Design is accessible for all users
- Provides necessary ARIA information
- Design won't cause issues with translation or internationalization
Independent and isolated
- Only affects itself
- Defines itself and its styles only in one place
- Ready to use "out of the box" in consumer apps or by other components
This package uses semver versioning to tag releases, although the patch version
is determined exclusively by the Travis build number for pushes to
Major and minor versions are hard-coded into the Makefile.
Manual pushes to
master and PR merges to master will be built by Travis, and
will kick off the yarn publish routine. The currently-published version of the
package is shown on the repo homepage on GitHub in a badge at the top of the
When developing a consumer application that requires changes to the platform code, you can release a beta version of the platform on npm by opening a PR in the meetup-web-platform repo. When it builds successfully, a new beta version will be added to the list of available npm versions. The generated version number is in the Travis build logs, which you can navigate to by clicking on 'Show all checks' in the box that says 'All checks have passed', and then getting the 'Details' of the Travis build.
At the bottom of the build log, there is a line that
If you click the disclosure arrow, the version number will be displayed, e.g.
You can then install this beta version into your consumer application with
> yarn add meetup-web-components@<version tag>
Each time you push a change to your
meetup-web-components PR, you'll need to
re-install it with the new tag in your consumer application code.
The overall workflow is:
- Open a PR for your
- Wait for Travis to successfully build your branch (this can take 5+ minutes)
- Get the version string from the build logs under
- (if needed) Push changes to your
- Repeat steps 2-3
You can generate the boilerplate files for React components using
yarn run generate, which invokes
The command will prompt you for a 'type' (select from the list of options),
and a 'name'. It generates the following files in
<ComponentName>.jsxComponent JSX module
<componentName>.test.jsxComponent test script
Located in the
src/ directory, component files live alongside
Filename casing conventions:
- Component files:
CamelCase, with a leading capital, i.e.
- Test files:
- Story files:
Redux Form Components
redux-form in our
mup-web app to help with validation flow.
redux-form can use our form components (just pass our MWC component to
Field as the
component prop), but we need to write wrappers to pass down the props from
Field to our form components in
The job of the wrapper for each component is mostly just parsing out the
other props from
redux-form and passing them on.
You can find the wrapper classes in
The files are named after the classes they wrap to avoid verbose file names.
forms/TogglePill.jsx has a
But the actual class name to import and
ReduxForm in the name.
export class ReduxFormTogglePill
We write wrappers as we need them, so if you don't find one that you need, please write it!
We've run into a couple gotchas already:
redux-form validates all fields on load, and its hard to tell when the form is first rendered. To avoid displaying errors right away, we added some logic to read
redux-form's implementation of checkboxes give them values of
ReduxFormTogglePill wrappers handle this now by passing the
input.value prop down as
isActive (which sets
checked on checkboxes)
We may need to do this for other checkbox, radio component wrappers.
src/ directory contains layout helpers, like
Chunk. These are
documented in Storybook, but a more detailed guide can be found here.
Unit testing UI components is a little weird compared with unit testing business logic.
- You have to decide what aspects of a UI element are intrinsic to its appearance rather than just implementation details
- UI elements evolve based on aesthetic tastes as much as functional requirements - inflexible tests require a lot of maintenance
- Headless testing of browser-dependent objects requires some extra tooling to simulate the target environment
TestUtils.Simulate appears to work correctly for our testing setup - it should be used
for all tests that involve simulating events, like
onClick. Check out
for an example.
Verifying child elements
In UI testing, there is an almost invisible line between testing the implementation (markup) and testing the behavior (appearance/content), and ideally you only should test the behavior - there are loads of ways to change markup without changing the fundamental app experience, and those kinds of markup changes should not be considered "bugs" that result in failed tests.
The implication for constructing unit tests is that you should avoid relying on the specific
markup (tags and DOM structure). Sometimes it's unavoidable, but if you are inclined to use
firstChild/lastChild, or a
querySelector(All) that includes a tag
name to access particular parts of the component UI, check whether there is a better way to skip
over the markup implementation details and grab what you want explicitly.
A useful option is to add a PCV
className to the element of interest, and just use
yourComponentEl.querySelector('.specificClassName') to find it. Classnames are free and
DOM-independent, which means that no matter what the markup is for your event name, you can
always unit-test the behavior (text content) accurately with
// good expect(eventNode.querySelector('.event-name').textContent).toEqual(testEventName); // bad - assumes both tag (h5) and structure (first h5 in the card) expect(eventNode.getElementsByTagName('h5').textContent).toEqual(testEventName);
To manually lint your code, run:
$ yarn run lint
Whitespace issues will be fixed automatically - just remember to commit the changes. Other style
issues will log errors. Our
.eslintrc configuration is based on the 'recommended' preset, with
a number of additional rules that have been requested by the dev team. It's a 'living' standard,
however, so please feel free to send PRs with updates!
Before building any components, it's helpful to know what related components have already been built into our Foundation library. We use React Storybook to display components outside of the app context. To open it, run:
$ yarn install $ yarn run storybook
And open the viewer at http://localhost:9001
All of the available components are listed on the left, and clicking on one will open it in the preview pane. Variants are also listed in the left column to show how different states affect the rendered component.