Skip to content

Commit 549ee46

Browse files
authored
refactor: rewrite toggleClass in typescript (#19091)
1 parent 65f005a commit 549ee46

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

packages/react/src/components/ComposedModal/ComposedModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { debounce } from 'es-toolkit/compat';
2828
import useIsomorphicEffect from '../../internal/useIsomorphicEffect';
2929
import mergeRefs from '../../tools/mergeRefs';
3030
import cx from 'classnames';
31-
import toggleClass from '../../tools/toggleClass';
31+
import { toggleClass } from '../../tools/toggleClass';
3232
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy';
3333
import wrapFocus, {
3434
elementOrParentIsFloatingMenu,

packages/react/src/components/Modal/Modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import React, {
1515
} from 'react';
1616
import classNames from 'classnames';
1717
import { Close } from '@carbon/icons-react';
18-
import toggleClass from '../../tools/toggleClass';
18+
import { toggleClass } from '../../tools/toggleClass';
1919
import Button from '../Button';
2020
import ButtonSet from '../ButtonSet';
2121
import InlineLoading from '../InlineLoading';

packages/react/src/tools/toggleClass.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright IBM Corp. 2019, 2025
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/**
9+
* Toggles a class on an element.
10+
*
11+
* @param element - The target element.
12+
* @param className - The class to toggle.
13+
* @param add - `true` to add the class, `false` to remove it.
14+
*/
15+
export const toggleClass = (
16+
element: Element,
17+
className: string,
18+
add: boolean
19+
) => {
20+
element.classList.toggle(className, add);
21+
};

0 commit comments

Comments
 (0)