Skip to content

Commit 95f9ffc

Browse files
committed
Simplify the PillButton component
1 parent 3d56ad1 commit 95f9ffc

4 files changed

Lines changed: 8 additions & 23 deletions

File tree

components/gallery/ArticleCTA.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export function ArticleCTA({ article }: { article: Article }) {
1717
standalone
1818
onClick={() => setCollapsed(false)}
1919
aria-label="Show new article"
20-
className="flex"
21-
contentClassName="pointer-events-auto flex h-8 min-w-[5.5rem] items-center justify-center gap-2 px-3"
20+
className="pointer-events-auto flex h-8 min-w-[5.5rem] items-center justify-center gap-2 px-3"
2221
>
2322
<span className="text-[0.6rem] leading-none tracking-[0.08em] uppercase">
2423
New Article

components/gallery/DemoSidebar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,15 @@ export function DemoSidebar({ demos, selected, collapsed, onSelect, onToggle }:
7474
<div
7575
className="absolute top-1/2 right-2 z-10"
7676
style={{
77-
translate: collapsed ? (near ? '85% -50%' : '45% -50%') : '50% -50%',
77+
translate: collapsed ? (near ? '95% -50%' : '45% -50%') : '50% -50%',
7878
transition: 'translate 0.25s ease',
7979
}}
8080
>
8181
<PillButton
8282
standalone
8383
onClick={onToggle}
8484
aria-label={collapsed ? 'Show demos' : 'Hide demos'}
85-
className="grid h-[5.5rem] w-9 place-items-center hover:bg-[#f5f5f5] hover:text-[#222]"
86-
contentClassName="flex h-full w-full items-center justify-center"
85+
className="grid h-[5rem] w-8 place-items-center hover:bg-[#f5f5f5] hover:text-[#222]"
8786
>
8887
<span className="flex flex-col items-center gap-1.5">
8988
<svg

components/gallery/NavPill.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,14 @@ export function NavPill() {
5757
<div className="hidden items-center gap-px sm:flex">
5858
<PillButton
5959
tooltip="Search"
60-
className="grid h-[1.8rem] w-[1.8rem] place-items-center"
61-
contentClassName="flex h-[0.95rem] w-[0.95rem] items-center justify-center [&_a]:flex [&_button]:!p-0 [&_svg]:h-[0.95rem] [&_svg]:w-[0.95rem]"
60+
className="grid h-[1.8rem] w-[1.8rem] place-items-center [&_button]:!p-0 [&_svg]:h-[0.95rem] [&_svg]:w-[0.95rem]"
6261
>
6362
<SearchButton />
6463
</PillButton>
6564

6665
<PillButton
6766
tooltip="Theme"
68-
className="grid h-[1.8rem] w-[1.8rem] place-items-center"
69-
contentClassName="flex h-[0.95rem] w-[0.95rem] items-center justify-center [&_a]:flex [&_button]:!p-0 [&_svg]:h-[0.95rem] [&_svg]:w-[0.95rem]"
67+
className="grid h-[1.8rem] w-[1.8rem] place-items-center [&_button]:!p-0 [&_svg]:h-[0.95rem] [&_svg]:w-[0.95rem]"
7068
>
7169
<ThemeSwitch />
7270
</PillButton>
@@ -81,7 +79,6 @@ export function NavPill() {
8179
rel="noopener noreferrer"
8280
aria-label={label}
8381
className="grid h-[1.8rem] w-[1.8rem] place-items-center"
84-
contentClassName="flex h-[0.95rem] w-[0.95rem] items-center justify-center [&_svg]:h-[0.95rem] [&_svg]:w-[0.95rem]"
8582
>
8683
<Icon className="h-[0.95rem] w-[0.95rem] fill-current" />
8784
</PillButton>

components/gallery/PillButton.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { ReactNode, MouseEventHandler } from 'react'
33
type PillButtonProps = {
44
children: ReactNode
55
className?: string
6-
contentClassName?: string
76
tooltip?: string
87
standalone?: boolean
98
href?: string
@@ -16,7 +15,6 @@ type PillButtonProps = {
1615
export function PillButton({
1716
children,
1817
className,
19-
contentClassName,
2018
tooltip,
2119
standalone = false,
2220
href,
@@ -41,24 +39,16 @@ export function PillButton({
4139
.filter(Boolean)
4240
.join(' ')
4341

44-
const content = contentClassName ? (
45-
<span className={contentClassName}>{children}</span>
46-
) : (
47-
children
48-
)
49-
5042
const surface = href ? (
5143
<a className={surfaceClassName} href={href} target={target} rel={rel} aria-label={ariaLabel}>
52-
{content}
44+
{children}
5345
</a>
5446
) : onClick ? (
5547
<button className={surfaceClassName} onClick={onClick} type="button" aria-label={ariaLabel}>
56-
{content}
48+
{children}
5749
</button>
5850
) : (
59-
<div className={surfaceClassName}>
60-
<div className={contentClassName}>{children}</div>
61-
</div>
51+
<div className={surfaceClassName}>{children}</div>
6252
)
6353

6454
return (

0 commit comments

Comments
 (0)