Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

@aircall/tractor

Package Overview
Dependencies
Maintainers
3
Versions
243
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aircall/tractor

UI Component Library for Modern Design

  • 2.0.0-beta.21
  • npm
  • Socket score

Version published
Weekly downloads
3.5K
decreased by-37.06%
Maintainers
3
Weekly downloads
Β 
Created
Source

Gitpod ready-to-code

🀩 @aircall/tractor

The Aircall Tractor design system Foundations.

Latest Staging version available on: https://tractor.aircall-staging.com/

Latest Production version available on: https://tractor.aircall.io/

✨ Features

  • 🌈 Aircall Design System designed for web applications.
  • πŸ“¦ A set of high-quality React components out of the box written with Styled-components.
  • πŸ›‘ Written in TypeScript with predictable static types.
  • 🎨 Powerful theme customization in every detail.

πŸ“¦ Install

npm install --save @aircall/tractor
yarn add @aircall/tractor

πŸ”¨ Usage

import { Tractor, Spacer, Typography } from '@aircall/tractor';

const App = () => (
  <Tractor injectStyle>
    <Spacer space="s">
      <Typography variant="displayM">Hello</Typography>
      <Typography variant="displayL">World</Typography>
    </Spacer>
  </Tractor>
);

You are ready to go 🚜 ⚑️

You must wrap your React Tree components using the Tractor component otherwise the Tractor components won't be able to grab the theme thus they will fail.

⌨️ Development

You first need to clone the repository locally:

$ git clone git@bitbucket.org:aircall/tractor.git
$ cd tractor
$ yarn
$ yarn dev

If you want to test this Design System with your project, you need to:

$ cd tractor
$ yarn link
$ yarn build:watch
$ cd path/to/your/project
$ yarn link "@aircall/tractor"

Make sure that your project is using a single version of React otherwise you will end up having errors:

Theming

Override DefaultTheme to get accurate typings for your project.

// create styled-components.d.ts in your project source
// if it isn't being picked up, check tsconfig compilerOptions.types
import "styled-components";
import { DefaultTheme as DefaultTractorTheme } from "@aircall/tractor";

declare module "@xstyled/system" {
  export interface Theme extends DefaultTractorTheme {}
}

declare module "styled-components" {
  export interface DefaultTheme extends DefaultTractorTheme {}
}

In the real world, we usually have to modify default webpack config for custom needs. We can achieve that by using craco which is one of create-react-app's custom config solutions.

Install craco and modify the scripts field in package.json.

$ npm install --save-dev @craco/craco
$ yarn add --dev @craco/craco
/* package.json */
"scripts": {
-   "start": "react-scripts start",
-   "build": "react-scripts build",
-   "test": "react-scripts test",
+   "start": "craco start",
+   "build": "craco build",
+   "test": "craco test",
}

Then create a craco.config.js at root directory of your project for further overriding.

/* craco.config.js */
const path = require('path');

module.exports = {
  webpack: {
    alias: {
      /**
       * You need to create only one reference for React and styled-components
       * when you want to link tractor into your current project
       *
       * If you don't link react, you'll end up having react complaining of having multiple instances of React
       * and if you don't link styled-components, you won't be able to access the theme prop exposed by Tractor.
       */
      react: path.resolve('./node_modules/react'),
      'styled-components': path.resolve('./node_modules/styled-components')
    },
    /**
     * You need to disable the ModuleScopePlugin otherwise, CRA won't allow you
     * to override the dependency path using aliases, because it will consider that
     * you are trying to import a module outside of the `src`.
     */
    configure: webpackConfig => {
      const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
        ({ constructor }) => constructor && constructor.name === 'ModuleScopePlugin'
      );

      webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
      return webpackConfig;
    }
  }
};

Use in project using Webpack

/* webpack.config.js */
const path = require('path');

module.exports = {
  resolve: {
    alias: {
      react: path.resolve('./node_modules/react'),
      'styled-components': path.resolve('./node_modules/styled-components')
    }
  }
};

If you are using Jest and in the same time linking tractor locally to your project, you might need to change your craco configuration to the following, in order to resolve the following issue: "hooks can only be called inside the body of a function component".

/* craco.config.js */
const CracoAlias = require('craco-alias');

module.exports = {
  plugins: [
    {
      plugin: CracoAlias,
      options: {
        source: 'options',
        baseUrl: './',
        aliases: {
          // You need to alias react to the one installed in the node_modules
          // in order to solve the error "hooks can only be called inside the body of a function component"
          // which is encountered during jest unit tests described at https://github.com/facebook/react/issues/13991
          react: './node_modules/react',
          'styled-components': './node_modules/styled-components'
        }
      }
    }
  ]
};

🀝 Contributing

Generating Components

The repo is using hygen to help us generate components using the command line.

yarn component HelloWorld

The command can take one argument: --stories, which determines whether the component should be generated with a stories.mdx file or not.

Linting

We decided to use commitlint which is a small library that enforces the conventional commit format.

In general the pattern mostly looks like this:

type(scope?): subject  #scope is optional

Real world examples can look like this:

chore: run tests on travis ci
fix(spacer): fix the margin on the small variant
feat(button): implement new button component

We recommend to use the type of the commit followed by the component name if possible and then followed when the actual commit message.

We also encourage developers to split as much as possible their commits into small chunks so that it easy for us to review.

Common types according to commitlint-config-conventional can be:

  • build
  • chore
  • ci
  • docs
  • feat
  • fix
  • impr
  • perf
  • refactor
  • revert
  • style
  • test

Release & Publish

When a or several PRs are merged into master, standard-version will generate the changelog and the bump the version of the package depending on all the commits between the previous tags and the latest commit on master.

Publishing the repository to NPM is a matter of clicking on the Bitbucket Pipeline Publish Button.

Create Manual pre-release

  • add .npmrc with npm token
  • yarn
  • npx standard-version --prerelease beta --dry-run // to see what it will do
  • npx standard-version --prerelease beta // bump version and make a commit
  • yarn build
  • npm publish --tag beta

folder structure:

To keep the folder structure constistent, here are 3 patterns of components.

  • simple case: Button

    .
    β”œβ”€β”€ components
    β”‚   β”œβ”€β”€ Button
    β”‚   β”‚   β”œβ”€β”€ Button.tsx
    β”‚   β”‚   β”œβ”€β”€ Button.decl.ts
    β”‚   β”‚   β”œβ”€β”€ index.ts
    β”‚   β”‚   β”œβ”€β”€ utils.ts
    β”‚   β”‚   β”œβ”€β”€ constants.ts
    
  • with components folder: List

    .
    β”œβ”€β”€ components
    β”‚   β”œβ”€β”€ List
    β”‚   β”‚   β”œβ”€β”€ List.tsx
    β”‚   β”‚   β”œβ”€β”€ List.decl.ts
    β”‚   β”‚   β”œβ”€β”€ index.ts
    β”‚   β”‚   β”œβ”€β”€ components
    β”‚   β”‚   β”‚   β”œβ”€β”€ ListView
    β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ListView.tsx
    β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ListView.decl.ts
    β”‚   β”‚   β”‚   β”œβ”€β”€ ListFooter
    β”‚   β”‚   β”‚   β”œβ”€β”€ ListItem
    
  • with components folder and context: Accordion

    .
    β”œβ”€β”€ components
    β”‚   β”œβ”€β”€ Accordion
    β”‚   β”‚   β”œβ”€β”€ Accordion.tsx
    β”‚   β”‚   β”œβ”€β”€ Accordion.decl.ts
    β”‚   β”‚   β”œβ”€β”€ index.ts
    β”‚   β”‚   β”œβ”€β”€ components
    β”‚   β”‚   β”‚   β”œβ”€β”€ AccordionItem
    β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€AccordionItem.tsx
    β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€AccordionItem.decl.ts
    β”‚   β”‚   β”œβ”€β”€ contexts
    

FAQs

Package last updated on 06 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc