Skip to content

Commit

Permalink
Replace classnames dependency with equivalent helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidje13 committed Dec 4, 2024
1 parent 072626a commit 77fc9a9
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 48 deletions.
73 changes: 36 additions & 37 deletions frontend/package-lock.json

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

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"dependencies": {
"@openfonts/open-sans_all": "1.x",
"classnames": "2.x",
"json-immutability-helper": "4.0.x",
"lean-qr": "2.x",
"react": "18.x",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/ExpandingTextEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SyntheticEvent,
MouseEvent,
} from 'react';
import classNames from 'classnames';
import { classNames } from '../../helpers/classNames';
import { isFocusable } from '../../helpers/isFocusable';
import { useKeyHandler } from '../../hooks/useKeyHandler';
import { useStateMap } from '../../hooks/useStateMap';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/PickerInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo, ReactNode } from 'react';
import classNames from 'classnames';
import { classNames } from '../../helpers/classNames';
import './PickerInput.less';

interface OptionT {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/TabControl.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, memo, ReactNode } from 'react';
import classNames from 'classnames';
import { classNames } from '../../helpers/classNames';
import './TabControl.less';

interface TabT {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CSSProperties,
useEffect,
} from 'react';
import classNames from 'classnames';
import { classNames } from '../../helpers/classNames';
import { useDebounced } from '../../hooks/useDebounced';
import {
getEmptyHeight,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/retro-formats/mood/MoodRetro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../helpers/classNames';
import { type RetroItem } from '../../../shared/api-entities';
import { MoodSection } from './categories/MoodSection';
import { ActionsPane } from './actions/ActionsPane';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, memo } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../../helpers/classNames';
import {
type RetroItem,
type UserProvidedRetroItemDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../../helpers/classNames';
import {
type RetroItem,
type UserProvidedRetroItemDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../../helpers/classNames';
import './FaceIcon.less';

type Type = 'happy' | 'meh' | 'sad';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../../helpers/classNames';
import { type RetroItem } from '../../../../shared/api-entities';
import { VoteCount } from './VoteCount';
import { WrappedButton } from '../../../common/WrappedButton';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from 'react';
import classNames from 'classnames';
import { classNames } from '../../../../helpers/classNames';
import { WrappedButton } from '../../../common/WrappedButton';
import { useThrottled } from '../../../../hooks/useThrottled';
import Heart from '../../../../../resources/heart.svg';
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/helpers/classNames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type ClassNamePart = string | Record<string, boolean> | null | undefined;

export function classNames(...parts: ClassNamePart[]): string {
const r: string[] = [];
for (const part of parts) {
if (part) {
if (typeof part === 'string') {
r.push(part);
} else {
r.push(
...Object.entries(part)
.filter(([, v]) => v)
.map(([k]) => k),
);
}
}
}
return r.join(' ');
}

0 comments on commit 77fc9a9

Please sign in to comment.