Skip to content

Commit

Permalink
🏷️ [#445] Replace classnames with clsx library
Browse files Browse the repository at this point in the history
The latter is typescript compatible.
  • Loading branch information
sergei-maertens committed Mar 6, 2025
1 parent 19fc530 commit d7e2353
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 42 deletions.
47 changes: 21 additions & 26 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@open-formulieren/formiojs": "^4.13.14",
"@open-formulieren/leaflet-tools": "^1.0.0",
"@sentry/react": "^8.50.0",
"classnames": "^2.3.1",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"flatpickr": "^4.6.9",
"formik": "^2.2.9",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Anchor/Anchor.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Link as UtrechtLink} from '@utrecht/component-library-react';
import classNames from 'classnames';
import clsx from 'clsx';
import PropTypes from 'prop-types';

export const ANCHOR_MODIFIERS = [
Expand All @@ -18,7 +18,7 @@ const Anchor = ({
...extraProps
}) => {
// extend with our own modifiers
const className = classNames(
const className = clsx(
'utrecht-link--openforms', // always apply our own modifier
{
'utrecht-link--current': modifiers.includes('current'),
Expand Down
4 changes: 2 additions & 2 deletions src/components/AppDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import classNames from 'classnames';
import clsx from 'clsx';

export interface AppDisplayProps {
/**
Expand Down Expand Up @@ -41,7 +41,7 @@ export const AppDisplay: React.FC<AppDisplayProps> = ({
router,
}) => (
<div
className={classNames('openforms-app', {
className={clsx('openforms-app', {
'openforms-app--no-progress-indicator': !progressIndicator,
'openforms-app--no-language-switcher': !languageSwitcher,
})}
Expand Down
4 changes: 2 additions & 2 deletions src/components/FAIcon.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import classNames from 'classnames';
import clsx from 'clsx';
import PropTypes from 'prop-types';

// not all icons need to be seen by assistive technologies.
Expand All @@ -10,7 +10,7 @@ const FAIcon = ({
noAriaHidden = false,
...props
}) => {
const className = classNames(
const className = clsx(
'fa',
'fas',
'fa-icon',
Expand Down
4 changes: 2 additions & 2 deletions src/components/PreviousLink.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import classNames from 'classnames';
import clsx from 'clsx';
import PropTypes from 'prop-types';

import FAIcon from 'components/FAIcon';
Expand All @@ -8,7 +8,7 @@ import {Literal} from 'components/Literal';
const VARIANTS = ['start', 'end'];

const PreviousLink = ({to, onClick, position}) => {
const className = classNames('openforms-previous-link', {
const className = clsx('openforms-previous-link', {
[`openforms-previous-link--${position}`]: position,
});
return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/forms/SelectField/SelectField.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HelpText, Label, ValidationErrors} from '@open-formulieren/formio-renderer';
import {FormField} from '@utrecht/component-library-react';
import classNames from 'classnames';
import clsx from 'clsx';
import {Field, useFormikContext} from 'formik';
import omit from 'lodash/omit';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -86,7 +86,7 @@ const SelectField = ({
inputId={id}
classNames={{
control: state =>
classNames('utrecht-select', 'utrecht-select--openforms', {
clsx('utrecht-select', 'utrecht-select--openforms', {
'utrecht-select--focus': state.isFocused,
'utrecht-select--focus-visible': state.isFocused,
'utrecht-select--disabled': disabled,
Expand All @@ -95,7 +95,7 @@ const SelectField = ({
}),
menu: () => 'rs-menu',
option: state =>
classNames('rs-menu__option', {
clsx('rs-menu__option', {
'rs-menu__option--focus': state.isFocused,
'rs-menu__option--visible-focus': state.isFocused,
}),
Expand Down
4 changes: 2 additions & 2 deletions src/formio/components/Component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import classNames from 'classnames';
import clsx from 'clsx';
import {Formio} from 'react-formio';

import {applyPrefix} from 'utils';
Expand All @@ -19,7 +19,7 @@ const FormioComponent = Formio.Components.components.component;
* @todo: check impact of --hidden modifier
*/
function getClassName() {
return classNames(
return clsx(
applyPrefix('form-control'),
applyPrefix(`form-control--${this.component.type}`),
{[applyPrefix(`form-control--${this.key}`)]: this.key},
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import classNames from 'classnames';
import clsx from 'clsx';

import {getEnv} from './env';

Expand Down Expand Up @@ -28,7 +28,7 @@ export const applyPrefix = name => {
export const getBEMClassName = (base, modifiers = []) => {
const prefixedBase = applyPrefix(base);
const prefixedModifiers = modifiers.map(mod => applyPrefix(`${base}--${mod}`));
return classNames(prefixedBase, ...prefixedModifiers);
return clsx(prefixedBase, ...prefixedModifiers);
};

// usage: await sleep(3000);
Expand Down

0 comments on commit d7e2353

Please sign in to comment.