-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Share Title and Description components
- Loading branch information
1 parent
0da97ea
commit f59ea74
Showing
5 changed files
with
110 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Trans } from "@lingui/macro"; | ||
import { Theme, Typography, TypographyProps } from "@mui/material"; | ||
import { makeStyles } from "@mui/styles"; | ||
import clsx from "clsx"; | ||
|
||
const useStyles = makeStyles<Theme, { hoverable?: boolean }>({ | ||
text: { | ||
marginBottom: 4, | ||
cursor: "pointer", | ||
|
||
"&:hover": { | ||
textDecoration: ({ hoverable }) => (hoverable ? "underline" : "none"), | ||
}, | ||
}, | ||
}); | ||
|
||
const getEmptyColor = (lighterColor?: boolean) => { | ||
return lighterColor ? "grey.500" : "secondary.main"; | ||
}; | ||
|
||
type Props = TypographyProps & { | ||
text: string; | ||
lighterColor?: boolean; | ||
}; | ||
|
||
export const Title = (props: Props) => { | ||
const { text, lighterColor, onClick, className, sx, ...rest } = props; | ||
const classes = useStyles({ hoverable: !!onClick }); | ||
|
||
return ( | ||
<Typography | ||
{...rest} | ||
variant="h2" | ||
className={clsx(classes.text, className)} | ||
onClick={onClick} | ||
sx={{ color: text === "" ? getEmptyColor(lighterColor) : "text", ...sx }} | ||
> | ||
{text === "" ? <Trans id="annotation.add.title">[ Title ]</Trans> : text} | ||
</Typography> | ||
); | ||
}; | ||
|
||
export const Description = (props: Props) => { | ||
const { text, lighterColor, onClick, className, sx, ...rest } = props; | ||
const classes = useStyles({ hoverable: !!onClick }); | ||
|
||
return ( | ||
<Typography | ||
{...rest} | ||
variant="body1" | ||
className={clsx(classes.text, className)} | ||
onClick={onClick} | ||
sx={{ color: text === "" ? getEmptyColor(lighterColor) : "text", ...sx }} | ||
> | ||
{text === "" ? ( | ||
<Trans id="annotation.add.description">[ Description ]</Trans> | ||
) : ( | ||
text | ||
)} | ||
</Typography> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters