-
Notifications
You must be signed in to change notification settings - Fork 5
Content: UUID Field Revamp #2549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
940dcfd
3245ff4
6016e7a
80c78c4
0256777
56a7c60
9309639
2166997
0ea3519
bb98e38
5303a9c
99e2a41
c3641e7
a3a2022
6d2faa9
4cc1833
d14917f
1a8bcc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import React, { useEffect } from "react"; | ||
import cx from "classnames"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faClipboard } from "@fortawesome/free-solid-svg-icons"; | ||
import { Input } from "@zesty-io/core/Input"; | ||
|
||
import { | ||
TextField, | ||
InputAdornment, | ||
Tooltip, | ||
IconButton, | ||
tooltipClasses, | ||
} from "@mui/material"; | ||
import styles from "./FieldTypeUUID.less"; | ||
import TagIcon from "@mui/icons-material/Tag"; | ||
import ContentCopyRoundedIcon from "@mui/icons-material/ContentCopyRounded"; | ||
import CheckIcon from "@mui/icons-material/Check"; | ||
|
||
export const FieldTypeUUID = React.memo(function FieldTypeUUID(props) { | ||
// console.log("FieldTypeUUID:render"); | ||
|
||
const [isCopied, setIsCopied] = React.useState(false); | ||
useEffect(() => { | ||
// NOTE may want to add a check to ensure the itemZUID is 'new' | ||
if (props.name && !props.value) { | ||
|
@@ -18,39 +23,87 @@ export const FieldTypeUUID = React.memo(function FieldTypeUUID(props) { | |
} | ||
}, []); | ||
|
||
// Set isCopied to false after 5 seconds | ||
useEffect(() => { | ||
if (isCopied) { | ||
const timeout = setTimeout(() => { | ||
setIsCopied(false); | ||
}, 5000); | ||
// Clear timeout if the component is unmounted | ||
return () => clearTimeout(timeout); | ||
} | ||
}, [isCopied]); | ||
|
||
return ( | ||
<label className={cx(styles.FieldTypeUUID, props.className)}> | ||
<div className={styles.DateFieldTypeInput}> | ||
<FontAwesomeIcon | ||
className={styles.Icon} | ||
icon={faClipboard} | ||
aria-hidden="true" | ||
title="Click to Copy" | ||
onClick={(e) => { | ||
const input = document.createElement("input"); | ||
document.body.appendChild(input); | ||
input.value = props.value; | ||
input.focus(); | ||
input.select(); | ||
const result = document.execCommand("copy"); | ||
input.remove(); | ||
if (result === "unsuccessful") { | ||
return props.dispatch( | ||
notify({ | ||
type: "error", | ||
message: "Failed to copy the team ID to your clipboard", | ||
}) | ||
); | ||
} | ||
<div> | ||
<Tooltip | ||
slotProps={{ | ||
popper: { | ||
modifiers: [ | ||
{ | ||
name: "offset", | ||
options: { | ||
offset: [0, -47], | ||
}, | ||
}, | ||
], | ||
}, | ||
}} | ||
/> | ||
placement="top" | ||
title="This field cannot be edited" | ||
> | ||
<TextField | ||
required={props.required} | ||
value={props.value || ""} | ||
readOnly={true} | ||
fullWidth | ||
type="text" | ||
sx={{ | ||
caretColor: "transparent", // This is to hide the cursor in the input field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like bad very bad UX. Why would we want a user to lose track of their cursor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not the cursor, actually but just the caret to make the button behave like disabled. it's just the blinking cursor along text inputs. input text can't be modified i did this just to hide the blinking cursor inside textfield @agalin920 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have not followed this pattern. Use the pattern where the input is properly disabled but the read only style text color is changed |
||
}} | ||
InputProps={{ | ||
startAdornment: ( | ||
<InputAdornment position="start" sx={{ marginRight: 0 }}> | ||
<TagIcon fontSize="small" /> | ||
</InputAdornment> | ||
), | ||
|
||
<Input | ||
type="text" | ||
readOnly={true} | ||
required={props.required} | ||
defaultValue={props.value || ""} | ||
/> | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<IconButton | ||
size="small" | ||
onClick={() => { | ||
const input = document.createElement("input"); | ||
jomarmontuya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
document.body.appendChild(input); | ||
input.value = props.value; | ||
input.focus(); | ||
input.select(); | ||
const result = document.execCommand("copy"); | ||
input.remove(); | ||
if (result === "unsuccessful") { | ||
return props.dispatch( | ||
notify({ | ||
type: "error", | ||
message: | ||
"Failed to copy the team ID to your clipboard", | ||
}) | ||
); | ||
} | ||
setIsCopied(true); | ||
}} | ||
> | ||
{isCopied ? ( | ||
<CheckIcon fontSize="small" /> | ||
) : ( | ||
<ContentCopyRoundedIcon fontSize="small" /> | ||
)} | ||
</IconButton> | ||
</InputAdornment> | ||
), | ||
}} | ||
/> | ||
</Tooltip> | ||
</div> | ||
</label> | ||
); | ||
|
Uh oh!
There was an error while loading. Please reload this page.