antDesign: tabs styles - reactjs

image-1:
image-2:
I have a project that contains several interfaces, and among these interfaces there is an interface that displays two tables through “Tabs”, when I click on the first tab it displays the first table and when I click on the second tab it displays the second table, but my problem is only in the style of the Tabs and not my problem In the content, I want the style of the second image to be the same as the style of the first image
file.tsx:
import _ from 'lodash';
import { FunctionComponent } from 'react';
import { Tabs } from 'antd';
import AllPatients from './components/all-patients';
import AllPresentPatient from './components/present-patients';
import { FormattedMessage } from 'react-intl';
const { TabPane } = Tabs;
interface PatientListPageProps { }
const PatientListPage: FunctionComponent<PatientListPageProps> = () => {
return (
<>
<div style={{ background: '#fff', padding: '16px', borderColor: 'transparent', borderRadius: '4px' }}>
<Tabs type="card">
<Tabs.TabPane
tab={<FormattedMessage id='all' />} key="1">
<AllPatients />
</Tabs.TabPane>
<Tabs.TabPane tab={<FormattedMessage id='attendees' />} key="2">
<AllPresentPatient />
</Tabs.TabPane>
</Tabs>
</div>
</>
);
};
export default PatientListPage;

i think you must custom the css.
in tabs add the new name of classname
.custom-classname .ant-tabs-rtl {
direction: ltr !important;
}
if it doesn't change you can try using
.custom-classname {
direction: ltr !important;
}
then if you want the contents of the tab to stay on the right, you have to also customize the css so that the direction stays on the right

i think you will use ":global" to overwrite the default style in antd
like this
:global {
.ant-select-selection-item {
// overwrite style
...
}
}

Related

React mui-datatables change header color

I'm trying to change the head of mui-datatables, but it is not working properly.
import MUIDataTable from "mui-datatables";
import { createMuiTheme, MuiThemeProvider } from '#material-ui/core/styles';
...
// here I set the them
const getMuiTheme = () => createMuiTheme({
overrides: {
MuiTableHead: {
root: {
backgroundColor: "#c1e1ec"
}
}
}
});
...
// rendering
<MuiThemeProvider theme={getMuiTheme()}>
<MUIDataTable
title={"Existing Users"}
data={users}
columns={columns}
options={options}
/>
</MuiThemeProvider>
It is not changing the color of the thead. It keep showing a white thead. However, if I inspect the element with Firefox, I can see the following styles for the thead element
.MuiTableHead-root {
display: table-header-group;
background-color: #c1e1ec;
}
Each child .MUIDataTableHeadCell-fixedHeader has own background so you rather should change this class then .MuiTableHeader-root
Or in this way which I think is better.
MuiTableCell: {
head: {
backgroundColor: "red !important"
}
}

MakeStyles (Material UI) apply style to child element

I was wondering if it's possible to apply a style to a child element only, using MakesStyles, for example in a normal HTML/CSS project:
<div className="parent">
<h1>Title!</h1>
</div>
.parent h1 {
color: #f00;
}
This would color every title inside the div.
I have tried a few differnt ways, one of them was this:
// Function
const { parent } = homeStyle()
return (
<div className={parent}>
<h1>Title!</h1>
</div>
)
// Style
const homeStyle = makeStyles(theme => ({
parent: {
background: "#fff",
h1: {
color: "#f00",
}
},
}))
But it didn't work.
If you are looking to just style material-ui H1 titles, you can select it with:
.parent .MuiTypography-h1 {
color: #f00;
}
In the photo below for an alternative solution, you'll see the classes that are applied to elements with material-ui. The inspector can be handy in identifying the names of the material-ui elements you want to select.
Your mileage may vary, depending on your CSS setup.
What I read from your question however, is a desire to select a single H1, within perhaps a <div> amonst other styled H1s. This can be done with ThemeProvider in the material-ui library (docs here):
import { Typography } from "#material-ui/core";
import {
createMuiTheme,
responsiveFontSizes,
ThemeProvider
} from "#material-ui/core/styles";
const Themed = ({ children }) => {
const theme = createMuiTheme({
overrides: { {/* <-- create a style override */}
MuiTypography: {
h1: {
"&.styled": { {/* <-- specify a className for overrides */}
color: "red"
}
}
}
}
});
return (
<ThemeProvider theme={responsiveFontSizes(theme)}>
<>{children}</>
</ThemeProvider>
);
};
const App = () => {
return (
<Themed>
<Typography
className="styled" {/* <-- add the style from above */}
variant="h1">
Styled H1
</Typography>
<Typography
variant="h1">
Not styled H1
</Typography>
<Typography
variant="h1">
Me neither
</Typography>
</Themed>
);
};
export default App;
Working CodeSandbox.

How can I make a dropdown menu from just an icon with ant design?

I'm trying to make a user icon with a dropdown menu using ant design libraries and reactjs. If I use Dropdown.Button, I'm getting a box around the icon. I think this is related to a CSS border-box property, but I can't seem to get rid of it. If I use the Dropdown component, then I can't add an icon and can use only text. What's the right way to achieve this result?
import { Menu, Dropdown } from 'antd';
import { UserOutlined } from '#ant-design/icons';
const Dummy = () => {
const userMenu = (
<Menu>
<Menu.Item key="1">Item 1</Menu.Item>
<Menu.Item key="2">Item 2</Menu.Item>
<Menu.Item key="3">Item 3</Menu.Item>
<Menu.Divider />
<Menu.Item key="3">Logout</Menu.Item>
</Menu>
);
return (
<div>
<Dropdown.Button
style={{ float: 'right' }}
overlay={userMenu}
icon={
<UserOutlined
style={{
fontSize: '28px',
backgroundColor: '#f0f0f0',
borderRadius: '50%',
}}
/>
}
></Dropdown.Button>
</div>
);
};
export default Dummy;
You can achieve the desired styling via CSS.
Add a className=dropdown-btn to the Dropdown.Button component
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Menu, Dropdown } from 'antd';
import { DownOutlined } from '#ant-design/icons';
import { Menu, Dropdown } from 'antd';
import { UserOutlined } from '#ant-design/icons';
const Dummy = () => {
const userMenu = (
<Menu>
<Menu.Item key="1">Item 1</Menu.Item>
<Menu.Item key="2">Item 2</Menu.Item>
<Menu.Item key="3">Item 3</Menu.Item>
<Menu.Divider />
<Menu.Item key="3">Logout</Menu.Item>
</Menu>
);
return (
<div>
<Dropdown.Button
style={{ float: 'right' }}
className="dropdown-btn"
overlay={userMenu}
icon={
<UserOutlined
style={{
fontSize: '28px',
backgroundColor: '#f0f0f0',
borderRadius: '50%',
}}
/>
}
></Dropdown.Button>
</div>
);
};
export default Dummy;
ReactDOM.render(
<Dummy/>,
document.getElementById('container'),
);
Add CSS to target the offending border and background-color:
.dropdown-btn > .ant-dropdown-trigger {
border: none;
}
.dropdown-btn > .ant-dropdown-trigger > span {
background-color: white !important;
}
If the use of !important is a problem, you can add more selectors to increase the specificity.
Working StackBlitz link:
https://ant-design-dropdown-link-button.stackblitz.io
P.S. Another quick and dirty solution is to add the type="link" attribute to the Dropdown.Button. This will get rid of the border styling, but the background color will remain and the icon will turn blue.

Material UI v1 with React - styling buttons

I'm trying to learn how to use Material UI with React.
I have incorporated v1 of Material UI in my project.
Nothing about coding comes intuitively to me, so I struggle to fill the gaps between the clues left in the documentation for resources.
I know I haven't got the hang of this yet, but piecing together what others have been able to do, I have set up a button in my project, as follows:
import React from 'react';
import Button from 'material-ui/Button';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import { fade } from 'material-ui/styles/colorManipulator';
const MyButton = (props) => {
return <span>
<Button {...props} />
</span>
};
export default MyButton;
I then try to use my button in a couple of places:
import React from 'react';
import MyButton from '../materialui/Button.js';
const style = {
background: '#FF5349',
color: 'white',
padding: '0 30px',
// marginBottom: '30px',
};
const Start = () => (
<span>
<MyButton style={style} size="large">
GET STARTED
</MyButton>
</span>
);
export default Start;
I am trying to change the size of the button.
The Material UI documentation indicates that I should be able to toggle the size property by inserting size="large".
The example given in the documentation is:
<Button size="large" className={classes.button}>
Large
</Button>
I've tried to insert size="large" in the const style in my Start component, in the use of MyButton in the start component and in the Button component itself. None of these attempts do anything to alter the size. The text label in the button looks miniature at the moment and I can't figure out how to manipulate the size.
Can anyone see how to increase the size of the button?
Here is how I have been using it.
You need to set the root Class of the button object (or another available class, refer to the documentation for each available class by components)
import React, { Component } from "react";
import { withStyles } from "material-ui/styles";
import Button from "material-ui/Button";
const styles = theme => ({
button: {
width: "300px",
margin: "0 auto",
textTransform: "uppercase",
padding: "20px 30px",
alignSelf: "center",
},
});
class MyCustomButton extends Component {
render() {
const { classes } = this.props;
return (
<Button color="primary" raised={true} classes={{ root: classes.button }} />
);
}
}
export default withStyles(styles)(MyCustomButton);

change active tab background color in react material-ui

want to change background color on active tab from material-ui Tabs:
http://www.material-ui.com/#/components/tabs
already how to change the underline:
inkBarStyle={{background: 'red'}}
but background color changed
thank you very much
Try this
const CustomTab = withStyles({
root: {
backgroundColor: 'orange',
},
selected: {
backgroundColor: 'purple',
},
})(Tab);
and then
<Tabs>
<CustomTab label='One' />
<CustomTab label='Two' />
<CustomTab label='Three' />
</Tabs>
Rather than updating one instance of the tab, perhaps it's better to update the theme in general. Then you wouldn't have to add the style to every individual use of that particular component.
Typically you'd have a theme file such as:
./themes/default/index.ts
import { createMuiTheme } from '#material-ui/core/styles';
import { Breakpoint } from '#material-ui/core/styles/createBreakpoints';
const overrides = {
MuiTab: {
// general overrides for your material tab component here
root: {
backgroundColor: 'red',
'&$selected': {
backgroundColor: 'blue',
}
},
},
};
const theme = createMuiTheme( {
overrides,
breakpoints,
palette,
typography,
shape,
});
Then in your application you can use this as:
./src/index.ts
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { MuiThemeProvider } from '#material-ui/core/styles';
import { App } from './components';
ReactDOM.render(
<MuiThemeProvider theme={themeSpec.theme}>
<App />
</MuiThemeProvider>,
document.getElementById('root') as HTMLElement
);
Source: https://material-ui.com/customization/components/#global-theme-override
Default values can be found here: https://material-ui.com/customization/default-theme/
The overrides for components can be found here: https://github.com/mui-org/material-ui/blob/2726ab46b2b1789bdd0a9aa1a2ff249a443ab1a8/packages/material-ui/src/styles/overrides.d.ts#L91-L173
More info regarding the material themes: https://material-ui.com/customization/themes/#themes
Note: Examples in typescript to be a bit more thorough, but the same would go for vanilla javascript
You can simply do by the conditional rendering of styles, your styles should look like this
const styles = theme => ({
default_tabStyle:{
color: 'black',
fontSize:11,
backgroundColor: 'blue',
},
active_tabStyle:{
fontSize:11,
color: 'white',
backgroundColor: 'red',
}
})
Then in your Component
class YourComponent extends Component {
state = {
value: 0,
}
handleChange = (event, value, index) => {
this.setState({ value:value });
}
render(){
const { classes } = this.props;
return (
<div>
<AppBar position="static" className={classes.appBarStyle}>
<Tabs value={this.state.value} indicatorColor="#E18F68"
onChange={this.handleChange}
fullWidth={true}
scrollButtons="auto"
>
<Tab label="Tab01"
className=
{this.state.value===0 ? classes.active_tab :classes.default_tabStyle} />
<Tab label="Tab02"
className=
{this.state.value===1 ?classes.active_tab :classes.default_tabStyle}/>
<Tab label="Tab02"
className=
{this.state.value===2 ?classes.active_tab :classes.default_tabStyle
}/>
</Tabs>
</AppBar>
</div>
)
}
}
By default, your tab will be at index 0 and as there is change at the index of tab active_tabStyle will apply.
To customize the background color of the tabs and the color of the inkBar, it is recommended to customize the Material-UI theme itself. There are specific settings for these two colors.
const muiTheme = getMuiTheme({
tabs: {
backgroundColor: 'red'
},
inkBar: {
backgroundColor: 'yellow'
}
})
Details on customizing the theme can be found here: http://www.material-ui.com/#/customization/themes

Resources