playroom 0.44.2 → 0.44.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # playroom
2
2
 
3
+ ## 0.44.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#446](https://github.com/seek-oss/playroom/pull/446) [`aa4ac22`](https://github.com/seek-oss/playroom/commit/aa4ac229ec731b0051b2419982f80e7eaf37c874) Thanks [@felixhabib](https://github.com/felixhabib)! - Update method to manage tab titles
8
+
9
+ Remove `react-helmet` dependency.
10
+
3
11
  ## 0.44.2
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playroom",
3
- "version": "0.44.2",
3
+ "version": "0.44.3",
4
4
  "description": "Design with code, powered by your own component library",
5
5
  "bin": {
6
6
  "playroom": "bin/cli.cjs"
@@ -81,7 +81,6 @@
81
81
  "prop-types": "^15.8.1",
82
82
  "react-docgen-typescript": "^2.2.2",
83
83
  "react-error-boundary": "^4.0.13",
84
- "react-helmet": "^6.1.0",
85
84
  "react-transition-group": "^4.4.5",
86
85
  "read-pkg-up": "^7.0.1",
87
86
  "scope-eval": "^1.0.0",
@@ -101,7 +100,6 @@
101
100
  "@testing-library/cypress": "^10.0.3",
102
101
  "@types/jest": "^29.2.4",
103
102
  "@types/node": "^18.11.9",
104
- "@types/react-helmet": "^6.1.6",
105
103
  "@types/react-transition-group": "^4.4.10",
106
104
  "@types/webpack-env": "^1.18.8",
107
105
  "concurrently": "^9.1.2",
@@ -6,9 +6,9 @@ import {
6
6
  useRef,
7
7
  useState,
8
8
  } from 'react';
9
- import { Helmet } from 'react-helmet';
10
9
 
11
10
  import { StoreContext, type EditorPosition } from '../../contexts/StoreContext';
11
+ import { useDocumentTitle } from '../../utils/useDocumentTitle';
12
12
  import { Box } from '../Box/Box';
13
13
  import { CodeEditor } from '../CodeEditor/CodeEditor';
14
14
  import Frames from '../Frames/Frames';
@@ -32,20 +32,6 @@ const resolveDirection = (
32
32
  return editorHidden ? 'up' : 'down';
33
33
  };
34
34
 
35
- const getTitle = (title: string | undefined) => {
36
- if (title) {
37
- return `${title} | Playroom`;
38
- }
39
-
40
- const configTitle = window?.__playroomConfig__.title;
41
-
42
- if (configTitle) {
43
- return `${configTitle} | Playroom`;
44
- }
45
-
46
- return 'Playroom';
47
- };
48
-
49
35
  const resizeHandlePosition: Record<
50
36
  EditorPosition,
51
37
  ComponentProps<typeof ResizeHandle>['position']
@@ -69,6 +55,9 @@ export default () => {
69
55
  },
70
56
  dispatch,
71
57
  ] = useContext(StoreContext);
58
+
59
+ useDocumentTitle({ title });
60
+
72
61
  const editorRef = useRef<HTMLElement | null>(null);
73
62
  const transitionTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);
74
63
  const [resizing, setResizing] = useState(false);
@@ -104,12 +93,6 @@ export default () => {
104
93
  [styles.editorSize]: editorHidden ? undefined : editorSize,
105
94
  })}
106
95
  >
107
- {title === undefined ? null : (
108
- <Helmet>
109
- <title>{getTitle(title)}</title>
110
- </Helmet>
111
- )}
112
-
113
96
  <Box position="relative" className={styles.frames}>
114
97
  <Box className={styles.framesContainer}>
115
98
  <Frames code={previewRenderCode || code} />
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState, type ReactNode } from 'react';
2
- import { Helmet } from 'react-helmet';
3
2
 
3
+ import { useDocumentTitle } from '../../utils/useDocumentTitle';
4
4
  import { Box } from '../Box/Box';
5
5
 
6
6
  import SplashScreen from './SplashScreen/SplashScreen';
@@ -17,6 +17,8 @@ interface PreviewProps {
17
17
  export default ({ title, children }: PreviewProps) => {
18
18
  const [loading, setLoading] = useState(true);
19
19
 
20
+ useDocumentTitle({ title, suffix: 'Playroom Preview' });
21
+
20
22
  useEffect(() => {
21
23
  const hideSplash = setTimeout(
22
24
  () => setLoading(false),
@@ -28,11 +30,6 @@ export default ({ title, children }: PreviewProps) => {
28
30
 
29
31
  return (
30
32
  <>
31
- <Helmet>
32
- <title>
33
- {title ? `${title} | Playroom Preview` : 'Playroom Preview'}
34
- </title>
35
- </Helmet>
36
33
  <Box position="relative" zIndex={0} aria-hidden={loading || undefined}>
37
34
  {children}
38
35
  </Box>
@@ -0,0 +1,27 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import playroomConfig from '../config';
4
+
5
+ interface UseDocumentTitleProps {
6
+ title?: string;
7
+ suffix?: string;
8
+ }
9
+
10
+ export function useDocumentTitle({ title, suffix }: UseDocumentTitleProps) {
11
+ useEffect(() => {
12
+ document.title = getTitle({ title, suffix });
13
+ }, [title, suffix]);
14
+ }
15
+
16
+ function getTitle({
17
+ title,
18
+ suffix = 'Playroom',
19
+ }: UseDocumentTitleProps): string {
20
+ const resolvedTitle = title || playroomConfig?.title;
21
+
22
+ if (resolvedTitle) {
23
+ return `${resolvedTitle} | ${suffix}`;
24
+ }
25
+
26
+ return suffix;
27
+ }