Skip to content

Commit 14ee3a9

Browse files
committed
Upgrade RenderConfig staticString prop to staticContent that is ReactNode instead of string
1 parent 55ca1e9 commit 14ee3a9

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

src/components/common/indicators/loading-pulse.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { ReactNode } from 'react';
2+
3+
14
export default function LoadingPulse(props: {
25
loadingPulseColor?: string, // Takes background color from currentcolor (i.e. text color) by default!
3-
content?: string // `content` is just used to determine width, but not actually displayed!
6+
content?: ReactNode // `content` is just used to determine width, but not actually displayed!
47
className?: string,
58
}) {
69
const color = props.loadingPulseColor ?? 'bg-[currentcolor]';

src/components/content/home-page/blocks/block-reward.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function BlockReward(props: {
2727
return (
2828
<span className='pl-2 md:pl-4'>
2929
<blockRewardData.Render
30-
staticString='Block Reward:'
30+
staticContent='Block Reward:'
3131
loadingPulseColor='bg-(--grey-fg-color)'
3232
/>
3333
&nbsp;&nbsp;

src/components/content/home-page/blocks/block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function Block(props: {
7272
</span>
7373
<span className='pl-2 md:pl-4 leading-5'>
7474
<blockData.Render
75-
staticString='Recipient:'
75+
staticContent='Recipient:'
7676
loadingPulseColor='bg-(--grey-fg-color)'
7777
/>
7878
&nbsp;&nbsp;

src/components/content/home-page/transactions/transaction.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function Transaction(props: {
3535
</span>
3636
<span className='px-2 md:pl-4'>
3737
<props.blockWithTransactions.Render
38-
staticString='Amount:'
38+
staticContent='Amount:'
3939
loadingPulseColor='bg-(--grey-fg-color)'
4040
/>
4141
&nbsp;&nbsp;
@@ -50,7 +50,7 @@ export default function Transaction(props: {
5050
<div className='flex flex-col ml-12 md:ml-4 my-2 md:my-0'>
5151
<span className='pl-2 md:pl-4'>
5252
<props.blockWithTransactions.Render
53-
staticString='From:'
53+
staticContent='From:'
5454
loadingPulseColor='bg-(--grey-fg-color)'
5555
/>
5656
&nbsp;&nbsp;
@@ -67,7 +67,7 @@ export default function Transaction(props: {
6767
</span>
6868
<span className='pl-7 md:pl-9'>
6969
<props.blockWithTransactions.Render
70-
staticString='To:'
70+
staticContent='To:'
7171
loadingPulseColor='bg-(--grey-fg-color)'
7272
/>
7373
&nbsp;&nbsp;

src/lib/data-state/constructors/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ export const useConfig: DataStateConstructor = <T, A extends any[], R>(config: F
7676
}
7777

7878
const Render = <K extends keyof T>(conf: RenderConfig<T, K> = {}): ReactNode => {
79-
const { valueCallback, field, staticString, error, loadingMessage, loadingPulseColor,
79+
const { valueCallback, field, staticContent, error, loadingMessage, loadingPulseColor,
8080
showFallback = true, loadingFallback, errorFallback, jointClass } = conf;
8181

8282
switch (dataRoot.status) {
8383
case 'loading':
8484
if (showFallback) {
8585
if (loadingFallback) return loadingFallback;
8686
else if (loadingMessage) return <LoadingIndicator message={loadingMessage} className={jointClass} />;
87-
else return <LoadingPulse loadingPulseColor={loadingPulseColor} className={jointClass} content={staticString} />;
87+
else return <LoadingPulse loadingPulseColor={loadingPulseColor} className={jointClass} content={staticContent} />;
8888
} return;
8989
case 'value':
9090
if (valueCallback) {
@@ -105,15 +105,15 @@ export const useConfig: DataStateConstructor = <T, A extends any[], R>(config: F
105105
return value;
106106
} else if (field) {
107107
return <span className={jointClass}>{ String(dataRoot.value[field]) }</span>;
108-
} else if (staticString) {
109-
return <span className={jointClass}>{ staticString }</span>;
108+
} else if (staticContent) {
109+
return <span className={jointClass}>{ staticContent }</span>;
110110
} else return <span className={jointClass}>{ String(dataRoot.value) }</span>;
111111
case 'error':
112-
// When only the staticString prop was provided for the Render function,
113-
// the staticString should be displayed regardless of possible errors,
114-
// since the errors have nothing to do with the static string to display:
115-
if (!valueCallback && !field && staticString) {
116-
return <span className={jointClass}>{ staticString }</span>;
112+
// When only the staticContent prop was provided for the Render function,
113+
// the staticContent should be displayed regardless of possible errors,
114+
// since the errors have nothing to do with the static content to be displayed:
115+
if (!valueCallback && !field && staticContent) {
116+
return <span className={jointClass}>{ staticContent }</span>;
117117
}
118118
else if (showFallback) {
119119
return errorFallback ?? <ErrorIndicator refetch={fetch} error={error} className={jointClass} />;

src/lib/data-state/types/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ export type RenderConfig<T, K extends keyof T> = {
6969
// Optionally render a specific key/field of the DataState's value (IFF it is present):
7070
// If valueCallback() is provided, it will take precedence over field!
7171
field?: K;
72-
// Optionally provide a static string to render:
73-
// This is useful for static content that should only display when other data
74-
// is also available to display, and show a LoadingIndicator if not.
75-
// If valueCallback() or field are provided, they will take precedence over staticString!
76-
// The staticString is also used for setting the width of the LoadingPulse component,
72+
// Optionally provide static content to render:
73+
// This is useful for content that should only display when other data
74+
// is already available to display, or show a LoadingIndicator when not ready available.
75+
// If valueCallback() or field are provided, they will take precedence over staticContent!
76+
// The staticContent is also used for setting the width of the LoadingPulse component,
7777
// so it can also be used for this even when providing a field or valueCallback that
7878
// will take precedence for the value that will be displayed.
79-
staticString?: string;
79+
staticContent?: ReactNode;
8080
// Optional error message to display instead of 'Error':
8181
error?: string;
8282
// Optional message to display while loading:

0 commit comments

Comments
 (0)