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

@lifterlms/components

v1.1.0

Published

UI components for LifterLMS.

Downloads

7

Readme

LifterLMS UI Components

UI components for use in LifterLMS and LifterLMS add-ons. This package extends functionality provided by @wordpress/components, adding additional components specific to the LifterLMS project.

Usage in a LifterLMS add-on

This package is included in the LifterLMS core plugin as a module and registered using the WordPress scripts dependency API (see [wp_register_script()][https://developer.wordpress.org/reference/functions/wp_register_script/]).

To use components you can add llms-components as a dependency to your script and access the module via window.llms.components, for example:

const { ButtonGroupControl } = window.llms.components;

LifterLMS Versions

The following table records the module version and which LifterLMS versions it has been included in.

| Module Version | LifterLMS Version | | -------------- | ----------------- | | 1.0.0 | 6.0.0 |

Installation

Install the module as a dependency in your project:

npm install --save-dev @lifterlms/components`

Changelog

View the Changelog

API Docs

BaseSearchControl

Searchable element powered by a WordPress REST API endpoint.

Parameters

  • args Object: Component arguments.
  • args.searchPath string: Required. API path used to perform the search.
  • args.onUpdate Function: Callback function invoked when the value of the select changes. The callback function is passed a single parameter, the new selected value object(s). For multiselects it will be an array of objects. If the select is clearable, the value will be null when the select is cleared.
  • args.selectedValue Array: The currently selected value(s). If an object is passed, it should contain at least a label and value key. Can pass IDs as integers and the values will be automatically hydrated.
  • args.placeholder string: The placeholder displayed within an empty search control.
  • args.className string: HTML class attribute added to the select control.
  • args.classNamePrefix string: Prefix added to select control subcomponent classnames. In most circumstances this should not be changed as it is used to style the compontents.
  • args.searchDebounceDelay number: Search debounce delay, in milliseconds.
  • args.additionalSearchArgs Object: Object of additional query string arguments to use with the API request.
  • args.label ?string: Search control label, passed to .
  • args.id ?string: Search control HTML ID attribute, passed to .
  • args.defaultOptions ?Object[]: Array of hydrated objects to preload into the select as options.
  • args.getSearchArgs ?Function: Function invoked to generate the query string arguments used when fetching results from the API. The callback function is passed the search string.
  • args.getSearchURL ?Function: Function invoked to create the search URL used to fetch results. The function is passed the searchPath and generated query string arguments from getSearchArgs().
  • args.hydrateValues ?Function: Function invoked to hydrate integer values. The function is passed the currently selected values, the searchPath, and an array of cached (and hydrated) objects previously loaded from the server.
  • args.formatSearchResults ?Function: Function invoked to format results retrieved from the server. The function is passed an array of objects from the server. It should return an array of objects, each containing at least a value and label property.
  • args.formatSearchResultLabel ?Function: Function invoked to format the display label for a result. The function is passed an object representing a single result and should return a string.
  • args.formatSearchResultValue ?Function: Function invoked to format the saved value for a result. The function is passed an object representing a single result and should the value to be stored.
  • args.selectProps ...*: Any remaining properties are passed to the component, {@link https://react-select.com/props#select-props}.

Returns

  • StyledBaseControl: The component.

ButtonGroupControl

Button Group Control component

Similar to the experimental <RadioGroup> component from @wordpress/components but it allows passing in an array of options.

Related

Parameters

  • props Object: Component properties object.
  • props.label string: Control label text.
  • props.className string: Control element css class name attribute.
  • props.id string: Control element ID attribute.
  • props.onClick Function: Callback function when a button in the group is clicked.
  • props.selected string: The value of the currently selected option.
  • props.options Object[]: An array of objects used to create the buttons in the group. Each object should contain at least a "label" and "value" property and can optionally include an "icon" property.

Returns

  • BaseControl: The rendered component.

CopyButton

A "click to copy" button.

Uses the useCopyToClipboard() hook with a on WP 5.8 & later, otherwise falls back to the deprecated .

Parameters

  • args Object: Component arguments.
  • args.buttonText string: Text to to display within the button.
  • args.copyText string: Text to copy to the clipboard.
  • args.tooltipText string: Text to use in the tooltip wrapper around the button.
  • args.onCopy Function: Copy success callback function.
  • args.buttonProps ...*: Remaining properties passed to the underlying component.

Returns

  • Object: The copy button fragment.

PostSearchControl

Searchable element powered by a WordPress REST API users endpoint.

This component is a wrapper around the component. It is configured to search users via the WordPress user REST API endpoint.

Parameters

  • args Object: Component arguments.
  • args.postType string: Post type endpoint.
  • args.baseSearchPath string: Base search path used to create the searchPath.
  • args.searchPath ?string: API path used to perform the search. If passed, will be used instead of the path generated from args.postType and args.baseSearchPath.
  • args.placeholder string: The placeholder displayed within an empty search control.
  • args.className string: HTML class attribute added to the select control.
  • args.formatSearchResultLabel ?Function: Function invoked to format the display label for a result. The function is passed
  • args.additionalSearchArgs Object: An object representing a single result and should return a string.
  • args.baseProps ...*: Any remaining properties are passed to the component.

Returns

  • BaseSearchControl: The component.

UserSearchControl

Searchable element powered by a WordPress REST API users endpoint.

This component is a wrapper around the component. It is configured to search users via the WordPress user REST API endpoint.

Parameters

  • args Object: Component arguments.
  • args.searchPath string: Required. API path used to perform the search.
  • args.placeholder string: The placeholder displayed within an empty search control.
  • args.className string: HTML class attribute added to the select control.
  • args.formatSearchResultLabel ?Function: Function invoked to format the display label for a result. The function is passed
  • args.additionalSearchArgs Object: An object representing a single result and should return a string.
  • args.baseProps ...*: Any remaining properties are passed to the component.

Returns

  • BaseSearchControl: The component.