Rails 6: How to add jquery-ui through webpacker?

后端 未结 8 940
失恋的感觉
失恋的感觉 2021-01-05 04:12

I\'m currently trying to implement a datepicker into my application, the problem is that there is no documentation on how to add the jquery-ui-rails gem through

8条回答
  •  失恋的感觉
    2021-01-05 04:32

    1. Run on the terminal (CLI)

    yarn add jquery jquery-ui-dist

    1. Add to the config/webpack/environment.js
    ...
    
    const webpack = require("webpack")
    environment.plugins.append("Provide", 
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery'
      })
    )
    
    const aliasConfig = {
        'jquery': 'jquery/src/jquery',
        'jquery-ui': 'jquery-ui-dist/jquery-ui.js'
    };
    
    environment.config.set('resolve.alias', aliasConfig);
    ...
    
    1. app/javascript/packs/application.js:

    require("jquery-ui")

    1. For the theme add code to any scss file. Do change according to your nee.
    .ui-autocomplete {
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 1000;
        float: left;
        display: none;
        min-width: 160px;   
        padding: 4px 0;
        margin: 0 0 10px 25px;
        list-style: none;
        background-color: #ffffff;
        border-color: #ccc;
        border-color: rgba(0, 0, 0, 0.2);
        border-style: solid;
        border-width: 1px;
        -webkit-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
        -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
        box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
        -webkit-background-clip: padding-box;
        -moz-background-clip: padding;
        background-clip: padding-box;
        *border-right-width: 2px;
        *border-bottom-width: 2px; }
    
    .ui-menu-item > a.ui-corner-all {
        display: block;
        padding: 3px 15px;
        clear: both;
        font-weight: normal;
        line-height: 18px;
        color: #555555;
        white-space: nowrap;
        text-decoration: none; }
    
    .ui-state-hover, .ui-state-active {
        color: #ffffff;
        text-decoration: none;
        background-color: #0088cc;
        border-radius: 0px;
        -webkit-border-radius: 0px;
        -moz-border-radius: 0px;
        background-image: none; }
    

提交回复
热议问题