Guide on adding font face to mui theme

I have a font-face defined in the index.css file. I am looking to move this configuration from the CSS file to a theme.js file created as part of my MUI library implementation. How can I achieve this?

// index.css

@font-face {
  font-family: 'ATTAleckSans_W_Lt';
  src: url('./fonts/ATTAleckSans_W_Lt.woff2');
}

// theme.js

const theme = createTheme({
// Place @font-face settings here.
})

CodeSandbox Demo

Answer №1

Check out this solution for implementing a similar approach.

Once you've added the font, you can customize your theme to include it (for example, setting the font to Monserrat).

import { createTheme } from '@mui/material/styles';

export const customTheme = createTheme({
  typography: {
    fontFamily: ['Montserrat', 'serif'].join(','),
    button: {
      fontSize: 16,
      fontWeight: 400,
    },
  }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Validating a particular value using Regex in React Formik

First, I need to ensure that the field is validated for any characters not included in this set: /[ùûüÿ€’“”«»–àâæçéèêëïîôœ]/. If a user enters a character outside of this set, I want Yup to trigger an error message. Secondly, I ...

Error encountered while implementing onMutate function in React Query for Optimistic Updates

export const usePostApi = () => useMutation(['key'], (data: FormData) => api.postFilesImages({ requestBody: data })); Query Definition const { mutateAsync } = usePostApi(); const {data} = await mutateAsync(formData, { onMutate: ...

What is the best way to customize the appearance of the material-ui select component using styled-components instead of material-ui classes in a React

I've been facing some challenges while trying to style my material-ui select component using styled-components instead of material- classes. The version I am working with is material-ui/core 4.12.3. When I use the old makeStyles component from materi ...

Cookie Not Found - Superagent

When making a POST request on an API using superagent, I am encountering an issue with setting a cookie after logging in. The code for making the request from a React component is as shown below: agent .post('http://localhost:3010/api/a ...

Using various colors to highlight specific sections of a letter or number

I am striving to recreate the unique image shown below, particularly interested in achieving the multi-colored effect on the numbers. This aspect of having different colors for parts of the number is intriguing and I would love to learn how it's done. ...

The declaration file for the 'react' module could not be located

I was exploring Microsoft's guide on TypeScript combined with React and Redux. After executing the command: npm install -S redux react-redux @types/react-redux I encountered an error when running npm run start: Type error: Could not find a decla ...

place an image next to a div element

Currently, I have a table-like structure with two columns that I am struggling to make mobile responsive. Take a look at the code snippet below: setTimeout(function() { odometer.innerHTML = '1925' }) .fiftyFiftySection { back ...

Leverage the power of React, Material-UI, and Typescript to inherit button props and incorporate a variety of unique

Looking to enhance the Material-UI button with additional variants like "square." How can I create a prop interface to merge/inherit props? Check out the following code snippet: import React from "react"; import { Button as MuiButton } from "@material-u ...

Managing email delivery and responses within Nextjs server functions using Nodemailer and React Email package

Currently, I'm working on a Next.js project that involves sending emails. The functionality works as expected, but I've encountered an issue when trying to verify if the email was successfully sent or not. Here's my current setup: await tran ...

Prevent Modal from moving along with the scrollbar by utilizing Material-UI's "mui-fixed" feature

Currently, I am in the process of implementing a Material-UI modal and have encountered an issue with the scrollbar causing the modal to shift every time it closes. Although I can address this by using the "mui-fixed" class, it introduces unwanted padding ...

Creating tabbed interfaces with JQuery

How do I build tabs using jQuery without displaying the content of all tabs until clicked? I have tried using this code, and it works well once a tab is clicked. However, when the page is refreshed, the content of both tabs is visible. jQuery (funct ...

What is the best way to implement useState within a loop?

I'm currently working on a mini app that allows users to select multiple music albums using Next.js. My album display is similar to the image below, and I want to include a check mark when an album is clicked, and remove it when clicked again. Here& ...

What steps can I take to convert my React class into a function in order to incorporate Material UI components effectively?

With Emailjs set up successfully, my next step is integrating Material UI text fields (link: https://material-ui.com/components/text-fields/#text-field) to enhance the design of my project. The challenge I'm facing is incorporating Material UI classe ...

Hovering over the Instagram icon will reveal a stunning visual effect

I am looking to change the appearance of my Instagram icon when hovering over it. I want the background to turn white and the icon to become colored. Here is my code snippet from Footer.js : <a href="https://www.instagram. ...

Looking for a straightforward method to handle local state using Apollo Client 2.5 in React? Wondering what the counterpart to 'client.writeData' is when it comes to reading data?

Exploring the local state management capabilities of Apollo Client 2.5 has been quite a challenge for me. While I found Apollo Server easy to grasp, this aspect is proving to be more complex. I have a basic understanding of setting up local resolvers and ...

The content within the iframe is not displayed

I've set up a dropdown menu with separate iframes for each option. Here's the code I used: $(function(){ $('#klanten-lijst').on('change',function(){ $('#klanten div').hide(); $('.klant-'+t ...

Testing the redirection feature of React Router v4

How can I effectively perform unit testing on a component within react router v4? I have been facing challenges in trying to unit test a basic component with a redirect feature using jest and enzyme. Here is the component I am working with: const AppCon ...

When attempting to run npm start, an error message appears indicating a failed compilation due to the inability to resolve

Error compiling ./node_modules/jest-serializer/build/index.js Module not located: Unable to find 'v8' in 'C:\Users\Desktop\reactapp\react-project\node_modules\jest-serializer\build' This issue arose du ...

Employing SWR within the Next.js global context will trigger a complete page re-render

I've encountered a piece of code that I'm currently working with: function MyApp({ Component, pageProps }: AppProps) { const { tronLinkAuth, tronLinkLoading, mutateTronLink } = useTronLink(); const { authenticatedUser, authLoading, authLo ...

The error message [TypeError: attempting to access 'getDocumentsDirectory' property on a null object] was encountered

I have been attempting to generate a PDF within my application using react-native-pdf-lib. However, I keep encountering the following error: [TypeError: null is not an object (evaluating '_reactNativePdfLib.default.getDocumentsDirectory')] Here ...