Skip to content

Commit

Permalink
Add StringUtils clsx
Browse files Browse the repository at this point in the history
  • Loading branch information
lubej committed Mar 7, 2024
1 parent 352047f commit 073b000
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 6 additions & 5 deletions frontend/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classes from './index.module.css'
import { FC, MouseEventHandler, PropsWithChildren } from 'react'
import { StringUtils } from '../../utils/string.utils.ts'

type ButtonSize = 'small' | 'medium'
type ButtonColor = 'primary' | 'secondary'
Expand Down Expand Up @@ -43,15 +44,15 @@ export const Button: FC<Props> = ({
type,
}) => (
<button
className={[
className={StringUtils.clsx(
className,
classes.button,
...(disabled ? [classes.buttonDisabled] : []),
...(fullWidth ? [classes.fullWidth] : []),
disabled ? classes.buttonDisabled : undefined,
fullWidth ? classes.fullWidth : undefined,
colorMap[color],
sizeMap[size],
variantMap[variant],
].join(' ')}
variantMap[variant]
)}
onClick={onClick}
disabled={disabled}
type={type}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { FC, PropsWithChildren } from 'react'
import classes from './index.module.css'
import { StringUtils } from '../../utils/string.utils.ts'

interface Props extends PropsWithChildren {
className?: string
}

export const Card: FC<Props> = ({ children, className }) => {
return <div className={[classes.card, ...(className ? [className] : [])].join(' ')}>{children}</div>
return <div className={StringUtils.clsx(classes.card, className)}>{children}</div>
}
7 changes: 7 additions & 0 deletions frontend/src/utils/string.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export abstract class StringUtils {
static getTransactionUrl = (baseUrl: string, txHash: string) => `${baseUrl}/tx/${txHash}`

static getAccountUrl = (baseUrl: string, address: string) => `${baseUrl}/address/${address}`

static clsx = (...classNames: (string | undefined)[]) => {
return classNames
.map(className => (className ? [className] : []))
.flat()
.join(' ')
}
}

0 comments on commit 073b000

Please sign in to comment.