123

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

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="sign-in-wrap">
  <div class="demo-content-container">
    <div class="demo-sign-in-container">
      <div class="demo-sign-in-container__logo">
                    <img src="http://designsystem.morningstar.com/images/sandbox/sample-pages/mstar-logo.svg">
                </div>
      <div id="app">
        <login-fail v-show="failed"></login-fail>
        <br>
        <form class="mds-form mds-form--medium-layout" method="post" action="form/preprocessor" onsubmit="return false">
          <fieldset class="mds-form__fieldset">
            <fields
              v-for="group in groups"
              v-bind="group"
              v-bind:error="group.error"
              v-bind:id="group.id"
              v-bind:title="group.title"
              v-bind:type="group.type"
              v-bind:described="group.described"></fields>
            <login-button></login-button>
            <info-links></info-links>
          </fieldset>
        </form>
      </div>
    </div>
    <div id="cards">
      <div class="mds-layout-grid">
        <div class="mds-layout-grid__row">
         <content-card
           v-for="post in posts"
           v-bind="post"
           v-bind:action="actions[post.id-1]"
           v-bind:caption="post.body"
           v-bind:image="images[post.id-1]"
           v-bind:postId="post.id"
           v-bind:title="post.title"></content-card>
        </div>
      </div>
    </div>
  </div>
  <div class="demo-footer">
    <div class="mds-layout-grid">
      <div class="mds-layout-grid__row">
          <div class="mds-layout-grid__col">
            <div class="demo-footer__copyright">© 2018 Morningstar, Inc.</div>
          </div>
          <div class="mds-layout-grid__col">
            <div class="demo-footer__links">
              <mds-link href="#">Ligula Vitae</mds-link>
              <mds-link href="#">Augue in Lorem</mds-link>
            </div>
          </div>
      </div>
    </div>
  </div>
</div>

<mds-notification-group>
    <mds-notification id="successNotification" role="alertdialog" status="success" tinted removable="false">
        Welcome! You have successfully logged in.
    </mds-notification>
</mds-notification-group>
<mds-modal id="contactModal" title="Contact us" triggered-by="contactBtn">
    <div class="mds-layout-grid">
      <div class="mds-layout-grid__row mds-layout-grid__row--zero-margin">
        <div class="mds-layout-grid__col">
          <div class="mds-long-form-text-section">
            <h4>Global Headquarters</h4>
            <p>22 West Washington Street<br> Chicago, IL 60602<br> United States<br> +1 312 696-6000<br></p>
           </div>
        </div>
        <div class="mds-layout-grid__col">
          <div class="mds-long-form-text-section">
            <h4>Data Questions</h4>
            <p>+1 312 696-6600<br> <a href="mailto:dataquestions@morningstar.com?Subject=Hello%20again&amp;cid=CON_BRD0001" target="_top" class="mds-link">dataquestions@morningstar.com</a>&nbsp;</p>
           </div>
        </div>
        <div class="mds-layout-grid__col">
          <div class="mds-long-form-text-section">
            <h4>U.S. Customer Service</h4>
            <p>General Information<br> +1 312 384-4000<br> <a href="mailto:productinfo@morningstar.com?cid=CON_BRD0001" class="mds-link">productinfo@morningstar.com</a></p>
          </div>
        </div>
      </div>
    </div>
    <span slot="mds-modal-actions">
        <mds-button type="button" variation="icon-only" icon="remove">Close</mds-button>
    </span>
</mds-modal>
<mds-overlay></mds-overlay>
<mds-popover triggered-by="forgotPwBtn" title="Current Password">
  <p>letMeIn</p>
</mds-popover>
            
          
!
            
              @mixin mds-font-reset() {
    font-family: $mds-font-family-sans-serif;
    font-style: normal;
    font-weight: $mds-font-weight-regular;
    line-height: $mds-font-line-height-body;
}

@mixin mds-heading-reset() {
    @include mds-font-reset;
    font-weight: $mds-font-weight-thin;
    line-height: $mds-font-line-height-headings;
}

body {
  margin: 0;
}

h4 {
  @include mds-heading-reset;
  font-size: $mds-font-size-heading-level-4;
}

@mixin mds-body-text-m() {
    @include mds-font-reset;
    font-size: $mds-font-size-m;
    font-weight: $mds-font-weight-light;
}

p {
  @include mds-body-text-m;
}

.sign-in-wrap {
    box-sizing: border-box;
    background-color: $mds-background-color-light-gray;
    border-top: 4px solid $mds-color-red-50;
    margin: 0;
    min-height: 100%;
    position: relative;

    .demo-content-container {
        margin-left: auto;
        margin-right: auto;
        max-width: 1200px;
        padding-bottom: 100px;
        padding-left: $mds-space-2-x;
        padding-right: $mds-space-2-x;
    }

    .demo-sign-in-container {
        background-color: $mds-background-color-white;
        border: $mds-border-container-on-all-backgrounds;
        border-radius: $mds-border-radius-panel;
        box-shadow: $mds-box-shadow-drop;
        margin: $mds-space-8-x auto $mds-space-4-x;
        max-width: 360px;
        padding: $mds-space-inset-2-x;
        width: 100%;
    }

    .demo-sign-in-container__logo {
        margin: $mds-space-3-x 0;
        text-align: center;
    }

    .demo-sign-in-container__controls {
        display: flex;
        margin: $mds-space-stack-2-x;

        & .demo-sign-in-container__controls-checkbox {
            flex-grow: 1;
        }

        & .demo-sign-in-container__controls-button {
            flex-grow: 1;
            text-align: right;
        }
    }

    .demo-sign-in-container__utilities {
        & .mds-button {
            display: block;
            text-align: left;
        }
    }

    .demo-card {
        margin: $mds-space-stack-4-x;
    }

    .demo-footer {
        background-color: $mds-background-color-white;
        border-top: $mds-border-container-on-all-backgrounds;
        bottom: 0;
        left: 0;
        padding: $mds-space-3-x $mds-space-2-x;
        position: absolute;
        right: 0;
    }

    .demo-footer__copyright {
        font-family: $mds-font-family-sans-serif;
        font-style: normal;
        font-weight: $mds-font-weight-regular;
        line-height: $mds-font-line-height-body;
        font-size: $mds-font-size-m;
        font-weight: $mds-font-weight-light;
        color: $mds-text-color-secondary-on-light;
    }

    .demo-footer__links {
        text-align: right;

        & .mds-link {
            margin: $mds-space-inline-right-1-x;
        }
    }
}//end .sign-in-wrap
            
          
!
            
              /**
* Sign In Example using MDS Web Components in Vue
* Key functionality:
* validate email format, display error
* enable login button when values in both inputs
* validate on login press, display error or notify successful
* show password on forgot password
* show contact info in modal
* display sub-content cards from data api, json object
**/

// Uses MDS-Alert in vue component to use v-show directive
Vue.component('login-fail',{
  template: `
    <mds-alert
            title="Login error"
            text="The information you have provided is incorrect."
            variation="error"
            size="small"
            tinted="true"
            dismissible="false"
        ></mds-alert>` 
});

// Maps vue component props to MDS component props for data binding and rendering multiple elements
Vue.component('fields',{
  props: ['post','id','title','described','error','type'],
  template: `
    <mds-field-group>
      <mds-label :for="id" required>{{title}}</mds-label>
      <mds-input :aria-describedby="described" :id="id" @blur="fieldsapp.emailError(event.target)" @input="fieldsapp.afterEdit()" :type="type"></mds-input>
      <mds-field-error :id="described">{{error}}</mds-field-error>
    </mds-field-group>`
});

// Group MDS components to compose Vue component and bind listeners via Vue app methods
Vue.component('login-button',{
  template: `
    <div class="demo-sign-in-container__controls">
      <mds-checkbox id="keepCheckbox" name="checkbox-name" value="accept" additional-class="demo-sign-in-container__controls-checkbox">Keep me logged in</mds-checkbox>
      <div class="demo-sign-in-container__controls-button">
      <mds-button id="loginButton" variation="primary" @click="fieldsapp.validateInput()" disabled> Login </mds-button> 
      </div>
    </div>`
});
Vue.component('info-links',{
  template: `
    <div class="demo-sign-in-container__utilities">
      <mds-button id="forgotPwBtn" variation="flat">Forgot your password?</mds-button>
      <br>
      <mds-button id="contactBtn" @click="contactModalOpen" variation="flat">Contact us</mds-button>
    </div>`
});

// Set Vue data properties for binding and form validation methods
const fieldsapp = new Vue({
  el: '#app',
  data: {
    failed: false,
    groups: [{
      'title':'Email',
      'id':'emailInput',
      'described': 'email-error',
      'error': 'Email must be formatted abc@xyz.com',
      'type': 'email'
    },{
      'title':'Password',
      'id':'passwordInput',
      'described': 'pw-error',
      'error': 'The information you have provided is incorrect.',
      'type': 'password'
    }]
  },
  methods: {
   afterEdit() {
      var emailFormatted = this.checkEmail();
      var passwordInput = document.getElementById("passwordInput");
      var passwordValue = passwordInput.value;
      var loginBtn = document.getElementById("loginButton");
      
      if(emailFormatted && passwordValue && passwordValue.length > 0) {
        loginBtn.firstElementChild.removeAttribute('disabled');
      } else {
        loginBtn.firstElementChild.setAttribute('disabled','true');
      }
    },
    disableBtn() {
      var loginBtn = document.getElementById("loginButton");
      loginBtn.firstElementChild.setAttribute('disabled','true');
    },
    emailError(eventTarget) {
      var emailInput = document.getElementById("emailInput");
      var validFormat = this.validateEmail();
      var emailFielderror = emailInput.nextElementSibling;
      var emailFieldgroup = emailInput.closest("mds-field-group");
      var emailInputLength = emailInput.value.length > 0;
      if(!validFormat && eventTarget.id.includes('emailInput') && emailInputLength) {
        emailFielderror.show();
      } else {
        this.clearErrors();
      }
    },
    checkEmail() {
      this.failed = false;
      var emailInput = document.getElementById("emailInput");
      var emailValue = emailInput.value;
      var validFormat = this.validateEmail();
      // "closest" & "nextElementSibling" not covered in IE may use polyfill
      var emailFieldgroup = emailInput.closest("mds-field-group");     
      
      return validFormat;
    },
    clearErrors() {
      var emailInput = document.getElementById("emailInput");
      var emailFielderror = emailInput.nextElementSibling;
      var emailFieldgroup = emailInput.closest("mds-field-group"); 
      
      emailFieldgroup.setAttribute('error','false');
      emailFielderror.setAttribute('visible','false');
      
      return true;
    },
    validateInput() {
      var emailInput = document.getElementById("emailInput");
      var successNotification = document.getElementById("successNotification");
      var emailValue = emailInput.value;
      var checkEmailMatch = true;         //some logic that checks to match email with pw
      
      this.failed = !(checkEmailMatch && this.checkPassword());
      successNotification.visible = !this.failed;
    },
    checkPassword() {
      var passwordInput = document.getElementById("passwordInput");
      var passwordValue = passwordInput.value;
       // "closest" & "nextElementSibling" not covered in IE may use polyfill
      var passwordFieldgroup = passwordInput.closest("mds-field-group");
      var passwordFielderror = passwordInput.nextElementSibling;
      
      if(passwordValue != "letMeIn") {
        return false;
      } 
      return true;
    },
    validateEmail() {
      var emailInput = document.getElementById("emailInput");
      var email = emailInput.value;
      var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      var copy = email+""
      return re.test(copy);
    }
  }
});

function contactModalOpen() {
  var modal = document.getElementById('contactModal');
  modal.open();
}

// Maps vue component props to MDS web component props for data binding and rendering multiple elements
Vue.component('content-card',{
  props: ['post','action','caption','image','postId','title'],
  template: `
    <div class="mds-layout-grid__col">
          <div class="demo-card">
          <mds-card :title= "title" :caption="caption" supplemental-content-first full-bleed>
    <img slot="mds-card-supplemental-content" :src="image">
    <mds-button slot="mds-card-action" variation="secondary">{{ action }}</mds-button>
</mds-card>
            </div>
        </div>
  `
})

// Sets posts data property via API fetch and formats data for display into MDS web component
const cardsapp = new Vue({
  data: {
    posts: [],
    images: [
  "http://designsystem.morningstar.com/images/sandbox/sample-pages/sign-in-access.png",
  "http://designsystem.morningstar.com/images/sandbox/sample-pages/sign-in-questions.png",
  "http://designsystem.morningstar.com/images/sandbox/sample-pages/sign-in-analysis.png"
    ],
    actions: [
      "Finibus",
      "Nunc Vitae",
      "Pellentesque"
    ]
  },
  methods: {
    truncateCaptions() {
      var vm = this;
      this.posts.forEach(function(post) {
        var title = post["title"].substring(0,12);
        var caption = post["body"].substring(0,50) + '...';
        var postID = post["id"];
        
        if(vm.posts[postID - 1]) {
          vm.posts[postID - 1]["title"] = title;
          vm.posts[postID - 1]["body"] = caption;
        }
      });
    }
  },
  created: function () {
    // Alias the component instance as `vm`, so that we  
    // can access it inside the promise function
    var vm = this
    // Fetch our array of posts from an API
    fetch('https://jsonplaceholder.typicode.com/posts')
      .then(function (response) {
        return response.json()
      })
      .then(function (data) {
        vm.posts = data
      })
      .then(function() {
        //clip to 3 objects
        vm.posts.length = 3;
        vm.truncateCaptions();
      })
  }
}).$mount('#cards');
            
          
!
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.

Console