MUI Dialog Background Color - material-ui

I have a mui dialog and would like to set its background to black. (no color), but I don't succeed.
And I don't understand why it doesn't work.
My Dialog:
export const MyDialog = (props: any) => {
return (
<ThemeProvider theme={TestTheme}>
<CssBaseline />
<Dialog open={true}>
<DialogTitle>Title</DialogTitle>
<DialogContentText>Text</DialogContentText>
</Dialog>
</ThemeProvider>
);
};
My TestTheme looks like this:
export const TestTheme = createTheme(
{palette: {
mode: 'dark',
background: {
paper: '#000000',
// paper: 'red',
default: '#000000',
},
}
}
)
and it looks like this:
As we can see the dialog color has not the same black as the background even I have set the colors for both correctly.
If I set the colors :
paper: 'red',
// paper: '#000000',
// default: '#000000',
default: 'blue',
How can I set the background color of the dialog to black (no color)? (Regardless if it make sence or not, I would like to understand)

You are doing everything right with the way you set the background color.
The reason you see two different black colours is because when the Dialog is open is getting a class of MuiBackdrop-root which has a background-colour of background-color: rgba(0, 0, 0, 0.5); so this additional semi transparent layer is causing this colour difference.
Here is a codesandbox with a solution to your issue.
Code:
<Dialog open={true}
sx={{ //You can copy the code below in your theme
background: '#000',
'& .MuiPaper-root': {
background: '#000'
},
'& .MuiBackdrop-root': {
backgroundColor: 'transparent' // Try to remove this to see the result
}
}}>
<DialogTitle sx={{ color: "white" }}>Title</DialogTitle>
<DialogContentText sx={{ color: "white" }}>Text</DialogContentText>
</Dialog>
Hope it helps.

Related

PayPal React JS Buttons background color

I am using react-paypal-js for the payments in the code as follows (Next.JS)
import { useEffect } from "react";
import {
PayPalScriptProvider,
PayPalButtons,
usePayPalScriptReducer
} from "#paypal/react-paypal-js";
import {
Badge,
Button,
Center,
Flex,
Heading,
Image,
Link,
Stack,
Text,
useColorModeValue,
} from '#chakra-ui/react';
const ButtonWrapper = ({ type }: any) => {
const [{ options }, dispatch] = usePayPalScriptReducer();
useEffect(() => {
dispatch({
type: "resetOptions",
value: {
...options,
intent: "subscription",
},
});
}, [dispatch]);
return (<PayPalButtons
createSubscription={(_data, actions) => {
return actions.subscription
.create({
plan_id: "P-3RX065706M3469222L5IFM4I",
})
.then((orderId) => {
return orderId;
});
}}
style={{
label: "subscribe",
color: "silver"
}}
/>);
}
export default function CheckoutPage() {
return (
<Center py={6}>
<Stack
borderWidth="1px"
borderRadius="lg"
w={{ sm: '100%', md: '540px' }}
height={{ sm: '476px', md: '20rem' }}
direction={{ base: 'column', md: 'row' }}
color={"white"}
// bg={useColorModeValue('white', 'gray.900')}
boxShadow={'2xl'}
padding={4}>
<Stack
flex={1}
flexDirection="column"
justifyContent="center"
alignItems="center"
p={1}
pt={2}>
<Heading fontSize={'2xl'} fontFamily={'body'}>
Checkout
</Heading>
<PayPalScriptProvider options={{
"client-id": "test",
components: "buttons",
intent: "subscription",
vault: true,
}}>
<ButtonWrapper type="subscription"></ButtonWrapper>
</PayPalScriptProvider>
</Stack>
</Stack>
</Center>
);
}
But due to dark mode on the website, the buttons appear to be really weird and I tried changing the color with classnames but it doesn't change to black.
I doubt if we can do anything to change the color but it seems as if this is not the issue if I plan to use the script in browser render as shown here
Please help me out on how can I change the background color to black
Updated image:
Using this Storybook demo as a simpler starting point, you can just add a black background div:
<div style={{ maxWidth: "750px", minHeight: "200px", backgroundColor: "black"}}>
<PayPalScriptProvider
options={{
"client-id": "test",
components: "buttons",
intent: "subscription",
vault: true,
}}
>
<ButtonWrapper type="subscription" />
</PayPalScriptProvider>
</div>
This seems to produce what you want. It's only viable for Subscriptions, not one-time checkouts, because for Subscriptions the black "Debit or Credit Card" button does not open an inline form.
For one-time payments, if including that black button the inline form it expands would have dark text that does not look correct on a dark background. The only viable option for a dark background site that includes this black button would be to put the buttons within a light-colored well, similar to the following (using plain HTML/JS to keep this example simple and universal, but the same can be done with react)
<script src="https://www.paypal.com/sdk/js?client-id=test&currency=USD"></script>
<div id="paypal-button-container" style="background-color:white; padding:5px; border-radius:5px;"></div>
<script>
paypal.Buttons({}).render('#paypal-button-container');
</script>
On a dark background page, this gives:

Material UI Alerts using custom colors

Can I set a custom color for a MUI Alert component? The docs suggest that the only color options are the four that match the four severity props.
For MUI V5 in case someone is looking to change the background color in the theme this worked for me.
export const theme = createTheme({
components: {
MuiAlert: {
styleOverrides: {
standardSuccess: {
backgroundColor: 'green',
color: 'white'
},
standardError: {
backgroundColor: 'red',
color: 'white'
},
standardWarning: {
backgroundColor: 'orange',
color: 'white'
},
standardInfo: {
backgroundColor: 'grey',
color: 'black'
}
}
},
},
});
And is working by setting the variant:
<Alert severity="success">Success</Alert>
<Alert severity="error">Error</Alert>
<Alert severity="warning">Warning</Alert>
<Alert severity="info">Info</Alert>
It's possible. Quoting the API docs:
You can override the style of the component thanks to one of these
customization points:
With a rule name of the classes object prop.
With a global class name.
With a theme and an overrides property.
A crude example in this codesandbox
A simple approach would be:
const useStyles = makeStyles((theme) => ({
myAlert: {
color: "#ffffff",
backgroundColor: "#000000"
}
});
function MyCustomAlert() {
const classes = useStyles();
return (
<Alert severity="error" className={classes.myAlert}>
<AlertTitle>Error</AlertTitle>
{"I am an error message !"}
</Alert>
);
}
I guess another option, if you don't wanna deal with css classes, could be:
(using mui v5 and typescript)
first u define your styled component:
interface IAlert extends AlertProps {
background?: string
}
export const Alert = styled(MUIAlert)<IAlert>(({ background }) => ({
background,
}))
then, on your component that uses the Alert:
const Component = ({type}) => {
...
const CUSTOM_COLORS_MAPPING = {
success: palette.success[500],
info: palette.secondary[500],
error: palette.error[500],
warning: palette.warning[500],
}
return (
...
<Alert severity={type} background={CUSTOM_COLORS_MAPPING[type]}>
{message}
</Alert>
)

MaterialUI - global font settings

How do you change the default 16px browser font-size to 10px using Material UI? As I understand it, MUI uses Nomralize.css under the hood?
In the my theme file I have
export default createMuiTheme({
overrides: {
MuiCssBaseline: {
'#global': {
html: {
padding: '0',
},
},
},
},
typography: {
htmlFontSize: 10,
fontSize: 8,
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
fontWeight: 400,
},
})
but I don't know if this is right..
My app is also wrapped with CssBaseLine
ReactDOM.render(
<Provider store={store}>
<MuiThemeProvider theme={theme}>
<CssBaseline />
<App />
</MuiThemeProvider>
</Provider>,
document.getElementById('root'),
Is this correct? I remember the 62.5% trick and trying to accomplish something similar I guess
Your code is just fine and for future reference use use React DevTools to verify if your properties really apply or not (after React DevTools setup look for the ThemeProvider props).

How can I override the selected style for a tab?

I'm trying to override the style for the selected tab, but some of the overrides don't work. I'm doing,
const StyledTab = withStyles({
root: {
color: '#0071bc',
fontWeight: '600'
},
selected: {
color: '#fff' <--- doesn't work
}
})(Tab)
which, to me, looks like what the documentation is telling me to do. If I set the background on selected, the background color changes, but the font color does not.
Am I doing something wrong with the override?
Edit
Using !important forces it, but I don't want to use !important if I can avoid it.
I could come up with a solution using overriding CSS using withStyles,
<Tabs
value={value}
onChange={this.handleChange}
scrollable
scrollButtons="on"
classes={{ indicator: classes.tabsIndicator }}
>
<Tab
label="Search"
icon={<PhoneIcon />}
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
/>
<Tab
favorites={favorites}
label="Favorites"
icon={<FavoriteIcon />}
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
/>
</Tabs>
If we take this as the code you can use this styles to override,
const styles = theme => ({
tabsIndicator: {
backgroundColor: "red"
},
tabRoot: {
"&:hover": {
color: "red",
opacity: 1
},
"&$tabSelected": {
color: "red",
fontWeight: theme.typography.fontWeightMedium
},
"&:focus": {
color: "red"
}
},
tabSelected: {}
});
find that tabSelected is an empty value but &$tabSelected overrides the values
here is a working sample - https://codesandbox.io/s/882o65xlyl
hope this will help you.

Styling react-select v2 with material-ui - Replace Input component

I'm having an issue with replacing the Input component for react-select v2 with the Input component from Material UI.
I've made an attempt so far in the codesandbox below, but unable to invoke the filtering upon typing into the Input?
https://codesandbox.io/s/jjjwoj3yz9
Also, any feedback on the Option replacement implementation would be appreciated. Am I going about it the right way with grabbing the text of the clicked option and search for the Option object from my options list to pass to the selectOption function?
Much appreciated,
Eric
V1
refer the documentation from here : https://material-ui.com/demos/autocomplete/
it provides clear documentation about how to use react-select with material-ui
here is a working example for your question: https://codesandbox.io/s/p9jpl9l827
as you can see material-ui Input component can take react-select as inputComponent.
V2
It's almost same as the previous approach :
implement the Input component:
<div className={classes.root}>
<Input
fullWidth
inputComponent={SelectWrapped}
value={this.state.value}
onChange={this.handleChange}
placeholder="Search your color"
id="react-select-single"
inputProps={{
options: colourOptions
}}
/>
</div>
and then SelectWrapped component implementation should be:
function SelectWrapped(props) {
const { classes, ...other } = props;
return (
<Select
components={{
Option: Option,
DropdownIndicator: ArrowDropDownIcon
}}
styles={customStyles}
isClearable={true}
{...other}
/>
);
}
and I overrides the component Option and DropdownIndicator to make it more material and added customStyles also:
const customStyles = {
control: () => ({
display: "flex",
alignItems: "center",
border: 0,
height: "auto",
background: "transparent",
"&:hover": {
boxShadow: "none"
}
}),
menu: () => ({
backgroundColor: "white",
boxShadow: "1px 2px 6px #888888", // should be changed as material-ui
position: "absolute",
left: 0,
top: `calc(100% + 1px)`,
width: "100%",
zIndex: 2,
maxHeight: ITEM_HEIGHT * 4.5
}),
menuList: () => ({
maxHeight: ITEM_HEIGHT * 4.5,
overflowY: "auto"
})
};
and Option:
class Option extends React.Component {
handleClick = event => {
this.props.selectOption(this.props.data, event);
};
render() {
const { children, isFocused, isSelected, onFocus } = this.props;
console.log(this.props);
return (
<MenuItem
onFocus={onFocus}
selected={isFocused}
onClick={this.handleClick}
component="div"
style={{
fontWeight: isSelected ? 500 : 400
}}
>
{children}
</MenuItem>
);
}
}
please find the example from here: https://codesandbox.io/s/7k82j5j1qx
refer the documentation from react select and you can add more changes if you wish.
hope these will help you.