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

@procore/labs-banners

v3.0.0

Published

Set of convenient components managing banners

Downloads

32

Maintainers

yzhou2024yzhou2024alyelashram_procorealyelashram_procoremelch-procoremelch-procorepeterknifpeterknifmoaz-ashrafmoaz-ashrafattachiattachia.elbadaweia.elbadaweihyogmanhyogmandmitri_wmdmitri_wmstephanie.breretonstephanie.breretonprocore-oss-userprocore-oss-userstevenkang3stevenkang3max.helmetagmax.helmetagcodyrobertsprocorecodyrobertsprocoremiguel.garcia-procoremiguel.garcia-procoremagdyyxmagdyyxatoaimaatoaimamustafa-abdelrahmanmustafa-abdelrahmanelewando-procoreelewando-procoreahmed.ghorabahmed.ghorablnspatz914lnspatz914richard.bunnrichard.bunnomar.wagdyomar.wagdymona.khairbekmona.khairbekmbartlett413mbartlett413cody_schindler_procorecody_schindler_procoreyoasyo25yoasyo25ritchleeritchleeandersontr15andersontr15steven.hinklesteven.hinklejamie-dugan-procorejamie-dugan-procorehgouhierprocorehgouhierprocoredenzylbalramdenzylbalramsarah.freitassarah.freitasalan.bresanialan.bresaniamyprocoreamyprocoreyoyis3000yoyis3000elijah.procoreelijah.procoremike-arndt-procoremike-arndt-procorejnhoang1jnhoang1pam-whisenhuntpam-whisenhuntshradha.khardshradha.kharddavid-christensen-procoredavid-christensen-procorejavio-procorejavio-procorechance.eakin.procorechance.eakin.procoregideon-procoregideon-procoreihor.diachenko_procoreihor.diachenko_procorejustinmwattsjustinmwattstedyangtedyangjyang-procorejyang-procorepwhisenhunt-procorepwhisenhunt-procorefairchildfairchildrodayna.ehabrodayna.ehabneil1023neil1023scottsternscottsternbrian.smith1brian.smith1g2mitchellg2mitchelldlameter-procoredlameter-procorekylepietzkylepietzabhijit-procoreabhijit-procorelhuang325lhuang325jake-pitkinjake-pitkinerikthoresonerikthoresonsimona.iancusimona.iancudecha-sansondecha-sansonaberkowitzaberkowitzasamayasamaymustafa-u-abdelrahmanmustafa-u-abdelrahmanrajatmenhdirattarajatmenhdirattajacksonleach-procorejacksonleach-procorepmfrawleypmfrawleyphunguyen-pcorphunguyen-pcortatsiana.cliftontatsiana.cliftondeiabdeiabsrichaitanya.peddintisrichaitanya.peddintikenny.foisykenny.foisymatheusprocorematheusprocorejgreene_procorejgreene_procorehectorthielehectorthieleetokarevetokarevdaniel.ferreira-contractordaniel.ferreira-contractordmccraw-procoredmccraw-procorecyrille.baicyrille.baigreg.sparksgreg.sparksfabiomelo513fabiomelo513phil.custerphil.custerbbreyel921bbreyel921amir-iskanderamir-iskanderneil.mckeemanneil.mckeemannickprocorenickprocorelzhou888lzhou888davidshuredavidshurestevenliprocorestevenliprocoreramysaid2ramysaid2refaiepcnrefaiepcnjgentesjgentesfaraz.haniffaraz.hanifmostafaeltazymostafaeltazyagamaleldinagamaleldinandrew.isaacandrew.isaacsaranahal2saranahal2rodrigo.dejuanarodrigo.dejuanakellen.stewartkellen.stewartbill-wagnerbill-wagnerezrasimeloffezrasimeloffjeffgiaquintojeffgiaquintogturkadzegturkadzesean.spearman.procoresean.spearman.procorekylemartinez-procorekylemartinez-procoreroobo-romeskiroobo-romeskiandres-mendez-procoreandres-mendez-procoregaurav.sharma.procoregaurav.sharma.procoretracy.ottotracy.ottosarah.herediasarah.herediavictorbendeck-pcvictorbendeck-pccbathgatecbathgatedavidkangprodavidkangprokyle.liukyle.liuamin.jaipuriamin.jaipurigrafffffffgrafffffffmishaelowoyemimishaelowoyemievan.cerwonka.procoreevan.cerwonka.procoreilya.dryha-contractorilya.dryha-contractorvaromirvaromiryogevfine1yogevfine1timofeeetimofeeematt.harris0223matt.harris0223winson.chuwinson.chuandersonbispoprocoreandersonbispoprocorescorgiat-procorescorgiat-procoreladavargaladavargaprocore_halzyprocore_halzyenyagaenyagawillpankonienwillpankoniensateesh-kadiyala-procoresateesh-kadiyala-procorechris.berberchris.berbertxin1txin1epalinprocoreepalinprocoremehrdad-panahandehmehrdad-panahandehtyler.wasden.procoretyler.wasden.procorejeremy.lundjeremy.lunddineshkumar.jayakdineshkumar.jayakryanfuentesprocoreryanfuentesprocorestajicsstajicsbrocktillotsonprocorebrocktillotsonprocorekyle.williamskyle.williamsdtorres-procoredtorres-procorenoor.alinoor.aliari-procoreari-procorealanprocorealanprocorejl4everjl4everjames.lawsonjames.lawsonajaykumar-procoreajaykumar-procoredennis.heckmandennis.heckmantara.chamberstara.chamberslalovar-procorelalovar-procorejames.clearyjames.clearychadryderchadryderdevin.cunningham.procoredevin.cunningham.procoreabhijit.patwardhanabhijit.patwardhanlydiaharalydiaharasherylnapigkitsherylnapigkitchangprocorechangprocoreapcarroll_procoreapcarroll_procoreandy.mayerandy.mayerbob.laskowskibob.laskowskivinaya-procorevinaya-procorekahliholmeskahliholmesandrew.wheelerandrew.wheelerleandro-procleandro-procyadhu.prakashyadhu.prakashjason-kayejason-kayejesse.olsenjesse.olsenpatrick.lardinpatrick.lardinbrad.uranibrad.uraniallenanle.procoreallenanle.procorebrookyboy009brookyboy009uddhavjoglekaruddhavjoglekardancingshelldancingshellrysmithprocorerysmithprocorerobbiegprocorerobbiegprocorejadamsssjadamsssjeremy.bouzigardjeremy.bouzigardtimdohertytimdohertyb.bookoutb.bookoutjalyngjalynghtaelhtaeldev-account-admindev-account-adminsseanwangsseanwangbhargavrndbhargavrndfarismmkfarismmkdannyporrellodannyporrellodanny.oudanny.oumessanjahmessanjaheyvettesoueyvettesoujgee67jgee67cagmzcagmzmariah_delaneymariah_delaneylukenispellukenispelkimhin267kimhin267juliana.hernandezjuliana.hernandezjudy-lu-pcjudy-lu-pcprocore-it-supportprocore-it-supportandrewburke-pcandrewburke-pcjkleintechjkleintechrachel.arkebauerrachel.arkebauerprocore-npm-botprocore-npm-botjames.dabbs-procorejames.dabbs-procorelaurenbrandsteinprocorelaurenbrandsteinprocorescottbieser-procorescottbieser-procorezach.mckenzie.procorezach.mckenzie.procoreshayonj_procoreshayonj_procoreheplayskeysheplayskeysmike.southmike.souththomasoboylethomasoboyledischordedischordederek-carter-procorederek-carter-procoredlgasserdlgassercfprocorecfprocoreevan.waitsevan.waitsjeremy-marcusjeremy-marcusjmejia-fsljmejia-fslersgonzaloersgonzalostephan-procorestephan-procorealeclarsenprocorealeclarsenprocoreyihai.zweifelyihai.zweifeljay-rajanjay-rajanjacky-leijacky-leipeter.jinpeter.jin

Keywords

Readme

Banners

A handy component you can insert into a form or inline on a page to communicate results of an application action which was performed with some status (e.g. success, warnings, failure or just information and others).

Installation

yarn add @procore/labs-banners

Dependencies

@procore/core-react and react are listed as external peer dependencies. The package will not bundle the code, and requires the app client to provide it as a dependency. The external peer dep is to assure React Context is consistent in a client's React tree, the child consumers can reference the correct parent provider. If the package uses latest features or bug fixes and a new minimum version of core-react is required, it should be considered a breaking change as the peer dependency version must be met.

Usage

import { I18nProvider } from '@procore/core-react';
import { Banners } from '@procore/labs-banners';

Motivation

A large amount of components need to interact with users and provide feedback messages for users actions. Main reason of Banners component is to prevent code duplication and create common and consistent interface to handle storing and displaying important informations for users.

Key points:

  • Straightforward API
const INFO_BANNER = 'INFO_BANNER';

showBanner({
  id: INFO_BANNER,
  msg: 'Some important information',
  variant: 'success',
});
  • Easy configuration
const ACTION_BANNER = 'ACTION_BANNER';

showBanner({
  id: ACTION_BANNER,
  msg: 'Some important information',
  variant: 'success',
  action: {
    title: 'Button title',
    handler: (banner) => console.log('button clicked', banner),
  },
  dismissible: true,
  afterClose: (banner) => console.log('button clicked', banner),
});
  • Delete programmatically by ID
const INFO_BANNER = 'INFO_BANNER';

hideBanner(INFO_BANNER);
  • Id uniqueness handling (we remove previous banner with the same id)
// state - [{id: 'INFO_BANNER', msg: 'Some important information', variant: 'success'}]
const INFO_BANNER = 'INFO_BANNER';

showBanner({
  id: INFO_BANNER,
  msg: 'Another important information',
  variant: 'success',
});

// state - [{id: 'INFO_BANNER', msg: 'Another important information', variant: 'success'}]

Using built-in BannersContext

  • Banners.Provider: Component that supply store for banners.
  • Banners: Component that consumes values from the nearest context (Banners.Provider) and renders to the tree.
  • useBanners: A function wrapper around React.useContext(BannersContext).
() => {
  const Inner = () => {
    const { showBanner, hideBanner, hideAllBanners } = useBanners();

    return (
      <FlexList marginBottom="xl">
        <Button
          variant="secondary"
          onClick={() =>
            showBanner({
              id: '2',
              variant: 'success',
              msg: 'Success banner description',
            })
          }
        >
          Show Success Banner
        </Button>
        <Button variant="secondary" onClick={() => hideBanner('2')}>
          Hide Success Banner
        </Button>
        <Button variant="secondary" onClick={() => hideAllBanners()}>
          Hide All Banners
        </Button>
      </FlexList>
    );
  };

  const bannersShownByDefault: Banner[] = [
    {
      id: '1',
      msg: 'Info banner description',
      variant: 'info',
      dismissible: false,
    },
  ];

  return (
    <I18nProvider>
      <Banners.Provider initialValue={bannersShownByDefault}>
        <Inner />
        <Banners />
      </Banners.Provider>
    </I18nProvider>
  );
};

Using own State

  • Banners.Bar: Component that consumes and renders Banners.
() => {
  const Inner = () => {
    const bannersShownByDefault: Banner[] = [
      {
        id: "1",
        msg: "Info banner description",
        variant: "info",
        dismissible: false,
      },
    ];

    const [banners, setBanners] = React.useState<Banner[]>(
      bannersShownByDefault
    );

    const hideBanner = (id: Banner["id"]) => {
      setBanners((prevBanners) =>
        prevBanners.filter((banner) => banner.id !== id)
      );
    };

    const showBanner = (newBanner: Banner) => {
      const isBannerExists = banners.find(
        (banner) => banner.id === newBanner.id
      );
      if (!isBannerExists) {
        setBanners((prevBanners) => [newBanner, ...prevBanners]);
      }
    };

    const hideAllBanners = () => setBanners([]);

    return (
      <>
        <FlexList marginBottom="xl">
          <Button
            variant="secondary"
            onClick={() =>
              showBanner({
                id: "2",
                variant: "success",
                msg: "Success banner description",
              })
            }
          >
            Show Success Banner
          </Button>
          <Button variant="secondary" onClick={() => hideBanner("2")}>
            Hide Success Banner
          </Button>
          <Button variant="secondary" onClick={() => hideAllBanners()}>
            Hide All Banners
          </Button>
        </FlexList>
        <Banners.Bar banners={banners} hideBanner={hideBanner} />
      </>
    );
  };
  return (
    <I18nProvider>
      <Inner />
    </I18nProvider>
  );
};