@multiplatform.one/forms 7.55.0 → 7.57.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 (45) hide show
  1. package/dist/cjs/DescriptionList/index.cjs +216 -54
  2. package/dist/cjs/DescriptionList/index.native.js +226 -57
  3. package/dist/cjs/DescriptionList/index.native.js.map +1 -1
  4. package/dist/cjs/FieldDisplay/index.cjs +8 -2
  5. package/dist/cjs/FieldDisplay/index.native.js +8 -2
  6. package/dist/cjs/FieldDisplay/index.native.js.map +1 -1
  7. package/dist/cjs/fields/Switch/index.cjs +13 -0
  8. package/dist/cjs/fields/Switch/index.native.js +13 -0
  9. package/dist/cjs/fields/Switch/index.native.js.map +1 -1
  10. package/dist/esm/DescriptionList/index.mjs +217 -56
  11. package/dist/esm/DescriptionList/index.mjs.map +1 -1
  12. package/dist/esm/DescriptionList/index.native.js +227 -59
  13. package/dist/esm/DescriptionList/index.native.js.map +1 -1
  14. package/dist/esm/FieldDisplay/index.mjs +8 -2
  15. package/dist/esm/FieldDisplay/index.mjs.map +1 -1
  16. package/dist/esm/FieldDisplay/index.native.js +8 -2
  17. package/dist/esm/FieldDisplay/index.native.js.map +1 -1
  18. package/dist/esm/fields/Switch/index.mjs +13 -0
  19. package/dist/esm/fields/Switch/index.mjs.map +1 -1
  20. package/dist/esm/fields/Switch/index.native.js +13 -0
  21. package/dist/esm/fields/Switch/index.native.js.map +1 -1
  22. package/dist/jsx/DescriptionList/index.mjs +217 -56
  23. package/dist/jsx/DescriptionList/index.mjs.map +1 -1
  24. package/dist/jsx/DescriptionList/index.native.js +226 -57
  25. package/dist/jsx/DescriptionList/index.native.js.map +1 -1
  26. package/dist/jsx/FieldDisplay/index.mjs +8 -2
  27. package/dist/jsx/FieldDisplay/index.mjs.map +1 -1
  28. package/dist/jsx/FieldDisplay/index.native.js +8 -2
  29. package/dist/jsx/FieldDisplay/index.native.js.map +1 -1
  30. package/dist/jsx/fields/Switch/index.mjs +13 -0
  31. package/dist/jsx/fields/Switch/index.mjs.map +1 -1
  32. package/dist/jsx/fields/Switch/index.native.js +13 -0
  33. package/dist/jsx/fields/Switch/index.native.js.map +1 -1
  34. package/package.json +8 -8
  35. package/src/DescriptionList/DescriptionList.secondaryInk.spec.tsx +49 -0
  36. package/src/DescriptionList/DescriptionList.spec.tsx +87 -1
  37. package/src/DescriptionList/index.tsx +235 -81
  38. package/src/FieldDisplay/index.tsx +4 -2
  39. package/src/fields/Switch/Switch.spec.tsx +21 -0
  40. package/src/fields/Switch/index.tsx +20 -0
  41. package/types/DescriptionList/index.d.ts +27 -4
  42. package/types/DescriptionList/index.d.ts.map +1 -1
  43. package/types/FieldDisplay/index.d.ts.map +1 -1
  44. package/types/fields/Switch/index.d.ts +7 -1
  45. package/types/fields/Switch/index.d.ts.map +1 -1
@@ -24,11 +24,14 @@ var DescriptionList_exports = {};
24
24
  __export(DescriptionList_exports, {
25
25
  DescriptionList: () => DescriptionList,
26
26
  DescriptionListRow: () => DescriptionListRow,
27
- PropertyList: () => PropertyList
27
+ PropertyList: () => PropertyList,
28
+ middleSplit: () => middleSplit
28
29
  });
29
30
  module.exports = __toCommonJS(DescriptionList_exports);
30
31
  var import_react = require("react");
32
+ var import_platform = require("@multiplatform.one/platform");
31
33
  var import_theme = require("@multiplatform.one/theme");
34
+ var import_react2 = require("@phosphor-icons/react");
32
35
  var import_tamagui = require("tamagui");
33
36
  var import_Button = require("../Button/index.cjs");
34
37
  var import_FormGrid = require("../FormGrid.cjs");
@@ -59,7 +62,7 @@ function listItemRhythm(sizeToken) {
59
62
  };
60
63
  }
61
64
  function resolvePlacement(prop, knobPlacement) {
62
- if (prop === "side" || prop === "top") return prop;
65
+ if (prop === "side" || prop === "top" || prop === "inline") return prop;
63
66
  if (knobPlacement === "top" || knobPlacement === "side") {
64
67
  return knobPlacement;
65
68
  }
@@ -99,17 +102,19 @@ function ListRule({
99
102
  });
100
103
  }
101
104
  function TermText({
102
- children
105
+ children,
106
+ inline = false
103
107
  }) {
104
108
  const {
105
109
  knobProps
106
110
  } = (0, import_theme.useResolvedKnobs)();
107
111
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
108
112
  "data-mpo-description-list-term": "",
109
- fontSize: 14,
110
- lineHeight: 25,
111
- ...knobProps.body,
112
- color: "$color11",
113
+ ...(inline ? {
114
+ ...knobProps.body,
115
+ ...knobProps.label,
116
+ color: "$textMuted"
117
+ } : knobProps.textRole.label),
113
118
  minWidth: 0,
114
119
  ...(import_tamagui.isWeb ? {
115
120
  style: {
@@ -119,6 +124,41 @@ function TermText({
119
124
  children
120
125
  });
121
126
  }
127
+ function TermLead({
128
+ row,
129
+ inline = false
130
+ }) {
131
+ const {
132
+ knobProps
133
+ } = (0, import_theme.useResolvedKnobs)();
134
+ const ink = (0, import_theme.useGlyphColor)("$textMuted");
135
+ if (row.icon == null) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermText, {
136
+ inline,
137
+ children: row.term
138
+ });
139
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
140
+ alignItems: "center",
141
+ minWidth: 0,
142
+ ...knobProps.gapSm,
143
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
144
+ "aria-hidden": true,
145
+ flexShrink: 0,
146
+ ...(import_tamagui.isWeb && ink ? {
147
+ style: {
148
+ color: ink
149
+ }
150
+ } : {}),
151
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_theme.IconSlot, {
152
+ icon: row.icon,
153
+ color: ink,
154
+ size: 16
155
+ })
156
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermText, {
157
+ inline,
158
+ children: row.term
159
+ })]
160
+ });
161
+ }
122
162
  function ChangeAction({
123
163
  onChange,
124
164
  label
@@ -135,27 +175,118 @@ function ChangeAction({
135
175
  })
136
176
  });
137
177
  }
178
+ function middleSplit(text) {
179
+ if (text.length <= 24) return [text, ""];
180
+ let start = text.length - 12;
181
+ let from = text.length - 2;
182
+ for (;;) {
183
+ const slash = text.lastIndexOf("/", from);
184
+ if (slash <= 0 || text.length - slash > 20) break;
185
+ start = slash;
186
+ from = slash - 1;
187
+ }
188
+ return [text.slice(0, start), text.slice(start)];
189
+ }
190
+ const CopyResultContext = (0, import_react.createContext)(void 0);
191
+ function IdentifierValue({
192
+ text
193
+ }) {
194
+ const onCopyResult = (0, import_react.useContext)(CopyResultContext);
195
+ const {
196
+ knobProps
197
+ } = (0, import_theme.useResolvedKnobs)();
198
+ const [head, tail] = middleSplit(text);
199
+ const ink = {
200
+ ...knobProps.body,
201
+ fontFamily: "$mono",
202
+ color: "$color"
203
+ };
204
+ const copy = async () => {
205
+ const ok = await (0, import_platform.writeToClipboard)(text);
206
+ onCopyResult?.(ok);
207
+ };
208
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
209
+ "data-mpo-description-list-identifier": "",
210
+ alignItems: "center",
211
+ minWidth: 0,
212
+ width: "100%",
213
+ ...knobProps.gapSm,
214
+ children: [import_tamagui.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
215
+ flex: 1,
216
+ minWidth: 0,
217
+ ...{
218
+ title: text
219
+ },
220
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
221
+ ...ink,
222
+ numberOfLines: 1,
223
+ flexShrink: 1,
224
+ minWidth: 0,
225
+ children: head
226
+ }), tail ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
227
+ ...ink,
228
+ numberOfLines: 1,
229
+ flexShrink: 0,
230
+ children: tail
231
+ }) : null]
232
+ }) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
233
+ ...ink,
234
+ flex: 1,
235
+ minWidth: 0,
236
+ numberOfLines: 1,
237
+ ellipsizeMode: "middle",
238
+ children: text
239
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Button.Button, {
240
+ nested: true,
241
+ chromeless: true,
242
+ circular: true,
243
+ flexShrink: 0,
244
+ icon: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react2.CopyIcon, {}),
245
+ "aria-label": (0, import_t.t)("Copy to clipboard"),
246
+ onPress: () => void copy()
247
+ })]
248
+ });
249
+ }
138
250
  function ValueSlot({
139
- row
251
+ row,
252
+ trailing = false
140
253
  }) {
141
254
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
142
255
  "data-mpo-description-list-value": "",
143
256
  minWidth: 0,
144
257
  width: "100%",
145
- children: row.children != null ? row.children : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_FieldDisplay.FieldDisplay, {
146
- field: row.field ?? "input",
147
- value: row.value,
148
- fieldProps: row.fieldProps,
149
- linkedValue: row.linkedValue,
150
- chromeless: true,
151
- align: "left",
152
- truncate: row.truncate
258
+ children: row.children != null ? trailing ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
259
+ justifyContent: "flex-end",
260
+ alignItems: "center",
261
+ minWidth: 0,
262
+ width: "100%",
263
+ children: row.children
264
+ }) : row.children : row.identifier && row.value != null && row.value !== "" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(IdentifierValue, {
265
+ text: String(row.value)
266
+ }) :
267
+ // FieldDisplay grows on flex 1 from a zero basis; in a column with no
268
+ // height of its own that collapsed it to 0 and the next rule ran
269
+ // through the value. A row lets it grow across and keep its height.
270
+ /* @__PURE__ */
271
+ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
272
+ minWidth: 0,
273
+ width: "100%",
274
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_FieldDisplay.FieldDisplay, {
275
+ field: row.field ?? "input",
276
+ value: row.value,
277
+ fieldProps: row.fieldProps,
278
+ linkedValue: row.linkedValue,
279
+ chromeless: true,
280
+ align: trailing ? "right" : "left",
281
+ truncate: trailing || row.truncate
282
+ })
153
283
  })
154
284
  });
155
285
  }
156
286
  function DescriptionListRowView({
157
287
  row,
158
288
  stacked,
289
+ inline = false,
159
290
  hasActionColumn,
160
291
  rhythm,
161
292
  showRule,
@@ -167,7 +298,8 @@ function DescriptionListRowView({
167
298
  }) : hasActionColumn && import_tamagui.isWeb && !stacked ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
168
299
  "data-mpo-description-list-action": ""
169
300
  }) : null;
170
- const rowStyle = import_tamagui.isWeb ? stacked ? {
301
+ const oneLine = inline && !row.identifier;
302
+ const rowStyle = oneLine ? void 0 : import_tamagui.isWeb ? stacked ? {
171
303
  display: "grid",
172
304
  gridTemplateColumns: hasActionColumn ? "minmax(0,1fr) max-content" : "minmax(0,1fr)",
173
305
  columnGap: void 0,
@@ -192,11 +324,32 @@ function DescriptionListRowView({
192
324
  } : {
193
325
  justifySelf: "end"
194
326
  } : void 0;
195
- const body = stacked ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
327
+ const body = oneLine ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
328
+ alignItems: "center",
329
+ width: "100%",
330
+ minWidth: 0,
331
+ gap: rhythm.columnGap,
332
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
333
+ flexShrink: 0,
334
+ maxWidth: "60%",
335
+ minWidth: 0,
336
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermLead, {
337
+ row,
338
+ inline: true
339
+ })
340
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
341
+ flex: 1,
342
+ minWidth: 0,
343
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ValueSlot, {
344
+ row,
345
+ trailing: true
346
+ })
347
+ }), action]
348
+ }) : stacked ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
196
349
  children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
197
350
  style: termStyle,
198
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermText, {
199
- children: row.term
351
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermLead, {
352
+ row
200
353
  })
201
354
  }), action ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
202
355
  style: actionStyle,
@@ -211,8 +364,8 @@ function DescriptionListRowView({
211
364
  }) : import_tamagui.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
212
365
  children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
213
366
  style: termStyle,
214
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermText, {
215
- children: row.term
367
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermLead, {
368
+ row
216
369
  })
217
370
  }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
218
371
  style: valueStyle,
@@ -232,8 +385,8 @@ function DescriptionListRowView({
232
385
  maxWidth: `${purposeMaxCh()}ch`,
233
386
  flexShrink: 0,
234
387
  width: `${purposeMaxCh()}ch`,
235
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermText, {
236
- children: row.term
388
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TermLead, {
389
+ row
237
390
  })
238
391
  }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
239
392
  flex: 1,
@@ -262,6 +415,7 @@ function DescriptionListRowView({
262
415
  function DescriptionListWeb({
263
416
  rows,
264
417
  stacked,
418
+ inline,
265
419
  hasAction,
266
420
  rhythm,
267
421
  quiet,
@@ -305,6 +459,7 @@ function DescriptionListWeb({
305
459
  children: rows.map((row, index) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionListRowView, {
306
460
  row,
307
461
  stacked,
462
+ inline,
308
463
  hasActionColumn: hasAction,
309
464
  rhythm,
310
465
  showRule: index > 0,
@@ -356,6 +511,7 @@ function DescriptionList({
356
511
  maxWidth = import_formSpacing.formReadableMaxWidth,
357
512
  labelColumnWidth = import_fieldDefaults.LABEL_COLUMN_WIDTH,
358
513
  size,
514
+ onCopyResult,
359
515
  testID
360
516
  }) {
361
517
  const {
@@ -377,38 +533,44 @@ function DescriptionList({
377
533
  wide,
378
534
  onLayout
379
535
  } = useContainerWide(measureCollapse);
380
- const stacked = placement === "top" || placement === "side" && !wide;
381
- const list = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_FieldDisplay.DescriptionListSlotProvider, {
382
- children: import_tamagui.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionListWeb, {
383
- rows,
384
- stacked,
385
- hasAction,
386
- rhythm,
387
- quiet,
388
- labelColumnWidth,
389
- sizeToken: knobProps.sizeToken,
390
- placement,
391
- framed
392
- }) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
393
- "data-mpo-description-list": "",
394
- "data-placement": placement,
395
- "data-stacked": stacked ? "true" : "false",
396
- "data-rhythm": rhythm.tight ? "tight" : "regular",
397
- "data-framed": framed ? "true" : "false",
398
- "data-quiet": quiet ? "true" : "false",
399
- "data-has-action": hasAction ? "true" : "false",
400
- "data-label-column-width": labelColumnWidth,
401
- "data-size-token": knobProps.sizeToken,
402
- width: "100%",
403
- minWidth: 0,
404
- children: rows.map((row, index) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionListRowView, {
405
- row,
536
+ const inline = placement === "inline";
537
+ const stacked = placement === "top" || inline || placement === "side" && !wide;
538
+ const list = /* @__PURE__ */(0, import_jsx_runtime.jsx)(CopyResultContext.Provider, {
539
+ value: onCopyResult,
540
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_FieldDisplay.DescriptionListSlotProvider, {
541
+ children: import_tamagui.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionListWeb, {
542
+ rows,
406
543
  stacked,
407
- hasActionColumn: hasAction,
544
+ inline,
545
+ hasAction,
408
546
  rhythm,
409
- showRule: index > 0,
410
- quiet
411
- }, index))
547
+ quiet,
548
+ labelColumnWidth,
549
+ sizeToken: knobProps.sizeToken,
550
+ placement,
551
+ framed
552
+ }) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
553
+ "data-mpo-description-list": "",
554
+ "data-placement": placement,
555
+ "data-stacked": stacked ? "true" : "false",
556
+ "data-rhythm": rhythm.tight ? "tight" : "regular",
557
+ "data-framed": framed ? "true" : "false",
558
+ "data-quiet": quiet ? "true" : "false",
559
+ "data-has-action": hasAction ? "true" : "false",
560
+ "data-label-column-width": labelColumnWidth,
561
+ "data-size-token": knobProps.sizeToken,
562
+ width: "100%",
563
+ minWidth: 0,
564
+ children: rows.map((row, index) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(DescriptionListRowView, {
565
+ row,
566
+ stacked,
567
+ inline,
568
+ hasActionColumn: hasAction,
569
+ rhythm,
570
+ showRule: index > 0,
571
+ quiet
572
+ }, index))
573
+ })
412
574
  })
413
575
  });
414
576
  const widthProps = {