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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              $bgcolor: #4b4a49;
$activeclr: #36cfc3;
$lineclr: #b95951;
$wdth: 300;
$hght: 150;
$linewdth: 5;

@function px2rem($px) {
  @return #{$px/16}rem;
}

.visuallyhidden {
    border: 0;
    clip: rect(0 0 0 0);
    height: pxToRem(1);
    margin: pxToRem(-1);
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: pxToRem(1);
}

body {
    background-color: $bgcolor;
    color: #eee8d5;
}

.SlideBtn {
    box-sizing: border-box;
    border-radius: px2rem($hght / 2);
    border: solid px2rem($linewdth);
    background-color: darken($bgcolor, 10%);
    color: $lineclr;
    display: block;
    height: px2rem($hght);
    position: relative;
    width: px2rem($wdth);
    transition: color .3s;
    margin: 5em auto;
    
    &:focus {
        outline: 0;
        box-shadow: 0 0 20px;
    }
    
    &.is-active {
        color: $activeclr;
    }
}

.SlideBtn-knob {
    box-sizing: border-box;
    display: block;
    position: absolute;
    height: px2rem($hght - 4 * $linewdth);
    width: px2rem($hght - 4 * $linewdth);
    background: linear-gradient(180deg, $bgcolor, darken($bgcolor, 10%));
    top: px2rem($linewdth);
    left: px2rem($linewdth);
    border: solid px2rem($linewdth);
    border-radius: px2rem(($hght - (2 * $linewdth)) / 2);
    transition: left .3s;
    
    .is-active > & {
        left: px2rem($wdth / 2 + $linewdth);
    }
}

.ToggledBackground {
    background: #4b4a49;
    bottom: 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transition: background .75s;
}

.ToggledBackground-lightsOn {
    background: #EEE8D8;
}
            
          
!
            
              var connect = ReactRedux.connect;
var createStore = Redux.createStore;

function ToggleBtn(props) {
    const activeCls = (props.isActive) ? ' is-active' : '';
    const activeTxt = (props.isActive) ? 'On'         : 'Off';
    return (
        <button className={'SlideBtn' + activeCls} onClick={props.onToggle}>
            <span className="SlideBtn-label visuallyhidden">{activeTxt}</span>
            <span className="SlideBtn-knob"></span>
        </button>
    );
}

function ToggledBackground(props) {
    const bgCls = (props.lightsOn) ? 'ToggledBackground-lightsOn' : '';
    return (
        <div className={'ToggledBackground ' + bgCls}>
            <ToggleBtn onToggle={props.onToggle} isActive={props.lightsOn}/>
        </div>
    );
}


function toggleBackgroundReducer(state = {lightsOn: false}, action) {
    if (action.type === 'LIGHTS_TOGGLE') {
        return {...state, lightsOn: !state.lightsOn};
    }
}

function triggerToggleAction() {
    return {type: 'LIGHTS_TOGGLE'};
}

function mapDispatchToProps(dispatch) {
    return {
        onToggle: () => dispatch(triggerToggleAction()),
    };
}

function mapStateToProps(state = {lightsOn: false}) {
    return {
        lightsOn: state.lightsOn,
    }
}

const ToggledBackgroundContainer = connect(mapStateToProps, mapDispatchToProps)(ToggledBackground);

function initialise() {
    const store = createStore(toggleBackgroundReducer);
    const el = document.querySelector('.js-AppContainer');
    ReactDOM.render(<ToggledBackgroundContainer store={store} />, el);
}

initialise();
            
          
!
999px
Loading ..................

Console