Skip to content

Commit d1cebad

Browse files
committed
Replace classnames dependency with internal utility
- to drop dependency on 'classnames', create a shared util in `CodeWebChat/packages/shared/src/utils` ├── apps │ ├── browser │ │ └── package.json │ └── editor │ ├── package.json │ ├── src │ │ └── views │ │ └── prompt │ │ └── frontend │ │ ├── Home │ │ │ └── Home.tsx │ │ ├── Prompt.tsx │ │ └── components │ │ ├── Layout │ │ │ └── Footer │ │ │ └── Footer.tsx │ │ └── recent-donations │ │ └── RecentDonationsFooter │ │ └── RecentDonationsFooter.tsx │ └── tsconfig.json └── packages ├── shared │ ├── package.json │ ├── src │ │ └── utils │ │ ├── classnames.ts │ │ ├── create-zip │ │ │ ├── create-zip.ts │ │ │ └── index.ts │ │ ├── display-token-count.ts │ │ ├── extract-path-from-line-of-code │ │ │ ├── extract-path-from-line-of-code.spec.ts │ │ │ ├── extract-path-from-line-of-code.ts │ │ │ └── index.ts │ │ ├── logger.ts │ │ └── simplify-prompt-symbols │ │ ├── index.ts │ │ ├── simplify-prompt-symbols.spec.ts │ │ └── simplify-prompt-symbols.ts │ └── tsconfig.json └── ui ├── package.json ├── src │ └── components │ └── editor │ ├── common │ │ ├── Button │ │ │ └── Button.tsx │ │ ├── Dropdown │ │ │ └── Dropdown.tsx │ │ ├── DropdownMenu │ │ │ └── DropdownMenu.tsx │ │ ├── IconButton │ │ │ └── IconButton.tsx │ │ ├── QuickPickButton │ │ │ └── QuickPickButton.tsx │ │ ├── Scrollable │ │ │ └── Scrollable.tsx │ │ ├── TextButton │ │ │ └── TextButton.tsx │ │ ├── Textarea │ │ │ └── Textarea.tsx │ │ ├── Tooltip │ │ │ └── Tooltip.tsx │ │ └── prompts │ │ ├── PromptField │ │ │ ├── PromptField.tsx │ │ │ └── components │ │ │ ├── CompletedTasks │ │ │ │ └── CompletedTasks.tsx │ │ │ ├── Footer │ │ │ │ └── Footer.tsx │ │ │ └── Tabs │ │ │ └── Tabs.tsx │ │ └── shared │ │ └── symbols │ │ └── get-highlighted-text.tsx │ ├── prompt-view │ │ ├── CodeReview │ │ │ ├── CodeReview.tsx │ │ │ └── components │ │ │ └── FileItem │ │ │ └── FileItem.tsx │ │ ├── CompactableActionButton │ │ │ └── CompactableActionButton.tsx │ │ ├── Configurations │ │ │ └── Configurations.tsx │ │ ├── Fieldset │ │ │ └── Fieldset.tsx │ │ ├── IconAccentButton │ │ │ └── IconAccentButton.tsx │ │ ├── KeycapWrapper │ │ │ └── KeycapWrapper.tsx │ │ ├── Notes │ │ │ └── Notes.tsx │ │ ├── RecentDonations │ │ │ └── RecentDonations.tsx │ │ ├── Responses │ │ │ └── Responses.tsx │ │ ├── StatusBar │ │ │ └── StatusBar.tsx │ │ ├── Tabs │ │ │ └── Tabs.tsx │ │ ├── TargetButton │ │ │ └── TargetButton.tsx │ │ ├── Tasks │ │ │ ├── Tasks.tsx │ │ │ └── components │ │ │ └── TaskGroup.tsx │ │ ├── UpdateAvailable │ │ │ └── UpdateAvailable.tsx │ │ └── modals │ │ └── Modal │ │ └── Modal.tsx │ └── settings-view │ ├── Group │ │ └── Group.tsx │ ├── Item │ │ └── Item.tsx │ ├── NavigationItemGroup │ │ └── NavigationItemGroup.tsx │ ├── NavigationItemSection │ │ └── NavigationItemSection.tsx │ ├── NavigationSection │ │ └── NavigationSection.tsx │ ├── Notices │ │ └── Notices.tsx │ ├── PromptInstructions │ │ └── PromptInstructions.tsx │ ├── Section │ │ └── Section.tsx │ └── SortableList │ └── SortableList.tsx └── tsconfig.json
1 parent b45dcb0 commit d1cebad

49 files changed

Lines changed: 108 additions & 64 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/browser/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"dependencies": {
2121
"@cwc/ui": "workspace:*",
2222
"@cwc/shared": "workspace:*",
23-
"classnames": "2.5.1",
2423
"react": "18.3.1",
2524
"react-dom": "18.3.1"
2625
}

‎apps/editor/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,6 @@
13921392
"@mozilla/readability": "0.6.0",
13931393
"@vscode/codicons": "0.0.46-51",
13941394
"axios": "1.21.0",
1395-
"classnames": "2.5.1",
13961395
"dayjs": "1.11.10",
13971396
"dotenv": "16.4.5",
13981397
"glob": "14.0.4",

‎apps/editor/src/views/prompt/frontend/Home/Home.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Tabs as UiTabs } from '@ui/components/editor/prompt-view/Tabs'
55
import { TargetButton as UiTargetButton } from '@ui/components/editor/prompt-view/TargetButton'
66
import { TargetButtons as UiTargetButtons } from '@ui/components/editor/prompt-view/TargetButtons'
77
import { Target } from '@shared/types/target'
8-
import cn from 'classnames'
8+
import cn from '@shared/utils/classnames'
99
import { post_message } from '../utils/post-message'
1010
import { BackendMessage } from '@/views/prompt/types/messages'
1111
import { Spacer as UiSpacer } from '@ui/components/editor/prompt-view/Spacer'

‎apps/editor/src/views/prompt/frontend/Prompt.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EditWebConfigurationForm } from '@/views/shared/forms/EditWebConfigurat
66
import { TextButton as UiTextButton } from '@ui/components/editor/common/TextButton'
77
import { Home } from './Home'
88
import styles from './Prompt.module.scss'
9-
import cn from 'classnames'
9+
import cn from '@shared/utils/classnames'
1010
import { post_message } from './utils/post-message'
1111
import { CodeReview as UiCodeReview } from '@ui/components/editor/prompt-view/CodeReview'
1212
import { Modal as UiModal } from '@ui/components/editor/prompt-view/modals/Modal'

‎apps/editor/src/views/prompt/frontend/components/Layout/Footer/Footer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from './Footer.module.scss'
33
import { use_compacting } from '@shared/hooks'
44
import { LayoutContext } from '../../../contexts/LayoutContext'
55
import { use_translation } from '../../../i18n/use-translation'
6-
import cn from 'classnames'
6+
import cn from '@shared/utils/classnames'
77
import { CompactableActionButton } from '@ui/components/editor/prompt-view/CompactableActionButton'
88
import { Icon as UiIcon } from '@ui/components/editor/common/Icon'
99
import { use_dimmed_icons } from './hooks/use-dimmed-icons'

‎apps/editor/src/views/prompt/frontend/components/recent-donations/RecentDonationsFooter/RecentDonationsFooter.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cn from 'classnames'
1+
import cn from '@shared/utils/classnames'
22
import { use_compacting } from '@shared/hooks'
33
import { Button as UiButton } from '@ui/components/editor/common/Button'
44
import styles from './RecentDonationsFooter.module.scss'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export type ClassValue =
2+
| string
3+
| number
4+
| boolean
5+
| undefined
6+
| null
7+
| { [key: string]: any }
8+
| ClassArray
9+
10+
export type ClassArray = ClassValue[]
11+
12+
export default function cn(...inputs: ClassValue[]): string {
13+
const classes: string[] = []
14+
15+
for (let i = 0; i < inputs.length; i++) {
16+
const arg = inputs[i]
17+
if (!arg) continue
18+
19+
const argType = typeof arg
20+
21+
if (argType === 'string' || argType === 'number') {
22+
classes.push(arg.toString())
23+
} else if (Array.isArray(arg)) {
24+
if (arg.length) {
25+
const inner = cn(...arg)
26+
if (inner) {
27+
classes.push(inner)
28+
}
29+
}
30+
} else if (argType === 'object') {
31+
if (
32+
arg.toString !== Object.prototype.toString &&
33+
!arg.toString.toString().includes('[native code]')
34+
) {
35+
classes.push(arg.toString())
36+
continue
37+
}
38+
39+
for (const key in arg as Record<string, any>) {
40+
if (
41+
Object.prototype.hasOwnProperty.call(arg, key) &&
42+
(arg as Record<string, any>)[key]
43+
) {
44+
classes.push(key)
45+
}
46+
}
47+
}
48+
}
49+
50+
return classes.join(' ')
51+
}

‎packages/ui/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"dependencies": {
1111
"@vscode/codicons": "0.0.46-51",
12-
"classnames": "2.5.1",
1312
"dayjs": "1.11.10",
1413
"react": "18.2.0",
1514
"react-dom": "18.2.0",

‎packages/ui/src/components/editor/common/Button/Button.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC, useEffect, useRef } from 'react'
22
import styles from './Button.module.scss'
3-
import cn from 'classnames'
3+
import cn from '@shared/utils/classnames'
44

55
type Props = {
66
on_click?: (

‎packages/ui/src/components/editor/common/Dropdown/Dropdown.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useRef, useEffect, useLayoutEffect, useMemo } from 'react'
2-
import cn from 'classnames'
2+
import cn from '@shared/utils/classnames'
33
import { DropdownMenu } from '../DropdownMenu'
44
import styles from './Dropdown.module.scss'
55

0 commit comments

Comments
 (0)