woocommerce/packages/js/components
Vladimir Reznichenko 21d14759b3
[dev] Monorepo: minor build speed improvement (tsconfig consolidation) (#52191)
In this PR, we consolidate TypeScript config files (using the 'include' setting) and JS test directory naming. The goal is to reduce the number of processed files during different build steps.
2024-10-23 13:48:36 +02:00
..
changelog [dev] Monorepo: minor build speed improvement (tsconfig consolidation) (#52191) 2024-10-23 13:48:36 +02:00
src [dev] Monorepo: minor build speed improvement (tsconfig consolidation) (#52191) 2024-10-23 13:48:36 +02:00
typings Add PhoneNumberInput component – cooldown (#40335) 2023-10-16 10:19:36 +02:00
.eslintrc.js CI: update linting jobs to skip build step (#49193) 2024-07-08 08:39:39 +02:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
CHANGELOG.md Prepare Packages for Release (#46976) 2024-05-01 11:21:29 -05:00
PREVIOUS_CHANGELOG.md @woocommerce/components: Prep changelog for release (#33359) 2022-06-14 14:21:02 +12:00
README.md Update / tweak a few more links in docs and comments (#41598) 2023-11-21 12:38:09 +01:00
babel.config.js Update/unify jest@27 across all packages (#34322) 2022-09-06 09:29:45 -05:00
composer.json bump php version in packages/js/*/composer.json (#42020) 2024-01-04 10:18:34 -04:00
composer.lock Update changelogger to 3.3.0 to support PR number capturing with merge (#36266) 2023-01-05 14:42:51 +05:30
jest.config.json Fix Jest Preset (#42707) 2023-12-12 09:58:13 -08:00
package.json [dev] CI: liverage composer packages cache in pr-lint-monorepo workflow (#52054) 2024-10-16 12:02:31 +02:00
tsconfig-cjs.json [dev] Monorepo: minor build speed improvement (tsconfig consolidation) (#52191) 2024-10-23 13:48:36 +02:00
tsconfig.json [dev] Monorepo: minor build speed improvement (tsconfig consolidation) (#52191) 2024-10-23 13:48:36 +02:00
webpack.config.js Emit error on webpack build when invalid export name used in import for JS (#37195) 2023-03-26 21:42:33 -04:00

README.md

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.