rift-ds 1.24.0 → 1.25.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.
Files changed (99) hide show
  1. package/README.md +4 -4
  2. package/chat/ChatWidget.d.ts +5 -1
  3. package/chat/ChatWidget.js +12 -1
  4. package/components/Attachment/Attachment.css +8 -0
  5. package/components/Attachment/AttachmentViewer.js +26 -5
  6. package/components/Attachment/fileTypes.d.ts +4 -0
  7. package/components/CurrencyInput/CurrencyInput.css +12 -0
  8. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  9. package/components/CurrencyInput/CurrencyInput.js +158 -0
  10. package/components/DataTable/columnTypes.js +4 -16
  11. package/components/DatePicker/DatePicker.d.ts +2 -0
  12. package/components/DatePicker/DatePicker.js +44 -131
  13. package/components/DatePicker/MonthGrid.d.ts +56 -0
  14. package/components/DatePicker/MonthGrid.js +65 -0
  15. package/components/DatePicker/calendar.d.ts +42 -0
  16. package/components/DatePicker/calendar.js +108 -0
  17. package/components/DateRangePicker/DateRangePicker.css +92 -0
  18. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  19. package/components/DateRangePicker/DateRangePicker.js +294 -0
  20. package/components/Deadline/Deadline.css +82 -0
  21. package/components/Deadline/Deadline.d.ts +44 -0
  22. package/components/Deadline/Deadline.js +94 -0
  23. package/components/Deadline/deadlineStatus.d.ts +15 -0
  24. package/components/Deadline/deadlineStatus.js +13 -0
  25. package/components/DescriptionList/DescriptionList.css +184 -0
  26. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  27. package/components/DescriptionList/DescriptionList.js +100 -0
  28. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  29. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  30. package/components/DocumentViewer/DocumentViewer.css +188 -0
  31. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  32. package/components/DocumentViewer/DocumentViewer.js +185 -0
  33. package/components/ErrorSummary/ErrorSummary.css +94 -0
  34. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  35. package/components/ErrorSummary/ErrorSummary.js +70 -0
  36. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  37. package/components/ErrorSummary/fieldErrors.js +19 -0
  38. package/components/Field/Field.css +12 -0
  39. package/components/Field/Field.d.ts +10 -2
  40. package/components/Field/Field.js +12 -5
  41. package/components/Heading/Heading.css +129 -0
  42. package/components/Heading/Heading.d.ts +31 -0
  43. package/components/Heading/Heading.js +39 -0
  44. package/components/Input/Input.css +120 -0
  45. package/components/Input/Input.d.ts +20 -1
  46. package/components/Input/Input.js +70 -5
  47. package/components/Link/Link.css +84 -0
  48. package/components/Link/Link.d.ts +43 -0
  49. package/components/Link/Link.js +74 -0
  50. package/components/List/List.css +173 -0
  51. package/components/List/List.d.ts +44 -0
  52. package/components/List/List.js +60 -0
  53. package/components/MaskedInput/MaskedInput.css +16 -0
  54. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  55. package/components/MaskedInput/MaskedInput.js +142 -0
  56. package/components/MaskedInput/mask.d.ts +58 -0
  57. package/components/MaskedInput/mask.js +106 -0
  58. package/components/ShaderScene/ShaderScene.css +19 -0
  59. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  60. package/components/ShaderScene/ShaderScene.js +144 -0
  61. package/components/ShaderScene/assemble.d.ts +5 -0
  62. package/components/ShaderScene/assemble.js +74 -0
  63. package/components/ShaderScene/common.glsl.d.ts +6 -0
  64. package/components/ShaderScene/common.glsl.js +49 -0
  65. package/components/ShaderScene/passes.d.ts +2 -0
  66. package/components/ShaderScene/passes.js +93 -0
  67. package/components/ShaderScene/renderer.d.ts +35 -0
  68. package/components/ShaderScene/renderer.js +125 -0
  69. package/components/ShaderScene/scenes.d.ts +20 -0
  70. package/components/ShaderScene/scenes.js +184 -0
  71. package/components/ShaderScene/types.d.ts +70 -0
  72. package/components/ShaderScene/types.js +8 -0
  73. package/components/SignaturePad/SignaturePad.css +141 -0
  74. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  75. package/components/SignaturePad/SignaturePad.js +287 -0
  76. package/components/SignaturePad/signature.d.ts +32 -0
  77. package/components/SignaturePad/signature.js +46 -0
  78. package/components/Text/Text.css +129 -0
  79. package/components/Text/Text.d.ts +36 -0
  80. package/components/Text/Text.js +36 -0
  81. package/components/Widget/Widget.css +111 -0
  82. package/components/Widget/Widget.d.ts +15 -1
  83. package/components/Widget/Widget.js +63 -11
  84. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  85. package/components/Widget/WidgetDisclosure.js +52 -0
  86. package/components/registry.json +111 -2
  87. package/components/registry.json.d.ts +111 -2
  88. package/components/registry.json.js +2 -2
  89. package/format/index.d.ts +15 -0
  90. package/format/index.js +17 -0
  91. package/format/money.d.ts +89 -0
  92. package/format/money.js +187 -0
  93. package/format/relative.d.ts +49 -0
  94. package/format/relative.js +50 -0
  95. package/index.d.ts +13 -0
  96. package/index.js +46 -0
  97. package/package.json +9 -2
  98. package/tokens/motion.d.ts +4 -0
  99. package/tokens/motion.js +4 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@ An open source React design system built for AI products and coding agents: comp
13
13
 
14
14
  ## Why Rift DS
15
15
 
16
- - **<!-- component-count -->165<!-- /component-count --> components.** Buttons, forms and tables through to charts, navigation and overlays, each typed and documented with live examples. Every one forwards a ref and your own attributes to its element, state you can own works controlled or uncontrolled (a modal opens when your app says so, by design), and every word a component writes has a prop you can localise. The build checks the first two on every component, and the words wherever they sit in markup. React and React DOM are the only required peer dependencies.
16
+ - **<!-- component-count -->178<!-- /component-count --> components.** Buttons, forms and tables through to charts, navigation and overlays, each typed and documented with live examples. Every one forwards a ref and your own attributes to its element, state you can own works controlled or uncontrolled (a modal opens when your app says so, by design), and every word a component writes has a prop you can localise. The build checks the first two on every component, and the words wherever they sit in markup. React and React DOM are the only required peer dependencies.
17
17
  - **AI patterns, the whole chat and templates, ready to use.** Composer, streaming chat thread, tool calls, reasoning and thread panel are in the box, the complete AI chat ships assembled as one widget that one command scaffolds, and the docs site has complete template screens built from them.
18
18
  - **Fully themeable.** The shipped themes are complete looks to start from, each in light and dark. One `data-brand` attribute applies a theme, and a few CSS overrides make your own.
19
19
  - **Ready for coding agents.** One command installs the agent skills, and a public MCP endpoint serves every component's props, so your agent builds with the library as it actually is. No key, no account.
@@ -107,13 +107,13 @@ import 'rift-ds/tokens/presets/presets.css';
107
107
 
108
108
  ## Components
109
109
 
110
- <!-- component-count -->165<!-- /component-count --> components, including a chat set for AI products (Chat thread, Composer, Tool call, Reasoning, Thread panel) and Shader field, a WebGL2 ambient background whose light sources read your colour tokens at runtime, so it re-themes with everything else. Details and live examples are on the [docs site](https://rift-ds.com/components).
110
+ <!-- component-count -->178<!-- /component-count --> components, including a chat set for AI products (Chat thread, Composer, Tool call, Reasoning, Thread panel) and Shader field, a WebGL2 ambient background whose light sources read your colour tokens at runtime, so it re-themes with everything else. Details and live examples are on the [docs site](https://rift-ds.com/components).
111
111
 
112
112
  <details>
113
113
  <summary>The full list</summary>
114
114
 
115
115
  <!-- component-list:start -->
116
- Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Chip · Circular button · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Data table · Date input · Date picker · Dialog · Divider · Document chip · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Event calendar · Field · Figure · File input · Filter bar · Funnel chart · Gantt chart · Gauge · Globe · Hover card · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link list · Map callout · Map legend · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Sidebar panel · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · World map
116
+ Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Chip · Circular button · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Currency input · Data table · Date input · Date picker · Date range picker · Deadline · Description list · Dialog · Divider · Document chip · Document viewer · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Error summary · Event calendar · Field · Figure · File input · Filter bar · Funnel chart · Gantt chart · Gauge · Globe · Heading · Hover card · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link · Link list · List · Map callout · Map legend · Masked input · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Shader scene · Sidebar panel · Signature pad · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Text · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · World map
117
117
  <!-- component-list:end -->
118
118
 
119
119
  </details>
@@ -124,7 +124,7 @@ Accordion · Action card · Action readout · Agent plan · Agent rail · Agent
124
124
  - **Vite 7**: dev server and library build
125
125
  - **Next.js 16**: the documentation site
126
126
  - **Storybook 10**: component explorer
127
- - **Vitest + Playwright + axe**: every Storybook story runs as a render test in headless Chromium, with an accessibility audit on each
127
+ - **Vitest + Playwright + axe**: every Storybook story runs as a render test in headless Chromium, with an accessibility audit on each, and the pure helpers have unit tests in Node
128
128
  - **TanStack Table + TanStack Virtual**: the headless engine and the windowing under `DataTable`, the package's runtime dependencies
129
129
  - **CSS custom properties**: all theming via semantic tokens, no CSS-in-JS
130
130
 
@@ -255,6 +255,10 @@ export interface ChatWidgetProps {
255
255
  composerLabels?: Pick<ComposerProps, 'attachLabel' | 'dropLabel' | 'filesLabel' | 'attachmentTileLabels' | 'stopLabel' | 'aria-label' | 'formatFileAnnouncement' | 'formatMentionAnnouncement'>;
256
256
  /** The drop overlay's headline when a file is dragged over the chat with attachments on, over AttachmentDropZone's "Drop files to attach". Its second line is `attachHint`. */
257
257
  attachmentDropZoneLabels?: Pick<AttachmentDropZoneProps, 'label'>;
258
+ /** Draws a sent file in the viewer its tile opens, in place of the built-in view: a document renderer of the host's own, a spreadsheet. Return nothing to keep the built-in view, which shows pictures, pasted text, and a PDF or a text file that carries a `fileUrl`. */
259
+ renderAttachmentPreview?: AttachmentGroupProps['renderPreview'];
260
+ /** Called with a sent file when the viewer's Download is pressed. Its presence renders the button. */
261
+ onAttachmentDownload?: AttachmentGroupProps['onDownload'];
258
262
  /** The words of the files on a sent message, over AttachmentGroup's English defaults: the list's name ("Attachments"), the overflow buttons ("Show 3 more", "Show fewer"), the tiles' status lines (`attachmentTileLabels`) and the viewer a pressed file opens in (`attachmentViewerLabels`). */
259
263
  attachmentGroupLabels?: Pick<AttachmentGroupProps, 'label' | 'showMoreLabel' | 'showLessLabel' | 'attachmentTileLabels' | 'attachmentViewerLabels'>;
260
264
  /** The conversation's names, over ChatThread's English defaults: the scrolling region ("Conversation") and the scroll-to-latest control ("Scroll to the latest message"). */
@@ -282,4 +286,4 @@ export interface ChatWidgetProps {
282
286
  * a stage card, a whole page). It reads all of its state from ChatProvider,
283
287
  * so the conversation is the same object wherever it shows.
284
288
  */
285
- export declare function ChatWidget({ fullscreenEnabled, layout, backdrop, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, startersPending, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, context: contextProp, contextClearLabel, contextLabel, contextNote, contextPlacement, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
289
+ export declare function ChatWidget({ fullscreenEnabled, layout, backdrop, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, startersPending, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, context: contextProp, contextClearLabel, contextLabel, contextNote, contextPlacement, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, renderAttachmentPreview, onAttachmentDownload, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
@@ -120,6 +120,8 @@ function ChatWidget({
120
120
  composerLabels,
121
121
  attachmentDropZoneLabels,
122
122
  attachmentGroupLabels,
123
+ renderAttachmentPreview,
124
+ onAttachmentDownload,
123
125
  chatThreadLabels,
124
126
  modelPickerLabels,
125
127
  artifactPanelLabels,
@@ -642,7 +644,16 @@ function ChatWidget({
642
644
  ChatMessage,
643
645
  {
644
646
  role: "user",
645
- attachments: turn.attachments ? /* @__PURE__ */ jsx(AttachmentGroup, { ...attachmentGroupLabels, align: "end", items: turn.attachments }) : /* @__PURE__ */ jsxs(Fragment, { children: [
647
+ attachments: turn.attachments ? /* @__PURE__ */ jsx(
648
+ AttachmentGroup,
649
+ {
650
+ ...attachmentGroupLabels,
651
+ align: "end",
652
+ items: turn.attachments,
653
+ renderPreview: renderAttachmentPreview,
654
+ onDownload: onAttachmentDownload
655
+ }
656
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
646
657
  turn.content,
647
658
  turnCards(turn).map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index))
648
659
  ] }),
@@ -812,6 +812,14 @@ button.ds-attachment-group__single:focus-visible {
812
812
  background-size: 26px 26px;
813
813
  }
814
814
 
815
+ .ds-attachment-viewer__document {
816
+ align-self: stretch;
817
+ flex: 1 1 auto;
818
+ min-width: 0;
819
+ border-radius: var(--radius-200);
820
+ background-color: var(--color-bg-container-primary);
821
+ }
822
+
815
823
  .ds-attachment-viewer__image {
816
824
  display: block;
817
825
  max-width: 100%;
@@ -5,6 +5,7 @@ import ReactDOM from "react-dom";
5
5
  import { Button } from "../Button/Button.js";
6
6
  import { CircularButton } from "../CircularButton/CircularButton.js";
7
7
  import { formatBytes } from "./fileTypes.js";
8
+ import { DocumentViewer } from "../DocumentViewer/DocumentViewer.js";
8
9
  import { renderTypeMark } from "./typeMark.js";
9
10
  import { useMounted } from "../../behaviors/useMounted.js";
10
11
  import { useLayer } from "../../behaviors/useLayer.js";
@@ -80,10 +81,15 @@ const AttachmentViewer = React.forwardRef(
80
81
  if (item) {
81
82
  const failed = item.status === "error" || item.status === "unavailable";
82
83
  const custom = failed ? void 0 : renderPreview?.(item);
83
- const imageSrc = item.src ?? item.previewSrc;
84
- if (custom !== void 0 && custom !== null && custom !== false) {
84
+ const imageSrc = item.src ?? item.previewSrc ?? (item.kind === "image" ? item.fileUrl : void 0);
85
+ const documentKind = item.kind === "pdf" || item.kind === "text" || item.kind === "code";
86
+ const showDocument = !failed && documentKind && Boolean(item.fileUrl);
87
+ const hasCustom = custom !== void 0 && custom !== null && custom !== false;
88
+ let emptyStage = null;
89
+ if (hasCustom) {
85
90
  stage = custom;
86
- } else if (!failed && imageSrc) {
91
+ } else if (showDocument) ;
92
+ else if (!failed && imageSrc) {
87
93
  stage = /* @__PURE__ */ jsx(
88
94
  "img",
89
95
  {
@@ -94,8 +100,9 @@ const AttachmentViewer = React.forwardRef(
94
100
  );
95
101
  } else if (!failed && item.excerpt) {
96
102
  stage = /* @__PURE__ */ jsx("p", { className: `${baseClass}__text`, children: item.excerpt });
97
- } else {
98
- stage = /* @__PURE__ */ jsxs("div", { className: `${baseClass}__empty`, children: [
103
+ }
104
+ if (!hasCustom && stage === null) {
105
+ emptyStage = /* @__PURE__ */ jsxs("div", { className: `${baseClass}__empty`, children: [
99
106
  /* @__PURE__ */ jsx("span", { className: `${baseClass}__empty-mark`, children: renderTypeMark(item.name, item.kind, { typeLabel: item.typeLabel }) }),
100
107
  /* @__PURE__ */ jsx("p", { className: `${baseClass}__empty-title`, children: failed ? failedLabel : noPreviewLabel }),
101
108
  /* @__PURE__ */ jsx("p", { className: `${baseClass}__empty-detail`, children: failed ? item.error ?? failedDescription : [item.name, sizeText].filter(Boolean).join(" · ") }),
@@ -121,6 +128,20 @@ const AttachmentViewer = React.forwardRef(
121
128
  )
122
129
  ] })
123
130
  ] });
131
+ stage = showDocument ? /* @__PURE__ */ jsx(
132
+ DocumentViewer,
133
+ {
134
+ className: `${baseClass}__document`,
135
+ bare: true,
136
+ src: item.fileUrl ?? "",
137
+ title: item.name,
138
+ fileName: item.name,
139
+ mimeType: item.mimeType,
140
+ download: false,
141
+ openInNewTab: false,
142
+ fallback: emptyStage
143
+ }
144
+ ) : emptyStage;
124
145
  }
125
146
  }
126
147
  const viewer = /* @__PURE__ */ jsxs("div", { className: containerClasses, children: [
@@ -102,6 +102,10 @@ export interface AttachmentItem {
102
102
  /** Full-size image for the viewer, when the preview is a thumbnail.
103
103
  Defaults to `previewSrc`. */
104
104
  src?: string;
105
+ /** The file itself, for the viewer to show a PDF or a text file in place
106
+ (through DocumentViewer) and for a picture with no `src`. Distinct
107
+ from `src`, which is always an image. */
108
+ fileUrl?: string;
105
109
  /** Intrinsic width of the preview, to reserve its shape before it loads. */
106
110
  width?: number;
107
111
  /** Intrinsic height of the preview. */
@@ -0,0 +1,12 @@
1
+ /* ============================================
2
+ CURRENCY INPUT
3
+ An Input with the currency as its prefix or
4
+ suffix; the field itself, its affixes and its
5
+ states are Input's. The amount sets in tabular
6
+ figures, so the digits hold still as they are
7
+ grouped on blur.
8
+ ============================================ */
9
+
10
+ .ds-currency-input .ds-input__field {
11
+ font-variant-numeric: tabular-nums;
12
+ }
@@ -0,0 +1,51 @@
1
+ import { default as React } from 'react';
2
+ import { DecimalString } from '../../format/money';
3
+ /** Props owned by CurrencyInput itself; everything else falls through to the visible `<input>`. */
4
+ type CurrencyInputOwnProps = {
5
+ /** Label text above the field. */
6
+ label?: string;
7
+ /** The amount as a decimal string (`"1234.50"`), or `null` for none (controlled). Pair with `onValueChange`. */
8
+ value?: DecimalString | null;
9
+ /** The amount the field starts with (uncontrolled). */
10
+ defaultValue?: DecimalString | null;
11
+ /** Called with the amount as a normalised decimal string as the reader types, or `null` while the field holds no number. Fires alongside the native `onChange`. */
12
+ onValueChange?: (value: DecimalString | null) => void;
13
+ /** The ISO 4217 code of the currency, such as `USD`, `EUR` or `JPY`. Defaults to `USD`. */
14
+ currency?: string;
15
+ /** How the currency shows inside the field: its symbol, its code, or nothing (when the label already says it). The side it sits on follows the locale. */
16
+ currencyDisplay?: 'symbol' | 'code' | 'none';
17
+ /** Digits after the point. Defaults to the currency's own: 0 for JPY, 2 for USD, 3 for KWD. */
18
+ fractionDigits?: number;
19
+ /** Accept a negative amount (a refund, an adjustment). Defaults to false. */
20
+ allowNegative?: boolean;
21
+ /** The smallest amount, as a decimal string. A value below it is raised to it when the field loses focus. */
22
+ min?: DecimalString;
23
+ /** The largest amount, as a decimal string. A value above it is lowered to it when the field loses focus. */
24
+ max?: DecimalString;
25
+ /** How much the Up and Down arrow keys add or take away, as a decimal string. Defaults to `"1"`. */
26
+ step?: DecimalString;
27
+ /** The BCP 47 locale the amount is read and written in, such as `de-DE`. Defaults to the nearest LocaleProvider's, else `en-US`. */
28
+ locale?: string;
29
+ /** Component size (not the native character-width `size` attribute). */
30
+ size?: 'default' | 'compact';
31
+ /** Helper text below the field. */
32
+ helperText?: string;
33
+ /** The error message under the field; setting it marks the field invalid. */
34
+ errorText?: React.ReactNode;
35
+ /** Error state without a message of its own. */
36
+ error?: boolean;
37
+ /** The form field name. The form receives the normalised decimal string through a hidden input, never the formatted text. */
38
+ name?: string;
39
+ /** Additional CSS classes, applied to the wrapper. */
40
+ className?: string;
41
+ };
42
+ export interface CurrencyInputProps extends CurrencyInputOwnProps, Omit<React.ComponentPropsWithRef<'input'>, keyof CurrencyInputOwnProps | 'type' | 'prefix'> {
43
+ }
44
+ /**
45
+ * An amount of money. The value is a decimal string, never a float, so a
46
+ * cent is never lost; the field reads the locale's own marks and a pasted
47
+ * amount in any convention, groups the digits once the reader moves on, and
48
+ * places the currency where the locale writes it.
49
+ */
50
+ export declare function CurrencyInput({ label, value: valueProp, defaultValue, onValueChange, currency, currencyDisplay, fractionDigits, allowNegative, min, max, step, locale: localeProp, size, helperText, errorText, error, name, disabled, className, onChange, onFocus, onBlur, onKeyDown, onPaste, ref, ...rest }: CurrencyInputProps): React.JSX.Element;
51
+ export {};
@@ -0,0 +1,158 @@
1
+ "use client";
2
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
3
+ import { useState, useMemo, useRef, useEffect } from "react";
4
+ import { Input } from "../Input/Input.js";
5
+ import { useLocale } from "../../behaviors/LocaleProvider.js";
6
+ import { currencyFractionDigits, addDecimal, subtractDecimal, compareDecimal, parseDecimal } from "../../format/money.js";
7
+ import "./CurrencyInput.css";
8
+ function affixFor(currency, locale, display) {
9
+ if (display === "none") return null;
10
+ const parts = new Intl.NumberFormat(locale, { style: "currency", currency, currencyDisplay: display }).formatToParts(1);
11
+ const at = parts.findIndex((p) => p.type === "currency");
12
+ if (at === -1) return null;
13
+ const firstNumber = parts.findIndex((p) => p.type === "integer");
14
+ return { text: parts[at].value, side: at < firstNumber ? "prefix" : "suffix" };
15
+ }
16
+ const decimalMarkOf = (locale) => new Intl.NumberFormat(locale).formatToParts(1.5).find((p) => p.type === "decimal")?.value ?? ".";
17
+ const editingText = (value, locale) => value == null ? "" : value.replace(".", decimalMarkOf(locale)).replace("-", "−");
18
+ function restingText(value, locale, digits) {
19
+ if (value == null) return "";
20
+ const format = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits });
21
+ return format.format(value);
22
+ }
23
+ const TYPABLE = /^[\p{Nd}.,'’\s٫٬\-−]*$/u;
24
+ function CurrencyInput({
25
+ label,
26
+ value: valueProp,
27
+ defaultValue = null,
28
+ onValueChange,
29
+ currency = "USD",
30
+ currencyDisplay = "symbol",
31
+ fractionDigits,
32
+ allowNegative = false,
33
+ min,
34
+ max,
35
+ step = "1",
36
+ locale: localeProp,
37
+ size = "default",
38
+ helperText,
39
+ errorText,
40
+ error,
41
+ name,
42
+ disabled,
43
+ className = "",
44
+ onChange,
45
+ onFocus,
46
+ onBlur,
47
+ onKeyDown,
48
+ onPaste,
49
+ ref,
50
+ ...rest
51
+ }) {
52
+ const locale = useLocale(localeProp);
53
+ const digits = fractionDigits ?? currencyFractionDigits(currency);
54
+ const controlled = valueProp !== void 0;
55
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
56
+ const value = controlled ? valueProp : uncontrolled;
57
+ const [focused, setFocused] = useState(false);
58
+ const [text, setText] = useState(() => restingText(value, locale, digits));
59
+ const affix = useMemo(() => affixFor(currency, locale, currencyDisplay), [currency, locale, currencyDisplay]);
60
+ const lastEmitted = useRef(value);
61
+ useEffect(() => {
62
+ if (!focused) setText(restingText(value, locale, digits));
63
+ else if (value !== lastEmitted.current) setText(editingText(value, locale));
64
+ lastEmitted.current = value;
65
+ }, [value, locale, digits]);
66
+ const clamp = (amount) => {
67
+ if (amount == null) return null;
68
+ let next = amount;
69
+ if (!allowNegative && compareDecimal(next, "0") < 0) next = "0";
70
+ if (min !== void 0 && compareDecimal(next, min) < 0) next = min;
71
+ if (max !== void 0 && compareDecimal(next, max) > 0) next = max;
72
+ return parseDecimal(next, { fractionDigits: digits });
73
+ };
74
+ const commit = (amount) => {
75
+ lastEmitted.current = amount;
76
+ if (!controlled) setUncontrolled(amount);
77
+ onValueChange?.(amount);
78
+ };
79
+ const read = (raw) => {
80
+ const parsed = parseDecimal(raw, { locale });
81
+ if (parsed == null) return null;
82
+ return !allowNegative && compareDecimal(parsed, "0") < 0 ? parsed.replace("-", "") : parsed;
83
+ };
84
+ const handleChange = (event) => {
85
+ const raw = event.target.value;
86
+ if (!TYPABLE.test(raw)) return;
87
+ if (!allowNegative && /[-−]/.test(raw)) return;
88
+ setText(raw);
89
+ onChange?.(event);
90
+ const parsed = read(raw);
91
+ if (parsed !== value) commit(parsed);
92
+ };
93
+ const handlePaste = (event) => {
94
+ onPaste?.(event);
95
+ if (event.defaultPrevented) return;
96
+ const pasted = event.clipboardData.getData("text");
97
+ if (TYPABLE.test(pasted)) return;
98
+ event.preventDefault();
99
+ const parsed = read(pasted);
100
+ if (parsed == null) return;
101
+ setText(editingText(parsed, locale));
102
+ commit(parsed);
103
+ };
104
+ const handleFocus = (event) => {
105
+ setFocused(true);
106
+ setText(editingText(value, locale));
107
+ onFocus?.(event);
108
+ };
109
+ const handleBlur = (event) => {
110
+ setFocused(false);
111
+ const settled = clamp(value);
112
+ if (settled !== value) commit(settled);
113
+ setText(restingText(settled, locale, digits));
114
+ onBlur?.(event);
115
+ };
116
+ const handleKeyDown = (event) => {
117
+ onKeyDown?.(event);
118
+ if (event.defaultPrevented || event.key !== "ArrowUp" && event.key !== "ArrowDown") return;
119
+ event.preventDefault();
120
+ const base = value ?? "0";
121
+ const next = clamp(event.key === "ArrowUp" ? addDecimal(base, step) : subtractDecimal(base, step));
122
+ if (next === value) return;
123
+ commit(next);
124
+ setText(editingText(next, locale));
125
+ };
126
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
127
+ /* @__PURE__ */ jsx(
128
+ Input,
129
+ {
130
+ ...rest,
131
+ id: rest.id ?? name,
132
+ ref,
133
+ className: ["ds-currency-input", className].filter(Boolean).join(" "),
134
+ label,
135
+ size,
136
+ type: "text",
137
+ inputMode: "decimal",
138
+ autoComplete: rest.autoComplete ?? "off",
139
+ value: text,
140
+ disabled,
141
+ error,
142
+ helperText,
143
+ errorText,
144
+ prefix: affix?.side === "prefix" ? affix.text : void 0,
145
+ suffix: affix?.side === "suffix" ? affix.text : void 0,
146
+ onChange: handleChange,
147
+ onPaste: handlePaste,
148
+ onFocus: handleFocus,
149
+ onBlur: handleBlur,
150
+ onKeyDown: handleKeyDown
151
+ }
152
+ ),
153
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value ?? "", disabled })
154
+ ] });
155
+ }
156
+ export {
157
+ CurrencyInput
158
+ };
@@ -1,3 +1,5 @@
1
+ import { formatMoney } from "../../format/money.js";
2
+ import { formatRelative } from "../../format/relative.js";
1
3
  const TYPE_DEFAULTS = {
2
4
  text: { align: "start", filter: "text", editor: "text" },
3
5
  number: { align: "end", filter: "number", editor: "number" },
@@ -21,26 +23,12 @@ const absoluteDate = (date, format, style) => new Intl.DateTimeFormat(format?.lo
21
23
  dateStyle: style ?? (format?.date && format.date !== "relative" ? format.date : "medium"),
22
24
  timeZone: "UTC"
23
25
  }).format(date);
24
- const MS_PER_DAY = 864e5;
25
- const relativeDate = (date, format, now) => {
26
- const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
27
- const days = Math.round((date.getTime() - today) / MS_PER_DAY);
28
- const rtf = new Intl.RelativeTimeFormat(format?.locale ?? DEFAULT_LOCALE, { numeric: "auto" });
29
- if (Math.abs(days) < 7) return rtf.format(days, "day");
30
- if (Math.abs(days) < 30) return rtf.format(Math.round(days / 7), "week");
31
- if (Math.abs(days) < 365) return rtf.format(Math.round(days / 30), "month");
32
- return rtf.format(Math.round(days / 365), "year");
33
- };
26
+ const relativeDate = (date, format, now) => formatRelative(date, { now, locale: format?.locale ?? DEFAULT_LOCALE, minUnit: "day" });
34
27
  const formatNumber = (type, value, format) => {
35
28
  const locale = format?.locale ?? DEFAULT_LOCALE;
36
29
  const digits = format?.fractionDigits;
37
30
  if (type === "currency")
38
- return new Intl.NumberFormat(locale, {
39
- style: "currency",
40
- currency: format?.currency ?? "USD",
41
- minimumFractionDigits: digits ?? 0,
42
- maximumFractionDigits: digits ?? 0
43
- }).format(value);
31
+ return formatMoney(value, { currency: format?.currency ?? "USD", locale, fractionDigits: digits ?? 0 });
44
32
  if (type === "progress")
45
33
  return new Intl.NumberFormat(locale, {
46
34
  style: "percent",
@@ -14,6 +14,8 @@ type DatePickerOwnProps = {
14
14
  max?: string;
15
15
  /** Callback when a date is selected */
16
16
  onDateSelect?: (date: string) => void;
17
+ /** Mark further days unavailable, beyond `min` and `max`: weekends, holidays, booked days. Given each day as a `YYYY-MM-DD` string; focus skips past none of them, but none can be chosen. */
18
+ isDateDisabled?: (date: string) => boolean;
17
19
  /** Accessible name of the previous-month button. */
18
20
  previousLabel?: string;
19
21
  /** Accessible name of the next-month button. */