-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from skilldeliver/add-typography-id
Add Typography component with ID and link button
- Loading branch information
Showing
10 changed files
with
123 additions
and
34 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
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,52 @@ | ||
import { PropsWithChildren, useState } from 'react' | ||
|
||
import { Theme, Typography, TypographyProps } from '@material-ui/core' | ||
import { createStyles, makeStyles } from '@material-ui/core/styles' | ||
import LinkIcon from '@material-ui/icons/Link' | ||
|
||
import LinkIconButton from 'components/common/LinkIconButton' | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
linkIcon: { | ||
transform: 'rotate(-45deg)', | ||
color: theme.palette.primary.main, | ||
'&:hover': { | ||
color: theme.palette.primary.dark, | ||
}, | ||
}, | ||
hideLinkIcon: { | ||
visibility: 'hidden', | ||
}, | ||
}), | ||
) | ||
|
||
type Linkable = | ||
| { | ||
id: string | ||
linkable: true | ||
} | ||
| { linkable?: false } | ||
|
||
type HeadingParams = PropsWithChildren<TypographyProps & Linkable> & { component?: string } | ||
|
||
export default function Heading({ children, id, linkable, ...props }: HeadingParams) { | ||
const [linkIconIsShown, setlinkIconIsShown] = useState(false) | ||
const classes = useStyles() | ||
|
||
return ( | ||
<div | ||
id={id} | ||
onMouseEnter={() => setlinkIconIsShown(true)} | ||
onMouseLeave={() => setlinkIconIsShown(false)}> | ||
<Typography {...props}> | ||
{children} | ||
{linkable && ( | ||
<LinkIconButton href={`#${id}`} className={linkIconIsShown ? '' : classes.hideLinkIcon}> | ||
<LinkIcon className={classes.linkIcon} /> | ||
</LinkIconButton> | ||
)} | ||
</Typography> | ||
</div> | ||
) | ||
} |
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
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