Change font of react-select component using theme
up vote
2
down vote
favorite
I'm trying to change the font of my entire react-select component (control, drop-down, etc). I'm using material-ui themes, so I tried setting theme:
<Select
theme={theme}
/>
But that didn't work. This also didn't work:
<Select
theme={theme => ({
...theme,
typography: {
...theme.typography,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}
})}
/>
Demo here
I figured out how to do it with styles (demo):
const customStyles = {
container: (provided, state) => ({
...provided,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}),
};
<Select
styles={customStyles}
/>
But it would be nice to use themes, since I already created a theme with my font.
material-ui react-select
add a comment |
up vote
2
down vote
favorite
I'm trying to change the font of my entire react-select component (control, drop-down, etc). I'm using material-ui themes, so I tried setting theme:
<Select
theme={theme}
/>
But that didn't work. This also didn't work:
<Select
theme={theme => ({
...theme,
typography: {
...theme.typography,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}
})}
/>
Demo here
I figured out how to do it with styles (demo):
const customStyles = {
container: (provided, state) => ({
...provided,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}),
};
<Select
styles={customStyles}
/>
But it would be nice to use themes, since I already created a theme with my font.
material-ui react-select
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm trying to change the font of my entire react-select component (control, drop-down, etc). I'm using material-ui themes, so I tried setting theme:
<Select
theme={theme}
/>
But that didn't work. This also didn't work:
<Select
theme={theme => ({
...theme,
typography: {
...theme.typography,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}
})}
/>
Demo here
I figured out how to do it with styles (demo):
const customStyles = {
container: (provided, state) => ({
...provided,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}),
};
<Select
styles={customStyles}
/>
But it would be nice to use themes, since I already created a theme with my font.
material-ui react-select
I'm trying to change the font of my entire react-select component (control, drop-down, etc). I'm using material-ui themes, so I tried setting theme:
<Select
theme={theme}
/>
But that didn't work. This also didn't work:
<Select
theme={theme => ({
...theme,
typography: {
...theme.typography,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}
})}
/>
Demo here
I figured out how to do it with styles (demo):
const customStyles = {
container: (provided, state) => ({
...provided,
fontFamily: ["Montserrat", "sans-serif"].join(",")
}),
};
<Select
styles={customStyles}
/>
But it would be nice to use themes, since I already created a theme with my font.
material-ui react-select
material-ui react-select
edited Nov 20 at 1:13
asked Nov 20 at 0:50
Melissa
806
806
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03
add a comment |
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
If you take a look at the theme.js
file below you will notice that there no font
option for now so no way to use this props to achieve what you're looking for.
import type { Theme } from './types';
export const colors = {
primary: '#2684FF',
primary75: '#4C9AFF',
primary50: '#B2D4FF',
primary25: '#DEEBFF',
danger: '#DE350B',
dangerLight: '#FFBDAD',
neutral0: 'hsl(0, 0%, 100%)',
neutral5: 'hsl(0, 0%, 95%)',
neutral10: 'hsl(0, 0%, 90%)',
neutral20: 'hsl(0, 0%, 80%)',
neutral30: 'hsl(0, 0%, 70%)',
neutral40: 'hsl(0, 0%, 60%)',
neutral50: 'hsl(0, 0%, 50%)',
neutral60: 'hsl(0, 0%, 40%)',
neutral70: 'hsl(0, 0%, 30%)',
neutral80: 'hsl(0, 0%, 20%)',
neutral90: 'hsl(0, 0%, 10%)',
};
const borderRadius = 4;
const baseUnit = 4; /* Used to calculate consistent margin/padding on elements */
const controlHeight = 38; /* The minimum height of the control */
const menuGutter = baseUnit * 2; /* The amount of space between the control and menu */
export const spacing = {
baseUnit,
controlHeight,
menuGutter,
};
export const defaultTheme: Theme = {
borderRadius,
colors,
spacing,
};
export type ThemeConfig = Theme | ((theme: Theme) => Theme);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
If you take a look at the theme.js
file below you will notice that there no font
option for now so no way to use this props to achieve what you're looking for.
import type { Theme } from './types';
export const colors = {
primary: '#2684FF',
primary75: '#4C9AFF',
primary50: '#B2D4FF',
primary25: '#DEEBFF',
danger: '#DE350B',
dangerLight: '#FFBDAD',
neutral0: 'hsl(0, 0%, 100%)',
neutral5: 'hsl(0, 0%, 95%)',
neutral10: 'hsl(0, 0%, 90%)',
neutral20: 'hsl(0, 0%, 80%)',
neutral30: 'hsl(0, 0%, 70%)',
neutral40: 'hsl(0, 0%, 60%)',
neutral50: 'hsl(0, 0%, 50%)',
neutral60: 'hsl(0, 0%, 40%)',
neutral70: 'hsl(0, 0%, 30%)',
neutral80: 'hsl(0, 0%, 20%)',
neutral90: 'hsl(0, 0%, 10%)',
};
const borderRadius = 4;
const baseUnit = 4; /* Used to calculate consistent margin/padding on elements */
const controlHeight = 38; /* The minimum height of the control */
const menuGutter = baseUnit * 2; /* The amount of space between the control and menu */
export const spacing = {
baseUnit,
controlHeight,
menuGutter,
};
export const defaultTheme: Theme = {
borderRadius,
colors,
spacing,
};
export type ThemeConfig = Theme | ((theme: Theme) => Theme);
add a comment |
up vote
1
down vote
accepted
If you take a look at the theme.js
file below you will notice that there no font
option for now so no way to use this props to achieve what you're looking for.
import type { Theme } from './types';
export const colors = {
primary: '#2684FF',
primary75: '#4C9AFF',
primary50: '#B2D4FF',
primary25: '#DEEBFF',
danger: '#DE350B',
dangerLight: '#FFBDAD',
neutral0: 'hsl(0, 0%, 100%)',
neutral5: 'hsl(0, 0%, 95%)',
neutral10: 'hsl(0, 0%, 90%)',
neutral20: 'hsl(0, 0%, 80%)',
neutral30: 'hsl(0, 0%, 70%)',
neutral40: 'hsl(0, 0%, 60%)',
neutral50: 'hsl(0, 0%, 50%)',
neutral60: 'hsl(0, 0%, 40%)',
neutral70: 'hsl(0, 0%, 30%)',
neutral80: 'hsl(0, 0%, 20%)',
neutral90: 'hsl(0, 0%, 10%)',
};
const borderRadius = 4;
const baseUnit = 4; /* Used to calculate consistent margin/padding on elements */
const controlHeight = 38; /* The minimum height of the control */
const menuGutter = baseUnit * 2; /* The amount of space between the control and menu */
export const spacing = {
baseUnit,
controlHeight,
menuGutter,
};
export const defaultTheme: Theme = {
borderRadius,
colors,
spacing,
};
export type ThemeConfig = Theme | ((theme: Theme) => Theme);
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
If you take a look at the theme.js
file below you will notice that there no font
option for now so no way to use this props to achieve what you're looking for.
import type { Theme } from './types';
export const colors = {
primary: '#2684FF',
primary75: '#4C9AFF',
primary50: '#B2D4FF',
primary25: '#DEEBFF',
danger: '#DE350B',
dangerLight: '#FFBDAD',
neutral0: 'hsl(0, 0%, 100%)',
neutral5: 'hsl(0, 0%, 95%)',
neutral10: 'hsl(0, 0%, 90%)',
neutral20: 'hsl(0, 0%, 80%)',
neutral30: 'hsl(0, 0%, 70%)',
neutral40: 'hsl(0, 0%, 60%)',
neutral50: 'hsl(0, 0%, 50%)',
neutral60: 'hsl(0, 0%, 40%)',
neutral70: 'hsl(0, 0%, 30%)',
neutral80: 'hsl(0, 0%, 20%)',
neutral90: 'hsl(0, 0%, 10%)',
};
const borderRadius = 4;
const baseUnit = 4; /* Used to calculate consistent margin/padding on elements */
const controlHeight = 38; /* The minimum height of the control */
const menuGutter = baseUnit * 2; /* The amount of space between the control and menu */
export const spacing = {
baseUnit,
controlHeight,
menuGutter,
};
export const defaultTheme: Theme = {
borderRadius,
colors,
spacing,
};
export type ThemeConfig = Theme | ((theme: Theme) => Theme);
If you take a look at the theme.js
file below you will notice that there no font
option for now so no way to use this props to achieve what you're looking for.
import type { Theme } from './types';
export const colors = {
primary: '#2684FF',
primary75: '#4C9AFF',
primary50: '#B2D4FF',
primary25: '#DEEBFF',
danger: '#DE350B',
dangerLight: '#FFBDAD',
neutral0: 'hsl(0, 0%, 100%)',
neutral5: 'hsl(0, 0%, 95%)',
neutral10: 'hsl(0, 0%, 90%)',
neutral20: 'hsl(0, 0%, 80%)',
neutral30: 'hsl(0, 0%, 70%)',
neutral40: 'hsl(0, 0%, 60%)',
neutral50: 'hsl(0, 0%, 50%)',
neutral60: 'hsl(0, 0%, 40%)',
neutral70: 'hsl(0, 0%, 30%)',
neutral80: 'hsl(0, 0%, 20%)',
neutral90: 'hsl(0, 0%, 10%)',
};
const borderRadius = 4;
const baseUnit = 4; /* Used to calculate consistent margin/padding on elements */
const controlHeight = 38; /* The minimum height of the control */
const menuGutter = baseUnit * 2; /* The amount of space between the control and menu */
export const spacing = {
baseUnit,
controlHeight,
menuGutter,
};
export const defaultTheme: Theme = {
borderRadius,
colors,
spacing,
};
export type ThemeConfig = Theme | ((theme: Theme) => Theme);
answered Nov 20 at 18:59
Laura
1,004619
1,004619
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384707%2fchange-font-of-react-select-component-using-theme%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In your example theme is already available.. i have tried to show in example check: codesandbox.io/s/9jx2z18jwy if MuiProvider at root you get theme via this: material-ui.com/customization/themes/… i have console logged both properties, to show how to use.
– Ajit T Stephen
Nov 20 at 10:54
Thanks. Your example has: styles={{ container: (provided, state) => ({ ...provided, fontFamily: theme.typography.fontFamily }) }} Is there a way to use the theme attribute, instead of style attribute? theme = {theme}
– Melissa
Nov 20 at 17:03