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

@thoughtindustries/catalog

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thoughtindustries/catalog

A base component for catalog

  • 1.2.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@thoughtindustries/catalog

The Catalog allows learners to search and browse for content. It is a central component to any online learning platform.

Table of contents:

  • Catalog
  • Core catalog components
  • Core catalog hooks

Catalog

The Catalog component takes a callback function to handle catalog item's add-to-queue event, and optional properties to customize the catalog like price formatting, currency formating, etc. It must be a descendent of the CatalogProvider component.

Example code

import { CatalogProvider, Catalog } from '@thoughtindustries/catalog';

export function MyComponent() {
  // ...
  const addToQueueHandler = (item) => Promise.resolve();

  return (
    <CatalogProvider ssr pathName="/catalog">
      <Catalog onAddedToQueue={addToQueueHandler} />
    </CatalogProvider>
  );
}

Props

NameRequiredTypeDescription
titleNostringThe title that appears on top of the catalog.
alternateTitleDisplayNobooleanOption to display the alternative title.
paginationNo(args: PaginationFnArgs) => ReactElementAn alternative view for the pagination display.
companyHasSessionLevelCustomFieldsFeatureNobooleanCompany feature flag for content hydration.
companyTimeZoneNostringCompany property to override item's timezone.
onAddedToQueueYes(item: CatalogResultItem) => Promise<boolean | void>Event handler for add to queue button for each item.
onClickNo(evt: SyntheticEvent, item: CatalogResultItem) => voidOptional click event handler for each item.
priceFormatNo(priceInCents: number) => stringA callback that is invoked to format monetary value with currency. It takes a number value for the price in cent unit and return the formatted value. Default value uses Intl.NumberFormat with props companyDefaultLocale and/or currencyCode to enable locale-specific currency formatting.
companyDefaultLocaleNostringA locale value to format price when prop priceFormat is not specified. Used to speficy the locale in Intl.NumberFormat. Default to en-US.
currencyCodeNostringA currency code value to format price when prop priceFormat is not specified. Used to speficy the currency code in Intl.NumberFormat. Default to USD.
numberOfContentItemsNonumberSpecify the number of items to display in the grid view.

Core catalog components

Core catalog components are objects that contain all of business logic for the catalog concept that they represent. They're used to parse and process data.

CatalogLinkButton

The CatalogLinkButton component renders a link button that conditionally overrides the link behavior to handle client side navigation. It must be a descendent of a CatalogProvider component. This is used internally by Catalog component to handle both server and client side rendering. If you are composing own version of Catalog component for different layout and styles, this component can be useful.

Example code
import { CatalogProvider, CatalogLinkButton } from '@thoughtindustries/catalog';

function CustomCatalog() {
  // ...

  return (
    <>
      {/* // ... */}
      <CatalogLinkButton href="/catalog?page=2" />
    </>
  );
}

export function MyComponent() {
  // ...

  return (
    <CatalogProvider ssr={false} pathName="/catalog">
      <CustomCatalog />
    </CatalogProvider>
  );
}
Props

This component is inherently an HTMLAnchorElement element with only the onClick prop omitted. The component will use own onClick handler.

CatalogProvider

The CatalogProvider component creates a context for using a catalog. It requires an url path name and a ssr flag to handle the data fetching as well as user interactions with catalog filters. It creates relevant context values that can be accessed by any descendent component using the useCatalog hook.

You must use this component if you want to use the useCatalog hook, or if you would like to use the CatalogLinkButton component.

Example code
import { CatalogProvider } from '@thoughtindustries/catalog';

export function App() {
  return <CatalogProvider ssr pathName="/catalog">{/* Your JSX */}</CatalogProvider>;
}
Props
NameRequiredTypeDescription
childrenYesReact.ReactNodeAny ReactNode elements.
pathNameYesstringThe URL path for the catalog.
searchStringNostringThe URL search string used to initialize the catalog.
layoutIdNostringThe id of the custom catalog widget layout. Use this along with widgetId to specify the custom catalog widget created in the core platform.
widgetIdNostringThe id of the custom catalog widget. Use this along with layoutId to specify the custom catalog widget created in the core platform.
ssrYesbooleanOption to render the catalog on the server side or client side. When set to true, catalog will be rendered on the server side and user interactions with the filters will cause a full page load. When set to false, catalog will be rendered on the client side and user interactions with the filters will only affect the catalog portion of the page.

HeightEqualizer

The HeightEqualizer component is a wrapper component that calculate the maximum height from its children HeightEqualizerElement components. With the max height value, it updates all children HeightEqualizerElement components to the same value. This is used internally by Catalog component to handle catalog item height in grid view. If you are composing own version of Catalog component for different layout and styles, this component can be useful.

Example code
import { HeightEqualizer, HeightEqualizerElement } from '@thoughtindustries/catalog';

export function MyComponent() {
  // ...

  return (
    <HeightEqualizer>
      <>
        <HeightEqualizerElement key="item-1">{/* Your JSX */}</HeightEqualizerElement>
        <HeightEqualizerElement key="item-2">{/* Your JSX */}</HeightEqualizerElement>
      </>
    </HeightEqualizer>
  );
}
Props
Props for HeightEqualizer
NameRequiredTypeDescription
childrenYesReactNodeA ReactNode element.
timeoutNonumberTime to recalculate heights.
animationSpeedNonumberTime of animation for height change (in milliseconds).
Props for HeightEqualizerElement
NameRequiredTypeDescription
childrenNoReactNodeA ReactNode element.
nameYesstringAll heights of elements with the same name will be compared.
asNostringAn HTML tag to be rendered as the base element wrapper. The default is div.
classNameNostringA string of styling class names to apply to the underlying element.

Core catalog hooks

Core catalog hooks are functions that allow you to use state and other methods inside catalog components.

useCatalog

The useCatalog hook provides access to the catalog context. It must be a descendent of a CatalogProvider component.

Example code
import { CatalogProvider, useCatalog } from '@thoughtindustries/catalog';

export function MyComponent() {
  return (
    <CatalogProvider ssr={false} pathName="/catalog">
      <CatalogLoader />
    </CatalogProvider>
  );
}

export function CatalogLoader() {
  const { isLoading } = useCatalog();

  if (isLoading) {
    return <>Loading data</>;
  }

  return ({/* Your JSX */});
}
Return value

The useCatalog hook returns an object with the following keys:

NameRequiredDescription
paramsYesThe catalog content and metadata.
urlManagerYesThe URL manager instance to manage URL state.
ssrYesThis is pass-through value for the prop ssr of CatalogProvider component.
navigateClientSideAsyncNoAn async function for user interaction with the catalog filters. This value is provided for client side render.
isLoadingYesThe loading state of data fetching. During server side render, this value is always false. During client side render, this value will reflect the data fetching loading state.
scrollToRefNoA reference to HTMLDivElement. During client side render, browser will scroll to the top of the assigned element when fetching data.
contentWrapperRefNoA reference to HTMLDivElement. During client side render, browser will mutate the height of the assigned element when fetching data. This will prevent flashing effect when user interface switches between catalog content and a loading indicator.

FAQs

Package last updated on 14 Nov 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