Skip to content

Commit

Permalink
after-action-change.tsx documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rafde committed Jan 5, 2025
1 parent 16ead83 commit 64189a5
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 60 deletions.
25 changes: 25 additions & 0 deletions site/src/components/nav-sidebar/config/use-cta-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ export const useCTAParameterCompareConfig: NavItem = {
],
title: 'Parameter: compare',
};

export const useCTAParameterAfterActionChangeExampleConfig: NavItem = {
desc: <>
Parameter:
{' '}
<Code>afterActionChange</Code>
{' '}
Example
</>,
href: 'use-cta-parameter-after-action-change-example',
title: 'Parameter: afterActionChange Example',
};
export const useCTAParameterAfterActionChangeConfig: NavItem = {
desc: <>
Parameter:
{' '}
<Code>afterActionChange</Code>
</>,
href: 'use-cta-parameter-after-action-change',
subNav: [
useCTAParameterAfterActionChangeExampleConfig,
],
title: 'Parameter: afterActionChange',
};
export const useCTAReturnValues0HistoryConfig: NavItem = {
desc: <>
<Code>useCTA return</Code>
Expand Down Expand Up @@ -123,6 +147,7 @@ export const useCTAConfig: NavItem = {
useCTAParameterInitialConfig,
useCTAParameterOnInitConfig,
useCTAParameterCompareConfig,
useCTAParameterAfterActionChangeConfig,
useCTAParameterActionsConfig,
useCTAReturnValuesConfig,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SourceCodeRecordProps, } from '../../types/source-code-record-props';
import PopoverTypes from './index';

export default function PopoverUseCTAParameterAfterActionChange( props: SourceCodeRecordProps, ) {
return <PopoverTypes className="max-w-[630px]" aria-label="Use CTA Parameter: after action change">
{props.sourceCodeRecord[ 'types/UseCTAParameterAfterActionChange.ts' ]}
</PopoverTypes>;
}
26 changes: 19 additions & 7 deletions site/src/components/topics/create-cta-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../nav-sidebar/config/create-cta-context-config';
import {
useCTAConfig,
useCTAParameterActionsConfig,
useCTAParameterActionsConfig, useCTAParameterAfterActionChangeConfig,
useCTAParameterCompareConfig,
useCTAParameterInitialConfig,
useCTAParameterOnInitConfig,
Expand All @@ -17,6 +17,7 @@ import { useCTAReturnValues1DispatchConfig, } from '../nav-sidebar/config/use-ct
import PopoverCTAHistory from '../popover/ctaHistory';
import PopoverCTAState from '../popover/ctaState';
import PopoverUseCTAParameterActionsRecordProp from '../popover/PopoverUseCTAParameterActionsRecordProp';
import PopoverUseCTAParameterAfterActionChange from '../popover/UseCTAParameterAfterActionChange';
import PopoverUseCTAParameterCompare from '../popover/UseCTAParameterCompare';
import PopoverUseCTAParameterOnInit from '../popover/UseCTAParameterOnInit';
import Anchor from '../ui/anchor';
Expand Down Expand Up @@ -106,18 +107,20 @@ export const useCTADispatchContext = context.useCTADispatchContext;
<PopoverUseCTAParameterOnInit sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor href={useCTAParameterActionsConfig.href} aria-label={useCTAParameterActionsConfig.title}>
<Code>actions</Code>
<Anchor
href={useCTAParameterAfterActionChangeConfig.href}
aria-label={useCTAParameterAfterActionChangeConfig.title}>
<Code>afterActionChange</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterActionsRecordProp sourceCodeRecord={props.sourceCodeRecord} />
<PopoverUseCTAParameterAfterActionChange sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor href={useCTAParameterCompareConfig.href} aria-label={useCTAParameterCompareConfig.title}>
<Code>compare</Code>
<Anchor href={useCTAParameterActionsConfig.href} aria-label={useCTAParameterActionsConfig.title}>
<Code>actions</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterCompare sourceCodeRecord={props.sourceCodeRecord} />
<PopoverUseCTAParameterActionsRecordProp sourceCodeRecord={props.sourceCodeRecord} />
</li>
</ul>
</Content>
Expand Down Expand Up @@ -174,6 +177,15 @@ export const useCTADispatchContext = context.useCTADispatchContext;
{' '}
<PopoverUseCTAParameterCompare sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor
href={useCTAParameterAfterActionChangeConfig.href}
aria-label={useCTAParameterAfterActionChangeConfig.title}>
<Code>afterActionChange</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterAfterActionChange sourceCodeRecord={props.sourceCodeRecord} />
</li>
</ul>
</li>
<li>
Expand Down
22 changes: 15 additions & 7 deletions site/src/components/topics/create-cta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import {
createCTAParametersConfig, createCTAReturnValuesConfig,
} from '../nav-sidebar/config/create-cta-config';
import {
useCTAConfig, useCTAParameterActionsConfig, useCTAParameterCompareConfig,
useCTAConfig, useCTAParameterActionsConfig, useCTAParameterAfterActionChangeConfig, useCTAParameterCompareConfig,
useCTAParameterInitialConfig,
useCTAReturnValues0HistoryConfig,
} from '../nav-sidebar/config/use-cta-config';
import { useCTAReturnValues1DispatchConfig, } from '../nav-sidebar/config/use-cta-return-values-1-dispatch-config';
import PopoverCTAHistory from '../popover/ctaHistory';
import PopoverCTAState from '../popover/ctaState';
import PopoverUseCTAParameterActionsRecordProp from '../popover/PopoverUseCTAParameterActionsRecordProp';
import PopoverUseCTAParameterAfterActionChange from '../popover/UseCTAParameterAfterActionChange';
import PopoverUseCTAParameterCompare from '../popover/UseCTAParameterCompare';
import Anchor from '../ui/anchor';
import Code from '../ui/code';
Expand Down Expand Up @@ -93,18 +94,25 @@ export dispatch = ctaValue[1];
<PopoverCTAState sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor href={useCTAParameterActionsConfig.href} aria-label={useCTAParameterActionsConfig.title}>
<Code>actions</Code>
<Anchor href={useCTAParameterCompareConfig.href} aria-label={useCTAParameterCompareConfig.title}>
<Code>compare</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterActionsRecordProp sourceCodeRecord={props.sourceCodeRecord} />
<PopoverUseCTAParameterCompare sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor href={useCTAParameterCompareConfig.href} aria-label={useCTAParameterCompareConfig.title}>
<Code>compare</Code>
<Anchor href={useCTAParameterAfterActionChangeConfig.href} aria-label={useCTAParameterAfterActionChangeConfig.title}>
<Code>afterActionChange</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterCompare sourceCodeRecord={props.sourceCodeRecord} />
<PopoverUseCTAParameterAfterActionChange sourceCodeRecord={props.sourceCodeRecord} />
</li>
<li>
<Anchor href={useCTAParameterActionsConfig.href} aria-label={useCTAParameterActionsConfig.title}>
<Code>actions</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterActionsRecordProp sourceCodeRecord={props.sourceCodeRecord} />
</li>
</ul>
</Content>
Expand Down
2 changes: 2 additions & 0 deletions site/src/components/topics/use-cta/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CodeBlock from '../../ui/codeBlock';
import ExampleDetails from '../../ui/exampleDetails';
import Sect from '../../ui/sect';
import UseCTAParameterActionsTopic from './parameters/actions';
import { UseCTAParameterAfterActionChangeTopic, } from './parameters/after-action-change';
import UseCTAParameterOnInitTopic from './parameters/on-init';
import UseCTAParameterInitialTopic from './parameters/initial';
import UseCTAParameterCompareTopic from './parameters/compare';
Expand Down Expand Up @@ -52,6 +53,7 @@ export function FC() {
<UseCTAParameterInitialTopic {...props} />
<UseCTAParameterOnInitTopic {...props} />
<UseCTAParameterCompareTopic {...props} />
<UseCTAParameterAfterActionChangeTopic {...props} />
<UseCTAParameterActionsTopic {...props} />
<UseCTAReturnValuesTopic {...props} />
</>;
Expand Down
104 changes: 104 additions & 0 deletions site/src/components/topics/use-cta/parameters/after-action-change.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { SourceCodeRecordProps, } from '../../../../types/source-code-record-props';
import {
useCTAParameterActionsConfig,
useCTAParameterAfterActionChangeConfig,
useCTAParameterAfterActionChangeExampleConfig, useCTAReturnValues0HistoryConfig,
} from '../../../nav-sidebar/config/use-cta-config';
import {
useCTAParameterActionsCustomConfig,
} from '../../../nav-sidebar/config/use-cta-parameter-actions-custom-config';
import PopoverUseCTAParameterActionsRecordProp from '../../../popover/PopoverUseCTAParameterActionsRecordProp';
import Anchor from '../../../ui/anchor';
import Code from '../../../ui/code';
import CodeBlock from '../../../ui/codeBlock';
import Content from '../../../ui/content';
import ExampleDetails from '../../../ui/exampleDetails';
import Sect from '../../../ui/sect';

export function UseCTAParameterAfterActionChangeTopic( props: SourceCodeRecordProps, ) {
return <>
<Sect {...useCTAParameterAfterActionChangeConfig}>
<Content>
<p>
<i>Optional</i>
{' '}
callback:
</p>
<CodeBlock>{props.sourceCodeRecord[ 'types/UseCTAParameterAfterActionChange.ts' ]}</CodeBlock>
<ol className="list-inside list-decimal">
<li>
<Code>ctaHistory</Code>
{': '}
New
{' '}
<Anchor
href={useCTAReturnValues0HistoryConfig.href}
aria-label={`Link to ${useCTAReturnValues0HistoryConfig.title} section`}>
state history
</Anchor>
.
</li>
<li>
<Code>ctaHistory</Code>
{': '}
Built-in
{' '}
<Anchor href={useCTAParameterActionsConfig.href} aria-label={useCTAParameterActionsConfig.title}>
<Code>actions</Code>
</Anchor>
{' '}
<PopoverUseCTAParameterActionsRecordProp sourceCodeRecord={props.sourceCodeRecord} />
{' '}
keys.
</li>
<li>
<Code>customActionName</Code>
{': '}
If any
{' '}
<Anchor
aria-label={useCTAParameterActionsCustomConfig.title}
href={useCTAParameterActionsCustomConfig.href}>
custom actions
</Anchor>
{' '}
were defined, the key will get passed to this parameter.
</li>
</ol>

<p>
There&#39;s no return value.
</p>

<b>Features:</b>
<ul className="list-inside list-[square]">
<li>Internally, this gets called asynchronously.</li>
<li>
Only runs after an action has changed the hook state history.
</li>
<li>
You can use this for logging, analytics, setting
{' '}
<Code>localStorage</Code>
, etc.
</li>
</ul>
</Content>
</Sect>
<Sect {...useCTAParameterAfterActionChangeExampleConfig} Header="h5">
<ExampleDetails
summary={<>
Click to view
{' '}
<Code>useCTA</Code>
{' '}
<Code>afterActionChange</Code>
{' '}
parameter example
</>}
title="react-hook-use-cta useCTA afterActionChange parameter example"
src=""
/>
</Sect>
</>;
}
95 changes: 52 additions & 43 deletions site/src/components/topics/use-cta/parameters/compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,58 @@ export default function UseCTAParameterCompareTopic( props: SourceCodeRecordProp
{' '}
callback:
</p>
<CodeBlock>{props.sourceCodeRecord[ 'types/UseCTAParameterCompare.ts' ]}</CodeBlock>
<p>
<Code>previousValue</Code>
{': '}
<Code>current</Code>
{' '}
state property value.
</p>
<p>
<Code>nextValue</Code>
{': '}
value sent from calling an action.
</p>
<p>
<Code>extra.key</Code>
{' '}
related to the state property being compared.
</p>
<p>
<Code>extra.cmp</Code>
{' '}
gives you access to
{' '}
<a
href="https://github.com/planttheidea/fast-equals/tree/v5.0.1?tab=readme-ov-file#strictdeepequal"
target="_blank"
className="underline"
rel="noreferrer"
>
strictDeepEqual
</a>
{' '}
from
{' '}
<a
href="https://github.com/planttheidea/fast-equals/tree/v5.0.1?tab=readme-ov-file#fast-equals"
target="_blank"
className="underline"
rel="noreferrer"
>
fast-equals
</a>
</p>
<CodeBlock>{props.sourceCodeRecord[ 'types/UseCTAParameterAfterActionChange.ts' ]}</CodeBlock>
<ol className="list-inside list-decimal">
<li>
<Code>previousValue</Code>
{': '}
<Code>current</Code>
{' '}
state property value.
</li>
<li>
<Code>nextValue</Code>
{': '}
value sent from calling an action.
</li>
<li>
<Code>extra</Code>
{': '}
object containing
<ul className="list-inside list-[square] pl-5">
<li>
<Code>extra.key</Code>
{': '}
related to the state property being compared.
</li>
<li>
<Code>extra.cmp</Code>
{': '}
gives you access to
{' '}
<a
href="https://github.com/planttheidea/fast-equals/tree/v5.0.1?tab=readme-ov-file#strictdeepequal"
target="_blank"
className="underline"
rel="noreferrer"
>
strictDeepEqual
</a>
{' '}
from
{' '}
<a
href="https://github.com/planttheidea/fast-equals/tree/v5.0.1?tab=readme-ov-file#fast-equals"
target="_blank"
className="underline"
rel="noreferrer"
>
fast-equals
</a>
</li>
</ul>
</li>
</ol>

<p>
It should return:
Expand Down
1 change: 1 addition & 0 deletions site/src/util/getSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const sourceFileList = [
'types/CTAHistory.ts',
'types/UseCTAParameterOnInit.ts',
'types/UseCTAParameterCompare.ts',
'types/UseCTAParameterAfterActionChange.ts',
'types/UseCTAParameterActionsRecordProp.ts',
{
filePath: 'types/UseCTAParameterActionsRecordProp.ts',
Expand Down
Loading

0 comments on commit 64189a5

Please sign in to comment.