-
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.
[redesign] implement toolbar menu and select in new design (#2631)
* implement toolbar menu in new design * implement `ToolbarListbox` in new design * better tooltips
- Loading branch information
1 parent
7bbdaa3
commit 319363d
Showing
36 changed files
with
526 additions
and
548 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
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 |
---|---|---|
|
@@ -118,6 +118,7 @@ languageservice | |
linenumber | ||
linenumbers | ||
linkify | ||
listbox | ||
listvalues | ||
matchingbracket | ||
modulemap | ||
|
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
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
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
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,39 +1,45 @@ | ||
import { forwardRef, useState } from 'react'; | ||
|
||
import { UnStyledButton } from '../ui'; | ||
import { Tooltip, UnStyledButton } from '../ui'; | ||
import { compose } from '../utility/compose'; | ||
|
||
import './button.css'; | ||
|
||
type ToolbarButtonProps = { | ||
label: string; | ||
}; | ||
|
||
export const ToolbarButton = forwardRef< | ||
HTMLButtonElement, | ||
JSX.IntrinsicElements['button'] | ||
>((props, ref) => { | ||
ToolbarButtonProps & JSX.IntrinsicElements['button'] | ||
>(({ label, ...props }, ref) => { | ||
const [error, setError] = useState<Error | null>(null); | ||
return ( | ||
<UnStyledButton | ||
{...props} | ||
ref={ref} | ||
type="button" | ||
className={ | ||
'graphiql-toolbar-button' + | ||
(error ? ' error' : '') + | ||
(props.className ? ' ' + props.className : '') | ||
} | ||
onClick={event => { | ||
try { | ||
props.onClick?.(event); | ||
setError(null); | ||
} catch (err) { | ||
setError( | ||
err instanceof Error | ||
? err | ||
: new Error(`Toolbar button click failed: ${err}`), | ||
); | ||
} | ||
}} | ||
title={error ? error.message : props.title} | ||
aria-invalid={error ? 'true' : props['aria-invalid']} | ||
/> | ||
<Tooltip label={label}> | ||
<UnStyledButton | ||
{...props} | ||
ref={ref} | ||
type="button" | ||
className={compose( | ||
'graphiql-toolbar-button', | ||
error ? 'error' : '', | ||
props.className, | ||
)} | ||
onClick={event => { | ||
try { | ||
props.onClick?.(event); | ||
setError(null); | ||
} catch (err) { | ||
setError( | ||
err instanceof Error | ||
? err | ||
: new Error(`Toolbar button click failed: ${err}`), | ||
); | ||
} | ||
}} | ||
aria-label={error ? error.message : label} | ||
aria-invalid={error ? 'true' : props['aria-invalid']} | ||
/> | ||
</Tooltip> | ||
); | ||
}); | ||
ToolbarButton.displayName = 'ToolbarButton'; |
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
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,2 +1,4 @@ | ||
export * from './button'; | ||
export * from './execute'; | ||
export * from './listbox'; | ||
export * from './menu'; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.graphiql-toolbar-listbox { | ||
display: block; | ||
height: var(--toolbar-width); | ||
width: var(--toolbar-width); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ComponentProps, forwardRef, ReactNode } from 'react'; | ||
import { Listbox, Tooltip } from '../ui'; | ||
import { createComponentGroup } from '../utility/component-group'; | ||
import { compose } from '../utility/compose'; | ||
|
||
import './listbox.css'; | ||
|
||
type ToolbarListboxProps = { | ||
button: ReactNode; | ||
label: string; | ||
}; | ||
|
||
const ToolbarListboxRoot = forwardRef< | ||
HTMLDivElement, | ||
ToolbarListboxProps & ComponentProps<typeof Listbox.Input> | ||
>(({ button, children, label, ...props }, ref) => { | ||
const labelWithValue = `${label}${props.value ? `: ${props.value}` : ''}`; | ||
return ( | ||
<Listbox.Input | ||
{...props} | ||
ref={ref} | ||
className={compose('graphiql-toolbar-listbox', props.className)} | ||
aria-label={labelWithValue} | ||
> | ||
<Tooltip label={labelWithValue}> | ||
<Listbox.Button>{button}</Listbox.Button> | ||
</Tooltip> | ||
<Listbox.Popover>{children}</Listbox.Popover> | ||
</Listbox.Input> | ||
); | ||
}); | ||
ToolbarListboxRoot.displayName = 'ToolbarListbox'; | ||
|
||
export const ToolbarListbox = createComponentGroup(ToolbarListboxRoot, { | ||
Option: Listbox.Option, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
button.graphiql-toolbar-menu { | ||
display: block; | ||
height: var(--toolbar-width); | ||
width: var(--toolbar-width); | ||
} |
Oops, something went wrong.