// Copyright (c) Meta Platforms, Inc. and affiliates. 'use client'; import * as stylex from '@stylexjs/stylex'; import {useOverflow} from '@astryxdesign/core/hooks'; import {Button} from '@astryxdesign/core/Button'; import {Card} from '@astryxdesign/core/Card'; import {DropdownMenu} from '@astryxdesign/core/DropdownMenu'; import {useToast} from '@astryxdesign/core/Toast'; const actions = [ 'Bold', 'Italic', 'Underline', 'Strikethrough', 'Link', 'Quote', 'Code', 'Clear formatting', ]; const GAP = 4; const styles = stylex.create({ box: { resize: 'horizontal', overflow: 'hidden', width: 480, minWidth: 120, maxWidth: '100%', }, row: {display: 'flex', gap: GAP}, // Takes no space and paints nothing, so the hook measures every item // without a flicker. Do not use display: none, which stops measurement. measure: { position: 'absolute', visibility: 'hidden', height: 0, overflow: 'hidden', whiteSpace: 'nowrap', pointerEvents: 'none', }, }); const demo = (label: string) => ({body: `Demo: ${label} would apply here`}); function MoreMenu({items}: {items: string[]}) { const showToast = useToast(); return ( ({ label, onClick: () => showToast(demo(label)), }))} /> ); } export default function UseOverflowHookUsage() { const showToast = useToast(); const {containerRef, measureRef, visibleCount, hasOverflow} = useOverflow( actions.length, {gap: GAP}, ); return (
{actions.slice(0, visibleCount).map(label => (
); }