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

Try: Replace classnames with clsx (outdated) #61091

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
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',
DaniGuardiola marked this conversation as resolved.
Show resolved Hide resolved
message:
"Please use `clsx` instead. It's a lighter and faster drop-in replacement for `classnames`.",
},
];

module.exports = {
Expand Down
6 changes: 3 additions & 3 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
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';
DaniGuardiola marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-compare/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import clsx from 'clsx';
// diff doesn't tree-shake correctly, so we import from the individual
// module here, to avoid including too much of the library
import { diffChars } from 'diff/lib/diff/character';
Expand All @@ -28,7 +28,7 @@ function BlockCompare( {
const difference = diffChars( originalContent, newContent );

return difference.map( ( item, pos ) => {
const classes = classnames( {
const classes = clsx( {
'block-editor-block-compare__added': item.added,
'block-editor-block-compare__removed': item.removed,
} );
Expand Down
Loading
Loading