From a4e25f1fdfcd652dc3ead45f40fb4fb91cbd3c75 Mon Sep 17 00:00:00 2001 From: Rafa Date: Sun, 5 Jan 2025 21:39:46 -0800 Subject: [PATCH] code syntax wrappers use tailwindcss clean up new lines appearing in code syntax --- .../components/topics/create-cta-context.tsx | 2 +- site/src/components/topics/create-cta.tsx | 2 +- .../topics/return-cta-parameter.tsx | 2 +- .../actions/UseCTAParameterActionsCustom.tsx | 27 ++++++---- .../UseCTAParameterActionsOverridable.tsx | 3 ++ .../use-cta/return/values-dispatch-cta.tsx | 25 +++++----- site/src/components/ui/code.tsx | 26 ++++++---- site/src/components/ui/codeBlock/index.tsx | 50 +++++++++++++++---- 8 files changed, 89 insertions(+), 48 deletions(-) diff --git a/site/src/components/topics/create-cta-context.tsx b/site/src/components/topics/create-cta-context.tsx index 2a7a85c..3203468 100644 --- a/site/src/components/topics/create-cta-context.tsx +++ b/site/src/components/topics/create-cta-context.tsx @@ -39,7 +39,7 @@ const context = createCTAContext({ export const Provider = context.Provider; export const useCTAHistoryContext = context.useCTAHistoryContext; export const useCTADispatchContext = context.useCTADispatchContext; - `} + `.trim()}
diff --git a/site/src/components/topics/create-cta.tsx b/site/src/components/topics/create-cta.tsx index b5822f6..bd33e33 100644 --- a/site/src/components/topics/create-cta.tsx +++ b/site/src/components/topics/create-cta.tsx @@ -36,7 +36,7 @@ const ctaValue = createCTA({ export history = ctaValue[0]; export dispatch = ctaValue[1]; - `} + `.trim()}
diff --git a/site/src/components/topics/return-cta-parameter.tsx b/site/src/components/topics/return-cta-parameter.tsx index e3f47c3..bd1f1b2 100644 --- a/site/src/components/topics/return-cta-parameter.tsx +++ b/site/src/components/topics/return-cta-parameter.tsx @@ -20,7 +20,7 @@ export const ctaParams = returnCTAParameter({ search: '', }, }); - `} + `.trim()}
diff --git a/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsCustom.tsx b/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsCustom.tsx index 47c09ca..1da32b8 100644 --- a/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsCustom.tsx +++ b/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsCustom.tsx @@ -64,8 +64,8 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco Click to view {' '} useCTA - {' '} - custom actions + {' custom '} + actions {' '} example } @@ -153,7 +153,7 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco
  • - {` CustomCTAHistory.updateAction( + {`CustomCTAHistory.updateAction( Partial, { useDefault?: boolean } | undefined, )`} @@ -177,10 +177,11 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco
  • - {` CustomCTAHistory.replaceAction( + {` +CustomCTAHistory.replaceAction( CTAState, { useDefault?: boolean } | undefined, - )`} + )`.trim()}
    @@ -201,10 +202,11 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco
  • - {` CustomCTAHistory.resetAction( + {` +CustomCTAHistory.resetAction( CTAState | undefined, { useDefault?: boolean } | undefined, - )`} + )`.trim()}
    @@ -225,10 +227,11 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco
  • - {` CustomCTAHistory.updateInitialAction( + {` +CustomCTAHistory.updateInitialAction( Partial | undefined, { useDefault?: boolean } | undefined, - )`} + )`.trim()}
    @@ -249,10 +252,12 @@ export default function UseCTAParameterActionsCustomTopic( props: SourceCodeReco
  • - {` CustomCTAHistory.replaceInitialAction( + { + `CustomCTAHistory.replaceInitialAction( CTAState | undefined, { useDefault?: boolean } | undefined, - )`} + )`.trim() + }
    diff --git a/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsOverridable.tsx b/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsOverridable.tsx index eccccb6..d0354e8 100644 --- a/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsOverridable.tsx +++ b/site/src/components/topics/use-cta/parameters/actions/UseCTAParameterActionsOverridable.tsx @@ -1,4 +1,5 @@ import { SourceCodeRecordProps, } from '../../../../../types/source-code-record-props'; +import { useCTAParameterTransformConfig, } from '../../../../nav-sidebar/config/use-cta-config'; import { useCTAParameterActionsOverridableConfig, @@ -29,6 +30,8 @@ export default function UseCTAParameterActionsOverridableTopic( props: SourceCod Optional +

    Alternative to overriding built-in actions.

    + {useCTAParameterTransformConfig.desc}
    {props.sourceCodeRecord.UseCTAParameterActionsOverridable} diff --git a/site/src/components/topics/use-cta/return/values-dispatch-cta.tsx b/site/src/components/topics/use-cta/return/values-dispatch-cta.tsx index 9291a8b..2fcbb1d 100644 --- a/site/src/components/topics/use-cta/return/values-dispatch-cta.tsx +++ b/site/src/components/topics/use-cta/return/values-dispatch-cta.tsx @@ -51,7 +51,7 @@ dispatch.cta.update( keyof CTAState, CTAState[keyof CTAState] ); dispatch.cta.update( Partial ); dispatch.cta.update( ( ctaHistory: CTAHistory ) => Partial | undefined ); - `} + `.trim()}
    @@ -68,7 +68,7 @@ dispatch( { type: 'update', payload: ( ctaHistory: CTAHistory ) => Partial | undefined } ); - `} + `.trim()}
    @@ -92,7 +92,7 @@ dispatch( { dispatch.cta.replace( CTAState ); dispatch.cta.replace( ( ctaHistory: CTAHistory ) => CTAState | undefined ); - `} + `.trim()}
    @@ -109,7 +109,7 @@ dispatch( { type: 'replace', payload: ( ctaHistory: CTAHistory ) => CTAState | undefined } ); - `} + `.trim()}
    @@ -139,7 +139,7 @@ dispatch.cta.reset( CTAState ); // sets the current state and initial state to what is returned from the callback // if the callback returns undefined, the state will not change dispatch.cta.reset( ( ctaHistory: CTAHistory ) => CTAState | undefined ); - `} + `.trim()}
    @@ -163,8 +163,7 @@ dispatch( { dispatch( { type: 'reset', payload: ( ctaHistory: CTAHistory ) => CTAState | undefined -} ); - `} +} );`.trim()}
    @@ -188,7 +187,7 @@ dispatch( { dispatch.cta.updateInitial( Partial ); dispatch.cta.updateInitial( ( ctaHistory: CTAHistory ) => Partial | undefined ); - `} + `.trim()} @@ -206,7 +205,7 @@ dispatch( { type: 'updateInitial', payload: ( ctaHistory: CTAHistory ) => Partial | undefined } ); - `} + `.trim()} @@ -230,7 +229,7 @@ dispatch( { dispatch.cta.replaceInitial( CTAState ); dispatch.cta.replaceInitial( ( ctaHistory: CTAHistory ) => CTAState | undefined ); - `} + `.trim()}
    @@ -247,7 +246,7 @@ dispatch( { type: 'replaceInitial', payload: ( ctaHistory: CTAHistory ) => CTAState | undefined } ); - `} + `.trim()}
    @@ -276,7 +275,7 @@ dispatch.cta.YourCustomActionWithArgs( Payload, ...any[] | undefined ); - `} + `.trim()} @@ -294,7 +293,7 @@ dispatch( { payload: Payload, args: any[] | undefined, } ); - `} + `.trim()} diff --git a/site/src/components/ui/code.tsx b/site/src/components/ui/code.tsx index f0a1bcc..bef2578 100644 --- a/site/src/components/ui/code.tsx +++ b/site/src/components/ui/code.tsx @@ -13,28 +13,32 @@ type CodeProps = { lang?: string } & Omit; -function CodeTag( props: PropsWithChildren<{ className: string - style: CSSProperties }>, ) { +function CodeTag( props: PropsWithChildren<{ + className: string + style: CSSProperties +}>, ) { const { + // eslint-disable-next-line @typescript-eslint/no-unused-vars style, + ..._props } = props; return ; } +function PreTag( props: PropsWithChildren<{ + className: string + style: CSSProperties +}>, ) { + return <>{props.children}; +} export default function Code( props: CodeProps, ) { const { lang = 'typescript', } = props; - return + return {props.children} ; } diff --git a/site/src/components/ui/codeBlock/index.tsx b/site/src/components/ui/codeBlock/index.tsx index 4fed6d5..b775e20 100644 --- a/site/src/components/ui/codeBlock/index.tsx +++ b/site/src/components/ui/codeBlock/index.tsx @@ -1,7 +1,30 @@ +import { CSSProperties, PropsWithChildren, } from 'react'; import { Prism as SyntaxHighlighter, } from 'react-syntax-highlighter'; import { vscDarkPlus, } from 'react-syntax-highlighter/dist/esm/styles/prism'; import CodeBlockCopyButton from './codeBlockCopyButton'; +function PreTag( props: PropsWithChildren<{ + className: string + style: CSSProperties +}>, ) { + return
    {props.children}
    ; +} + +function CodeTag( props: PropsWithChildren<{ + className: string + style: CSSProperties +}>, ) { + const { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + style, + ..._props + } = props; + return ; +} + type CodeBlockProp = { lang?: string children: string @@ -11,19 +34,26 @@ type CodeBlockProp = { export default function CodeBlock( props: CodeBlockProp, ) { const { - lang = 'tsx', + lang = 'typescript', children, copyButton = false, className = '', } = props; const code = children; - return
    - {copyButton && } - - {code} - -
    ; + const codeBlock = + {code} + ; + if ( copyButton ) { + return
    + + {codeBlock} +
    ; + } + + return codeBlock; }