Skip to content

Commit 4f96fda

Browse files
authored
fix(List): propagate skeleton property to children via shared Context (#7161)
1 parent e412612 commit 4f96fda

18 files changed

Lines changed: 333 additions & 22 deletions

packages/dnb-eufemia/src/components/list/ItemAccordion.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { omitSpacingProps, pickSpacingProps } from '../flex/utils'
1919
import ItemIcon from './ItemIcon'
2020
import ItemTitle from './ItemTitle'
2121
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
22+
import Context from '../../shared/Context'
2223

2324
export type ItemAccordionIconPosition = 'left' | 'right'
2425

@@ -141,6 +142,7 @@ function AccordionHeader(props: AccordionHeaderProps) {
141142
title,
142143
} = useContext(ItemAccordionContext)
143144

145+
const context = useContext(Context)
144146
const inheritedSkeleton = useContext(ListContext)?.skeleton
145147
const isInactive = pending || disabled
146148

@@ -166,7 +168,7 @@ function AccordionHeader(props: AccordionHeaderProps) {
166168
[handleClick]
167169
)
168170

169-
return (
171+
const content = (
170172
<FlexItem
171173
className={classnames(
172174
'dnb-list__item__accordion__header',
@@ -191,20 +193,33 @@ function AccordionHeader(props: AccordionHeaderProps) {
191193
{chevronPosition === 'right' && <ChevronIcon />}
192194
</FlexItem>
193195
)
196+
197+
if (inheritedSkeleton) {
198+
return (
199+
<Context.Provider
200+
value={{ ...context, skeleton: inheritedSkeleton }}
201+
>
202+
{content}
203+
</Context.Provider>
204+
)
205+
}
206+
207+
return content
194208
}
195209
ItemAccordion.Header = AccordionHeader
196210
AccordionHeader._supportsSpacingProps = true
197211

198212
function AccordionContent(props: ItemContentProps) {
199213
const { className, children, ...rest } = props
214+
const context = useContext(Context)
200215
const { openState, accordionId, keepInDOM } = useContext(
201216
ItemAccordionContext
202217
)
203218
const inheritedSkeleton = useContext(ListContext)?.skeleton
204219

205220
const spacingProps = pickSpacingProps(rest)
206221

207-
return (
222+
const content = (
208223
<FlexItem
209224
className={classnames(
210225
'dnb-list__item__accordion__content',
@@ -223,6 +238,18 @@ function AccordionContent(props: ItemContentProps) {
223238
</HeightAnimation>
224239
</FlexItem>
225240
)
241+
242+
if (inheritedSkeleton) {
243+
return (
244+
<Context.Provider
245+
value={{ ...context, skeleton: inheritedSkeleton }}
246+
>
247+
{content}
248+
</Context.Provider>
249+
)
250+
}
251+
252+
return content
226253
}
227254
ItemAccordion.Content = AccordionContent
228255
AccordionContent._supportsSpacingProps = true

packages/dnb-eufemia/src/components/list/ItemCenter.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlexItem, { type Props as FlexItemProps } from '../flex/Item'
44
import { ListContext } from './ListContext'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
export type ItemCenterProps = FlexItemProps & {
910
/** Font size of the center content. Defaults to `basis`. */
@@ -19,12 +20,14 @@ function ItemCenter({
1920
fontSize = 'basis',
2021
fontWeight = 'regular',
2122
skeleton,
23+
children,
2224
...rest
2325
}: ItemCenterProps) {
26+
const context = useContext(Context)
2427
const inheritedSkeleton = useContext(ListContext)?.skeleton
2528
const appliedSkeleton = skeleton ?? inheritedSkeleton
2629

27-
return (
30+
const content = (
2831
<FlexItem
2932
className={classnames(
3033
'dnb-list__item__center',
@@ -35,8 +38,20 @@ function ItemCenter({
3538
)}
3639
innerSpace={{ left: 'small' }}
3740
{...rest}
38-
/>
41+
>
42+
{children}
43+
</FlexItem>
3944
)
45+
46+
if (appliedSkeleton) {
47+
return (
48+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
49+
{content}
50+
</Context.Provider>
51+
)
52+
}
53+
54+
return content
4055
}
4156

4257
ItemCenter._supportsSpacingProps = true

packages/dnb-eufemia/src/components/list/ItemContent.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ListVariant, ListContext } from './ListContext'
44
import FlexContainer, { Props as FlexProps } from '../flex/Container'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
export type ItemContentProps = {
910
variant?: ListVariant
@@ -24,14 +25,15 @@ function ItemContent(props: ItemContentProps) {
2425
skeleton,
2526
...rest
2627
} = props
28+
const context = useContext(Context)
2729
const inheritedVariant = useContext(ListContext)?.variant
2830
const inheritedSkeleton = useContext(ListContext)?.skeleton
2931
const inheritedDisabled = useContext(ListContext)?.disabled
3032
const appliedVariant = variant ?? inheritedVariant
3133
const appliedSkeleton = skeleton ?? inheritedSkeleton
3234
const appliedDisabled = disabled ?? inheritedDisabled
3335

34-
return (
36+
const content = (
3537
<FlexContainer
3638
element="li"
3739
direction="horizontal"
@@ -55,6 +57,16 @@ function ItemContent(props: ItemContentProps) {
5557
{pending && <Pending />}
5658
</FlexContainer>
5759
)
60+
61+
if (appliedSkeleton) {
62+
return (
63+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
64+
{content}
65+
</Context.Provider>
66+
)
67+
}
68+
69+
return content
5870
}
5971
ItemContent._supportsSpacingProps = true
6072

packages/dnb-eufemia/src/components/list/ItemEnd.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlexItem, { type Props as FlexItemProps } from '../flex/Item'
44
import { ListContext } from './ListContext'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
/**
910
* Props for List.Cell.End (ItemEnd).
@@ -24,12 +25,14 @@ function ItemEnd(props: ItemEndProps) {
2425
fontSize = 'basis',
2526
skeleton,
2627
className,
28+
children,
2729
...rest
2830
} = props
31+
const context = useContext(Context)
2932
const inheritedSkeleton = useContext(ListContext)?.skeleton
3033
const appliedSkeleton = skeleton ?? inheritedSkeleton
3134

32-
return (
35+
const content = (
3336
<FlexItem
3437
className={classnames(
3538
'dnb-list__item__end',
@@ -40,8 +43,20 @@ function ItemEnd(props: ItemEndProps) {
4043
)}
4144
innerSpace={{ left: 'small', right: 'medium' }}
4245
{...rest}
43-
/>
46+
>
47+
{children}
48+
</FlexItem>
4449
)
50+
51+
if (appliedSkeleton) {
52+
return (
53+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
54+
{content}
55+
</Context.Provider>
56+
)
57+
}
58+
59+
return content
4560
}
4661
ItemEnd._supportsSpacingProps = true
4762

packages/dnb-eufemia/src/components/list/ItemFooter.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Hr from '../../elements/Hr'
55
import { ListContext } from './ListContext'
66
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
77
import type { SkeletonShow } from '../Skeleton'
8+
import Context from '../../shared/Context'
89

910
export type ItemFooterProps = FlexItemProps & {
1011
/** If `true`, applies skeleton loading state. Inherits from parent List context when not set. */
@@ -17,10 +18,11 @@ function ItemFooter({
1718
children,
1819
...rest
1920
}: ItemFooterProps) {
21+
const context = useContext(Context)
2022
const inheritedSkeleton = useContext(ListContext)?.skeleton
2123
const appliedSkeleton = skeleton ?? inheritedSkeleton
2224

23-
return (
25+
const content = (
2426
<>
2527
<Hr
2628
top={false}
@@ -39,6 +41,16 @@ function ItemFooter({
3941
</FlexItem>
4042
</>
4143
)
44+
45+
if (appliedSkeleton) {
46+
return (
47+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
48+
{content}
49+
</Context.Provider>
50+
)
51+
}
52+
53+
return content
4254
}
4355
ItemFooter._supportsSpacingProps = true
4456

packages/dnb-eufemia/src/components/list/ItemOverline.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlexItem, { type Props as FlexItemProps } from '../flex/Item'
44
import { ListContext } from './ListContext'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
/**
910
* Props for List.Cell.Title.Overline (ItemOverline).
@@ -26,10 +27,11 @@ function ItemOverline({
2627
children,
2728
...rest
2829
}: ItemOverlineProps) {
30+
const context = useContext(Context)
2931
const inheritedSkeleton = useContext(ListContext)?.skeleton
3032
const appliedSkeleton = skeleton ?? inheritedSkeleton
3133

32-
return (
34+
const content = (
3335
<FlexItem
3436
className={classnames(
3537
'dnb-list__item__overline',
@@ -43,6 +45,16 @@ function ItemOverline({
4345
{children}
4446
</FlexItem>
4547
)
48+
49+
if (appliedSkeleton) {
50+
return (
51+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
52+
{content}
53+
</Context.Provider>
54+
)
55+
}
56+
57+
return content
4658
}
4759
ItemOverline._supportsSpacingProps = true
4860

packages/dnb-eufemia/src/components/list/ItemStart.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlexItem, { type Props as FlexItemProps } from '../flex/Item'
44
import { ListContext } from './ListContext'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
/**
910
* Props for List.Cell.Start (ItemStart).
@@ -23,12 +24,14 @@ function ItemStart({
2324
fontSize = 'basis',
2425
fontWeight = 'regular',
2526
skeleton,
27+
children,
2628
...rest
2729
}: ItemStartProps) {
30+
const context = useContext(Context)
2831
const inheritedSkeleton = useContext(ListContext)?.skeleton
2932
const appliedSkeleton = skeleton ?? inheritedSkeleton
3033

31-
return (
34+
const content = (
3235
<FlexItem
3336
className={classnames(
3437
'dnb-list__item__start',
@@ -39,8 +42,20 @@ function ItemStart({
3942
)}
4043
innerSpace={{ left: 'small' }}
4144
{...rest}
42-
/>
45+
>
46+
{children}
47+
</FlexItem>
4348
)
49+
50+
if (appliedSkeleton) {
51+
return (
52+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
53+
{content}
54+
</Context.Provider>
55+
)
56+
}
57+
58+
return content
4459
}
4560
ItemStart._supportsSpacingProps = true
4661

packages/dnb-eufemia/src/components/list/ItemSubline.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FlexItem, { type Props as FlexItemProps } from '../flex/Item'
44
import { ListContext } from './ListContext'
55
import { createSkeletonClass } from '../skeleton/SkeletonHelper'
66
import type { SkeletonShow } from '../Skeleton'
7+
import Context from '../../shared/Context'
78

89
export type ItemSublineVariant = 'description'
910

@@ -31,10 +32,11 @@ function ItemSubline({
3132
children,
3233
...rest
3334
}: ItemSublineProps) {
35+
const context = useContext(Context)
3436
const inheritedSkeleton = useContext(ListContext)?.skeleton
3537
const appliedSkeleton = skeleton ?? inheritedSkeleton
3638

37-
return (
39+
const content = (
3840
<FlexItem
3941
className={classnames(
4042
'dnb-list__item__subline',
@@ -49,6 +51,16 @@ function ItemSubline({
4951
{children}
5052
</FlexItem>
5153
)
54+
55+
if (appliedSkeleton) {
56+
return (
57+
<Context.Provider value={{ ...context, skeleton: appliedSkeleton }}>
58+
{content}
59+
</Context.Provider>
60+
)
61+
}
62+
63+
return content
5264
}
5365
ItemSubline._supportsSpacingProps = true
5466

0 commit comments

Comments
 (0)