Added copy button and description input type
This commit is contained in:
1 parent
a84b340d6e
commit
51ce98f5e9
3 files changed
+139
-66
No files matched your search
@@ -4,12 +4,14 @@
|
|||||||
.field h3.MuiTypography-root,
|
.field h3.MuiTypography-root,
|
||||||
.field h5.MuiTypography-root,
|
.field h5.MuiTypography-root,
|
||||||
.field input,
|
.field input,
|
||||||
|
.field textarea,
|
||||||
.field .input-error {
|
.field .input-error {
|
||||||
font-size: var(--env-var-font-size-medium);
|
font-size: var(--env-var-font-size-medium);
|
||||||
}
|
}
|
||||||
.field h3.MuiTypography-root,
|
.field h3.MuiTypography-root,
|
||||||
.field h5.MuiTypography-root,
|
.field h5.MuiTypography-root,
|
||||||
.field input {
|
.field input,
|
||||||
|
.field textarea {
|
||||||
color: var(--env-var-color-5);
|
color: var(--env-var-color-5);
|
||||||
}
|
}
|
||||||
.field h3.MuiTypography-root {
|
.field h3.MuiTypography-root {
|
||||||
@@ -28,22 +30,42 @@
|
|||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
padding-right: var(--env-var-spacing-1-minus);
|
padding-right: var(--env-var-spacing-1-minus);
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root {
|
.field .MuiInputBase-root:has(input) {
|
||||||
height: 34px;
|
height: 34px;
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
||||||
padding-right: var(--env-var-spacing-1-minus);
|
padding-right: var(--env-var-spacing-1-minus);
|
||||||
}
|
}
|
||||||
|
.field .MuiInputBase-root:has(.MuiInputAdornment-root > .MuiButtonBase-root) {
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
.field .MuiInputBase-root .MuiInputAdornment-root .MuiButtonBase-root {
|
||||||
|
padding: 0 var(--env-var-spacing-1-minus);
|
||||||
|
font-size: var(--env-var-font-size-medium);
|
||||||
|
border-radius: 0;
|
||||||
|
height: 34px;
|
||||||
|
}
|
||||||
|
.field .MuiInputBase-root .MuiInputAdornment-root .MuiButtonBase-root svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
.field .MuiInputBase-root .MuiInputAdornment-root .MuiButtonBase-root:hover {
|
||||||
|
border-color: var(--env-var-color-29);
|
||||||
|
}
|
||||||
.field input {
|
.field input {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0 var(--env-var-spacing-1-minus);
|
padding: 0 var(--env-var-spacing-1-minus);
|
||||||
}
|
}
|
||||||
|
.field .MuiInputBase-root:has(textarea) {
|
||||||
|
padding: var(--env-var-spacing-1-minus);
|
||||||
|
}
|
||||||
.field .MuiOutlinedInput-root fieldset {
|
.field .MuiOutlinedInput-root fieldset {
|
||||||
border-color: var(--env-var-color-29);
|
border-color: var(--env-var-color-29);
|
||||||
border-radius: var(--env-var-radius-1);
|
border-radius: var(--env-var-radius-1);
|
||||||
}
|
}
|
||||||
.field:not(:has(.input-error))
|
.field:not(:has(.input-error))
|
||||||
.MuiOutlinedInput-root:hover:not(:has(input:focus))
|
.MuiOutlinedInput-root:hover:not(:has(input:focus)):not(:has(textarea:focus))
|
||||||
fieldset {
|
fieldset {
|
||||||
border-color: var(--env-var-color-29);
|
border-color: var(--env-var-color-29);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
||||||
import Visibility from "@mui/icons-material/Visibility";
|
import Visibility from "@mui/icons-material/Visibility";
|
||||||
|
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
||||||
|
import Button from "../../Button";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
const Field = ({
|
const Field = ({
|
||||||
type = "text",
|
type = "text",
|
||||||
@@ -18,6 +21,7 @@ const Field = ({
|
|||||||
isOptional,
|
isOptional,
|
||||||
isVisible,
|
isVisible,
|
||||||
setVisibility,
|
setVisibility,
|
||||||
|
hasCopy,
|
||||||
autoComplete,
|
autoComplete,
|
||||||
placeholder,
|
placeholder,
|
||||||
value,
|
value,
|
||||||
@@ -27,6 +31,13 @@ const Field = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
// TODO - are we using this feature anywhere ?
|
||||||
|
const [copy, setCopy] = useState(false);
|
||||||
|
const handleCopy = () => {
|
||||||
|
setCopy(true);
|
||||||
|
setTimeout(() => setCopy(false), 1000);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.gap.xs} className={`field field-${type}`}>
|
<Stack gap={theme.gap.xs} className={`field field-${type}`}>
|
||||||
{label && (
|
{label && (
|
||||||
@@ -41,6 +52,8 @@ const Field = ({
|
|||||||
id={id}
|
id={id}
|
||||||
autoComplete={autoComplete}
|
autoComplete={autoComplete}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
multiline={type === "description"}
|
||||||
|
rows={type === "description" ? 4 : 1}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -57,28 +70,48 @@ const Field = ({
|
|||||||
<Typography component="h5">https://</Typography>
|
<Typography component="h5">https://</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
),
|
),
|
||||||
endAdornment: type === "password" && (
|
endAdornment:
|
||||||
<InputAdornment position="end">
|
type === "password" ? (
|
||||||
<IconButton
|
<InputAdornment position="end">
|
||||||
aria-label="toggle password visibility"
|
<IconButton
|
||||||
onClick={() => setVisibility((show) => !show)}
|
aria-label="toggle password visibility"
|
||||||
tabIndex={-1}
|
onClick={() => setVisibility((show) => !show)}
|
||||||
sx={{
|
tabIndex={-1}
|
||||||
color: theme.palette.section.borderColor,
|
sx={{
|
||||||
padding: `calc(${theme.gap.xs} / 2)`,
|
color: theme.palette.section.borderColor,
|
||||||
"&:focus": {
|
padding: `calc(${theme.gap.xs} / 2)`,
|
||||||
outline: "none",
|
"&:focus": {
|
||||||
},
|
outline: "none",
|
||||||
"& .MuiTouchRipple-root": {
|
},
|
||||||
pointerEvents: "none",
|
"& .MuiTouchRipple-root": {
|
||||||
display: "none",
|
pointerEvents: "none",
|
||||||
},
|
display: "none",
|
||||||
}}
|
},
|
||||||
>
|
}}
|
||||||
{!isVisible ? <VisibilityOff /> : <Visibility />}
|
>
|
||||||
</IconButton>
|
{!isVisible ? <VisibilityOff /> : <Visibility />}
|
||||||
</InputAdornment>
|
</IconButton>
|
||||||
),
|
</InputAdornment>
|
||||||
|
) : (
|
||||||
|
hasCopy && (
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<Button
|
||||||
|
level="tertiary"
|
||||||
|
label={copy ? "Copied" : "Copy"}
|
||||||
|
img={<ContentCopyIcon />}
|
||||||
|
onClick={handleCopy}
|
||||||
|
sx={{
|
||||||
|
borderLeft: `solid 1px ${theme.palette.section.borderColor}`,
|
||||||
|
lineHeight: 0,
|
||||||
|
"& .MuiTouchRipple-root": {
|
||||||
|
pointerEvents: "none",
|
||||||
|
display: "none",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</InputAdornment>
|
||||||
|
)
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{error && (
|
{error && (
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import EmailTextField from "../../Components/TextFields/Email/EmailTextField";
|
|
||||||
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
|
|
||||||
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
|
|
||||||
import WebsiteTextField from "../../Components/TextFields/Website/WebsiteTextField";
|
|
||||||
import DescriptionTextField from "../../Components/TextFields/Description/DescriptionTextField";
|
|
||||||
import PlayGroundCharts from "./PlayGround-Charts";
|
import PlayGroundCharts from "./PlayGround-Charts";
|
||||||
import PlayGroundPopupModals from "./PlayGround-Popup-Modals";
|
import PlayGroundPopupModals from "./PlayGround-Popup-Modals";
|
||||||
import PlayGroundTooltips from "./PlayGround-Tooltips";
|
import PlayGroundTooltips from "./PlayGround-Tooltips";
|
||||||
|
import Field from "../../Components/TextFields/Field";
|
||||||
|
|
||||||
// This Component is just for the development and test
|
// This Component is just for the development and test
|
||||||
// purposes and just to see what my components look like while development
|
// purposes and just to see what my components look like while development
|
||||||
@@ -15,49 +11,71 @@ function PlayGround() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{/* Default state of Email Text Fields */}
|
{/* Default state of Email Text Fields */}
|
||||||
<EmailTextField
|
<div
|
||||||
error={false}
|
style={{
|
||||||
placeholder="olivia@untitledui.com"
|
display: "flex",
|
||||||
id="outlined-basic"
|
flexDirection: "column",
|
||||||
helperText="This is a hint text to help user."
|
gap: "10px",
|
||||||
/>
|
maxWidth: "400px",
|
||||||
{/* Email Text Field when validation error occures */}
|
padding: "10px",
|
||||||
<EmailTextField
|
}}
|
||||||
error={true}
|
>
|
||||||
placeholder="olivia@untitledui.com"
|
<Field
|
||||||
id="outlined-basic"
|
type="email"
|
||||||
icon={<ErrorOutlineIcon style={{ fill: "red" }} />}
|
id="outlined-basic"
|
||||||
helperText="This is an error message"
|
label="Email"
|
||||||
/>
|
placeholder="olivia@untitledui.com"
|
||||||
{/* Email Text Field while mouse hover */}
|
/>
|
||||||
<EmailTextField
|
{/* Email Text Field when validation error occures */}
|
||||||
error={false}
|
<Field
|
||||||
placeholder="olivia@untitledui.com"
|
type="email"
|
||||||
id="outlined-basic"
|
id="outlined-basic"
|
||||||
icon={<HelpOutlineIcon />}
|
label="Email"
|
||||||
helperText="This is a hint text to help user."
|
placeholder="olivia@untitledui.com"
|
||||||
/>
|
error="This is an error message"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
{/* Now, illustration of the Website text fields */}
|
|
||||||
|
|
||||||
<WebsiteTextField hintText="This is a hint text to help user." />
|
{/* Now, illustration of the Website text fields */}
|
||||||
<WebsiteTextField
|
<div
|
||||||
hasCopyButton={true}
|
style={{
|
||||||
hintText="This is a hint text to help user."
|
display: "flex",
|
||||||
/>
|
flexDirection: "column",
|
||||||
|
gap: "10px",
|
||||||
|
maxWidth: "400px",
|
||||||
|
padding: "10px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Field type="url" label="Website" />
|
||||||
|
<Field type="url" label="Website" hasCopy={true} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
{/* Now, illustration of the Description text fields */}
|
{/* Now, illustration of the Description text fields */}
|
||||||
|
|
||||||
<DescriptionTextField
|
<div
|
||||||
hasError={false}
|
style={{
|
||||||
hintText="This is a hint text to help user."
|
display: "flex",
|
||||||
/>
|
flexDirection: "column",
|
||||||
<DescriptionTextField
|
gap: "10px",
|
||||||
hasError={true}
|
maxWidth: "400px",
|
||||||
hintText="This is a hint text to help user."
|
padding: "10px",
|
||||||
/>
|
}}
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
type="description"
|
||||||
|
label="Description"
|
||||||
|
placeholder="Enter a description... "
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
type="description"
|
||||||
|
label="Description"
|
||||||
|
placeholder="Enter a description... "
|
||||||
|
error="This is an error message"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<PlayGroundCharts />
|
<PlayGroundCharts />
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
Reference in new issue
Block a user