-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forward refs and props for UI components
- Loading branch information
1 parent
9831e06
commit 9c81d2b
Showing
7 changed files
with
153 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import { forwardRef } from 'react'; | ||
|
||
import './button-group.css'; | ||
|
||
export function ButtonGroup(props: JSX.IntrinsicElements['div']) { | ||
return ( | ||
<div | ||
{...props} | ||
className={`graphiql-button-group ${props.className || ''}`.trim()} | ||
/> | ||
); | ||
} | ||
export const ButtonGroup = forwardRef< | ||
HTMLDivElement, | ||
JSX.IntrinsicElements['div'] | ||
>((props, ref) => ( | ||
<div | ||
{...props} | ||
ref={ref} | ||
className={`graphiql-button-group ${props.className || ''}`.trim()} | ||
/> | ||
)); | ||
ButtonGroup.displayName = 'ButtonGroup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,38 @@ | ||
import { forwardRef } from 'react'; | ||
import { compose } from '../utility/compose'; | ||
|
||
import './button.css'; | ||
|
||
export function UnStyledButton(props: JSX.IntrinsicElements['button']) { | ||
return ( | ||
<button | ||
{...props} | ||
className={compose('graphiql-un-styled', props.className)} | ||
/> | ||
); | ||
} | ||
export const UnStyledButton = forwardRef< | ||
HTMLButtonElement, | ||
JSX.IntrinsicElements['button'] | ||
>((props, ref) => ( | ||
<button | ||
{...props} | ||
ref={ref} | ||
className={compose('graphiql-un-styled', props.className)} | ||
/> | ||
)); | ||
UnStyledButton.displayName = 'UnStyledButton'; | ||
|
||
type ButtonProps = { state?: 'success' | 'error' }; | ||
|
||
export function Button(props: ButtonProps & JSX.IntrinsicElements['button']) { | ||
return ( | ||
<button | ||
{...props} | ||
className={compose( | ||
'graphiql-button', | ||
props.state === 'success' | ||
? 'graphiql-button-success' | ||
: props.state === 'error' | ||
? 'graphiql-button-error' | ||
: '', | ||
props.className, | ||
)} | ||
/> | ||
); | ||
} | ||
export const Button = forwardRef< | ||
HTMLButtonElement, | ||
ButtonProps & JSX.IntrinsicElements['button'] | ||
>((props, ref) => ( | ||
<button | ||
{...props} | ||
ref={ref} | ||
className={compose( | ||
'graphiql-button', | ||
props.state === 'success' | ||
? 'graphiql-button-success' | ||
: props.state === 'error' | ||
? 'graphiql-button-error' | ||
: '', | ||
props.className, | ||
)} | ||
/> | ||
)); | ||
Button.displayName = 'Button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import { Dialog as ReachDialog } from '@reach/dialog'; | ||
import { VisuallyHidden } from '@reach/visually-hidden'; | ||
import { ComponentProps } from 'react'; | ||
import { ComponentProps, forwardRef } from 'react'; | ||
import { CloseIcon } from '../icons'; | ||
import { createComponentGroup } from '../utility/component-group'; | ||
import { compose } from '../utility/compose'; | ||
import { UnStyledButton } from './button'; | ||
|
||
import './dialog.css'; | ||
|
||
export function Dialog(props: ComponentProps<typeof ReachDialog>) { | ||
return <ReachDialog {...props} />; | ||
} | ||
const DialogRoot = forwardRef< | ||
HTMLDivElement, | ||
ComponentProps<typeof ReachDialog> | ||
>((props, ref) => <ReachDialog {...props} ref={ref} />); | ||
DialogRoot.displayName = 'Dialog'; | ||
|
||
function DialogClose(props: JSX.IntrinsicElements['button']) { | ||
return ( | ||
<UnStyledButton | ||
{...props} | ||
className={compose('graphiql-dialog-close', props.className)}> | ||
<VisuallyHidden>Close dialog</VisuallyHidden> | ||
<CloseIcon /> | ||
</UnStyledButton> | ||
); | ||
} | ||
const DialogClose = forwardRef< | ||
HTMLButtonElement, | ||
JSX.IntrinsicElements['button'] | ||
>((props, ref) => ( | ||
<UnStyledButton | ||
{...props} | ||
ref={ref} | ||
className={compose('graphiql-dialog-close', props.className)}> | ||
<VisuallyHidden>Close dialog</VisuallyHidden> | ||
<CloseIcon /> | ||
</UnStyledButton> | ||
)); | ||
DialogClose.displayName = 'Dialog.Close'; | ||
|
||
Dialog.Close = DialogClose; | ||
export const Dialog = createComponentGroup(DialogRoot, { Close: DialogClose }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { forwardRef } from 'react'; | ||
import { compose } from '../utility/compose'; | ||
|
||
import './spinner.css'; | ||
|
||
export function Spinner() { | ||
return <div className="graphiql-spinner" />; | ||
} | ||
export const Spinner = forwardRef<HTMLDivElement, JSX.IntrinsicElements['div']>( | ||
(props, ref) => ( | ||
<div | ||
{...props} | ||
ref={ref} | ||
className={compose('graphiql-spinner', props.className)} | ||
/> | ||
), | ||
); | ||
Spinner.displayName = 'Spinner'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters