--- id: 5a24c314108439a4d4036182 title: Add Inline Styles in React challengeType: 6 isRequired: false forumTopicId: 301378 localeTitle: Добавить встроенные стили в действии --- ## Description
Возможно, вы заметили в последнем случае, что в дополнение к атрибуту style установленному для объекта JavaScript, было несколько других различий синтаксиса из встроенных стилей HTML. Во-первых, имена некоторых свойств стиля CSS используют случай верблюда. Например, последний вызов задает размер шрифта с fontSize вместо font-size . Переплетенные слова, такие как font-size являются недопустимым синтаксисом для свойств объекта JavaScript, поэтому React использует случай верблюда. Как правило, любые свойства дефисного стиля записываются с использованием верблюжьего случая в JSX. Предполагается, что все единицы длины значения свойства (например, height , width и fontSize ) находятся в px если не указано иное. Если вы хотите использовать em , например, вы переносите значение и единицы в кавычки, например {fontSize: "4em"} . Помимо значений длины, которые по умолчанию px , все остальные значения свойств должны быть заключены в кавычки.
## Instructions
If you have a large set of styles, you can assign a style object to a constant to keep your code organized. Uncomment the styles constant and declare an object with three style properties and their values. Give the div a color of "purple", a font-size of 40, and a border of "2px solid purple". Then set the style attribute equal to the styles constant.
## Tests
```yml tests: - text: The styles variable should be an object with three properties. testString: assert(Object.keys(styles).length === 3); - text: The styles variable should have a color property set to a value of purple. testString: assert(styles.color === 'purple'); - text: The styles variable should have a fontSize property set to a value of 40. testString: assert(styles.fontSize === 40); - text: The styles variable should have a border property set to a value of 2px solid purple. testString: assert(styles.border === "2px solid purple"); - text: The component should render a div element. testString: assert((function() { const mockedComponent = Enzyme.shallow(React.createElement(Colorful)); return mockedComponent.type() === 'div'; })()); - text: The div element should have its styles defined by the styles object. testString: assert((function() { const mockedComponent = Enzyme.shallow(React.createElement(Colorful)); return (mockedComponent.props().style.color === "purple" && mockedComponent.props().style.fontSize === 40 && mockedComponent.props().style.border === "2px solid purple"); })()); ```
## Challenge Seed
```jsx // const styles = // change code above this line class Colorful extends React.Component { render() { // change code below this line return (
Style Me!
); // change code above this line } }; ```
### After Tests
```jsx ReactDOM.render(, document.getElementById('root')) ```
## Solution
```jsx const styles = { color: "purple", fontSize: 40, border: "2px solid purple" }; // change code above this line class Colorful extends React.Component { render() { // change code below this line return (
Style Me!
// change code above this line ); } }; ```