aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/newlightbox/components/EditableText/EditableText.tsx
diff options
context:
space:
mode:
authorsrichman333 <sarah_n_richman@brown.edu>2023-07-18 13:22:36 -0400
committersrichman333 <sarah_n_richman@brown.edu>2023-07-18 13:22:36 -0400
commit7311dc5e358e34b074391b398e51439b20391ecb (patch)
treef42285e7bdc5baa081f8ac920361fbb84a59ef92 /src/client/views/newlightbox/components/EditableText/EditableText.tsx
parent51718316b592e86c0009b7a27e1e32ba74d2488b (diff)
parent5da0b8c1e12abe13d60361af4f6bbb8454b6814d (diff)
Merge branch 'master' into data-visualization-sarah
Diffstat (limited to 'src/client/views/newlightbox/components/EditableText/EditableText.tsx')
-rw-r--r--src/client/views/newlightbox/components/EditableText/EditableText.tsx65
1 files changed, 65 insertions, 0 deletions
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>
+ )
+}