Skip to content

Commit ebcde55

Browse files
committed
fixed missing autoFocus prop on buttons and missing outline styles.
added Badge component
1 parent 105c9da commit ebcde55

File tree

10 files changed

+621
-448
lines changed

10 files changed

+621
-448
lines changed

library/src/components/Badge.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from "react"
2+
import { twMerge } from "tailwind-merge"
3+
4+
type BadgeAppearance =
5+
| "added"
6+
| "default"
7+
| "important"
8+
| "removed"
9+
| "primary"
10+
| "primaryInverted"
11+
12+
type BadgeProps = {
13+
appearance?: BadgeAppearance
14+
children: React.ReactNode
15+
style?: React.CSSProperties
16+
className?: string
17+
}
18+
19+
const defaultStyle = "bg-neutral"
20+
const addedStyle = "bg-success text-success-text"
21+
const importantStyle = "bg-danger-border text-white"
22+
const removedStyle = "bg-danger text-danger-text"
23+
const primaryStyle = "bg-brand-bold text-text-inverse"
24+
const primaryInvertedStyle = "bg-surface text-brand-bold"
25+
26+
const appearanceStyles: { [appearance in BadgeAppearance]: string } = {
27+
default: defaultStyle,
28+
added: addedStyle,
29+
important: importantStyle,
30+
removed: removedStyle,
31+
primary: primaryStyle,
32+
primaryInverted: primaryInvertedStyle,
33+
} as const
34+
35+
export function Badge({
36+
appearance = "default",
37+
children,
38+
style,
39+
className,
40+
}: BadgeProps) {
41+
return (
42+
<span
43+
className={twMerge(
44+
"box-border flex items-center justify-center rounded-lg pe-[0.4rem] ps-[0.4rem] text-[1rem] leading-6",
45+
appearanceStyles[appearance],
46+
className,
47+
)}
48+
style={style}
49+
>
50+
{children}
51+
</span>
52+
)
53+
}

library/src/components/Button.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type ButtonProps = {
1111
iconAfter?: React.ReactNode
1212
isDisabled?: boolean
1313
isSelected?: boolean
14+
autoFocus?: boolean
1415
children?: React.ReactNode
1516
style?: CSSProperties
1617
className?: string
@@ -52,6 +53,7 @@ export const Button = ({
5253
iconAfter,
5354
isDisabled = false,
5455
isSelected = false,
56+
autoFocus = false,
5557
style,
5658
children,
5759
className,
@@ -60,11 +62,12 @@ export const Button = ({
6062
return (
6163
<button
6264
title={title}
65+
autoFocus={autoFocus}
6366
aria-label={label}
6467
style={style}
6568
className={twMerge(
6669
ButtonStyles[appearance],
67-
"disabled:bg-disabled disabled:text-disabled-text relative flex items-center justify-center gap-1 rounded px-3 py-1.5 disabled:cursor-not-allowed",
70+
"disabled:bg-disabled disabled:text-disabled-text outline-brand-hovered relative flex items-center justify-center gap-1 rounded px-3 py-1.5 outline-1 outline-offset-2 focus:outline disabled:cursor-not-allowed",
6871
isSelected ? ButtonSelectedStyles : undefined,
6972
className,
7073
)}

library/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from "./Button"
1111
export * from "./Avatar"
1212
export * from "./IconSizeHelper"
1313
export * from "./Tooltip"
14+
export * from "./Badge"

0 commit comments

Comments
 (0)