@hyddenlabs/hydn-ui 0.3.0-alpha.184 → 0.3.0-alpha.185

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
@@ -5307,6 +5307,137 @@ function Code({ children, size = "md", variant = "default", className = "" }) {
5307
5307
  }
5308
5308
  Code.displayName = "Code";
5309
5309
  var code_default = Code;
5310
+ function EditableText({
5311
+ value: controlledValue,
5312
+ defaultValue = "",
5313
+ onSave,
5314
+ onChange,
5315
+ onCancel,
5316
+ onEdit,
5317
+ placeholder = "Click to edit",
5318
+ disabled = false,
5319
+ size = "md",
5320
+ validationState = "default",
5321
+ className = "",
5322
+ id,
5323
+ name,
5324
+ required = false,
5325
+ autoFocus = true,
5326
+ maxLength,
5327
+ saveOnEnter = true
5328
+ }) {
5329
+ const isControlled = controlledValue !== void 0;
5330
+ const [internalValue, setInternalValue] = React.useState(defaultValue);
5331
+ const [isEditing, setIsEditing] = React.useState(false);
5332
+ const [editValue, setEditValue] = React.useState("");
5333
+ const inputRef = React.useRef(null);
5334
+ const currentValue = isControlled ? controlledValue : internalValue;
5335
+ React.useEffect(() => {
5336
+ if (isEditing && autoFocus && inputRef.current) {
5337
+ inputRef.current.focus();
5338
+ inputRef.current.select();
5339
+ }
5340
+ }, [isEditing, autoFocus]);
5341
+ const handleClick = () => {
5342
+ if (disabled) return;
5343
+ setEditValue(currentValue);
5344
+ setIsEditing(true);
5345
+ onEdit?.();
5346
+ };
5347
+ const handleSave = () => {
5348
+ const trimmedValue = editValue.trim();
5349
+ if (!isControlled) {
5350
+ setInternalValue(trimmedValue);
5351
+ }
5352
+ onSave?.(trimmedValue);
5353
+ onChange?.(trimmedValue);
5354
+ setIsEditing(false);
5355
+ };
5356
+ const handleCancel = () => {
5357
+ setEditValue(currentValue);
5358
+ setIsEditing(false);
5359
+ onCancel?.();
5360
+ };
5361
+ const handleKeyDown = (e) => {
5362
+ if (e.key === "Escape") {
5363
+ e.preventDefault();
5364
+ handleCancel();
5365
+ } else if (e.key === "Enter" && saveOnEnter && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
5366
+ e.preventDefault();
5367
+ handleSave();
5368
+ }
5369
+ };
5370
+ const handleBlur = (e) => {
5371
+ setTimeout(() => {
5372
+ const relatedTarget = e.relatedTarget;
5373
+ const isClickingButton = relatedTarget?.closest("[data-editable-actions]");
5374
+ if (!isClickingButton) {
5375
+ handleCancel();
5376
+ }
5377
+ }, 0);
5378
+ };
5379
+ const handleChange = (e) => {
5380
+ setEditValue(e.target.value);
5381
+ };
5382
+ const sizeConfig = {
5383
+ xs: "text-sm sm:text-xs",
5384
+ sm: "text-base sm:text-sm",
5385
+ md: "text-base sm:text-sm",
5386
+ lg: "text-lg sm:text-base",
5387
+ xl: "text-xl sm:text-lg"
5388
+ }[size];
5389
+ if (isEditing) {
5390
+ const validationBorder = {
5391
+ default: "border-b-foreground/30 focus:border-b-foreground",
5392
+ error: "border-b-destructive focus:border-b-destructive",
5393
+ success: "border-b-success focus:border-b-success",
5394
+ warning: "border-b-warning focus:border-b-warning"
5395
+ }[validationState];
5396
+ const commonProps = {
5397
+ ref: inputRef,
5398
+ value: editValue,
5399
+ onChange: handleChange,
5400
+ onKeyDown: handleKeyDown,
5401
+ onBlur: handleBlur,
5402
+ placeholder,
5403
+ disabled,
5404
+ id,
5405
+ name,
5406
+ required,
5407
+ maxLength,
5408
+ className: `${sizeConfig} w-full border-0 border-b ${validationBorder} bg-transparent py-1 outline-none transition-colors placeholder:text-muted-foreground`
5409
+ };
5410
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
5411
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ...commonProps, type: "text" }),
5412
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-editable-actions": true, className: "flex items-center gap-1", children: [
5413
+ /* @__PURE__ */ jsxRuntime.jsx(icon_button_default, { icon: "IconX", ariaLabel: "Cancel", onClick: handleCancel, variant: "error", size: "xs" }),
5414
+ /* @__PURE__ */ jsxRuntime.jsx(icon_button_default, { icon: "IconCheck", ariaLabel: "Save", onClick: handleSave, variant: "success", size: "xs" })
5415
+ ] })
5416
+ ] });
5417
+ }
5418
+ const displayText = currentValue || placeholder;
5419
+ const isPlaceholder = !currentValue;
5420
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5421
+ "button",
5422
+ {
5423
+ type: "button",
5424
+ onClick: handleClick,
5425
+ disabled,
5426
+ className: `group ${sizeConfig} ${className} relative inline-flex items-center gap-2 cursor-text border-b border-transparent py-1 text-left transition-all hover:border-b-foreground/30 focus:outline-none focus:ring-2 focus:ring-ring/20 focus:rounded disabled:cursor-not-allowed disabled:opacity-50 ${isPlaceholder ? "text-muted-foreground" : "text-foreground"} w-fit max-w-full`,
5427
+ children: [
5428
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 truncate", children: displayText }),
5429
+ /* @__PURE__ */ jsxRuntime.jsx(
5430
+ Icon,
5431
+ {
5432
+ name: "IconPencil",
5433
+ className: "shrink-0 opacity-0 transition-opacity group-hover:opacity-50 group-focus:opacity-50",
5434
+ size: "xs"
5435
+ }
5436
+ )
5437
+ ]
5438
+ }
5439
+ );
5440
+ }
5310
5441
  var alignClasses3 = {
5311
5442
  start: "items-start",
5312
5443
  center: "items-center",
@@ -6319,6 +6450,7 @@ exports.Divider = divider_default;
6319
6450
  exports.Drawer = drawer_default;
6320
6451
  exports.Dropdown = dropdown_default;
6321
6452
  exports.DropdownItem = DropdownItem;
6453
+ exports.EditableText = EditableText;
6322
6454
  exports.EmptyState = empty_state_default;
6323
6455
  exports.FeatureSection = feature_section_default;
6324
6456
  exports.Fieldset = fieldset_default;