@@ -4,6 +4,12 @@ import cx from 'classix';
44import { For , type JSX , splitProps , Suspense } from 'solid-js' ;
55import { isServer } from 'solid-js/web' ;
66
7+ import {
8+ PLACEHOLDER_DELAY_ATTR ,
9+ placeholderDelayedHide ,
10+ placeholderDelayedShow ,
11+ } from '~/shared/components/callbacks/placeholder' ;
12+ import { callbackAttrs } from '~/shared/utility/callback-attrs/callback-registry' ;
713import { randInt } from '~/shared/utility/random' ;
814import { useT } from '~/shared/utility/solid/locale-context' ;
915
@@ -33,6 +39,45 @@ export function Placeholder(props: PlaceholderProps) {
3339 ) ;
3440}
3541
42+ /**
43+ * Fixed width pill placeholder, used for inline elements in text
44+ */
45+ export function MissingPlaceholder ( props : JSX . HTMLAttributes < HTMLSpanElement > ) {
46+ const [ local , rest ] = splitProps ( props , [ 'class' ] ) ;
47+ const t = useT ( ) ;
48+
49+ return (
50+ < span class = { cx ( 'c-placeholder--missing' , local . class ) } aria-label = { t `Missing` } { ...rest } />
51+ ) ;
52+ }
53+
54+ /**
55+ * Show placeholder for a given amount of time before rendering content
56+ */
57+ export function DelayedPlaceholder ( props : {
58+ delay ?: number | undefined ;
59+ fallback ?: JSX . Element ;
60+ children : JSX . Element ;
61+ } ) {
62+ return (
63+ < >
64+ < div
65+ { ...{ [ PLACEHOLDER_DELAY_ATTR ] : String ( props . delay ?? 3000 ) } }
66+ { ...callbackAttrs ( placeholderDelayedHide ) }
67+ >
68+ { props . fallback ?? < Placeholder /> }
69+ </ div >
70+ < div
71+ class = "t-hidden"
72+ { ...{ [ PLACEHOLDER_DELAY_ATTR ] : String ( props . delay ?? 3000 ) } }
73+ { ...callbackAttrs ( placeholderDelayedShow ) }
74+ >
75+ { props . children }
76+ </ div >
77+ </ >
78+ ) ;
79+ }
80+
3681/**
3782 * Fixed width pill placeholder, used for inline elements in text
3883 */
@@ -53,7 +98,38 @@ export function InlineMissingPlaceholder(props: JSX.HTMLAttributes<HTMLSpanEleme
5398 const t = useT ( ) ;
5499
55100 return (
56- < span class = { cx ( 'c-placeholder--missing' , local . class ) } aria-label = { t `Missing` } { ...rest } />
101+ < span
102+ class = { cx ( 'c-placeholder--inline-missing' , local . class ) }
103+ aria-label = { t `Missing` }
104+ { ...rest }
105+ />
106+ ) ;
107+ }
108+
109+ /**
110+ * Show placeholder for a given amount of time before rendering content
111+ */
112+ export function InlineDelayedPlaceholder ( props : {
113+ delay ?: number | undefined ;
114+ fallback ?: JSX . Element ;
115+ children : JSX . Element ;
116+ } ) {
117+ return (
118+ < >
119+ < span
120+ { ...{ [ PLACEHOLDER_DELAY_ATTR ] : String ( props . delay ?? 3000 ) } }
121+ { ...callbackAttrs ( placeholderDelayedHide ) }
122+ >
123+ { props . fallback ?? < InlinePlaceholder /> }
124+ </ span >
125+ < span
126+ class = "t-hidden"
127+ { ...{ [ PLACEHOLDER_DELAY_ATTR ] : String ( props . delay ?? 3000 ) } }
128+ { ...callbackAttrs ( placeholderDelayedShow ) }
129+ >
130+ { props . children }
131+ </ span >
132+ </ >
57133 ) ;
58134}
59135
0 commit comments