predikt/oracle/web/components/sized-container.tsx
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

32 lines
1019 B
TypeScript

import { CSSProperties, ReactNode } from 'react'
import { useMeasureSize } from 'web/hooks/use-measure-size'
/** Automatically calculate size and pass it to children */
export const SizedContainer = (props: {
children: (width: number, height: number) => ReactNode
/**
* You must set width and height to a value (like h-8)
* or to a % of the parent (like w-full) for resizing.
* Unless the parent be flexin'
*
* (Normally the browser sets an element's width and height by its content)
*
* So, className is not optional. Set to "" only if you know what you're doing.
*/
className: string
style?: CSSProperties
}) => {
const { children, className, style } = props
const { elemRef, width, height } = useMeasureSize()
// put containerRef on the inner div so that size excludes padding
return (
<div className={className} style={style}>
<div ref={elemRef} className="h-full w-full">
{width && height ? children(width, height) : null}
</div>
</div>
)
}