@wistia/ui 0.4.14 → 0.5.0-beta.0d4c5f2f.6eaaa8c

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.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*
3
- * @license @wistia/ui v0.4.14
3
+ * @license @wistia/ui v0.5.0-beta.0d4c5f2f.6eaaa8c
4
4
  *
5
5
  * Copyright (c) 2024-2025, Wistia, Inc. and its affiliates.
6
6
  *
@@ -56,6 +56,7 @@ __export(index_exports, {
56
56
  DataCardTrend: () => DataCardTrend,
57
57
  DataCards: () => DataCards,
58
58
  Divider: () => Divider,
59
+ EditableHeading: () => EditableHeading,
59
60
  Ellipsis: () => Ellipsis,
60
61
  Form: () => Form,
61
62
  FormErrorSummary: () => FormErrorSummary,
@@ -9313,18 +9314,18 @@ DataCard.displayName = "DataCard";
9313
9314
 
9314
9315
  // src/components/DataCards/DataCards.tsx
9315
9316
  var import_styled_components63 = __toESM(require("styled-components"));
9316
- var import_type_guards35 = require("@wistia/type-guards");
9317
9317
  var import_jsx_runtime212 = require("react/jsx-runtime");
9318
9318
  var StyledDataCards = (0, import_styled_components63.default)(Box)`
9319
9319
  ${({ $colorScheme }) => getColorScheme($colorScheme)};
9320
+ margin-top: 0; /* Remove default <dl> style */
9320
9321
  > * {
9321
9322
  min-width: 120px;
9322
- max-width: ${({ $cardMaxWidth }) => (0, import_type_guards35.isNotUndefined)($cardMaxWidth) ? `${$cardMaxWidth}px` : "none"};
9323
+ max-width: ${({ $cardMaxWidth }) => $cardMaxWidth};
9323
9324
  }
9324
9325
  `;
9325
9326
  var DataCards = ({
9326
9327
  children,
9327
- cardMaxWidth,
9328
+ cardMaxWidth = "none",
9328
9329
  colorScheme = "inherit",
9329
9330
  ...props
9330
9331
  }) => {
@@ -9382,6 +9383,158 @@ var DataCardTrend = ({
9382
9383
  )
9383
9384
  ] });
9384
9385
  };
9386
+
9387
+ // src/components/EditableHeading/EditableHeading.tsx
9388
+ var import_styled_components65 = __toESM(require("styled-components"));
9389
+ var import_react46 = require("react");
9390
+ var import_jsx_runtime214 = require("react/jsx-runtime");
9391
+ var sharedInputStyles = import_styled_components65.css`
9392
+ padding: var(--wui-space-02);
9393
+ border-radius: var(--wui-border-radius-01);
9394
+ overflow-wrap: anywhere;
9395
+ width: 100%;
9396
+ `;
9397
+ var StyledEditableHeadingInput = import_styled_components65.default.textarea`
9398
+ :not([rows]) {
9399
+ min-height: unset;
9400
+ }
9401
+
9402
+ ${sharedInputStyles}
9403
+ font-size: var(--wui-typography-heading-1-size);
9404
+ font-weight: var(--wui-typography-heading-1-weight);
9405
+ line-height: var(--wui-typography-heading-1-line-height);
9406
+ font-family: var(--wui-typography-heading-1-family);
9407
+ box-sizing: border-box;
9408
+ margin: 0;
9409
+ display: block;
9410
+ overflow: hidden;
9411
+ resize: vertical;
9412
+ height: ${({ $headingHeight }) => `${$headingHeight}px`};
9413
+ background: transparent;
9414
+ border: none;
9415
+ outline: 2px solid var(--wui-color-focus-ring);
9416
+ outline-offset: -2px;
9417
+
9418
+ &:focus {
9419
+ outline: 2px solid var(--wui-color-focus-ring);
9420
+ outline-offset: -2px;
9421
+ }
9422
+ `;
9423
+ var StyledHeading2 = (0, import_styled_components65.default)(Heading)`
9424
+ ${sharedInputStyles}
9425
+ transition: all var(--wui-motion-duration-01) var(--wui-motion-ease);
9426
+ ${({ $editingDisabled }) => !$editingDisabled && import_styled_components65.css`
9427
+ cursor: pointer;
9428
+
9429
+ &:hover {
9430
+ background: var(--wui-color-bg-surface-hover);
9431
+ }
9432
+ `}
9433
+ `;
9434
+ var EditableHeading = ({
9435
+ children,
9436
+ onValueChange,
9437
+ onEditingChange,
9438
+ tooltipText = "Click to edit title",
9439
+ ariaLabel = "Edit title",
9440
+ forceEditing = false,
9441
+ editingDisabled = false,
9442
+ textareaProps,
9443
+ headingProps,
9444
+ dataTestId
9445
+ }) => {
9446
+ const [isEditing, setIsEditing] = (0, import_react46.useState)(false);
9447
+ const [value, setValue] = (0, import_react46.useState)(children);
9448
+ const [previousValue, setPreviousValue] = (0, import_react46.useState)(children);
9449
+ const [headingHeight, setHeadingHeight] = (0, import_react46.useState)("60");
9450
+ const headingRef = (0, import_react46.useRef)(null);
9451
+ const handleSetEditing = (editing) => {
9452
+ if (editingDisabled) return;
9453
+ if (editing && headingRef.current) {
9454
+ setHeadingHeight(`${headingRef.current.offsetHeight}`);
9455
+ }
9456
+ if (editing) {
9457
+ setPreviousValue(value);
9458
+ }
9459
+ setIsEditing(editing);
9460
+ onEditingChange?.(editing);
9461
+ };
9462
+ const handleFinishEditing = () => {
9463
+ const trimmedValue = value.trim();
9464
+ if (trimmedValue === "") {
9465
+ setValue(previousValue);
9466
+ } else if (trimmedValue !== previousValue && onValueChange) {
9467
+ onValueChange(trimmedValue);
9468
+ } else {
9469
+ setValue(trimmedValue);
9470
+ }
9471
+ handleSetEditing(false);
9472
+ };
9473
+ const handleKeyDown = (event) => {
9474
+ if (event.key === "Enter" && !event.shiftKey) {
9475
+ event.preventDefault();
9476
+ handleFinishEditing();
9477
+ }
9478
+ if (event.key === "Escape") {
9479
+ setValue(previousValue);
9480
+ handleSetEditing(false);
9481
+ }
9482
+ };
9483
+ const HeadingComponent2 = /* @__PURE__ */ (0, import_jsx_runtime214.jsx)(
9484
+ StyledHeading2,
9485
+ {
9486
+ ...headingProps,
9487
+ ref: headingRef,
9488
+ $editingDisabled: editingDisabled,
9489
+ "data-testid": dataTestId,
9490
+ onClick: () => handleSetEditing(true),
9491
+ variant: "heading1",
9492
+ children: value
9493
+ }
9494
+ );
9495
+ if (editingDisabled) {
9496
+ return HeadingComponent2;
9497
+ }
9498
+ if (isEditing || forceEditing) {
9499
+ return /* @__PURE__ */ (0, import_jsx_runtime214.jsx)(
9500
+ StyledEditableHeadingInput,
9501
+ {
9502
+ ...textareaProps,
9503
+ $headingHeight: headingHeight,
9504
+ "aria-label": ariaLabel,
9505
+ autoFocus: true,
9506
+ "data-testid": dataTestId,
9507
+ onBlur: handleFinishEditing,
9508
+ onChange: (event) => setValue(event.target.value),
9509
+ onFocus: (event) => {
9510
+ const { length } = event.currentTarget.value;
9511
+ event.currentTarget.setSelectionRange(length, length);
9512
+ },
9513
+ onKeyDown: handleKeyDown,
9514
+ value,
9515
+ children: value
9516
+ }
9517
+ );
9518
+ }
9519
+ return /* @__PURE__ */ (0, import_jsx_runtime214.jsxs)(import_jsx_runtime214.Fragment, { children: [
9520
+ /* @__PURE__ */ (0, import_jsx_runtime214.jsx)(
9521
+ Tooltip,
9522
+ {
9523
+ compact: true,
9524
+ content: tooltipText,
9525
+ children: HeadingComponent2
9526
+ }
9527
+ ),
9528
+ /* @__PURE__ */ (0, import_jsx_runtime214.jsx)(ScreenReaderOnly, { children: /* @__PURE__ */ (0, import_jsx_runtime214.jsx)(
9529
+ "button",
9530
+ {
9531
+ "aria-label": ariaLabel,
9532
+ onClick: () => handleSetEditing(true),
9533
+ type: "button"
9534
+ }
9535
+ ) })
9536
+ ] });
9537
+ };
9385
9538
  // Annotate the CommonJS export names for ESM import in node:
9386
9539
  0 && (module.exports = {
9387
9540
  ActionButton,
@@ -9401,6 +9554,7 @@ var DataCardTrend = ({
9401
9554
  DataCardTrend,
9402
9555
  DataCards,
9403
9556
  Divider,
9557
+ EditableHeading,
9404
9558
  Ellipsis,
9405
9559
  Form,
9406
9560
  FormErrorSummary,