From 3958654925e92b1046b3ed5d49160514b6e48258 Mon Sep 17 00:00:00 2001
From: geireann <geireann.lindfield@gmail.com>
Date: Tue, 6 Jun 2023 14:36:21 -0400
Subject: added rec stuff and begun updating components

---
 .../components/EditableText/EditableText.tsx       | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 src/client/views/newlightbox/components/EditableText/EditableText.tsx

(limited to 'src/client/views/newlightbox/components/EditableText/EditableText.tsx')

diff --git a/src/client/views/newlightbox/components/EditableText/EditableText.tsx b/src/client/views/newlightbox/components/EditableText/EditableText.tsx
new file mode 100644
index 000000000..e9e7ca264
--- /dev/null
+++ b/src/client/views/newlightbox/components/EditableText/EditableText.tsx
@@ -0,0 +1,65 @@
+import * as React from 'react'
+import './EditableText.scss'
+import { Size } from 'browndash-components'
+
+export interface IEditableTextProps {
+  text: string
+  placeholder?: string
+  editing: boolean
+  onEdit: (newText: string) => void
+  setEditing: (editing: boolean) => void
+  backgroundColor?: string
+  size?: Size
+  height?: number
+}
+
+/**
+ * Editable Text is used for inline renaming of some text.
+ * It appears as normal UI text but transforms into a text input field when the user clicks on or focuses it.
+ * @param props
+ * @returns
+ */
+export const EditableText = (props: IEditableTextProps) => {
+  const {
+    editing,
+    height,
+    size,
+    text,
+    onEdit,
+    setEditing,
+    backgroundColor,
+    placeholder,
+  } = props
+
+  const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+    onEdit(event.target.value)
+  }
+
+  return editing ? (
+    <input
+      style={{ background: backgroundColor, height: height }}
+      placeholder={placeholder}
+      size={1}
+      className="lb-editableText"
+      autoFocus
+      onChange={handleOnChange}
+      onBlur={() => setEditing(false)}
+      defaultValue={text}
+    ></input>
+  ) : (
+    <input
+      style={{ background: backgroundColor, height: height }}
+      placeholder={placeholder}
+      size={1}
+      className="lb-editableText"
+      autoFocus
+      onChange={handleOnChange}
+      onBlur={() => setEditing(false)}
+      defaultValue={text}
+    ></input>
+    // <div className="lb-displayText" onClick={(e) => {
+    //     e.stopPropagation()
+    //     setEditing(true)
+    // }}>{text}</div>
+  )
+}
-- 
cgit v1.2.3-70-g09d2

