Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
5a5975d7
Unverified
Commit
5a5975d7
authored
1 year ago
by
fusagiko / takayamaki
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add type annotation for IconButton component (#24753)
parent
32a030dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/javascript/mastodon/components/icon_button.tsx
+38
-36
38 additions, 36 deletions
app/javascript/mastodon/components/icon_button.tsx
with
38 additions
and
36 deletions
app/javascript/mastodon/components/icon_button.
j
sx
→
app/javascript/mastodon/components/icon_button.
t
sx
+
38
−
36
View file @
5a5975d7
import
React
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
classNames
from
'
classnames
'
;
import
Icon
from
'
mastodon/components/icon
'
;
import
AnimatedNumber
from
'
mastodon/components/animated_number
'
;
export
default
class
IconButton
extends
React
.
PureComponent
{
static
propTypes
=
{
className
:
PropTypes
.
string
,
title
:
PropTypes
.
string
.
isRequired
,
icon
:
PropTypes
.
string
.
isRequired
,
onClick
:
PropTypes
.
func
,
onMouseDown
:
PropTypes
.
func
,
onKeyDown
:
PropTypes
.
func
,
onKeyPress
:
PropTypes
.
func
,
size
:
PropTypes
.
number
,
active
:
PropTypes
.
bool
,
expanded
:
PropTypes
.
bool
,
style
:
PropTypes
.
object
,
activeStyle
:
PropTypes
.
object
,
disabled
:
PropTypes
.
bool
,
inverted
:
PropTypes
.
bool
,
animate
:
PropTypes
.
bool
,
overlay
:
PropTypes
.
bool
,
tabIndex
:
PropTypes
.
number
,
counter
:
PropTypes
.
number
,
obfuscateCount
:
PropTypes
.
bool
,
href
:
PropTypes
.
string
,
ariaHidden
:
PropTypes
.
bool
,
};
import
{
Icon
}
from
'
./icon
'
;
import
{
AnimatedNumber
}
from
'
./animated_number
'
;
type
Props
=
{
className
?:
string
;
title
:
string
;
icon
:
string
;
onClick
?:
React
.
MouseEventHandler
<
HTMLButtonElement
>
;
onMouseDown
?:
React
.
MouseEventHandler
<
HTMLButtonElement
>
;
onKeyDown
?:
React
.
KeyboardEventHandler
<
HTMLButtonElement
>
;
onKeyPress
?:
React
.
KeyboardEventHandler
<
HTMLButtonElement
>
;
size
:
number
;
active
:
boolean
;
expanded
?:
boolean
;
style
?:
React
.
CSSProperties
;
activeStyle
?:
React
.
CSSProperties
;
disabled
:
boolean
;
inverted
?:
boolean
;
animate
:
boolean
;
overlay
:
boolean
;
tabIndex
:
number
;
counter
?:
number
;
obfuscateCount
?:
boolean
;
href
?:
string
;
ariaHidden
:
boolean
;
}
type
States
=
{
activate
:
boolean
,
deactivate
:
boolean
,
}
export
default
class
IconButton
extends
React
.
PureComponent
<
Props
,
States
>
{
static
defaultProps
=
{
size
:
18
,
...
...
@@ -45,7 +47,7 @@ export default class IconButton extends React.PureComponent {
deactivate
:
false
,
};
componentWillReceiveProps
(
nextProps
)
{
UNSAFE_
componentWillReceiveProps
(
nextProps
:
Props
)
{
if
(
!
nextProps
.
animate
)
return
;
if
(
this
.
props
.
active
&&
!
nextProps
.
active
)
{
...
...
@@ -55,27 +57,27 @@ export default class IconButton extends React.PureComponent {
}
}
handleClick
=
(
e
)
=>
{
handleClick
:
React
.
MouseEventHandler
<
HTMLButtonElement
>
=
(
e
)
=>
{
e
.
preventDefault
();
if
(
!
this
.
props
.
disabled
)
{
if
(
!
this
.
props
.
disabled
&&
this
.
props
.
onClick
!=
null
)
{
this
.
props
.
onClick
(
e
);
}
};
handleKeyPress
=
(
e
)
=>
{
handleKeyPress
:
React
.
KeyboardEventHandler
<
HTMLButtonElement
>
=
(
e
)
=>
{
if
(
this
.
props
.
onKeyPress
&&
!
this
.
props
.
disabled
)
{
this
.
props
.
onKeyPress
(
e
);
}
};
handleMouseDown
=
(
e
)
=>
{
handleMouseDown
:
React
.
MouseEventHandler
<
HTMLButtonElement
>
=
(
e
)
=>
{
if
(
!
this
.
props
.
disabled
&&
this
.
props
.
onMouseDown
)
{
this
.
props
.
onMouseDown
(
e
);
}
};
handleKeyDown
=
(
e
)
=>
{
handleKeyDown
:
React
.
KeyboardEventHandler
<
HTMLButtonElement
>
=
(
e
)
=>
{
if
(
!
this
.
props
.
disabled
&&
this
.
props
.
onKeyDown
)
{
this
.
props
.
onKeyDown
(
e
);
}
...
...
@@ -132,7 +134,7 @@ export default class IconButton extends React.PureComponent {
</
React
.
Fragment
>
);
if
(
href
&&
!
this
.
prop
)
{
if
(
href
!=
null
)
{
contents
=
(
<
a
href
=
{
href
}
target
=
'_blank'
rel
=
'noopener noreferrer'
>
{
contents
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment