<div id="app"></div>
body {
  background-color: #5225bd;
}

#app {
  text-align: center;
}

.buttonContainer {
  width: 300px;
  height: 30px;
  margin-top: 20px;
  margin-bottom: 10px;
  border-radius: 5px;
  background-color: #FFF;
  transition: all .5s ease;
  border: none;
  &.dark {
    background-color: #000;
    color: #FFF;
    transition: all .5s ease;
  }

}

.testContainer {
  margin: auto;
  width: 300px;
  height: 300px;
  background-color: #FFF;
  overflow: hidden;
  position: relative;
  border-radius: 10px;
  .testInnerContainer {
    position: absolute;
    top: 0;
    left: -100px;
    width: 50px;
    border-radius: 50%;
    max-height: 0;
    min-height: 0;
    background-color: #000;
    transform: scale(0);
    &.dark {
      min-height: 100px;
      transition: all .5s ease;
      transform: scale(20);
    }
    &.light {
      transition: all .5s ease;
      transform: scale(0);
    }
  }
}
View Compiled
const ThemeContext = React.createContext('light')

class App extends React.Component {
  constructor(props) {
    super(props)
    
    this.state = {
      theme: 'light'
    }
  }
  
  changeTheme() {
    const actualTheme = this.state.theme
    let newTheme
    if (actualTheme == 'dark') {
      newTheme = 'light'
    } else {
      newTheme = 'dark'
    }
    
    this.setState({
      theme: newTheme
    })
  }
  
  render() {
    const { theme } = this.state
    return (
      <ThemeContext.Provider value={theme}>
        <Button changeTheme={() => this.changeTheme()}/>
        <Test />
      </ThemeContext.Provider>
    );
  }
}

class Button extends React.Component {
  static contextType = ThemeContext;
  
  render() {
    return (
      <button 
        onClick={() => this.props.changeTheme()} 
        className={`buttonContainer ${this.context}`}
        >
        Cambiar tema
      </button>
    )
  }
}

class Test extends React.Component {
  static contextType = ThemeContext;
  render() {
    return(
      <div className="testContainer">
        <div className={`testInnerContainer ${this.context}`}></div>
      </div>
    )
  }
}
ReactDOM.render(<App />, document.getElementById("app"));
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.12.0/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.11.0/umd/react-dom.production.min.js