Is it possible to change the icon of the checkbox from the theme in Material UI?
props: {
MuiButtonBase: {
disableRipple: buttonRippleDisable
},
MuiButton: {
disableElevation: buttonElevationDisable
},
MuiCheckbox: {
icon: CheckCircleOutline,
}
}
yes. pass the icon in props object in theme as you've done above.
const theme = createMuiTheme({
props:{
MuiCheckbox:{
icon: <FavoriteBorder />,
checkedIcon:<Favorite />
}
}
});
Now wherever you use the checkbox in the scope of this theme, you'll get this icon by default.
Working demo:
In MUI v5
const theme = createMuiTheme({
components: {
MuiCheckbox: {
defaultProps: {
icon: {YOUR ICON},
checkedIcon: {YOUR ICON}
}
}
}
});
Related
I am trying to set new breakpoints for my container width in MUI System. It works without typescript, but in my typescript project, it does not recognize my custom breakpoints and only recognizes the default breakpoints (xs, sm, md, lg, and xl). I followed the suggested BreakpointOverrides suggested here
```
import React from 'react';
import Container from '#mui/system/Container';
import { createTheme, ThemeProvider } from '#mui/system';
declare module '#mui/system' {
interface BreakpointOverrides {
// Your custom breakpoints
laptop: true;
tablet: true;
mobile: true;
desktop: true;
xldesktop: true;
// Remove default breakpoints
xs: false;
sm: false;
md: false;
lg: false;
xl: false;
}
}
const theme = createTheme({
breakpoints: {
// eslint-disable-next-line #typescript-eslint/ban-ts-comment
//#ts-ignore
values: {
mobile: 0,
tablet: 640,
laptop: 1024,
desktop: 1280,
},
},
});
const HeroHomepage = ({}) => {
return (
<ThemeProvider theme={theme}>
<Container
sx={{
bgcolor: {
mobile: 'green',
tablet: 'blue',
laptop: 'orange',
desktop: 'yellow',
},
width: 200,
height: 500,
}}
>
<div>hello world</div>
</Container>
</ThemeProvider>
);
};
```
When I do this, no color at all is applied to the container, as it does not recognize the custom breakpoints.
Try to use latest version of MUI. It seems to be recently fixed, according to this discussion https://github.com/mui/material-ui/issues/26369.
In my case it helped: no TS errors now and breakpoints works.
I want to set a property of a dart object related to another property of the same object. I have the following code for the button press function:
onPressed: () {
setState(() {
if (textEditController.text.trim().isNotEmpty) {
_sendMessage();
myMessagesList.add(OwnMessageCard(
myMessage:
textEditController.text.trim(),
isSeen: false,
deliverIconColor: Colors.grey));
}
});
},
I want to create condition for deliverIconColor. If isSeen == true then deliverIconColor must be Colors.blue and if not then it must be Colors.grey.
How can I make such a relation in Flutter?
Simply you can use ternary operator
onPressed: () {
setState(() {
if (textEditController.text.trim().isNotEmpty) {
_sendMessage();
myMessagesList.add(OwnMessageCard(
myMessage:
textEditController.text.trim(),
isSeen: false,
deliverIconColor: isSeen? Colors.blue : Colors.grey));
}
});
},
I'm using MUI v5's styled() and want to return a different color based on two props of the component (darkMode and destructive).
Here's what I'm doing:
const StyledButton = styled(Button)<ButtonProps>(({ darkMode, destructive }) => ({
'&.MuiButton-contained': {
backgroundColor: () => {
if (!darkMode) return 'purple';
else return 'red';
},
'&:hover': {
backgroundColor: colors.standardHoverColor
},
'&:focus': {
backgroundColor: colors.standardFocusColor
}
},
}));
I want the backgroundColor to be purple if darkMode is off, and red if it's on. There's other configurations based on destructive too, but this is a POC.
Any ideas how I can accomplish this dynamic styling based on the two props?
Thanks in advance.
I have an AccountCircleIcon Material UI icon and I want to increase the size, I've tried several things:
import AccountCircleIcon from '#material-ui/icons/AccountCircle';
import {withStyles} from '#material-ui/styles';
const StyledIcon = withStyles({
root: {
fontSize: '50rem',
},
})(AccountCircleIcon);
const login = () => {
return (
<div><StyledIcon /></div>
);
};
import AccountCircleIcon from '#material-ui/icons/AccountCircle';
import {makeStyles} from '#material-ui/styles';
const useStyles = makeStyles({
root: {
fontSize: '50rem',
},
});
const login = () => {
const classes = useStyles();
return (
<div><AccountCircleIcon classes={{root: classes.root}} /></div>
);
};
import AccountCircleIcon from '#material-ui/icons/AccountCircle';
import {makeStyles} from '#material-ui/styles';
const useStyles = makeStyles({
avatarIcon: {
fontSize: '50rem',
},
});
const login = () => {
const classes = useStyles();
return (
<div><AccountCircleIcon className={classes.avatarIcon} /></div>
);
};
But each time the default icon styling overrides the added styling:
I missed the StyledEngineProvider https://mui.com/guides/interoperability/ wrapping that around your app assures the custom css is injected first:
import * as React from 'react';
import { StyledEngineProvider } from '#mui/material/styles';
export default function GlobalCssPriority() {
return (
<StyledEngineProvider injectFirst>
{/* Your component tree. Now you can override MUI's styles. */}
</StyledEngineProvider>
);
}
https://codesandbox.io/s/laughing-alex-nyszr?file=/src/Demo.tsx
How can I open keyboard type == emoji. Not number, not letter, just emoji. Without using emoji_picker package
To open the emoji container emoji_picker
Create A method emojiContainer
emojiContainer() {
return EmojiPicker(
bgColor: Colors.red,
indicatorColor: Colors.blue,
rows: 3,
columns: 7,
onEmojiSelected: (emoji, category) {
setState(() {
isWriting = true;
});
textFieldController.text = textFieldController.text + emoji.emoji;
},
recommendKeywords: ["face", "happy", "party", "sad"],
numRecommended: 50,
);
}
And use an onPressed
onPressed: () {
if (!showEmojiPicker) {
// keyboard is visible
hideKeyboard();
showEmojiContainer();
} else {
//keyboard is hidden
showKeyboard();
hideEmojiContainer();
}
},