Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace classnames with clsx #61138

Merged
merged 21 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .eslintrc.js
Expand Up @@ -76,6 +76,11 @@ const restrictedImports = [
message:
"edit-widgets is a WordPress top level package that shouldn't be imported into other packages",
},
{
name: 'classnames',
message:
"Please use `clsx` instead. It's a lighter and faster drop-in replacement for `classnames`.",
},
];

module.exports = {
Expand Down
2 changes: 2 additions & 0 deletions README.md
@@ -1,3 +1,5 @@
please refresh the PR github thank you
DaniGuardiola marked this conversation as resolved.
Show resolved Hide resolved

# Gutenberg

[![End-to-End Tests](https://github.com/WordPress/gutenberg/workflows/End-to-End%20Tests/badge.svg)](https://github.com/WordPress/gutenberg/actions?query=workflow%3A%22End-to-End+Tests%22+branch%3Atrunk)
Expand Down
6 changes: 3 additions & 3 deletions docs/contributors/code/coding-guidelines.md
Expand Up @@ -39,13 +39,13 @@ Components may be assigned with class names that indicate states (for example, a

**Example:**

Consider again the Notices example. We may want to apply specific styling for dismissible notices. The [`classnames` package](https://www.npmjs.com/package/classnames) can be a helpful utility for conditionally applying modifier class names.
Consider again the Notices example. We may want to apply specific styling for dismissible notices. The [`clsx` package](https://www.npmjs.com/package/clsx) can be a helpful utility for conditionally applying modifier class names.

```jsx
import classnames from 'classnames';
import clsx from 'clsx';

export default function Notice( { children, onRemove, isDismissible } ) {
const classes = classnames( 'components-notice', {
const classes = clsx( 'components-notice', {
'is-dismissible': isDismissible,
} );

Expand Down
79 changes: 41 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/block-editor/package.json
Expand Up @@ -65,7 +65,7 @@
"@wordpress/warning": "file:../warning",
"@wordpress/wordcount": "file:../wordcount",
"change-case": "^4.1.2",
"classnames": "^2.3.1",
"clsx": "^2.1.1",
"colord": "^2.7.0",
"deepmerge": "^4.3.0",
"diff": "^4.0.2",
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import classNames from 'classnames';
import clsx from 'clsx';

/**
* WordPress dependencies
Expand Down Expand Up @@ -85,7 +85,7 @@ function BlockAlignmentUI( {
key={ controlName }
icon={ icon }
iconPosition="left"
className={ classNames(
className={ clsx(
'components-dropdown-menu__menu-item',
{
'is-active': isSelected,
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-card/index.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import clsx from 'clsx';

/**
* WordPress dependencies
Expand Down Expand Up @@ -45,7 +45,7 @@ function BlockCard( { title, icon, description, blockType, className } ) {
const { selectBlock } = useDispatch( blockEditorStore );

return (
<div className={ classnames( 'block-editor-block-card', className ) }>
<div className={ clsx( 'block-editor-block-card', className ) }>
{ parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here.
<Button
onClick={ () => selectBlock( parentNavBlockClientId ) }
Expand Down