1.9.1 • Published 1 year ago

@arcanetechnology/react-ui-lib v1.9.1

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Arcane UI Library for React applications

https://arcanetechnology.github.io/react-ui-lib/

This component library aims to unify the UI and front-end functionality across the different Arcane React applications.

Install

  • Include Poppins from Google Fonts in your global <head> section.
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
  • npm install @arcanetechnology/react-ui-lib --save - to install the library

Usage

Prerequisites

  • import '@arcanetechnology/react-ui-lib/lib/index.css'; at application entry point - to include global styles, including the Poppins font, and components styles. Adding components styles as early as the app entry point prevents flickering on loading.
  • import '@arcanetechnology/react-ui-lib/lib/toggle.css'; at application entry point to use the <Toggle> component.
  • Wrap your React application inside the ArcaneUIProvider component, providing the LinkComponent the application uses. The LinkComponent component should accept a href prop.

    • For create-react-app applications, you may provide the react-router Link component. Note that the react-router Link accept a to instead of href prop, so we need to handle that in our application.

      import { ArcaneUIProvider } from '@arcanetechnology/react-ui-lib';
      import { Link, BrowserRouter as Router } from 'react-router-dom';
      
      export default function App() {
        return (
          <Router>
            <ArcaneUIProvider LinkComponent={RouterLink}>
              <MyApp />
            </ArcaneUIProvider>
          </Router>
        );
      }
      
      function RouterLink({ href, children, ...props }) {
        return (
          <Link to={href} {...props}>
            {children}
          </Link>
        );
      }
    • For next.js applications, you may provide the next.js Link component.

      import { ArcaneUIProvider } from '@arcanetechnology/react-ui-lib';
      import Link from 'next/link';
      
      export default function MyApp({ Component, pageProps }) {
        return (
          <ArcaneUIProvider LinkComponent={NextLink}>
            <Component {...pageProps} />)
          </ArcaneUIProvider>
        );
      }
      
      function NextLink({ href, children, ...props }) {
        return (
          <Link href={href} {...props}>
            <a href={href} {...props}>
              {children}
            </a>
          </Link>
        );
      }
      • Note: Having an a tag inside the Link component is no longer necessary starting from Next.js 13.
    • You can also use the basic <a> tag (e.g. for unit tests)

      <ArcaneUIProvider LinkComponent={({...props}) => (<a {...props} />)}>
        // ...
      </ArcaneUIProvider>
  • In addition to the LinkComponent, also provide the PortalComponent to the ArcaneUIProvider. This is the Portal component the application uses.

    • For next.js applications, the implementation can look like this:

      import { useClientSide } from 'hooks';
      import ReactDOM from 'react-dom';
      
      const AppPortal = ({ children }) => {
        const isClientSide = useClientSide();
      
        return isClientSide
          ? ReactDOM.createPortal(children, document.querySelector('#__next'))
          : null;
      };
      
      export default AppPortal;
      import { useEffect, useState } from 'react';
      
      const useClientSide = () => {
        const [mounted, setMounted] = useState(false);
      
        useEffect(() => {
          setMounted(true);
        }, []);
      
        return mounted;
      };
      
      export default useClientSide;

Components

  • import { Button } from '@arcanetechnology/react-ui-lib'; - to import a component in an ESM module.

Responsive Design

All Arcane applications should use common threshold points for respinsive design.

  • @import '@arcanetechnology/react-ui-lib/lib/vars.scss'; in your SCSS files to use SCSS variables like $mobile-width and $tablet-width.

Authentication

If an app uses authentication, it should also be wrapped inside AuthProvider:

<AuthProvider>
  <App />
</AuthProvider>

Firebase needs to be initialized: call initializeApp(firebaseConfig).

You can then use the <SignInSignOutButton> component to authenticate / log out, and the useUser custom hook to access the current user.

Developing components

To run storybook locally:

  • npm run storybook

A component should in most cases consist of:

  • a folder inside the components folder
  • index.tsx - the React / Typescript implementation of the component
  • index.module.scss - SCSS modules
  • index.test.js - Unit tests
  • index.stories.tsx - Storybook stories.
  • Exports in components/index.ts and index.ts.

By implementing the same structure for each Arcane app, it is possible (and recommended) as a front-end developer to first implement the component in the specific Arcane app with a rapid pace, and, only when it is production ready and tested, to move it to this library. The move should ideally happen transparently without any extra effort.

For library maintainers

The project is set up with create-react-app, which is used when running storybook. The idea is to duplicate Arcane apps' toolchain while developing components.

In order to package the project as a library (ESM & CJS), rollup.js is used. rollup.config.js defines the configuration that transpiles the src folder to the lib folder, which is published on NPM.

Publish a new version on npmjs

  • Make a code change
  • commit and push
  • npm run build-lib
  • npm publish
  • Update application references you are responsible for: npm install --save @arcanetechnology/react-ui-lib@latest

Deploy a new static version of the library

The library is hosted on GitHub Pages (can be hosted on any static server too). To update the static library version:

Release = Publish + Deploy

  • npm run release
1.9.1

1 year ago

1.8.0

1 year ago

1.7.5

1 year ago

1.9.0

1 year ago

1.6.2

2 years ago

1.6.1

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.10

2 years ago

1.2.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.1.8

2 years ago

1.5.3

2 years ago

1.1.7

2 years ago

1.5.2

2 years ago

1.1.6

2 years ago

1.5.1

2 years ago

1.3.3

2 years ago

1.1.5

2 years ago

1.5.0

2 years ago

1.3.2

2 years ago

1.1.4

2 years ago

1.3.1

2 years ago

1.1.3

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.4.5

2 years ago

0.3.6

2 years ago

0.2.7

2 years ago

0.6.2

2 years ago

0.5.3

2 years ago

0.4.4

2 years ago

0.3.5

2 years ago

0.2.6

2 years ago

0.4.7

2 years ago

0.2.9

2 years ago

0.4.6

2 years ago

0.3.7

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.3.2

2 years ago

0.2.3

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

0.4.3

2 years ago

0.3.4

2 years ago

0.2.5

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.3.3

2 years ago

0.2.4

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago