@handled-ai/design-system 0.18.32 → 0.18.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,123 +0,0 @@
1
- import "@testing-library/jest-dom/vitest"
2
-
3
- import React from "react"
4
- import { fireEvent, render, screen } from "@testing-library/react"
5
- import { describe, expect, it, vi } from "vitest"
6
-
7
- import { BRAND_ICONS } from "../../lib/icons"
8
- import { RelatedRecordActionCard } from "../related-record-action-card"
9
-
10
- describe("RelatedRecordActionCard", () => {
11
- it("renders an enabled href as a link with pointer affordance", () => {
12
- render(
13
- <RelatedRecordActionCard
14
- kind="account"
15
- label="Open account"
16
- subtitle="Acme Corp"
17
- href="/accounts/acme"
18
- testId="record-card"
19
- />
20
- )
21
-
22
- const card = screen.getByTestId("record-card")
23
-
24
- expect(card.tagName).toBe("A")
25
- expect(card).toHaveAttribute("href", "/accounts/acme")
26
- expect(card.className).toContain("cursor-pointer")
27
- expect(card.className).toContain("hover:bg-muted/50")
28
- expect(card.className).toContain("hover:border-border/80")
29
- expect(card.className).toContain("focus-visible:ring-2")
30
- expect(card.className).toContain("active:text-primary")
31
- expect(screen.getByText("Acme Corp")).toBeInTheDocument()
32
- })
33
-
34
- it("renders an enabled onClick action as a button and invokes the callback", () => {
35
- const onClick = vi.fn()
36
-
37
- render(
38
- <RelatedRecordActionCard
39
- kind="case"
40
- label="Open case"
41
- onClick={onClick}
42
- testId="record-card"
43
- />
44
- )
45
-
46
- const card = screen.getByRole("button", { name: /open case/i })
47
-
48
- expect(card.tagName).toBe("BUTTON")
49
- expect(card).toHaveAttribute("type", "button")
50
- expect(card.className).toContain("cursor-pointer")
51
-
52
- fireEvent.click(card)
53
-
54
- expect(onClick).toHaveBeenCalledTimes(1)
55
- })
56
-
57
- it("renders a disabled card when disabledReason is present", () => {
58
- render(
59
- <RelatedRecordActionCard
60
- kind="opportunity"
61
- label="Open opportunity"
62
- disabledReason="Connect Salesforce to view this opportunity."
63
- href="/opportunities/1"
64
- testId="record-card"
65
- />
66
- )
67
-
68
- const card = screen.getByTestId("record-card")
69
-
70
- expect(card.tagName).toBe("DIV")
71
- expect(card).toHaveAttribute("aria-disabled", "true")
72
- expect(card.className).toContain("cursor-not-allowed")
73
- expect(card.className).toContain("text-muted-foreground")
74
- expect(card.className).not.toContain("cursor-pointer")
75
- expect(card.className).not.toContain("hover:bg-muted/50")
76
- expect(screen.getByText("Connect Salesforce to view this opportunity.")).toBeInTheDocument()
77
- })
78
-
79
- it("renders a disabled card when no action is available", () => {
80
- render(<RelatedRecordActionCard kind="generic" label="Unavailable record" testId="record-card" />)
81
-
82
- const card = screen.getByTestId("record-card")
83
-
84
- expect(card.tagName).toBe("DIV")
85
- expect(card).toHaveAttribute("aria-disabled", "true")
86
- expect(card.className).toContain("cursor-not-allowed")
87
- })
88
-
89
- it("sets external link attributes and exposes an accessible external-link cue", () => {
90
- const { container } = render(
91
- <RelatedRecordActionCard
92
- kind="salesforce"
93
- label="Open in Salesforce"
94
- href="https://example.salesforce.com/001"
95
- external
96
- testId="record-card"
97
- />
98
- )
99
-
100
- const card = screen.getByTestId("record-card")
101
-
102
- expect(card).toHaveAttribute("target", "_blank")
103
- expect(card).toHaveAttribute("rel", "noopener noreferrer")
104
- expect(screen.getByText("opens in a new tab")).toHaveClass("sr-only")
105
- expect(container.querySelector('[data-slot="related-record-action-card-external-icon"]')).not.toBeNull()
106
- })
107
-
108
- it("renders the Salesforce brand icon when icon is salesforce", () => {
109
- const { container } = render(
110
- <RelatedRecordActionCard
111
- kind="generic"
112
- label="Salesforce record"
113
- href="https://example.salesforce.com/001"
114
- icon="salesforce"
115
- />
116
- )
117
-
118
- const icon = container.querySelector('[data-slot="related-record-action-card-icon"] img')
119
-
120
- expect(icon).toHaveAttribute("src", BRAND_ICONS.salesforce)
121
- expect(icon).toHaveAttribute("alt", "Salesforce")
122
- })
123
- })
@@ -1,169 +0,0 @@
1
- "use client"
2
-
3
- import * as React from "react"
4
- import { ExternalLink } from "lucide-react"
5
-
6
- import { BRAND_ICONS } from "../lib/icons"
7
- import { cn } from "../lib/utils"
8
-
9
- export type RelatedRecordActionCardKind = "case" | "account" | "opportunity" | "salesforce" | "generic"
10
-
11
- export type RelatedRecordActionIcon = "salesforce" | React.ReactNode
12
-
13
- export interface RelatedRecordActionCardProps {
14
- kind: RelatedRecordActionCardKind
15
- label: string
16
- subtitle?: string
17
- disabledReason?: string
18
- href?: string
19
- external?: boolean
20
- icon?: RelatedRecordActionIcon
21
- onClick?: React.MouseEventHandler<HTMLButtonElement>
22
- className?: string
23
- testId?: string
24
- }
25
-
26
- function renderActionIcon(icon: RelatedRecordActionIcon | undefined, kind: RelatedRecordActionCardKind) {
27
- if (icon === "salesforce" || kind === "salesforce") {
28
- return (
29
- <img
30
- src={BRAND_ICONS.salesforce}
31
- alt="Salesforce"
32
- className="h-4 w-4 object-contain"
33
- draggable={false}
34
- />
35
- )
36
- }
37
-
38
- if (icon) {
39
- return icon
40
- }
41
-
42
- return <span aria-hidden="true">{kind.slice(0, 1).toUpperCase()}</span>
43
- }
44
-
45
- export function RelatedRecordActionCard({
46
- kind,
47
- label,
48
- subtitle,
49
- disabledReason,
50
- href,
51
- external,
52
- icon,
53
- onClick,
54
- className,
55
- testId,
56
- }: RelatedRecordActionCardProps) {
57
- const isDisabled = Boolean(disabledReason) || (!href && !onClick)
58
-
59
- const content = (
60
- <>
61
- <span
62
- data-slot="related-record-action-card-icon"
63
- className={cn(
64
- "flex h-8 w-8 shrink-0 items-center justify-center rounded-md border text-xs font-semibold transition-colors",
65
- isDisabled
66
- ? "border-border/60 bg-muted/40 text-muted-foreground"
67
- : "border-border bg-muted/30 text-muted-foreground group-hover:bg-muted/60 group-active:text-primary"
68
- )}
69
- >
70
- {renderActionIcon(icon, kind)}
71
- </span>
72
- <span className="min-w-0 flex-1">
73
- <span
74
- data-slot="related-record-action-card-label"
75
- className={cn(
76
- "block truncate text-sm font-medium transition-colors",
77
- isDisabled ? "text-muted-foreground" : "text-foreground group-active:text-primary"
78
- )}
79
- >
80
- {label}
81
- </span>
82
- {subtitle && (
83
- <span
84
- data-slot="related-record-action-card-subtitle"
85
- className="mt-0.5 block truncate text-xs text-muted-foreground"
86
- >
87
- {subtitle}
88
- </span>
89
- )}
90
- {disabledReason && (
91
- <span
92
- data-slot="related-record-action-card-disabled-reason"
93
- className="mt-1 block text-xs text-muted-foreground"
94
- >
95
- {disabledReason}
96
- </span>
97
- )}
98
- </span>
99
- {external && (
100
- <>
101
- <span className="sr-only">opens in a new tab</span>
102
- <ExternalLink
103
- aria-hidden="true"
104
- data-slot="related-record-action-card-external-icon"
105
- className={cn(
106
- "h-3.5 w-3.5 shrink-0 text-muted-foreground transition-colors",
107
- isDisabled ? "" : "group-active:text-primary"
108
- )}
109
- />
110
- </>
111
- )}
112
- </>
113
- )
114
-
115
- if (isDisabled) {
116
- return (
117
- <div
118
- aria-disabled="true"
119
- data-kind={kind}
120
- data-slot="related-record-action-card"
121
- data-testid={testId}
122
- className={cn(
123
- "group flex w-full items-center gap-3 rounded-lg border px-3 py-2 text-left transition-colors",
124
- "cursor-not-allowed border-border/60 bg-muted/20 text-muted-foreground opacity-70",
125
- className
126
- )}
127
- >
128
- {content}
129
- </div>
130
- )
131
- }
132
-
133
- if (href) {
134
- return (
135
- <a
136
- href={href}
137
- target={external ? "_blank" : undefined}
138
- rel={external ? "noopener noreferrer" : undefined}
139
- data-kind={kind}
140
- data-slot="related-record-action-card"
141
- data-testid={testId}
142
- className={cn(
143
- "group flex w-full items-center gap-3 rounded-lg border border-border bg-background px-3 py-2 text-left transition-colors",
144
- "cursor-pointer hover:bg-muted/50 hover:border-border/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 active:text-primary",
145
- className
146
- )}
147
- >
148
- {content}
149
- </a>
150
- )
151
- }
152
-
153
- return (
154
- <button
155
- type="button"
156
- onClick={onClick}
157
- data-kind={kind}
158
- data-slot="related-record-action-card"
159
- data-testid={testId}
160
- className={cn(
161
- "group flex w-full items-center gap-3 rounded-lg border border-border bg-background px-3 py-2 text-left transition-colors",
162
- "cursor-pointer hover:bg-muted/50 hover:border-border/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 active:text-primary",
163
- className
164
- )}
165
- >
166
- {content}
167
- </button>
168
- )
169
- }