npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@repay/cactus-web

v9.13.2

Published

A UI component library for web built in React by REPAY

Downloads

66

Readme

@repay/cactus-web

UI component library build for React, used by REPAY.

Usage

For usage, see the documentation for Cactus Web

Contributing

Running storybook for local development

yarn start

Testing the build

yarn test

Creating a new component

yarn new ComponentName

This will generate skeleton files for the component, tests, story, and documentation (.mdx) using the provided ComponentName.

Usage: node make-component.js [...options] ComponentName
- component name must be the last argument, contain no spaces,
  and should be pascal case.

  Options:
  --help, -h      display this information
  --force, -f     overwrite component if it exists

Building the repository

yarn build

Running the build in watch mode which will re-build on changes

yarn dev

Best Practices

Development

Components should have associated stories so that you as a developer can test the component in an active situation. The convention is to create an primary story called "Basic Usage" which allows the user to control the required properties. Then additional stories are created for optional properties.

Components are ideally exported as a styled component. This allows them to be styled directly by a parent component such as:

import styled from 'styled-components'
import { Button } from '@repay/cactus-web'

const Container = styled.div`
  padding: ${p => p.theme.space[0]};

  ${Button} {
    margin-left: ${p => p.theme.space[4]};
  }
`

If the component is not a static tag like styled.div, you can create a "base" component and style that:

import * as React from 'react'
import styled from 'styled-components'
import CloseIcon from '@repay/cactus-icons/i/actions-close'

interface ComponentProps & React.HTMLProps<HTMLDivElement> {
  showIcon: boolean
}

const ComponentBase = ({ showIcon, children, className, ...props }) => {
  return (
    <div className={className} {...props}>
      {showIcon && <CloseIcon />}
      {children}
    </div>
  )
}

export const Component = styled(ComponentBase)`
  padding: 8px;
`

export default Component

The requirement here, is that the className prop must be provided to the element that is being styled.

Styled System

We use Styled System to help ensure theme value adherence and decrease the difficulty of proper customizations. Most components should provide the margin properties.

Writing Documentation

Stories are both for development and documentation.

Documentation can be added directly to the mdx files alongside the components. You can also use the 'website-src' source alias which will point to the source root in the website directory.

The best practices section should include information related to accessibility or other critical information when using the component. However this section can be removed if there are none.

Basic usage section should have at least one example of usage as JSX. If usage in TypeScript is complex or interesting include that as well. Ideally any code written as basic usage can be copied and used directly.

A description can be added to a property via comment above the property definition. To force the inclusion of a property in the Properties section that is not showing up, add the prop to the definition with a comment above and type !important in the comment.

Testing

Components should be tested from the perspective of the end-user as possible; this means using the user-event library in combination with fireEvent() from react-testing-library. Additionally, when a label is rendered with text, it should be used to select the input element. This will best mimic the user's actions of reading the text to find the element and clicking or typing from there and enforces best practices for accessibility.

Example:

test('should trigger onChange event', () => {
  const onChange = jest.fn()
  const { getByLabelText } = render(
    <ThemeProvider theme={cactusTheme}>
      <CheckBoxField label="Katastro" name="katastro" onChange={onChange} />
    </ThemeProvider>
  )

  // Select the checkbox by label text, and fire the click event on it.
  fireEvent.click(getByLabelText('Katastro'))
  expect(onChange).toHaveBeenCalledWith('katastro', true)
})

Also, be sure to test the negative cases alongside the positive, such as when there is a diabled property:

test('should not trigger onChange event', () => {
  const onChange = jest.fn()
  const { getByLabelText } = render(
    <ThemeProvider theme={cactusTheme}>
      <CheckBoxField label="Flow" name="flow" onChange={onChange} disabled />
    </ThemeProvider>
  )

  userEvent.click(getByLabelText('Flow'))
  expect(onChange).not.toHaveBeenCalled()
})

Accessing Local Storybooks on iOS

Sometimes it may be necessary to view the storybooks on a mobile device to test/debug features like accessibility. To do this, you can follow these steps:

  1. Plug an iPhone in to your Mac & make sure the phone is on the same network as the computer.
  2. In the iPhone's settings, navigate to Safari > Advanced and make sure "Web Inspector" is turned on.
  3. On your Mac, open Safari > Preferences > Advanced and make sure "Show develop menu in menu bar" is checked.
  4. In the Safari search bar on the iPhone, type your computer's IP address followed by the port the storybooks are running on, which defaults to 9001. (Ex: 10.1.2.345:9001)
  5. You can view the development console on Mac by clicking Develop > (your iPhone's name) > and selecting the browser window from the list of open windows on the iOS device.

Note: If you don't know your computer's IP address, you can get it by running ifconfig in your terminal. The IP address you'll want will be directly after inet in the last result returned from ifconfig.