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

propro-shared-components

v0.0.27

Published

Reusable components for propro client apps

Downloads

50

Readme

propro-shared-components

propro-shared-components is a comprehensive suite of reusable React components and authentication hooks, tailored for seamless integration with a custom authentication system. It provides a consistent user interface and authentication logic across various parts of your application, such as HubHub, MapMap, ProPro-Admin, StreamBreak, StampStamp, and others.

Features

  • ProProUserButton: A button component for handling user sign-in and sign-out actions.
  • proproAuth: A collection of hooks and utilities for managing authentication state and logic.
  • AccountManagementPopup: A component that provides a user interface for managing account details and security settings.

Installation

Install propro-shared-components with npm or yarn:

yarn add propro-shared-components
# or
npm install propro-shared-components

Usage

Below are examples and descriptions of how to use the components and hooks provided by propro-shared-components.

ProProUserButton

ProProUserButton is a customizable button for user sign-in and sign-out. It can be used as a standalone component or as a child component of ProProUserMenu.

Props

| Name | Type | Default | Description | | ----------------- | -------- | ------- | ------------------------------------------------ | | afterSignOutUrl | string | null | The URL to redirect to after the user signs out. |

Example

import React from 'react';
import { ProProUserButton } from 'propro-shared-components';

import { ProProUserButton } from 'propro-shared-components';

const Header = ({ afterSignOutUrl }) => (
  <header>
    {/* ... our other header content ... */}
    <ProProUserButton afterSignOutUrl={afterSignOutUrl} />
  </header>
);

export default Header;

proproAuth

proproAuth is a set of hooks and utilities to manage authentication state and logic.

useAuth()

useAuth() is a React hook that returns an object with the following properties:

| Name | Type | Description | | ----------------- | ---------- | ----------------------------------------- | | user | object | The user object returned by proproAuth. | | isAuthenticated | boolean | Whether the user is authenticated. | | isLoading | boolean | Whether the user is being loaded. | | signIn | function | A function to sign in the user. | | signOut | function | A function to sign out the user. | | refreshUser | function | A function to refresh the user. |

Example

import React from 'react';
import { useAuth } from 'propro-components';

const Header = ({ afterSignOutUrl }) => {
  const { user, isAuthenticated, isLoading, signIn, signOut } = useAuth();

  return (
    <header>
      {/* ... our other header content ... */}
      {isAuthenticated ? (
        <button onClick={signOut}>Sign Out</button>
      ) : (
        <button onClick={signIn}>Sign In</button>
      )}
    </header>
  );
};

export default Header;

withAuth()

withAuth() is a higher-order component that injects the proproAuth object into a component's props.

Example

import React from 'react';
import { withAuth } from 'propro-components';

const Header = ({ afterSignOutUrl, proproAuth }) => {
  const { user, isAuthenticated, isLoading, signIn, signOut } = proproAuth;

  return (
    <header>
      {/* ... our other header content ... */}
      {isAuthenticated ? (
        <button onClick={signOut}>Sign Out</button>
      ) : (
        <button onClick={signIn}>Sign In</button>
      )}
    </header>
  );
};

export default withProProAuth(Header);

AccountManagementPopup

A component that displays a modal for users to manage their account and security settings.

Props

| Name | Type | Default | Description | | --------- | ---------- | ------- | -------------------------------------------- | | user | object | null | The user object returned by proproAuth. | | onClose | function | null | A function to call when the modal is closed. |

Example

The AccountManagementPopup component can be used as a standalone component or as a child component of ProProUserMenu.

import React from 'react';
import { AccountManagementPopup } from 'propro-components';

const Header = ({ afterSignOutUrl }) => {
  const { user, isAuthenticated, isLoading, signIn, signOut } = useAuth();
  const [showAccountManagement, setShowAccountManagement] = useState(false);

  return (
    <header>
      {/* ... our other header content ... */}
      {isAuthenticated ? (
        <>
          <button onClick={signOut}>Sign Out</button>
          <button onClick={() => setShowAccountManagement(true)}>
            Manage Account
          </button>
          {showAccountManagement && (
            <AccountManagementPopup
              user={user}
              onClose={() => setShowAccountManagement(false)}
            />
          )}
        </>
      ) : (
        <button onClick={signIn}>Sign In</button>
      )}
    </header>
  );
};