MCPcopy Index your code
hub / github.com/primer/react / Buttons

Function Buttons

packages/react/src/Dialog/Dialog.tsx:539–570  ·  view source on GitHub ↗
({buttons})

Source from the content-addressed store, hash-verified

537`
538
539const Buttons: React.FC<React.PropsWithChildren<{buttons: DialogButtonProps[]}>> = ({buttons}) => {
540 const autoFocusRef = useProvidedRefOrCreate<HTMLButtonElement>(buttons.find(button => button.autoFocus)?.ref)
541 let autoFocusCount = 0
542 const [hasRendered, setHasRendered] = useState(0)
543 useEffect(() => {
544 // hack to work around dialogs originating from other focus traps.
545 if (hasRendered === 1) {
546 autoFocusRef.current?.focus()
547 } else {
548 setHasRendered(hasRendered + 1)
549 }
550 }, [autoFocusRef, hasRendered])
551
552 return (
553 <>
554 {buttons.map((dialogButtonProps, index) => {
555 const {content, buttonType = 'default', autoFocus = false, ...buttonProps} = dialogButtonProps
556 return (
557 <Button
558 key={index}
559 {...buttonProps}
560 // 'normal' value is equivalent to 'default', this is used for backwards compatibility
561 variant={buttonType === 'normal' ? 'default' : buttonType}
562 ref={autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null}
563 >
564 {content}
565 </Button>
566 )
567 })}
568 </>
569 )
570}
571const DialogCloseButton = styled(Button)`
572 border-radius: 4px;
573 background: transparent;

Callers

nothing calls this directly

Calls 1

useProvidedRefOrCreateFunction · 0.90

Tested by

no test coverage detected