From 73843bf273a6bd723987235dcfc5aec39f41d426 Mon Sep 17 00:00:00 2001 From: Inbal Tish Date: Wed, 11 Dec 2024 15:54:31 +0200 Subject: [PATCH 1/5] Docs - ContentItem component - add tooltip with code snippet --- .../components/pageComponents/ContentItem.tsx | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/docuilib/src/components/pageComponents/ContentItem.tsx b/docuilib/src/components/pageComponents/ContentItem.tsx index ea49ad32dd..feda84d869 100644 --- a/docuilib/src/components/pageComponents/ContentItem.tsx +++ b/docuilib/src/components/pageComponents/ContentItem.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useState} from 'react'; import '../ComponentPage.module.scss'; import {LiveProvider, LivePreview} from 'react-live'; import ReactLiveScope from '../../theme/ReactLiveScope'; @@ -26,7 +26,7 @@ function generateComponentCodeSnippet(componentName, componentProps) { return `<${componentName} ${propString} />`; } -const ComponentItem = (props: ComponentItemProps) => { +function getCode(props) { const {componentName, props: componentProps} = props; let code = ''; @@ -37,14 +37,53 @@ const ComponentItem = (props: ComponentItemProps) => { } else { code = generateComponentCodeSnippet(componentName, componentProps); } + return code; +} +const ComponentItem = (props: ComponentItemProps) => { return ( - ${code} `} scope={ReactLiveScope}> + ${getCode(props)}`} scope={ReactLiveScope}> ); }; +const Tooltip = (props: ComponentItemProps) => { + const code = getCode(props); + return ( +
+ + {code} + +
+
+ ); +}; + type Item = { component?: string; props?: any; @@ -55,6 +94,16 @@ type ContentItemProps = { componentName: string; }; export const ContentItem = ({item, componentName}: ContentItemProps) => { + const [show, setShow] = useState(false); + + const onHover = () => { + setShow(true); + }; + + const onLeave = () => { + setShow(false); + }; + const getFigmaEmbed = item => { const value = item.value; const height = item.height || 450; @@ -73,7 +122,12 @@ export const ContentItem = ({item, componentName}: ContentItemProps) => { const isComponentExists = !!ReactLiveScope[name]; if (isComponentExists) { - return ; + return ( +
+ {show && } + +
+ ); } else if (!value) { return
Component Not Supported
; } From fb340a782724c27531c1997e8ab595a6800daeab Mon Sep 17 00:00:00 2001 From: Inbal Tish Date: Thu, 12 Dec 2024 09:16:21 +0200 Subject: [PATCH 2/5] Add copy to clipboard --- .../components/pageComponents/ContentItem.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/docuilib/src/components/pageComponents/ContentItem.tsx b/docuilib/src/components/pageComponents/ContentItem.tsx index feda84d869..f84c47ac8e 100644 --- a/docuilib/src/components/pageComponents/ContentItem.tsx +++ b/docuilib/src/components/pageComponents/ContentItem.tsx @@ -48,17 +48,30 @@ const ComponentItem = (props: ComponentItemProps) => { ); }; +const copy = () => { + let copyText = document.getElementById('component_code').innerHTML; + copyText = copyText.replace('<', '<'); + copyText = copyText.replace(' />', '/>'); + navigator.clipboard.writeText(copyText); + console.log('copied: ', copyText); +}; + +// const copyIcon = 'https://github.com/wix/react-native-ui-lib/blob/2155a91386f884db816c4d45d97e47bed6024d98/docuilib/src/assets/icons/copy.png?raw=true'; +const copyIcon = require('../../assets/icons/copy.png'); + const Tooltip = (props: ComponentItemProps) => { const code = getCode(props); return ( -
+
{ marginLeft: '-60px' }} > - {code} +
{code}
+
Date: Thu, 12 Dec 2024 09:56:41 +0200 Subject: [PATCH 3/5] Add copy icon --- docuilib/src/components/pageComponents/ContentItem.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docuilib/src/components/pageComponents/ContentItem.tsx b/docuilib/src/components/pageComponents/ContentItem.tsx index f84c47ac8e..fa2b8dde56 100644 --- a/docuilib/src/components/pageComponents/ContentItem.tsx +++ b/docuilib/src/components/pageComponents/ContentItem.tsx @@ -56,8 +56,7 @@ const copy = () => { console.log('copied: ', copyText); }; -// const copyIcon = 'https://github.com/wix/react-native-ui-lib/blob/2155a91386f884db816c4d45d97e47bed6024d98/docuilib/src/assets/icons/copy.png?raw=true'; -const copyIcon = require('../../assets/icons/copy.png'); +const copyIcon = 'https://github.com/wix/react-native-ui-lib/blob/master/docuilib/src/assets/icons/copy.png?raw=true'; const Tooltip = (props: ComponentItemProps) => { const code = getCode(props); @@ -81,7 +80,7 @@ const Tooltip = (props: ComponentItemProps) => { }} >
{code}
- +
Date: Thu, 12 Dec 2024 09:58:21 +0200 Subject: [PATCH 4/5] remove console --- docuilib/src/components/pageComponents/ContentItem.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/docuilib/src/components/pageComponents/ContentItem.tsx b/docuilib/src/components/pageComponents/ContentItem.tsx index fa2b8dde56..9e8a4aeaa5 100644 --- a/docuilib/src/components/pageComponents/ContentItem.tsx +++ b/docuilib/src/components/pageComponents/ContentItem.tsx @@ -53,7 +53,6 @@ const copy = () => { copyText = copyText.replace('<', '<'); copyText = copyText.replace(' />', '/>'); navigator.clipboard.writeText(copyText); - console.log('copied: ', copyText); }; const copyIcon = 'https://github.com/wix/react-native-ui-lib/blob/master/docuilib/src/assets/icons/copy.png?raw=true'; From 66c13606d795dcf978c83b449aa63bd621de3680 Mon Sep 17 00:00:00 2001 From: Inbal Tish Date: Tue, 31 Dec 2024 10:21:40 +0200 Subject: [PATCH 5/5] replace hover with button and fix copy --- .../components/pageComponents/ContentItem.tsx | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/docuilib/src/components/pageComponents/ContentItem.tsx b/docuilib/src/components/pageComponents/ContentItem.tsx index 9e8a4aeaa5..670d09f837 100644 --- a/docuilib/src/components/pageComponents/ContentItem.tsx +++ b/docuilib/src/components/pageComponents/ContentItem.tsx @@ -50,8 +50,8 @@ const ComponentItem = (props: ComponentItemProps) => { const copy = () => { let copyText = document.getElementById('component_code').innerHTML; - copyText = copyText.replace('<', '<'); - copyText = copyText.replace(' />', '/>'); + copyText = copyText.replace(new RegExp('<', 'g'), '<'); + copyText = copyText.replace(new RegExp(' />', 'g'), '/>'); navigator.clipboard.writeText(copyText); }; @@ -60,25 +60,26 @@ const copyIcon = 'https://github.com/wix/react-native-ui-lib/blob/master/docuili const Tooltip = (props: ComponentItemProps) => { const code = getCode(props); return ( -
+
-
{code}
+
{code}
{ const [show, setShow] = useState(false); - const onHover = () => { - setShow(true); - }; - - const onLeave = () => { - setShow(false); + const toggleCodeTooltip = () => { + setShow(!show); }; const getFigmaEmbed = item => { @@ -132,12 +129,14 @@ export const ContentItem = ({item, componentName}: ContentItemProps) => { if (item.props) { const name = item.component ?? componentName; const isComponentExists = !!ReactLiveScope[name]; - + const buttonLabel = show ? 'Hide code' : 'Show code'; + if (isComponentExists) { return ( -
- {show && } +
+
{buttonLabel}
+ {show && }
); } else if (!value) {