@orsetra/shared-ui 1.14.0 → 1.16.0
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.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Info } from "lucide-react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
import { splitDescription } from "../../lib/field-description"
|
|
6
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The description of a form field: its summary, and an information icon that shows the whole
|
|
10
|
+
* description on hover or focus when it says more.
|
|
11
|
+
*/
|
|
12
|
+
export function FieldDescription({ text, className }: { text?: string | null; className?: string }) {
|
|
13
|
+
if (!text) return null
|
|
14
|
+
const { summary, detail } = splitDescription(text)
|
|
15
|
+
return (
|
|
16
|
+
<p className={cn("text-xs text-ibm-gray-60", className)}>
|
|
17
|
+
{summary}
|
|
18
|
+
{detail && (
|
|
19
|
+
<TooltipProvider delayDuration={150}>
|
|
20
|
+
<Tooltip>
|
|
21
|
+
<TooltipTrigger asChild>
|
|
22
|
+
<button
|
|
23
|
+
type="button"
|
|
24
|
+
aria-label="More about this field"
|
|
25
|
+
className="inline-flex align-text-bottom ml-1 text-ibm-gray-50 hover:text-ibm-blue-60 focus:outline-none focus-visible:text-ibm-blue-60"
|
|
26
|
+
>
|
|
27
|
+
<Info className="h-3.5 w-3.5" />
|
|
28
|
+
</button>
|
|
29
|
+
</TooltipTrigger>
|
|
30
|
+
<TooltipContent side="top" align="start" className="max-w-xs rounded-none text-xs leading-relaxed">
|
|
31
|
+
{detail}
|
|
32
|
+
</TooltipContent>
|
|
33
|
+
</Tooltip>
|
|
34
|
+
</TooltipProvider>
|
|
35
|
+
)}
|
|
36
|
+
</p>
|
|
37
|
+
)
|
|
38
|
+
}
|
package/components/ui/index.ts
CHANGED
|
@@ -6,9 +6,11 @@ export { Avatar, AvatarImage, AvatarFallback } from './avatar'
|
|
|
6
6
|
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from './dropdown-menu'
|
|
7
7
|
export { Separator } from './separator'
|
|
8
8
|
export { Logo } from './logo'
|
|
9
|
+
export { ProductMark, PRODUCT_IDENTITIES, type ProductId, type ProductMarkProps, type ProductMarkVariant } from './product-mark'
|
|
9
10
|
export { UserMenu, type UserMenuItem, type UserMenuConfig } from './user-menu'
|
|
10
11
|
export { Input } from './input'
|
|
11
12
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from './tooltip'
|
|
13
|
+
export { FieldDescription } from './field-description'
|
|
12
14
|
export { PageHeader } from './page-header'
|
|
13
15
|
export { DetailPageHeader, type DetailPageHeaderProps, type DetailPageHeaderTab, type HeaderBreadcrumb } from './detail-page-header'
|
|
14
16
|
export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, type ChartConfig } from './chart'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mark of a service of the platform: its pictogram on a square tile, and optionally its code.
|
|
3
|
+
* Drawn from graphic/product/svg; the rules are in graphic/BRAND-GUIDELINES.md, Product Identities.
|
|
4
|
+
*/
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
export type ProductId = "cis" | "cms" | "apim"
|
|
8
|
+
export type ProductMarkVariant = "mark" | "tile" | "gray"
|
|
9
|
+
|
|
10
|
+
export const PRODUCT_IDENTITIES: Record<ProductId, { code: string; name: string; color: string; tint: string }> = {
|
|
11
|
+
cis: { code: "CIS", name: "Camel Integration Service", color: "#0F62FE", tint: "#EDF5FF" },
|
|
12
|
+
cms: { code: "CMS", name: "Camel Messaging Service", color: "#007D79", tint: "#D9FBFB" },
|
|
13
|
+
apim: { code: "APIM", name: "API Management", color: "#8A3FFC", tint: "#F6F2FF" },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function Pictogram({ product, ink }: { product: ProductId; ink: string }) {
|
|
17
|
+
const line = { fill: "none", stroke: ink, strokeWidth: 2, strokeLinecap: "square" as const, strokeLinejoin: "miter" as const }
|
|
18
|
+
if (product === "cis") {
|
|
19
|
+
return (
|
|
20
|
+
<g>
|
|
21
|
+
<rect x="6" y="19" width="8" height="10" {...line} />
|
|
22
|
+
<path d="M14 24h4" {...line} />
|
|
23
|
+
<path d="M24 17l7 7-7 7-7-7z" fill={ink} />
|
|
24
|
+
<path d="M31 24h6" {...line} />
|
|
25
|
+
<path d="M34 21l3 3-3 3" {...line} />
|
|
26
|
+
<rect x="38" y="19" width="4" height="10" {...line} />
|
|
27
|
+
</g>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
if (product === "cms") {
|
|
31
|
+
return (
|
|
32
|
+
<g>
|
|
33
|
+
<rect x="7" y="9" width="8" height="8" {...line} />
|
|
34
|
+
<rect x="20" y="9" width="8" height="8" {...line} />
|
|
35
|
+
<rect x="33" y="9" width="8" height="8" {...line} />
|
|
36
|
+
<path d="M11 17v12M24 17v12M37 17v12" {...line} />
|
|
37
|
+
<rect x="7" y="29" width="34" height="10" fill={ink} />
|
|
38
|
+
</g>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
<g>
|
|
43
|
+
<path d="M17 40V8h14v32" {...line} />
|
|
44
|
+
<path d="M6 24h34" {...line} />
|
|
45
|
+
<path d="M37 21l3 3-3 3" {...line} />
|
|
46
|
+
<rect x="21" y="12" width="6" height="6" fill={ink} />
|
|
47
|
+
</g>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ProductMarkProps {
|
|
52
|
+
product: ProductId
|
|
53
|
+
/** Side of the tile, in pixels. */
|
|
54
|
+
size?: number
|
|
55
|
+
variant?: ProductMarkVariant
|
|
56
|
+
/** Shows the code of the service next to the tile, from 32px. */
|
|
57
|
+
withCode?: boolean
|
|
58
|
+
/** Names the mark for assistive technologies; without it the mark is decorative. */
|
|
59
|
+
label?: string
|
|
60
|
+
className?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ProductMark({ product, size = 40, variant = "mark", withCode = false, label, className }: ProductMarkProps) {
|
|
64
|
+
const identity = PRODUCT_IDENTITIES[product]
|
|
65
|
+
const ground = variant === "tile" ? identity.color : variant === "gray" ? "#F4F4F4" : identity.tint
|
|
66
|
+
const ink = variant === "tile" ? "#FFFFFF" : variant === "gray" ? "#6F6F6F" : identity.color
|
|
67
|
+
return (
|
|
68
|
+
<span className={cn("inline-flex items-center gap-2.5 align-middle", className)}>
|
|
69
|
+
<svg
|
|
70
|
+
width={size}
|
|
71
|
+
height={size}
|
|
72
|
+
viewBox="0 0 48 48"
|
|
73
|
+
className="block flex-shrink-0"
|
|
74
|
+
role={label ? "img" : undefined}
|
|
75
|
+
aria-label={label}
|
|
76
|
+
aria-hidden={label ? undefined : true}
|
|
77
|
+
>
|
|
78
|
+
<rect width="48" height="48" fill={ground} />
|
|
79
|
+
<Pictogram product={product} ink={ink} />
|
|
80
|
+
</svg>
|
|
81
|
+
{withCode && size >= 32 && (
|
|
82
|
+
<span
|
|
83
|
+
className="font-mono text-[11px] font-semibold tracking-wider leading-tight px-1.5 py-0.5 border"
|
|
84
|
+
style={{ color: identity.color, borderColor: identity.color }}
|
|
85
|
+
>
|
|
86
|
+
{identity.code}
|
|
87
|
+
</span>
|
|
88
|
+
)}
|
|
89
|
+
</span>
|
|
90
|
+
)
|
|
91
|
+
}
|
package/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './lib/project-requirement'
|
|
|
10
10
|
export * from './lib/env-services'
|
|
11
11
|
export * from './lib/quick-access-href'
|
|
12
12
|
export * from './lib/status-indicator'
|
|
13
|
+
export * from './lib/field-description'
|
|
13
14
|
export { createPlatformConfigSource, templateFilter, configOfHit, environmentWithTargets, type ConfigSource } from './lib/config-source'
|
|
14
15
|
export { default as HttpClient, useHttpClient, ApiError } from './lib/http-client'
|
|
15
16
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The description of a form field, as a form shows it: a summary under the field, and the whole
|
|
3
|
+
* text behind an information icon when it says more than the summary.
|
|
4
|
+
*/
|
|
5
|
+
export interface FieldDescriptionParts {
|
|
6
|
+
summary: string
|
|
7
|
+
/** The whole description, or null when the summary is all of it. */
|
|
8
|
+
detail: string | null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Past this length, a first sentence is cut at its first colon or semicolon. */
|
|
12
|
+
const LONG_SUMMARY = 100
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The summary is the first sentence: a period, a question or an exclamation mark followed by a
|
|
16
|
+
* capital, so that "e.g.", "0.5" or "500Mi." inside a sentence do not end it. A first sentence
|
|
17
|
+
* longer than a line is cut at its first colon or semicolon, when it has one.
|
|
18
|
+
*/
|
|
19
|
+
export function splitDescription(text: string | null | undefined): FieldDescriptionParts {
|
|
20
|
+
const whole = (text ?? "").trim().replace(/\s+/g, " ")
|
|
21
|
+
const sentence = whole.match(/^(.+?[.!?])\s+(?=["'(«`]?[A-Z])/)?.[1] ?? whole
|
|
22
|
+
let summary = sentence
|
|
23
|
+
if (summary.length > LONG_SUMMARY) {
|
|
24
|
+
const cut = summary.search(/[:;]\s/)
|
|
25
|
+
if (cut > 0) summary = summary.slice(0, cut) + "."
|
|
26
|
+
}
|
|
27
|
+
return { summary, detail: summary === whole ? null : whole }
|
|
28
|
+
}
|