How to make mui toggle button lowercase in react js?
January 02, 2024Hi Friends 👋,
Welcome To aGuideHub!
To make mui toggle button lowercase in react js, you can use style={{ textTransform: "lowercase" }}
in ToggleButtonGroup. it will make mui toggle button lowercase in React JS.
Today, I am going to show you, How to make mui toggle button lowercase in react js
Installation
Install the following packages to use mui toggle button in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
Table of contents
- Install MUI and create a new React app.
- Import Material-UI toggle button.
- Use the toggle button Component.
Step 1: Install MUI and create a new React app.
First you have to install the React project. You should use create-react-app
command to create a new React project.
npx create-react-app my-app
cd my-app
npm start
Step 2: Import Material-UI toggle button.
After installing MUI
, you have to import your React component. To do this, add the following line to the top of your component file.
import React from "react";
import ToggleButton from "@mui/material/ToggleButton";
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
import Typography from "@mui/material/Typography";
Step 3: Use the toggle button Component.
Toggle Button Group provides a way to get mutually exclusive actions closer together by sharing a common container.
<ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment}>
<ToggleButton value="left">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Left
</Typography>
</ToggleButton>
<ToggleButton value="center">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Center
</Typography>
</ToggleButton>
<ToggleButton value="right">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Right
</Typography>
</ToggleButton>
<ToggleButton value="justify">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Justify
</Typography>
</ToggleButton>
</ToggleButtonGroup>
MUI material make mui toggle button lowercase example.
The below code is an example, you need to import toggle button
Component. Then, you can use style={{ textTransform: "lowercase" }}
in ToggleButtonGroup. Then it will make mui toggle button lowercase in react js.
App.js
import React from "react";
import ToggleButton from "@mui/material/ToggleButton";
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
import Typography from "@mui/material/Typography";
const MyToggleButtonGroup = () => {
const [alignment, setAlignment] = React.useState("left");
const handleAlignment = (event, newAlignment) => {
if (newAlignment !== null) {
setAlignment(newAlignment);
}
};
return (
<ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment}>
<ToggleButton value="left">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Left
</Typography>
</ToggleButton>
<ToggleButton value="center">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Center
</Typography>
</ToggleButton>
<ToggleButton value="right">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Right
</Typography>
</ToggleButton>
<ToggleButton value="justify">
<Typography variant="body1" style={{ textTransform: "lowercase" }}>
Justify
</Typography>
</ToggleButton>
</ToggleButtonGroup>
);
};
export default MyToggleButtonGroup;
In the above code example, I have used the @mui/material
component and make mui toggle button lowercase in react js.
Here, we are provided code sandbox links for the above program make mui toggle button lowercase in react js. Then you can use whenever you want and do the changes as per your requirements.
All the best 👍