cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              html {
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZwAAAGcCAMAAADan+YLAAAAXVBMVEUAAACampqlpaWampq8vLzBwcG8vLy6urq+vr66urqysrK3t7eGhoaGhoa7u7u1tbW1tbUuLi4uLi67u7ulpaWysrK/v7+3t7eurq6urq6/v7////++vr7///+/v78dKYbrAAAAH3RSTlMAEBUAOlAAMEAAICoLADUlAAUAAAAARQAbAEoFAAAAsAJybgAAC6FJREFUeAHt3eF62jgTBWBkzocOkhjVkHpVku79X+YXtk4akm7LkwQz9p73J3/PYzOWNKOVvCEiIiIiIhK6sJYrWK0/Dv/D5gpktfm4yLi9AlltP07hKBwHFI4oHIUzRwpHFI7C0Ueo44/QDy/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ewbuYyRefqGXblM5JAVjld5GEzLN17VoVtKKR3Ko67sFqRfzH4OCGDggzi8mzrRHmloqMvXWqE90q0vPqu1CHuEjTjcz2m0R0P7Jg6Xb0gAtIM4/M7pSyl93+9lklJaFI7CEYUjCkfhiMJROKJwROEoHFE4CkcUjiicvoSWkqWvk+tbTU1npX+hL11LOZoBPHmYXAVPkrqpzyUCfAa7xf0lRhAghqzjuOfiYBYNFnNNoQJ2mFolLKzXAWDTa+1cJGLZ/VDBMH3HG+xw0hNQN/UrBoxv+0DE7dTSc69oRwb1hL5C8Ec6Bvb7qVXaYQQ2vdZeKcQ/530bb3G/6c9weoXzC2EAw/13AJvptefXWiM7dVO/0Qj0jUxfp9c/VYhFBcGvJZoZsLmFSqC76xswqJT+pUzcrNEk6iP0DyIRtzdSeYKmtbV/Y8ewvpmupvAJs2+CWVgvUT9RGX3FIRHdAAzdnUdqOzSYwQ4eqT/HcTgKx/NrTd3UUxYEolVphSMKR+GIwhGFo3BE4SgcUTiicBSOKByFIwpHFI7CEYWjcEThiMJROKJwFI4oHFE4CkcUjsIRhSMKR+HIdfwfS0PTmI4IFGAAAAAASUVORK5CYII=), linear-gradient(225deg, #1e3794 0%, #0575E6 100%);
  font-size: 18px;
  min-height: 100vh;
}

body {
  color: #32325d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

h1 {
  color: #fff;
}

h2 {
  font-weight: 500;
  margin-top: 0;
  text-align: center;
}

input {
  border-radius: 3px;
}

input:disabled {
  opacity: 0.5;
}

input[type="text"] {
  border: 3px solid #e9e9e9;
  margin-bottom: 10px;
  padding: 14px;
  text-align: center;
  width: 100%;
}

input.error {
  border-color: #EB4F52;
}

.error-message {
  color: #EB4F52;
  font-size: 14px;
  padding-bottom: 12px;
  text-align: center;
}

button,
input[type="submit"] {
  background-color: #00bb5b;
  border: 0;
  color: #fff;
  cursor: pointer;
  padding: 14px;
  transition: background-color 0.25s linear;
  width: 100%;
}

button,
input[type="submit"]:hover {
  background-color: #04a754;
}

.login-form {
  background: #fff;
  border-radius: 3px;
  box-shadow: 1px 3px 8px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  padding: 40px;
  width: 400px;
}
            
          
!
            
              const { Machine } = xstate;

// Authentication state machine 
const appMachine = Machine({
  initial: 'loggedOut',
  states: {
    loggedOut: {
      onEntry: ['error'],
      on: {
        SUBMIT: 'loading',
      },
    },
    loading: {
      on: {
        SUCCESS: 'loggedIn',
        FAIL: 'loggedOut',
      },
    },
    loggedIn: {
      onEntry: ['setUser'],
      onExit: ['unsetUser'],
      on: {
        LOGOUT: 'loggedOut',
      },
    },
  },
});

/**
 * Create context and set up defaults.
 *
 * @see https://css-tricks.com/digging-into-react-context/
 */
const Auth = React.createContext({
  authState: 'loggedOut',
  error: '',
  logout: () => {},
  user: {},
});

// Display a welcome message to an authenticated user.
const Dashboard = () => (
  <Auth.Consumer>
    {({ user, logout }) => (
      <div className="welcome">
        <h1>Hello, {user.name}!</h1>
        <button
          className="bw0 br1 pa2 bg-green white pointer"
          onClick={e => logout(e)}
        >
          Logout
        </button>
      </div>
    )}
  </Auth.Consumer>
);


class Login extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      yourName: '',
    }

    this.handleInput = this.handleInput.bind(this);
  }

  handleInput(e) {
    this.setState({
      yourName: e.target.value,
    });
  }

  /**
   * This is where your authentication logic would go. For the purposes
   * of this demo, we're just faking an async request with a setTimeout
   */
  doLogin(e) {
    e.preventDefault();

    this.props.transition({ type: 'SUBMIT' });

    setTimeout(() => {
      if (this.state.yourName) {
        return this.props.transition({
          type: 'SUCCESS',
          username: this.state.yourName,
        }, () => {
          this.setState({ yourName: '' });
        });
      }

      return this.props.transition({
        type: 'FAIL',
        error: 'Uh oh, you must enter your name!',
      });
    }, 2000);
  }

  render() {
    return (
      <Auth.Consumer>
        {({ authState, error }) => {
          const errorClass = error ? 'error' : '';
            return (
              <form onSubmit={e => this.doLogin(e)} className="login-form">
                <h2>Login to your account</h2>
                <div className="error-message">{error}</div>
                <label htmlFor="yourName">
                  <input
                    id="yourName"
                    name="yourName"
                    type="text"
                    autoComplete="off"
                    placeholder="Your name"
                    className={errorClass}
                    value={this.state.yourName}
                    onChange={this.handleInput}
                  />
                </label>
                <input
                  type="submit"
                  value={authState === 'loading' ? 'Logging in...' : 'Login' }
                  disabled={authState === 'loading' ? true : false}
                />
              </form>
           )
          }}
      </Auth.Consumer>
    );
  }
}

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      authState: appMachine.initialState.value,
      error: '',
      logout: e => this.logout(e),
      user: {},
    };
  }

  transition(event) {
    const currentState = this.state.authState;
    const nextAuthState = appMachine.transition(currentState, event.type);

    const nextState = nextAuthState.actions.reduce(
      (state, action) => this.command(action, event) || state,
      undefined,
    );

    // Set our new state, along with any variables we might need based on the new state
    this.setState({
      authState: nextAuthState.value,
      ...nextState,
    });
  }

  /**
   * Get any variables we need to set in state, based on
   * the onEntry or onExit action for a given state.
   */
  command(action, event) {
    switch (action) {
      case 'setUser':
        if (event.username) {
          return { user: { name: event.username }, error: '' };
        }
        break;
      case 'unsetUser':
        return {
          user: {},
        };
      case 'error':
        if (event.error) {
          return {
            error: event.error,
          };
        }
        break;
      default:
        break;
    }
  }

  logout(e) {
    e.preventDefault();
    this.transition({ type: 'LOGOUT' });
  }

  render() {
    const { authState, error } = this.state;

    return (
      <Auth.Provider value={this.state}>
        <div>
          {authState === 'loggedIn' ? (
            <Dashboard />
          ) : (
            <Login transition={event => this.transition(event)} />
          )}
        </div>
      </Auth.Provider>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('app'));

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console