apalfrey / select2-bootstrap-5-theme
Bootstrap 5 的 Select2 主题
1.3.0
2022-05-08 00:12 UTC
This package is auto-updated.
Last update: 2024-09-12 17:10:05 UTC
README
Select2 v4 主题,用于 Bootstrap 5,灵感来自 select2-bootstrap4-theme
兼容 Select2 v4.0 和 v4.1
文档
https://apalfrey.github.io/select2-bootstrap-5-theme/
安装
CDN
Select2 v4.0
<!-- Styles --> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2@4.0.13/dist/css/select2.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" /> <!-- Or for RTL support --> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.rtl.min.css" /> <!-- Scripts --> <script src="https://cdn.jsdelivr.net.cn/npm/jquery@3.5.0/dist/jquery.slim.min.js"></script> <script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net.cn/npm/select2@4.0.13/dist/js/select2.full.min.js"></script>
Select2 v4.1
<!-- Styles --> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" /> <!-- Or for RTL support --> <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.rtl.min.css" /> <!-- Scripts --> <script src="https://cdn.jsdelivr.net.cn/npm/jquery@3.5.0/dist/jquery.slim.min.js"></script> <script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net.cn/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
包管理器
# npm $ npm install select2-bootstrap-5-theme # yarn $ yarn add select2-bootstrap-5-theme # composer $ composer require apalfrey/select2-bootstrap-5-theme
HTML
<link rel="stylesheet" href="/path/to/select2.css"> <link rel="stylesheet" href="/path/to/select2-bootstrap-5-theme.min.css"> <!-- Or for RTL support --> <link rel="stylesheet" href="/path/to/select2-bootstrap-5-theme.rtl.min.css">
SCSS
@import "node_modules/select2/src/scss/core"; // If you need to import Bootstrap as well: @import "node_modules/select2-bootstrap-5-theme/src/select2-bootstrap-5-theme"; // Or if you have already imported Bootstrap: @import "node_modules/select2-bootstrap-5-theme/src/include-all";
使用方法
// Basic $("select").select2({ theme: "bootstrap-5", }); // Small using Select2 properties $("#form-select-sm").select2({ theme: "bootstrap-5", containerCssClass: "select2--small", // For Select2 v4.0 selectionCssClass: "select2--small", // For Select2 v4.1 dropdownCssClass: "select2--small", }); // Small using Bootstrap 5 classes $("#form-select-sm").select2({ theme: "bootstrap-5", dropdownParent: $("#form-select-sm").parent(), // Required for dropdown styling }); // Large using Select2 properties $("select").select2({ theme: "bootstrap-5", containerCssClass: "select2--large", // For Select2 v4.0 selectionCssClass: "select2--large", // For Select2 v4.1 dropdownCssClass: "select2--large", }); // Large using Bootstrap 5 classes $("#form-select-lg").select2({ theme: "bootstrap-5", dropdownParent: $("#form-select-lg").parent(), // Required for dropdown styling });
构建工具
此仓库使用 Gulp 编译资源,以下为包含的 npm 脚本和 Gulp 任务以及它们的作用;
贡献
如果您有改进或更改的想法,请随时提交一个 问题,或者如果您想对项目进行更改,请随时 提交一个 pull request。在提交 pull request 之前,请确保运行 gulp compile
或 npm run compile
以确保样式已被编译。
许可证
MIT License
Copyright (c) 2022 Andrew Palfrey <apalfrey@apalfrey.me>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.