From fb7ba6f392b65809a932b5a26fe60111bba24081 Mon Sep 17 00:00:00 2001
From: Allison Levine <1689238+allilevine@users.noreply.github.com>
Date: Mon, 30 Dec 2024 11:29:35 -0500
Subject: [PATCH] Notifications: Refactor gridicons as functional component and
add translations (#97784)
* Refactor gridicons as functional component and add translations.
* Fix more tooltip text.
* Fix failing test by filtering instead of checking for an exact match.
* Convert file to tsx, change class variable name, change Hide to Dismiss.
* Undo svg path changes.
* Undo another svg path change.
---
.../{gridicons.jsx => gridicons.tsx} | 106 +++++++++---------
.../lib/components/notifications-component.ts | 3 +-
2 files changed, 53 insertions(+), 56 deletions(-)
rename apps/notifications/src/panel/templates/{gridicons.jsx => gridicons.tsx} (77%)
diff --git a/apps/notifications/src/panel/templates/gridicons.jsx b/apps/notifications/src/panel/templates/gridicons.tsx
similarity index 77%
rename from apps/notifications/src/panel/templates/gridicons.jsx
rename to apps/notifications/src/panel/templates/gridicons.tsx
index 829b37bbf56fe..6fd77bc06e318 100644
--- a/apps/notifications/src/panel/templates/gridicons.jsx
+++ b/apps/notifications/src/panel/templates/gridicons.tsx
@@ -1,33 +1,33 @@
import clsx from 'clsx';
-import PropTypes from 'prop-types';
-import { Component } from 'react';
+import { useTranslate } from 'i18n-calypso';
+import { forwardRef } from 'react';
-export default class extends Component {
- static displayName = 'Gridicons';
-
- static propTypes = {
- icon: PropTypes.string.isRequired,
- size: PropTypes.number,
- onClick: PropTypes.func,
- };
+interface GridiconsProps {
+ icon: string;
+ size?: number;
+ onClick?: () => void;
+}
- render() {
- const { onClick, size = 24 } = this.props;
- const icon = `gridicons-${ this.props.icon }`;
+const Gridicons = forwardRef< SVGSVGElement, GridiconsProps >(
+ ( { icon, size = 24, onClick }, ref ) => {
+ const translate = useTranslate();
+ const gridiconClass = `gridicons-${ icon }`;
const sharedProps = {
- className: clsx( 'gridicon', icon ),
+ className: clsx( 'gridicon', gridiconClass ),
height: size,
width: size,
onClick,
+ ref,
};
- switch ( icon ) {
+ switch ( gridiconClass ) {
default:
return ;
case 'gridicons-checkmark':
return (
@@ -36,6 +36,7 @@ export default class extends Component {
case 'gridicons-spam':
return (
@@ -44,6 +45,7 @@ export default class extends Component {
case 'gridicons-star':
return (
@@ -52,7 +54,7 @@ export default class extends Component {
case 'gridicons-star-outline':
return (