forked from mastodon/mastodon
-
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.
[Proposal] Make able to write React in Typescript (mastodon#16210)
Co-authored-by: berlysia <berlysia@gmail.com> Co-authored-by: fusagiko / takayamaki <takayamaki@users.noreply.github.com>
- Loading branch information
1 parent
2f7c3cb
commit 4520e64
Showing
26 changed files
with
1,100 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
export const useHovering = (animate?: boolean) => { | ||
const [hovering, setHovering] = useState<boolean>(animate ?? false); | ||
|
||
const handleMouseEnter = useCallback(() => { | ||
if (animate) return; | ||
setHovering(true); | ||
}, [animate]); | ||
|
||
const handleMouseLeave = useCallback(() => { | ||
if (animate) return; | ||
setHovering(false); | ||
}, [animate]); | ||
|
||
return { hovering, handleMouseEnter, handleMouseLeave }; | ||
}; |
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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
import * as React from 'react'; | ||
import classNames from 'classnames'; | ||
import { autoPlayGif } from '../initial_state'; | ||
import { useHovering } from '../../hooks/useHovering'; | ||
import type { Account } from '../../types/resources'; | ||
|
||
type Props = { | ||
account: Account; | ||
size: number; | ||
style?: React.CSSProperties; | ||
inline?: boolean; | ||
animate?: boolean; | ||
} | ||
|
||
export const Avatar: React.FC<Props> = ({ | ||
account, | ||
animate = autoPlayGif, | ||
size = 20, | ||
inline = false, | ||
style: styleFromParent, | ||
}) => { | ||
|
||
const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(animate); | ||
|
||
const style = { | ||
...styleFromParent, | ||
width: `${size}px`, | ||
height: `${size}px`, | ||
}; | ||
|
||
const src = (hovering || animate) ? account?.get('avatar') : account?.get('avatar_static'); | ||
|
||
return ( | ||
<div className={classNames('account__avatar', { 'account__avatar-inline': inline })} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} style={style}> | ||
{src && <img src={src} alt={account?.get('acct')} />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Avatar; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// @ts-check | ||
import React from 'react'; | ||
// @ts-expect-error | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
/** | ||
|
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
Oops, something went wrong.