0.1.176 • Published 2 years ago

axil-shared-components-library v0.1.176

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Axil Shared Components Library

Getting started

In this directory, first run:

yarn install

Once a yarn lock file is generated, then you can write TypeScript components in the src directory.

Writing components

Each component will be a directory that includes an index.tsx and a styles.module.css.

index.tsx

This is a standard TS component with one exception.

The styles must be imported like import cssClasses from "./styles.module.css".

Then, you can apply styles like className={cssClasses['css-className']}.

Icons

Notice in the src directory, there is a folder called icons.

These are components that directly implement SVG's/images to work-around issues with importing them through Rollup.JS.

For example if you want to add an SVG icon, you would make a new Functional Component file in the icons directory that looks something like this:

export default function SomeIcon() {
  return (
    <svg
      width='24'
      height='24'
      viewBox='0 0 24 24'
    >
      <path id='Path_245' d='M0,0H24V24H0Z' fill='none' />
      <path
        id='Path_246'
        d='M12,8,6,14l1.41,1.41L12,10.83l4.59,4.58L18,14Z'
        fill='#fff'
      />
    </svg>
  );
}

Note: You can edit the styles directly SVG in this file directly by adding the style={{ }} attribute to the svg tag.

Once the SVG component is saved, you can import and use the SVG Component like:

import SomeIcon from "../icons/SomeIcon"

export default function ExampleWithIcon() {
  return (
    <div>
      <h1>Icon Example</h1>
      <SomeIcon />
    </div>;
  )
}

Once you have added your component to the src directory, then make sure you update the index.ts file to export it properly.

export { default as NewComponent } from './new-component';
export * from './new-component';

Bundling Components

Using Rollup.JS (https://rollupjs.org/guide/en/) we are able to bundle files together and publish them to NPM.

In package.json there is the script "build": "rollup -c".

This bundles our src directory into a compiled lib folder.

After running yarn build, we can update the version of the package accordingly.

Publishing Components

First: Make sure you have an NPM account AND are a listed maintainer of the NPM package.

Login in to NPM using npm login.

Run npm publish.

Note: If you didn't update the version in the package it will fail with an authentication error and cancel publishing.

How this works

In this directory, you will notice:

Folders: lib and src,
Package file: package.json,
Rollup config: rollup.config.js,
TS config: tsconfig.json,

Rollup.JS

In order to use Rollup.JS, we need to provide a rollup.config.js file.

import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

import typescript from 'rollup-plugin-typescript2';
import postCSS from 'rollup-plugin-postcss';

import pkg from './package.json';

export default {
  input: 'src/index.ts',
  output: [
    {
      file: './lib/cjs/index.js',
      format: 'cjs',
    },
    {
      file: './lib/esm/index.js',
      format: 'es',
    },
  ],
  external: [...Object.keys(pkg.peerDependencies || {})],
  plugins: [
    commonjs(),
    typescript({
      typescript: require('typescript'),
    }),
    postCSS({
      plugins: [require('autoprefixer')],
    }),
    nodeResolve(),
  ],
};

This config file takes in our input then we can specify the output to which Rollup outputs our code as a usable JS module.

Notice we are using dependencies nodeResolve, commonjs,typescript, and postcss.

These plugins help process various file types, such as css and typescript, which aren't supported by default.

TypeScript

In order to properly use TypeScript, our tsconfig.json file looks like:

{
  "compilerOptions": {
    "outDir": "lib/esm",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom", "es2016", "es2017"],
    "jsx": "react-jsx",
    "declaration": true,
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "esModuleInterop": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*.ts*"],
  "exclude": ["node_modules", "lib"],
}

Note: In order to use CSS files, we have to make sure our module can interpret the file.

To solve this we add a global.d.ts file to our src directory and in it we have:

declare module '*.module.css' {
  const classes: { readonly [key: string]: string };
  export default classes;
}

This is where we can also define any other types our library may need.

0.1.176

2 years ago

0.1.175

2 years ago

0.1.174

2 years ago

0.1.173

2 years ago

0.1.172

2 years ago

0.1.171

2 years ago

0.1.17

2 years ago

0.1.159

2 years ago

0.1.158

2 years ago

0.1.157

2 years ago

0.1.156

2 years ago

0.1.155

2 years ago

0.1.154

2 years ago

0.1.153

2 years ago

0.1.152

2 years ago

0.1.151

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.999

2 years ago

0.0.998

2 years ago

0.0.997

2 years ago

0.0.996

2 years ago

0.0.995

2 years ago

0.0.994

2 years ago

0.0.993

2 years ago

0.0.992

2 years ago

0.0.991

2 years ago

0.0.99

2 years ago

0.0.989

2 years ago

0.0.988

2 years ago

0.0.987

2 years ago

0.0.986

2 years ago

0.0.985

2 years ago

0.0.984

2 years ago

0.0.983

2 years ago

0.0.982

2 years ago

0.0.981

2 years ago

0.0.98

2 years ago

0.0.979

2 years ago

0.0.978

2 years ago

0.0.977

2 years ago

0.0.976

2 years ago

0.0.975

2 years ago

0.0.974

2 years ago

0.0.973

2 years ago

0.0.972

2 years ago

0.0.971

2 years ago

0.0.97

2 years ago

0.0.969

2 years ago

0.0.968

2 years ago

0.0.967

2 years ago

0.0.966

2 years ago

0.0.965

2 years ago

0.0.964

2 years ago

0.0.963

2 years ago

0.0.962

2 years ago

0.0.961

2 years ago

0.0.96

2 years ago

0.0.959

2 years ago

0.0.958

2 years ago

0.0.957

2 years ago

0.0.956

2 years ago

0.0.955

2 years ago

0.0.954

2 years ago

0.0.953

2 years ago

0.0.952

2 years ago

0.0.951

2 years ago

0.0.95

2 years ago

0.0.94

2 years ago

0.0.93

2 years ago

0.0.92

2 years ago

0.0.91

2 years ago

0.0.90

2 years ago

0.0.899

2 years ago

0.0.898

2 years ago

0.0.897

2 years ago

0.0.896

2 years ago

0.0.895

2 years ago

0.0.894

2 years ago

0.0.893

2 years ago

0.0.892

2 years ago

0.0.891

2 years ago

0.0.89

2 years ago

0.0.88

2 years ago

0.0.875

2 years ago

0.0.874

2 years ago

0.0.872

2 years ago

0.0.871

2 years ago

0.0.87

2 years ago

0.0.869

2 years ago

0.0.868

2 years ago

0.0.867

2 years ago

0.0.866

2 years ago

0.0.865

2 years ago

0.0.864

2 years ago

0.0.863

2 years ago

0.0.86

2 years ago

0.0.859

2 years ago

0.0.858

2 years ago

0.0.857

2 years ago

0.0.856

2 years ago

0.0.855

2 years ago

0.0.854

2 years ago

0.0.853

2 years ago

0.0.852

2 years ago

0.0.851

2 years ago

0.0.85

2 years ago

0.0.84

2 years ago

0.0.83

2 years ago

0.0.82

2 years ago

0.0.81

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago