Przeglądaj źródła

Merge pull request #3209 from pyth-network/bduran/address-typing-issue

chore(component-library): responded to PR feedback about having stricter typings and removed runtime guards
Ben Duran 3 dni temu
rodzic
commit
9131a23c32

+ 1 - 1
apps/insights/src/components/LivePrices/index.tsx

@@ -103,7 +103,7 @@ const Price = ({
 
   return (
     <>
-      {updatePageTitle && <DocumentTitle prefix={val} />}
+      {updatePageTitle && <DocumentTitle prefix title={val} />}
       <span
         className={styles.price}
         data-direction={prev ? getChangeDirection(prev, current) : "flat"}

+ 2 - 2
packages/component-library/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/component-library",
-  "version": "0.1.0",
+  "version": "0.1.1",
   "private": true,
   "type": "module",
   "engines": {
@@ -398,4 +398,4 @@
       "./theme": "./dist/theme.scss"
     }
   }
-}
+}

+ 3 - 3
packages/component-library/src/DocumentTitle/document-title.test.tsx

@@ -35,7 +35,7 @@ describe("<DocumentTitle /> tests", () => {
     document.title = initial;
 
     const prefix = "pizza pasta pepperoni";
-    render(<DocumentTitle prefix={prefix} />);
+    render(<DocumentTitle prefix title={prefix} />);
 
     expect(document.title).toBe(`${prefix} | ${initial}`);
   });
@@ -45,14 +45,14 @@ describe("<DocumentTitle /> tests", () => {
     document.title = initial;
 
     const prefix1 = "pizza pasta pepperoni";
-    const { rerender } = render(<DocumentTitle prefix={prefix1} />);
+    const { rerender } = render(<DocumentTitle prefix title={prefix1} />);
 
     expect(document.title).toBe(`${prefix1} | ${initial}`);
 
     await setTimeout(200);
 
     const prefix2 = "tacos and burritos";
-    rerender(<DocumentTitle prefix={prefix2} />);
+    rerender(<DocumentTitle prefix title={prefix2} />);
 
     expect(document.title).toBe(`${prefix2} | ${initial}`);
   });

+ 4 - 9
packages/component-library/src/DocumentTitle/index.tsx

@@ -1,19 +1,19 @@
 import { useEffect, useRef } from "react";
 
-type DocumentTitleProps = Partial<{
+type DocumentTitleProps = {
   /**
    * set this if you want to keep the existing
    * title but want some dynamic content prepended
    * to it
    */
-  prefix: string;
+  prefix?: boolean;
 
   /**
    * set this if you want to explicitly fully-reset the
    * page title and want to fully control it.
    */
   title: string;
-}>;
+};
 
 /**
  * updates the html document.title property
@@ -28,13 +28,8 @@ export function DocumentTitle({ prefix, title }: DocumentTitleProps) {
 
   /** effects */
   useEffect(() => {
-    if (prefix && title) {
-      throw new Error(
-        "<DocumentTitle /> supports either the prefix or title prop, but not both at the same time",
-      );
-    }
     if (prefix) {
-      document.title = `${prefix} | ${initialPageTitleRef.current}`;
+      document.title = `${title} | ${initialPageTitleRef.current}`;
     } else if (title) {
       document.title = title;
     }