Browse Source
- Move Motivation to top @bvaughn - Copy in some Motivation text from the RFC for the intro para - Update examples - Remove state from simple example - Remove "random color" example; just toggle a theme variable instead - Update highlightsmain
Alex Krolick
7 years ago
7 changed files with 107 additions and 88 deletions
@ -0,0 +1,33 @@ |
|||
class Button extends React.Component { |
|||
render() { |
|||
return ( |
|||
<button style={{background: this.props.color}}> |
|||
{this.props.children} |
|||
</button> |
|||
); |
|||
} |
|||
} |
|||
|
|||
class Message extends React.Component { |
|||
render() { |
|||
// highlight-range{1-3}
|
|||
// The Message component must take `color` as as prop to pass it
|
|||
// to the Button. Using context, the Button could connect to the
|
|||
// color context on its own.
|
|||
return ( |
|||
<div> |
|||
{this.props.text} <Button color={this.props.color}>Delete</Button> |
|||
</div> |
|||
); |
|||
} |
|||
} |
|||
|
|||
class MessageList extends React.Component { |
|||
render() { |
|||
const color = "purple"; |
|||
const children = this.props.messages.map((message) => |
|||
<Message text={message.text} color={color} /> |
|||
); |
|||
return <div>{children}</div>; |
|||
} |
|||
} |
@ -1,5 +1,15 @@ |
|||
const defaultTheme = {highlight: 'blue', accent: 'purple'}; |
|||
export const themes = { |
|||
light: { |
|||
foreground: '#ffffff', |
|||
background: '#222222', |
|||
}, |
|||
dark: { |
|||
foreground: '#000000', |
|||
background: '#eeeeee', |
|||
}, |
|||
}; |
|||
|
|||
const ThemeContext = React.createContext(defaultTheme); |
|||
// highlight-next-line
|
|||
const ThemeContext = React.createContext(themes.dark); |
|||
|
|||
export default ThemeContext; |
|||
|
Loading…
Reference in new issue