From 44a7d87cb1f5df953b6c14c16c59e2e4ead1bcb9 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Mon, 20 Feb 2023 03:20:59 +0100 Subject: Rename JSX files with proper `.jsx` extension (#23733) --- app/javascript/mastodon/components/icon_button.jsx | 164 +++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 app/javascript/mastodon/components/icon_button.jsx (limited to 'app/javascript/mastodon/components/icon_button.jsx') diff --git a/app/javascript/mastodon/components/icon_button.jsx b/app/javascript/mastodon/components/icon_button.jsx new file mode 100644 index 000000000..003692373 --- /dev/null +++ b/app/javascript/mastodon/components/icon_button.jsx @@ -0,0 +1,164 @@ +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.string, + counter: PropTypes.number, + obfuscateCount: PropTypes.bool, + href: PropTypes.string, + ariaHidden: PropTypes.bool, + }; + + static defaultProps = { + size: 18, + active: false, + disabled: false, + animate: false, + overlay: false, + tabIndex: '0', + ariaHidden: false, + }; + + state = { + activate: false, + deactivate: false, + }; + + componentWillReceiveProps (nextProps) { + if (!nextProps.animate) return; + + if (this.props.active && !nextProps.active) { + this.setState({ activate: false, deactivate: true }); + } else if (!this.props.active && nextProps.active) { + this.setState({ activate: true, deactivate: false }); + } + } + + handleClick = (e) => { + e.preventDefault(); + + if (!this.props.disabled) { + this.props.onClick(e); + } + }; + + handleKeyPress = (e) => { + if (this.props.onKeyPress && !this.props.disabled) { + this.props.onKeyPress(e); + } + }; + + handleMouseDown = (e) => { + if (!this.props.disabled && this.props.onMouseDown) { + this.props.onMouseDown(e); + } + }; + + handleKeyDown = (e) => { + if (!this.props.disabled && this.props.onKeyDown) { + this.props.onKeyDown(e); + } + }; + + render () { + const style = { + fontSize: `${this.props.size}px`, + width: `${this.props.size * 1.28571429}px`, + height: `${this.props.size * 1.28571429}px`, + lineHeight: `${this.props.size}px`, + ...this.props.style, + ...(this.props.active ? this.props.activeStyle : {}), + }; + + const { + active, + className, + disabled, + expanded, + icon, + inverted, + overlay, + tabIndex, + title, + counter, + obfuscateCount, + href, + ariaHidden, + } = this.props; + + const { + activate, + deactivate, + } = this.state; + + const classes = classNames(className, 'icon-button', { + active, + disabled, + inverted, + activate, + deactivate, + overlayed: overlay, + 'icon-button--with-counter': typeof counter !== 'undefined', + }); + + if (typeof counter !== 'undefined') { + style.width = 'auto'; + } + + let contents = ( + + + ); + + if (href && !this.prop) { + contents = ( + + {contents} + + ); + } + + return ( + + ); + } + +} -- cgit From ec0c104bf25f2689c31bb79f9f447be1a9b3da7f Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 4 Apr 2023 10:33:44 -0400 Subject: Ensure tabIndex is number instead of string (#24409) --- .../mastodon/components/admin/ReportReasonSelector.jsx | 4 ++-- .../mastodon/components/autosuggest_input.jsx | 2 +- .../mastodon/components/autosuggest_textarea.jsx | 2 +- .../mastodon/components/column_back_button_slim.jsx | 2 +- app/javascript/mastodon/components/dropdown_menu.jsx | 2 +- app/javascript/mastodon/components/gifv.jsx | 4 ++-- app/javascript/mastodon/components/icon_button.jsx | 4 ++-- .../components/intersection_observer_article.jsx | 4 ++-- .../components/picture_in_picture_placeholder.jsx | 2 +- app/javascript/mastodon/components/poll.jsx | 2 +- app/javascript/mastodon/components/status.jsx | 4 ++-- app/javascript/mastodon/components/status_content.jsx | 6 +++--- app/javascript/mastodon/features/about/index.jsx | 2 +- app/javascript/mastodon/features/audio/index.jsx | 8 ++++---- .../features/compose/components/language_dropdown.jsx | 2 +- .../mastodon/features/compose/components/poll_form.jsx | 2 +- .../features/compose/components/privacy_dropdown.jsx | 2 +- .../mastodon/features/compose/components/search.jsx | 2 +- .../mastodon/features/compose/components/upload.jsx | 2 +- .../direct_timeline/components/conversation.jsx | 2 +- .../mastodon/features/filters/select_filter.jsx | 4 ++-- .../features/list_editor/components/search.jsx | 2 +- app/javascript/mastodon/features/list_editor/index.jsx | 2 +- .../mastodon/features/list_timeline/index.jsx | 4 ++-- .../notifications/components/clear_column_button.jsx | 2 +- .../components/grant_permission_button.jsx | 2 +- .../features/notifications/components/notification.jsx | 18 +++++++++--------- .../mastodon/features/report/components/option.jsx | 2 +- app/javascript/mastodon/features/status/index.jsx | 2 +- .../mastodon/features/ui/components/actions_modal.jsx | 2 +- .../mastodon/features/ui/components/media_modal.jsx | 4 ++-- app/javascript/mastodon/features/video/index.jsx | 6 +++--- 32 files changed, 55 insertions(+), 55 deletions(-) (limited to 'app/javascript/mastodon/components/icon_button.jsx') diff --git a/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx b/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx index 58a861fde..cd14dac4e 100644 --- a/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx +++ b/app/javascript/mastodon/components/admin/ReportReasonSelector.jsx @@ -33,7 +33,7 @@ class Category extends React.PureComponent { const { id, text, disabled, selected, children } = this.props; return ( -
+
{selected && }
@@ -74,7 +74,7 @@ class Rule extends React.PureComponent { const { id, text, disabled, selected } = this.props; return ( -
+
{selected && } {text} diff --git a/app/javascript/mastodon/components/autosuggest_input.jsx b/app/javascript/mastodon/components/autosuggest_input.jsx index f9616c581..a68e2a01b 100644 --- a/app/javascript/mastodon/components/autosuggest_input.jsx +++ b/app/javascript/mastodon/components/autosuggest_input.jsx @@ -180,7 +180,7 @@ export default class AutosuggestInput extends ImmutablePureComponent { } return ( -
+
{inner}
); diff --git a/app/javascript/mastodon/components/autosuggest_textarea.jsx b/app/javascript/mastodon/components/autosuggest_textarea.jsx index c04491298..a627bc1ec 100644 --- a/app/javascript/mastodon/components/autosuggest_textarea.jsx +++ b/app/javascript/mastodon/components/autosuggest_textarea.jsx @@ -186,7 +186,7 @@ export default class AutosuggestTextarea extends ImmutablePureComponent { } return ( -
+
{inner}
); diff --git a/app/javascript/mastodon/components/column_back_button_slim.jsx b/app/javascript/mastodon/components/column_back_button_slim.jsx index cc8bfb151..46ac23736 100644 --- a/app/javascript/mastodon/components/column_back_button_slim.jsx +++ b/app/javascript/mastodon/components/column_back_button_slim.jsx @@ -8,7 +8,7 @@ export default class ColumnBackButtonSlim extends ColumnBackButton { render () { return (
-
+
diff --git a/app/javascript/mastodon/components/dropdown_menu.jsx b/app/javascript/mastodon/components/dropdown_menu.jsx index c04c513fb..eaaa72fd8 100644 --- a/app/javascript/mastodon/components/dropdown_menu.jsx +++ b/app/javascript/mastodon/components/dropdown_menu.jsx @@ -119,7 +119,7 @@ class DropdownMenu extends React.PureComponent { return (
  • - + {text}
  • diff --git a/app/javascript/mastodon/components/gifv.jsx b/app/javascript/mastodon/components/gifv.jsx index 9ec201c6c..1ce7e7c29 100644 --- a/app/javascript/mastodon/components/gifv.jsx +++ b/app/javascript/mastodon/components/gifv.jsx @@ -46,7 +46,7 @@ export default class GIFV extends React.PureComponent { width={width} height={height} role='button' - tabIndex='0' + tabIndex={0} aria-label={alt} title={alt} lang={lang} @@ -57,7 +57,7 @@ export default class GIFV extends React.PureComponent {