MDCSnackbarFoundation Class usage

随声附和 提交于 2019-12-08 17:11:31

问题


How do I use MDCSnackbarFoundation ? with MDCSnackbar

This documentation is not clear enough to get an idea. https://github.com/material-components/material-components-web/tree/master/packages/mdc-snackbar#using-the-foundation-class

This is my code and I need to bind MDCSnackbarFoundation for it.

logger = new MDCSnackbar($selector[0]);

Thanks


回答1:


At first you have to have a Node.js server. And then you have to install a package snackbar for Node.js like follows:

npm install @material/snackbar

Responding to a Snackbar Action

To respond to a snackbar action, assign a function to the optional actionHandler property in the object that gets passed to the show method. If you choose to set this property, you must also set the actionText property.

<div class="mdc-snackbar"
     aria-live="assertive"
     aria-atomic="true"
     aria-hidden="true">
  <div class="mdc-snackbar__text"></div>
  <div class="mdc-snackbar__action-wrapper">
    <button type="button" class="mdc-snackbar__action-button"></button>
  </div>
</div>
import {MDCSnackbar} from '@material/snackbar';
​
const snackbar = new MDCSnackbar(document.querySelector('.mdc-snackbar'));
const dataObj =
{
    message: 'The text message to display.',
    actionText: 'Take action',
    //The function to execute when the action is clicked.
    actionHandler: function()
    {
        console.log('my cool function');
    }
};
​
snackbar.show(dataObj);

For further information:

  • Design & API Documentation
  • Demo Snackbar

Before you start with Node.js I would recommend to read one from two books:

  • Learning Node: Moving to the Server-Side
  • Node.js Web Development: Server-side development


来源:https://stackoverflow.com/questions/50679264/mdcsnackbarfoundation-class-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!