@woocommerce/components
TypeScript icon, indicating that this package has built-in type declarations

12.3.0 • Public • Published

Components

This packages includes a library of components that can be used to create pages in the WooCommerce dashboard and reports pages.

Installation

Install the module

pnpm install @woocommerce/components --save

Usage

/**
 * WooCommerce dependencies
 */
import { Card } from '@woocommerce/components';

export default function MyCard() {
  return (
    <Card title="Store Performance" description="Key performance metrics">
      <p>Your stuff in a Card.</p>
    </Card>
  );
}

Many components include CSS to add style, you will need to add in order to appear correctly. Within WooCommerce, add the wc-components stylesheet as a dependency of your plugin's stylesheet. See wp_enqueue_style documentation for how to specify dependencies.

In non-WordPress projects, link to the build-style/card/style.css file directly, it is located at node_modules/@woocommerce/components/build-style/<component_name>/style.css.

Usage with tests

If you are using these components in a project that uses Jest for testing, you may get an error that looks like this:

Cannot find module '@woocommerce/settings' from 'node_modules/@woocommerce/experimental/node_modules/@woocommerce/navigation/build/index.js'

To fix this, you will need to mock the @woocommerce/settings because it's an alias that points to the window.wcSettings, which in turn comes from and is maintained by the WC Blocks package, the front-end code for this is located here.

This can be done by adding the following to your Jest config:

module.exports = {
  moduleNameMapper: {
    '@woocommerce/settings': path.resolve(
      __dirname,
      './mock/woocommerce-settings'
    ),
  }
  setupFiles: [
    path.resolve( __dirname, 'build/setup-globals.js' ),
  ],
  // ...other config
}

Then, you will need to create the following files:

  1. Create a new file called woocommerce-settings.js in the ./mock directory. You can find the content for this file here.
  2. Next, create a file named setup-globals.js. You can find the content for this file here. The purpose of this file is to mock the wcSettings global variable.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
12.3.01,325latest
1.1.02next

Version History

VersionDownloads (Last 7 Days)Published
12.3.01,325
12.2.0655
12.1.01
12.0.050
11.1.01
10.3.072
10.2.11
10.2.01,265
10.1.01
10.0.01
9.0.01
8.2.02
8.1.16
8.1.0194
7.1.02
7.0.01
6.2.01
6.1.21
6.1.11
6.1.01
6.0.01
5.1.32
5.1.2189
5.1.11
5.1.01
5.0.01
4.0.015
3.2.02
3.1.0110
3.0.01
2.0.01
1.6.02
1.5.01
1.4.21
1.4.11
1.4.01
1.3.01
1.2.01
1.1.02
1.0.11
1.0.01

Package Sidebar

Install

npm i @woocommerce/components

Weekly Downloads

3,918

Version

12.3.0

License

GPL-3.0-or-later

Unpacked Size

2.05 MB

Total Files

1041

Last publish

Collaborators

  • mikejolley
  • albertjuhe
  • nerrad
  • obliviousharmony
  • louwie17
  • joshuatf
  • chihsuan
  • ~woocommerce
  • zhongruige
  • opr