@material-ui/core#ToolbarProps TypeScript Examples

The following examples show how to use @material-ui/core#ToolbarProps. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TechDocsReaderPageSubheader.tsx    From backstage with Apache License 2.0 5 votes vote down vote up
TechDocsReaderPageSubheader = ({
  toolbarProps,
}: {
  toolbarProps?: ToolbarProps;
}) => {
  const classes = useStyles();
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);

  const handleClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {
    setAnchorEl(event.currentTarget);
  }, []);

  const handleClose = useCallback(() => {
    setAnchorEl(null);
  }, []);

  const {
    entityMetadata: { value: entityMetadata, loading: entityMetadataLoading },
  } = useTechDocsReaderPage();

  const addons = useTechDocsAddons();

  const subheaderAddons = addons.renderComponentsByLocation(
    locations.Subheader,
  );

  const settingsAddons = addons.renderComponentsByLocation(locations.Settings);

  if (!subheaderAddons && !settingsAddons) return null;

  // No entity metadata = 404. Don't render subheader on 404.
  if (entityMetadataLoading === false && !entityMetadata) return null;

  return (
    <Toolbar classes={classes} {...toolbarProps}>
      <Box
        display="flex"
        justifyContent="flex-end"
        width="100%"
        flexWrap="wrap"
      >
        {subheaderAddons}
        {settingsAddons ? (
          <>
            <Tooltip title="Settings">
              <IconButton
                aria-controls="tech-docs-reader-page-settings"
                aria-haspopup="true"
                onClick={handleClick}
              >
                <SettingsIcon />
              </IconButton>
            </Tooltip>
            <Menu
              id="tech-docs-reader-page-settings"
              getContentAnchorEl={null}
              anchorEl={anchorEl}
              anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
              open={Boolean(anchorEl)}
              onClose={handleClose}
              keepMounted
            >
              {settingsAddons}
            </Menu>
          </>
        ) : null}
      </Box>
    </Toolbar>
  );
}