question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Toolbar component

See original GitHub issue

image

Reference: Rethinking the date picker UI

Is your feature request related to a problem? Please describe.

It is not, as far as I’ve searched for the “toolbar” in all the Issues.

Describe the solution you’d like

In order to create the DatePicker described in the referenced article, I’d like to be able to pass my own <Toolbar /> component in place of the default one, ideally with the currently selected date as a prop.

<DatePicker 
  ToolbarComponent={({ year, month, date }) => (<div>{year}</div><div>{month}</div>))
/>

Describe alternatives you’ve considered

I looked through Dialog and Popover documentations for more specific prop name instead of proposed ToolbarComponent, but this one seems self-descriptive enough, I guess.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
monteizcommented, Dec 30, 2019

This is a basic implementation of a CustomToolbar that mimics the default behaviour. It can be further customised.

It may help someone.

import React, { useState } from 'react';
import PickerToolbar from "@material-ui/pickers/_shared/PickerToolbar";
import ToolbarButton from "@material-ui/pickers/_shared/ToolbarButton";
import { makeStyles } from '@material-ui/core';

export const useStyles = makeStyles({
	toolbar: {
		display: "flex",
		flexDirection: "column",
		alignItems: "flex-start"
	}
});

const CustomToolbar = function (props) {

	const { date,
		isLandscape,
		openView,
		setOpenView,
		title} = props;

	const handleChangeViewClick = (view) => (e) => {

		setOpenView(view);

	}

	const classes = useStyles();

	return (
		<PickerToolbar className={classes.toolbar} title={title} isLandscape={isLandscape}>
			<ToolbarButton
				onClick={handleChangeViewClick("year")}
				variant="h6"
				label={date.format("YYYY")}
				selected={openView === "year"}
			/>
			<ToolbarButton
				onClick={handleChangeViewClick("date")}
				variant="h4"
				selected={openView === "date"}
				label={date.format("LL")}
			/>
		</PickerToolbar>
	);

}

export default CustomToolbar;
5reactions
simrommcommented, Sep 26, 2019

How do you overload the ToolbarComponent with additionnal compoment?

Something like but I don’t know how to call the default toolbar:

<DatePicker 
  ToolbarComponent={(props) => (<div><ToolbarComponentDefault {...props /><OtherComponent /></div>))
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-admin - The Toolbar Component - Marmelab
Create a custom toolbar using <Toolbar> , then inject it to <SimpleForm> or <TabbedForm> using the toolbar prop: // in src/MyToolbar.jss import {...
Read more >
Toolbar Customization Guide - Material React Table Docs
How to customize the Toolbars, add buttons to toolbars, or customize progress bars and alert banners in Material React Table.
Read more >
Custom Toolbar in Angular Grid component - Syncfusion
Custom Toolbar is used to customize the whole toolbar. It can be added by defining toolbarTemplate. Actions for this toolbar template items are...
Read more >
Toolbar component - Finsemble
The Toolbar component is highly customizable. Let's look at its default structure and customization points, including menus and favorites.
Read more >
Toolbar API - Material UI - MUI
API reference docs for the React Toolbar component. ... With a rule name as part of the component's styleOverrides property in a custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found