MCPcopy Create free account
hub / github.com/ampproject/amphtml / ContainWrapperWithRef

Function ContainWrapperWithRef

src/preact/component/contain.jsx:38–85  ·  view source on GitHub ↗

* The wrapper component that implements different "contain" parameters. This * most often indicates that the element's size doesn't depend on its children * (e.g. `contain:size`), but there might be other variances as well. * * See https://developer.mozilla.org/en-US/docs/Web/CSS/contain * * C

(
  {
    as: Comp = 'div',
    children,
    contentAs: ContentComp = 'div',
    contentClassName,
    contentProps,
    contentRef,
    contentStyle,
    layout = false,
    paint = false,
    size = false,
    'style': style,
    wrapperClassName,
    wrapperStyle,
    [propName('class')]: className,
    ...rest
  },
  ref
)

Source from the content-addressed store, hash-verified

36 * @return {import('preact').VNode}
37 */
38function ContainWrapperWithRef(
39 {
40 as: Comp = 'div',
41 children,
42 contentAs: ContentComp = 'div',
43 contentClassName,
44 contentProps,
45 contentRef,
46 contentStyle,
47 layout = false,
48 paint = false,
49 size = false,
50 'style': style,
51 wrapperClassName,
52 wrapperStyle,
53 [propName('class')]: className,
54 ...rest
55 },
56 ref
57) {
58 // The formula: `size << 2 | layout << 1 | paint`.
59 const containIndex = (size ? 4 : 0) + (layout ? 2 : 0) + (paint ? 1 : 0);
60 return (
61 <Comp
62 {...rest}
63 ref={ref}
64 class={`${className || ''} ${wrapperClassName || ''}`.trim() || null}
65 style={{
66 ...style,
67 ...wrapperStyle,
68 contain: CONTAIN[containIndex],
69 }}
70 >
71 <ContentComp
72 {...contentProps}
73 ref={contentRef}
74 class={contentClassName}
75 style={{
76 ...(size && SIZE_CONTENT_STYLE),
77 'overflow': paint ? 'hidden' : 'visible',
78 ...contentStyle,
79 }}
80 >
81 {children}
82 </ContentComp>
83 </Comp>
84 );
85}
86
87const ContainWrapper = forwardRef(ContainWrapperWithRef);
88

Callers

nothing calls this directly

Calls 1

propNameFunction · 0.90

Tested by

no test coverage detected