createStyleSheet
λ₯Ό μ¬μ©ν λ κ΅¬μ± μμμ μνμ μ‘μΈμ€ν μ μλ λ°©λ²μ΄ μμ΅λλ€. ν¬κΈ°, URL μ΄λ―Έμ§ λ° κΈ°ν μ€νμΌμ κ΅¬μ± μμμ μνμΌλ‘ μ λ¬νλ €λ κ²½μ°κ° μμΌλ―λ‘ μ΄κ²μ΄ μ€μνλ€κ³ μκ°ν©λλ€.
μ€λλ μ΄κ²μ λν μ μΌν ν΄κ²°μ±
μ μ΄λ¬ν κ²λ€μ μΈλΌμΈ μ€νμΌλ‘ λΆλ¦¬νλ κ²μ΄μ§λ§ λ΄κ° μλ ν material-ui v1μ jss
λ° react-jss
λ₯Ό μ¬μ©νκ³ μ΄ λ κ°μ§λ μ΄λ―Έ κ°λ₯μ±μ μ 곡ν©λλ€ propsλ₯Ό λ°μ λ€μ μνλ μ€νμΌμ λ°ννλ ν¨μλ₯Ό ν΅ν΄ propsμ μ‘μΈμ€νλ λ°©λ²μ λ€μκ³Ό κ°μ΅λλ€.
const styles = {
button: {
background: props => props.color
},
root: {
backgroundImage: props => `url(${props.backgroundImage})`
}
}
// Reference: https://github.com/cssinjs/react-jss#example
material-uiμμλ μ΄μ κ°μ κ²μ ꡬννλ κ²μ λν΄ μ΄λ»κ² μκ°νμλκΉ?
react-jssλ ν΄λΉ κΈ°λ₯μ ꡬνν©λλ€. μ°λ¦¬μ μ€νμΌλ§ μ루μ μμ νμ μ¬μ©ν μ μμ΅λλ€. μ¬κΈ°μμ ν΄λΉ κΈ°λ₯μ ꡬννλ μ§μ ν λκΈ°λ κ΅¬μ± μμμ λ κ°λ¨νκ³ λ λμ λ΄λΆ ꡬνμ κ΄ν κ²μ λλ€.
react-jss injectStyles() λ μ΄ μμ
μ μννμ§λ§ StyleRuleCallback
μ propsλ₯Ό μΆκ°νλ κ²μ΄ λ λμ κ² κ°μ΅λλ€.
const styles = (props, theme) => ({})
κ·Έλ κ² νλ©΄ μνμ λ°λΌ κ°μλ§ μ νλμ§ μμ΅λλ€.
@Shamplol νΌλλ°±μ ν΅ν΄ μ¬μ©μκ° μ¬μ μ μλ νλͺ© λμ μ¬μ©μ μ μ color
λ₯Ό κ΅¬μ± μμμ μ 곡ν μ μλλ‘ μ΄ μλ‘μ΄ κΈ°λ₯μ νμ©ν μ μλ€κ³ μκ°ν©λλ€. CSS ν¬κΈ° μν₯μ λͺ
ννμ§ μμ§λ§ κ΅¬μ± μμ μμ μ¬μ μλ₯Ό ν¨μ¬ λ κ°λ¨νκ² λ§λλλ€. μ΄κ²μ μ‘°μ¬ν μ¬νμ
λλ€. κ·Έλ° λ€μ CSS λ³μ λΈλΌμ°μ μ§μμ΄ μΆ©λΆν λμΌλ©΄(μ§κΈλΆν° 2λ
?), μ°λ¦¬λ κ·Έκ²μ μμ‘΄ν μ μμ΅λλ€.
@oliviertassinari κ²½μ°μ λ°λΌ CSS ν¬κΈ°κ° μ€μ λ‘ μ€μ΄λ€μ§ μμ΅λκΉ?
λ΄κ° μλ ν, μ°λ¦¬λ νμ¬ ...Primary
λ° ...Accent
λν λͺ¨λ ν΄λμ€λ₯Ό μ μν©λλ€. μ΄ λ³κ²½μ ...Colorized
λν ν΄λμ€λ§ μ μ§ν΄μΌ νλ€λ κ²μ μλ―Ένμ§ μμ΅λκΉ? μλλ©΄ μμ±λ CSSκ° κ±±μ λμλκΉ?
μ΄λ μͺ½μ΄λ , κΈ°λ³Έμ μΌλ‘ https://github.com/callemall/material-ui/blob/v1-beta/src/Button/Button.js#L11 κ³Ό κ°μ 볡μ‘ν ν΄λμ€λ₯Ό λ€μ ꡬνν΄μΌ νλ―λ‘ dxκ° ν¬κ² ν₯μλ κ²μ΄λΌκ³ μκ°ν©λλ€. λΉ νλ νΈ μμμ μ¬μ©νκ³ μΆμ΅λλ€.
μ΄λ€ κ²½μ°μλ CSS ν¬κΈ°κ° μ€μ λ‘ μ€μ΄λ€μ§ μμ΅λκΉ?
@sakulstra λ§νκΈ° μ΄λ ΅μ΅λλ€. ꡬνμ λ°λΌ λ€λ¦ λλ€. μλ§λ :).
TypeScript νμ΄ν κ΄μ μμ _ props
λ° theme
λͺ¨λ μ€νμΌ μ¬μ λ΄μμ λ€μκ³Ό κ°μ΄ μ‘μΈμ€ν μ μμΌλ©΄ μ’μ κ²μ
λλ€.
const styles = {
button: {
background: ({ theme }) => theme.palette.primary[200]
},
root: {
backgroundImage: ({ props }) => `url(${props.backgroundImage})`
}
};
κ·Έ μ΄μ λ TypeScriptκ° ν¨μ κ°μ²΄λ₯Ό μ λ¬ν λ withStyles
λν μ¬λ°λ₯Έ μ νμ μΆλ‘ νλ λ° μμ£Ό μ€ν¨νκΈ° λλ¬Έμ
λλ€. λ°λΌμ μλνλ €λ©΄ μΆκ° μ ν μ£Όμμ μ 곡ν΄μΌ ν©λλ€.
withStyles<'button' | 'root'>(theme => ...)
μνλ μ λ¬λλ©΄ λ€μμ΄ λ©λλ€.
withStyles<'button' | 'root', Props>((theme, props) => ...)
νμ¬ μνλ μ΄λ»μ΅λκΉ? κ·Έ κΈ°λ₯μ΄ μμΌλ©΄ μ λ§ μ’κ² μ§λ§
@lucasmafra μ΄ κΈ°λ₯μ v1 λ¦΄λ¦¬μ€ μ΄μ ν μ΄νμ μΆκ°νμ΅λλ€. v1μ 빨리 μΆμν μλ‘ μ’μ΅λλ€.
μ΄ κΈ°λ₯μ μν, λ―Έλμ΄ μΏΌλ¦¬ λ° λνν μνλ₯Ό κ²°ν©νλ νν μ€νμΌ κ·μΉμ μμ±ν μ μλ ν΅μ¬μ
λλ€. ν΄λΉ κΈ°λ₯μ μΈλΌμΈ μ€νμΌλ‘ λ°κΏ μ μμ΅λλ€. λΆννλ withStyles
λ μ΄κ²μ΄ μΆκ°λ λκΉμ§ λ΄ νλ‘μ νΈμμ μ¬μ©ν μ μμ΅λλ€.
μΈμ λ μ§ μ¬μ©μ μ μ ν λ§λ₯Ό μ€μ ν μ μκ³ λ€μ κ·μΉμ μ¬μ©ν μ μμ΅λλ€. μ°λ¦¬λ μ€νμΌμ΄ μ§μ λ κ΅¬μ± μμκ° λͺ¨λ theme={theme}λ₯Ό νΈμΆν λ MuiThemeProvider λ΄λΆμ ThemeProviderλ₯Ό μ€μ²©νμ¬ κΈ°λ³Έμ μΌλ‘ props.themeμ μ‘μΈμ€ν μ μλ λ°©λ²μ μ λ§ μ’μν©λλ€. muiκ° λ ΈμΆνλ κΈ°λ³Έ ν λ§λ₯Ό νμ₯ν©λλ€.
//inline with HOC Method
h1 style= {{ 'color: this.props.theme.palette.primary[500]' }}
//styled components ( no method necessary )
const Heading = styled.h1`
color: ${p => p.theme.palette.primary['500']};
`
μ λ κ·Έλ₯ ν¨μ κ°μ μ¬μ©ν΄μΌ ν΄μ react-jssμ injectSheet()
ν¨μλ₯Ό μ¬μ©νμ΅λλ€. Muiμ withStyles()
ν¨μλ₯Ό μ¬μ©νλλ°, withStyle λμ injectSheetλ₯Ό μ¬μ©ν λ λ¨μ μ΄ μμ΅λκΉ?
@damien-monni MUI ν λ§μ μ‘μΈμ€ν μ μμ΅λλ€.
μλ νμΈμ, Material-UI styled-components-like APIμ μ λ²μ μ 곡μ νκ³ μΆμμ΅λλ€. "λ§μ΄" ν μ€νΈλμ§λ μμμ§λ§ μ μλνκ³ λ€μμ μ 곡ν©λλ€.
props
λ° theme
λ₯Ό μ€νμΌ κΈ°λ₯μΌλ‘ λμ΄ μ¬λ Έμ΅λλ€.props
μ λ¬React.forwardRef
λ₯Ό ν΅ν΄ μ°Έμ‘° μ λ¬function
λλ object
μλ½μ΄ νμν κ²μ
λλ€ κ΄λ ¨ λ¬Έμ : #10825, #7633
styled.js
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
function styled(WrappedComponent, customProps) {
return (style, options) => {
class StyledComponent extends Component {
render() {
let {
forwardRef,
classes,
className,
...passThroughProps
} = this.props;
return (
<WrappedComponent
ref={forwardRef}
className={classNames(classes.root, className)}
{...passThroughProps}
{...customProps}
/>
);
}
}
StyledComponent.propTypes = {
classes: PropTypes.object.isRequired,
className: PropTypes.string,
};
let hoistedProps = {};
const styles =
typeof style === 'function'
? theme => {
return { root: style({ ...theme, theme, props: hoistedProps }) };
}
: { root: style };
const WithRef = withStyles(styles, options)(StyledComponent);
return React.forwardRef((props, ref) => {
hoistedProps = props;
return <WithRef {...props} forwardRef={ref} />;
});
};
}
export default styled;
μ¬μ© μ
const MobileNav = styled('nav')(({ theme, props }) => ({
'&.pos-fixed': {
top: 0,
position: props.fixed ? 'fixed' : 'absolute',
zIndex: 99,
animation: 'fadeInDown 0.3s ease-out forwards',
backgroundColor: theme.palette.common.white,
},
}));
컀μ€ν μνμΌλ‘
const StyledButton = styled(Button, { component: Link })(
({ theme, props }) => ({
color: props.disabled ? 'gray' : 'blue',
[theme.breakpoints.down('sm')]: {
color: 'red',
},
})
);
@oliviertassinari μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ μλ μ루μ μ μ¬μ©νκ³ μμ΅λλ€.
componentWillMount() {
const {color} = this.props;
jss.setup(jssPreset());
const stylesheet = jss.createStyleSheet({
underline: {
"&:after": {
backgroundColor: `${color} !important`
}
}
}).attach();
this.underlineClass = stylesheet.classes.underline;
}
μ μλνμ§λ§ λ΄κ° λ³΄μ§ λͺ»νλ μ μ¬μ μΈ λ¬Έμ κ° μμ΅λκΉ? μλ₯Ό λ€μ΄ jss.setupμ λ λ² νΈμΆν΄μΌ νλ κ²μ΄ λ§μμ λ€μ§ μμ΅λλ€. jss
μλͺ
μ£ΌκΈ°λ₯Ό μ΄ν΄νκ³ μλμ§ μ λͺ¨λ₯΄κ² μ΅λλ€. μ¬κΈ°μ setup()
λ₯Ό νΈμΆν΄μΌ νλ€λ μ¬μ€μ λλμ΅λλ€.
μ μλνμ§λ§ λ΄κ° λ³΄μ§ λͺ»νλ μ μ¬μ μΈ λ¬Έμ κ° μμ΅λκΉ?
@wcandillon λ΄κ° λ³Ό μ μλ λͺ κ°μ§ μ μ¬μ μΈ λ¬Έμ : 1. κ΅¬μ± μμμ μΈμ€ν΄μ€κ° λ§μ΄νΈλ λλ§λ€ μ ν΄λμ€ μ΄λ¦μ μ½μ ν©λλ€. 2. μλ² μΈ‘μμ κ΅¬μ± μμλ₯Ό λ λλ§ν μ μμ΅λλ€. 3. μ¬λ°λ₯Έ CSS μ¬μ μ μ£Όμ μμλ₯Ό μ»μ§ λͺ»ν κ²μ λλ€.
μ€νμΌμ΄ μλ μνμ κ°λλ‘ μ΄ λΌμ΄λΈλ¬λ¦¬λ₯Ό κ°λ°νμ΅λλ€.
https://github.com/JacquesBonet/jss-material-ui
νλ‘μ νΈμμ μ±κ³΅μ μΌλ‘ ν μ€νΈλμμ΅λλ€.
μ²μμλ danielmahon μ루μ μ μ¬μ©νμ§λ§ μ€νμΌ μμ λ¬Έμ κ° λ°μν©λλ€.
@oliviertassinari νμ¬ λμ CSS/μ λλ©μ΄μ μ λ§λ€κΈ° μν λμμ΄ μμ΅λκΉ? κ°μ¬ ν΄μ :)
@HunderlineK λͺ κ°μ§ λμ: https://material-ui.com/customization/overrides/#2 -dynamic-variation-for-a-one-time-situation.
@danielmahon λΉμ μ μ κ·Ό λ°©μμ λ°λ‘ μ§κΈ λ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ μ°Ύκ³ μλ κ²μ λλ€. νμ§λ§ "μ€νμΌ κ΅¬μ± μμ"λ μ μνμ λ°μ λ λ€μ λ λλ§λμ§ μμ΅λλ€. λ€λ₯Έ κ²μ μλν΄ λ³΄μ ¨μ΅λκΉ?
λλ λ€λ₯Έ κ²μ μκ°ν κ²μ΄κ³ , λ΄κ° μκ°λλ κ²μ΄ μμΌλ©΄ λΉμ μκ² μλ €μ€ κ²μ΄λ€.
π° λ°©κΈ $50 νμκΈμ κ±Έμμ΅λλ€ :)
@lewisdiamondκ° λ§νλ―μ΄ const styles = (props, theme) => ({})
λ μ λ§ κΉλν©λλ€.
λλ const styles = (theme, props) => ({})
μ΄ μλ μλ μμ΅λλ€.
μ΄ λ¬Έμ λ₯Ό v1.x λ§μΌμ€ν€ μ μΆκ°νκ³ μμ΅λλ€. λ§μ λΆλ€μ΄ μμ²νκ³ μμ΅λλ€. μ°λ¦¬λ 곧 κ·Έκ²μ μ»μ κ²μ λλ€.
@oliviertassinari μ΄κ²μ μλ§λ withStyles
μ
λ ₯μ μ€μν μλ―Έκ° μμ κ²μ
λλ€. μ κ° λμλ릴 μ μλμ§ μλ €μ£ΌμΈμ.
@pelotom κ°μ¬ν©λλ€, μλ €λλ¦¬κ² μ΅λλ€. μ΄λ² λ¬μ λ¬Έμ λ₯Ό μ΄ν΄λ³Ό μ μκΈ°λ₯Ό λ°λλλ€.
μ΄μ λν μμ μ΄ μ§ν μ€μ λκΉ? IMOμ ν΅μ¬ κΈ°λ₯μ λλ€. μ κ° λμλ릴 μ μμ΅λλ€.
νΈμ§: λλ κ·Έκ²μ λν΄ μμ
νκΈ° μμνμ΅λλ€. withStyles
νμ©νλ styles
ν¨μμ propsλ₯Ό μ λ¬νμ§λ§ λ¬Έμ λ propsκ° λ³κ²½λ λ μ€νμΌμ΄ μ
λ°μ΄νΈλμ§ μλλ€λ κ²μ
λλ€. ν΄κ²°λλ©΄ PRμ μμ±ν©λλ€.
μλ νμΈμ μ λ μλ°ν κ΅¬μ± μμμ μμμ μ¬μ©μ μ μνκΈ° μν΄ μ΄κ²μ΄ νμν μ¬μ© μ¬λ‘λ₯Ό λ°κ²¬νμΌλ©° μ΄κ² μ΄μΈμ κ΅¬μ± μμμ λͺ¨λ λ³νμ λν μ€νμΌμ μ μ΄ν μ μλ λ€λ₯Έ λ°©λ²μ΄ μμ΅λλ€.
const styles = theme => ({
chip:{
},
separator: {
marginRight: theme.spacing.unit,
},
fright: {
float: 'right',
},
fleft: {
float: 'left',
},
outlinedPrimary:{
color: props => stringToColor( props.username),
border: props => `1px solid ${fade(stringToColor(props.username), 0.5)}`,
'$clickable&:hover, $clickable&:focus, $deletable&:focus': props => ({
backgroundColor: fade(stringToColor(props.username), theme.palette.action.hoverOpacity),
border: `1px solid ${stringToColor(props.username)}`,
}),
},
outlined: {
backgroundColor: 'transparent',
border: props => `1px solid ${
theme.palette.type === 'light' ? stringToColor(props.username) : fade(stringToColor(props.username))
}`,
'$clickable&:hover, $clickable&:focus, $deletable&:focus': props => ({
backgroundColor: fade(stringToColor(props.username), theme.palette.action.hoverOpacity),
}),
},
});
λ΄ μ루μ Japrogramerλ₯Ό νμΈν μ μμ΅λλ€. https://github.com/JacquesBonet/jss-material-ui
κ°μ¬ν©λλ€. μ μ΄ν΄λ³΄κ² μ΅λλ€.
μ€λ μΌμ° μ΄ κΈ°λ₯μ΄ νμνκΈ° λλ¬Έμ HOCλ₯Ό μμ±νμ΅λλ€. withStyles
λ μ체μ μΌλ‘ μΊμ±μ μννλ―λ‘ μ΄κ²μ΄ μΌλ§λ μν₯μ λ―ΈμΉλμ§ λ§ν μλ μμ§λ§ μ¬κ° μκ°μ withStyles
μ μΊμ± ꡬνμ μ΄ν΄λ³΄κ² μ΅λλ€. μνκ³Ό ν
λ§λ₯Ό λΉ λ₯΄κ² μ¬μ©νμ¬ λ©μ§κ² νλ μ΄ν μ μμ΅λλ€.
μ΄ κ΅¬μ± μμλ propsκ° withStyles HOCμμ λ³κ²½λλ μ€νμΌμνΈ ν΄λμ€μ μΈλ±μ€ λ²νΈ λλ 무μΈκ°λ₯Ό λ³κ²½νλ κ²½μ° μ 체 λ€μ λ§μ΄νΈλ₯Ό μνν©λλ€.
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
const { createElement, forwardRef } = React
const withPropsStyles = ( style ) => {
const withPropsStyles = ( component ) => {
return forwardRef( (props, ref) => {
const proxy = (theme) => style(props, theme)
const hoc = withStyles(proxy)(component)
return props.children ?
createElement(hoc, { ...props, ref}, props.children) :
createElement(hoc, {...props, ref})
})
}
return withPropsStyles
}
export default withPropsStyles
const styles = (props, theme) => ({
root:{
backgroundColor: props.light ? theme.palette.primary.light : theme.palette.primary.main
},
})
const SomeComponent = ({classes}) => <div className={classes.root}/>
export default withPropsStyles(styles)(SomeComponent)
κ°λ¨νκ³ μλν©λλ€(κ·Έλ¬λ μ 체 λ€μ λ§μ΄νΈ λΉμ©λ rem)
μ΄ λ³κ²½μΌλ‘ 100% JSSλ₯Ό μν΄ λΌμ΄λΈλ¬λ¦¬μμ μΈλΌμΈ μ€νμΌ μ¬μ©μ μ κ±°ν μ μμ΅λκΉ? λ΄ μ±μ μΈλΌμΈ μ€νμΌμμ μλνμ§ μμΌλ©° νκΈ ν¨κ³Όλ₯Ό JSSλ‘ κ΅μ²΄νλ €κ³ νμ λ μ΄ κΈ°λ₯μ΄ νμνλ€λ κ²μ κΉ¨λ¬μμ΅λλ€. μ½κ°μ μ±λ₯ μ νκ° μμ μ μμ§λ§ λ κΉ¨λν΄ λ³΄μ λλ€.
@koshea λ μΈλΌμΈ μ€νμΌμ withStyles
λ₯Ό λ체νλ λλ‘μΈμΌλ‘ μ μλν΄μΌ ν©λλ€.
μΈλΌμΈ μ€νμΌμ μ¬μ©νλ©΄ κ°λ ₯ν μ½ν
μΈ λ³΄μ μ μ±
μ μ¬μ©ν μ μλ€λ μ λ μΈκΈνκ³ μΆμμ΅λλ€.
μμ νμ§ μμ μ€νμΌ μ§μλ¬Έμ unsafe-inline
νλκ·Έλ₯Ό μΆκ°ν΄μΌ ν©λλ€.
μν μ§μμ΄ μλ λμ μ€νμΌμ μ΄ λ¬Έμ λ₯Ό ν΄κ²°ν΄μΌ ν©λλ€.
μλ νμΈμ μ¬λ¬λΆ, "μ΄λ° μμΌλ‘" ν λ‘ μ λ°μ΄λ€μ΄μ μ£μ‘ν©λλ€. λλ μ΅κ·Όμ Mui(Typescript ν¬ν¨)λ₯Ό μ¬μ©νκΈ° μμνμΌλ©° λ§€μ° κ°λ ₯ν λΌμ΄λΈλ¬λ¦¬λΌκ³ μκ°νμ§λ§ νμ€ν 볡μ‘ν©λλ€.
μμ μΌλΆ λκΈμμ μ΄ κΈ°λ₯μ΄ (props, theme) => {}
λλ (theme, props) => {}
μ¬μΌ νλμ§μ λν μ½κ°μ ν λ‘ μ΄ μμμ μμμ΅λλ€. @pelotomμ΄ props
λ° theme
λͺ
λͺ
λ μμ±μ λͺ¨λ λ§λλ κ²μ λν΄ κ·Έμ μ견 μ κ°ννκ³ μΆμ΅λλ€. κ·Έλ κ² νλ©΄ μ΄ λ³κ²½ μ¬νμ΄ μ μ©λλ©΄ μ€νμΌ μ μλ₯Ό 리ν©ν λ§νκΈ°κ° λ μ¬μμ§ κ²μ
λλ€. 건배 π
κΈ°λ€λ €μ£Όμ λͺ¨λ λΆλ€κ» κ°μ¬λ립λλ€! μ΄ λ¬Έμ λ #13503μμ μ²λ¦¬λκ³ μμ΅λλ€. ꡬννλ €λ κ΅¬μ± μμ λμ°λ―Έμ μꡬ μ¬νμ λλ€. μ°λ¦¬λ λν νν¬ API μ€νμ μμνμ΅λλ€: https://twitter.com/olivtassinari/status/1058805751404261376.
μ΄κ±° 4.0μΌλ‘ λμλμ? makeStyles
μ½λ°±μ props
맀κ°λ³μκ° μλ κ² κ°μ΅λλ€.
@city41 const classes = useStyles(props);
μ κ² μ΄μ. κ·Έλμ κ·Έλ° κ² κ°λ€.
const useStyles = makeStyles(theme => {
return {
foo: {
color: theme.props.danger ? '#ff0000' : '#00ff00'
}
};
});
function MyComponent(props) {
const classes = useStyles(props);
return <div className={classes.foo}>...</div>;
}
μΉ μ¬μ΄νΈμ μ€νμΌ API μΉμ μ μ΄κ²μ΄ λ¬Έμνλμ΄ μλ κ²μ λ³Ό μ μμ΅λλ€. λ΄κ° PRμ λ³΄λΌ μ μλμ§ λ³΄μ.
@city41 https://material-ui.com/styles/basics/#adapting -based -on-propsμ λ¬Έμ μμμ΄ μμ΅λλ€.
λ©μ§κ³ , λ¬Έμκ° μ λ°μ΄νΈλλ κ²μ λ³΄κ² λμ΄ κΈ°μ©λλ€. μ΄ λ¬Έμ λ₯Ό λ€λ£¨λ λ€λ₯Έ μ¬λμ μν΄ λ€μμ κ΅¬μ± μμμ μ€νμΌμ μ§μ νκΈ° μν΄ ν λ§μ μνμ κ²°ν©ν λ°©λ²μ λλ€.
import React from 'react';
import { Button, Theme, makeStyles } from '@material-ui/core';
interface ButtonProps {
destructive: boolean;
}
const useButtonStyles = makeStyles<Theme, ButtonProps>(theme => {
return {
root: props => ({
backgroundColor: props.destructive ? theme.palette.error.main : theme.palette.primary.main
})
};
});
export const PrimaryButton: React.FunctionComponent<ButtonProps> = props => {
const classes = useButtonStyles(props);
return <Button {...props} className={classes.root} variant="contained" />;
};
μΈλΆ μ€νμΌ json νμΌμμ propμ μ΄λ»κ² μ¬μ©ν μ μμ΅λκΉ?
μλ₯Ό λ€μ΄ μ΄κ²μ μΈλΆ νμΌμ λλ€.
const typographyStyle = {
title2: {
fontFamily:"Montserrat",
fontStyle:"normal",
fontWeight:"800",
fontSize:"72px",
lineHeight:"88px",
letterSpacing:"-0.02em",
// color:"#304C82"
color : props => {
console.log(props,'c1');
return props.color
}
}
};
export default typographyStyle;
μ΄ νμΌμ κ°μ Έμμ κ°μ²΄λ₯Ό νΌλ¨λ¦½λλ€.
import typographyStyle from "../assets/jss/material-kit-pro-react/views/componentsSections/typographyStyle";
const styles = theme => ({
...typographyStyle,
homeSearch:{
width: '100%',
'& div':{
'& input':{
"color":"#304C82",
height: 65,
fontFamily: 'Open Sans',
fontStyle: 'normal',
fontWeight: 800,
fontSize: '48px',
lineHeight: '65px',
letterSpacing: '-0.03em',
'&::placeholder':{
fontFamily: 'Open Sans',
fontStyle: 'normal',
fontWeight: 800,
fontSize: '48px',
lineHeight: '65px',
letterSpacing: '-0.03em',
color: '#EAEAEA'
}
}
}
},
});
μ΄μ μμ κΈ°λ₯μμ props = {} λ₯Ό μ»μ΅λλ€.
λκ΅°κ°κ° μ΄μ κ΄λ ¨νμ¬ λλ₯Ό λμΈ μ μμ΅λκΉ?
μ λ°μ΄νΈ:
λ΄ κΈ°λ³Έ styles.js νμΌμμλ λΉ κ°μ²΄κ° λ°μνκΈ° λλ¬Έμ λκ° μλͺ»λ μΌμ νκ³ μλ κ² κ°μ΅λλ€.
homeSearch: props => {
console.log(props);
return {
width: '100%',
border: `1px solid ${props.color}`
,
'& div':{
'& input':{
"color":"#304C82",
height: 65,
fontFamily: 'Open Sans',
fontStyle: 'normal',
fontWeight: 800,
fontSize: '48px',
lineHeight: '65px',
letterSpacing: '-0.03em',
'&::placeholder':{
fontFamily: 'Open Sans',
fontStyle: 'normal',
fontWeight: 800,
fontSize: '48px',
lineHeight: '65px',
letterSpacing: '-0.03em',
color: '#EAEAEA'
}
}
}
}
},
κ°μ₯ μ μ©ν λκΈ
μ΄ λ¬Έμ λ₯Ό v1.x λ§μΌμ€ν€ μ μΆκ°νκ³ μμ΅λλ€. λ§μ λΆλ€μ΄ μμ²νκ³ μμ΅λλ€. μ°λ¦¬λ 곧 κ·Έκ²μ μ»μ κ²μ λλ€.