@orsetra/shared-ui 1.14.0 → 1.15.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
+ }
@@ -9,6 +9,7 @@ export { Logo } from './logo'
9
9
  export { UserMenu, type UserMenuItem, type UserMenuConfig } from './user-menu'
10
10
  export { Input } from './input'
11
11
  export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from './tooltip'
12
+ export { FieldDescription } from './field-description'
12
13
  export { PageHeader } from './page-header'
13
14
  export { DetailPageHeader, type DetailPageHeaderProps, type DetailPageHeaderTab, type HeaderBreadcrumb } from './detail-page-header'
14
15
  export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, type ChartConfig } from './chart'
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",