Skip to content

Commit

Permalink
fix <Shortcut /> (#609)
Browse files Browse the repository at this point in the history
* f

* f

* Create early-apes-judge.md
  • Loading branch information
prichodko authored Oct 11, 2024
1 parent d48508b commit 7f21132
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-apes-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@status-im/components": patch
---

fix `<Shortcut />`icon prop and symbol centering
2 changes: 1 addition & 1 deletion packages/components/src/shortcut/shortcut.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const variants = ['primary', 'secondary', 'gray'] as const
// eslint-disable-next-line react/display-name
const renderVariant = (variant: (typeof variants)[number]) => (props: any) => (
<div className="flex items-center gap-2">
<Shortcut {...props} variant={variant} icon={CommandIcon} />
<Shortcut {...props} variant={variant} icon={<CommandIcon />} />
<Shortcut {...props} variant={variant} symbol="K" />
</div>
)
Expand Down
15 changes: 9 additions & 6 deletions packages/components/src/shortcut/shortcut.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { forwardRef } from 'react'
import { cloneElement, forwardRef } from 'react'

import { match, P } from 'ts-pattern'

import { cva } from '../utils/variants'

import type { IconElement } from '../types'
import type { VariantProps } from '../utils/variants'

const styles = cva({
base: 'flex size-4 flex-shrink-0 items-center justify-center rounded-6 border',
base: 'grid size-4 flex-shrink-0 place-items-center rounded-6 border',
variants: {
variant: {
primary: [
Expand All @@ -32,7 +33,7 @@ const styles = cva({
type Props = VariantProps<typeof styles> &
(
| {
icon: React.ComponentType<React.SVGProps<SVGSVGElement>>
icon: IconElement
symbol?: never
}
| {
Expand All @@ -42,15 +43,17 @@ type Props = VariantProps<typeof styles> &
)

const Shortcut = (props: Props, ref: React.Ref<HTMLDivElement>) => {
const { variant = 'primary', ...rest } = props
const { variant = 'primary' } = props

return (
<div className={styles({ variant })} ref={ref} {...rest}>
<div className={styles({ variant })} ref={ref}>
{match(props)
.with({ symbol: P.string }, ({ symbol }) => (
<span className="text-11 font-medium">{symbol}</span>
))
.with({ icon: P._ }, ({ icon: Icon }) => <Icon className="size-3" />)
.with({ icon: P._ }, ({ icon }) =>
cloneElement(icon, { className: 'size-3' }),
)
.exhaustive()}
</div>
)
Expand Down

0 comments on commit 7f21132

Please sign in to comment.