diff --git a/.stylelintrc b/.stylelintrc index 32fecd2..3c16391 100644 --- a/.stylelintrc +++ b/.stylelintrc @@ -3,6 +3,13 @@ "stylelint-config-twbs-bootstrap/scss" ], "rules": { - "selector-class-pattern": "^[a-z][a-z0-9\\-_]*[a-z0-9]$" + "block-closing-brace-empty-line-before": "never", + "declaration-no-important": null, + "rule-empty-line-before": ["always", { + "except": ["first-nested"], + "ignore": ["after-comment"] + }], + "selector-class-pattern": "^[a-z][a-z0-9\\-_]*[a-z0-9]$", + "selector-no-qualifying-type": null } } diff --git a/README.md b/README.md index b35c84a..7aace16 100644 --- a/README.md +++ b/README.md @@ -43,19 +43,22 @@ $ composer require ttskch/select2-bootstrap4-theme ```js $('select').select2({ - theme: 'bootstrap4', + theme: 'bootstrap4', + width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style' }); ``` ## Getting involved -1. Fix [src/_layout.scss](src/_layout.scss), [src/_single.scss](src/_single.scss) or [src/_multiple.scss](src/_multiple.scss) -1. Do `npm run build:both` -1. Send me a Pull Request +1. Edit SCSS files in the [src folder](src) +1. Run `npm run build:both` +1. Send a Pull Request You can use [docs](docs) dir for your development. -1. Do `npm run prepare` (this creates symlink to `dist/select2-bootstrap4.css` onto `docs`) -1. Serve `docs` with your local web server (e.g. `php -S localhost:8888 -t docs`) -1. Do `npm run watch` -1. Tweak scss and browse demo page on your browser +1. Run `npm run prepare` (this creates symlink to `dist/select2-bootstrap4.css` onto `docs`) +1. Serve `docs` from your local web server, examples: + - Using PHP: `php -S localhost:8888 -t docs` + - Using Python 3: `python3 -m http.server -d docs 8888` +1. Run `npm run watch` +1. Tweak SCSS and browse demo page on your browser diff --git a/dist/select2-bootstrap4.css b/dist/select2-bootstrap4.css index 4bb4db5..da9c1d6 100644 --- a/dist/select2-bootstrap4.css +++ b/dist/select2-bootstrap4.css @@ -1,201 +1,203 @@ -.select2-container { +.select2-container--bootstrap4 { display: block; } - .select2-container *:focus { + .select2-container--bootstrap4 *:focus { outline: 0; } - -.input-group .select2-container--bootstrap4 { - -webkit-box-flex: 1; - -ms-flex-positive: 1; - flex-grow: 1; } - -.input-group-prepend ~ .select2-container--bootstrap4 .select2-selection { - border-top-left-radius: 0; - border-bottom-left-radius: 0; } - -.input-group > .select2-container--bootstrap4:not(:last-child) .select2-selection { - border-top-right-radius: 0; - border-bottom-right-radius: 0; } - -.select2-container--bootstrap4 .select2-selection { - width: 100%; - background-color: #fff; - border: 1px solid #ced4da; - border-radius: 0.25rem; - -webkit-transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out; - transition: border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out; - transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; - transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out; } - @media (prefers-reduced-motion: reduce) { - .select2-container--bootstrap4 .select2-selection { - -webkit-transition: none; - transition: none; } } - -.select2-container--bootstrap4.select2-container--focus .select2-selection { - border-color: #80bdff; - -webkit-box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); - box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); } - -.select2-container--bootstrap4.select2-container--focus.select2-container--open .select2-selection { - border-bottom: none; - border-bottom-right-radius: 0; - border-bottom-left-radius: 0; } - -.select2-container--bootstrap4.select2-container--open.select2-container--above .select2-selection { - border-top-left-radius: 0; - border-top-right-radius: 0; } - -.select2-container--bootstrap4.select2-container--open.select2-container--below .select2-selection { - border-bottom-right-radius: 0; - border-bottom-left-radius: 0; } - -.select2-container--bootstrap4.select2-container--disabled .select2-selection, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-selection { - cursor: not-allowed; - background-color: #e9ecef; - border-color: #ced4da; - -webkit-box-shadow: none; - box-shadow: none; } - -.select2-container--bootstrap4.select2-container--disabled .select2-search__field, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-search__field { - background-color: transparent; } - -select.is-invalid ~ .select2-container--bootstrap4 .select2-selection, -form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection { - border-color: #dc3545; } - -select.is-valid ~ .select2-container--bootstrap4 .select2-selection, -form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection { - border-color: #28a745; } - -.select2-container--bootstrap4 .select2-search { - width: 100%; } - -.select2-container--bootstrap4 .select2-dropdown { - border-color: #ced4da; - border-radius: 0; } - .select2-container--bootstrap4 .select2-dropdown.select2-dropdown--below { - border-top: none; - border-bottom-right-radius: 0.25rem; - border-bottom-left-radius: 0.25rem; } - .select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above { - border-top: 1px solid #ced4da; - border-top-left-radius: 0.25rem; - border-top-right-radius: 0.25rem; } - .select2-container--bootstrap4 .select2-dropdown .select2-results__option[aria-selected="true"] { - color: #212529; - background-color: #f2f2f2; } - -.select2-container--bootstrap4 .select2-results__option--highlighted, -.select2-container--bootstrap4 .select2-results__option--highlighted.select2-results__option[aria-selected="true"] { - color: #fff; - background-color: #007bff; } - -.select2-container--bootstrap4 .select2-results__option[role="group"] { - padding: 0; } - .select2-container--bootstrap4 .select2-results__option[role="group"] .select2-results__options--nested .select2-results__option { - padding-left: 1em; } - -.select2-container--bootstrap4 .select2-results__option { - padding: 0.375rem 0.75rem; } - -.select2-container--bootstrap4 .select2-results > .select2-results__options { - max-height: 15em; - overflow-y: auto; } - -.select2-container--bootstrap4 .select2-results__group { - display: list-item; - padding: 6px; - color: #6c757d; } - -.select2-container--bootstrap4 .select2-selection__clear { - float: right; - width: .9em; - height: .9em; - padding-left: .15em; - margin-top: .7em; - margin-right: .3em; - line-height: .75em; - color: #f8f9fa; - background-color: #c8c8c8; - border-radius: 100%; } - .select2-container--bootstrap4 .select2-selection__clear:hover { - background-color: #afafaf; } + .input-group .select2-container--bootstrap4 { + -ms-flex-positive: 1; + flex-grow: 1; } + .input-group-prepend ~ .select2-container--bootstrap4 .select2-selection { + border-top-left-radius: 0; + border-bottom-left-radius: 0; } + .input-group > .select2-container--bootstrap4:not(:last-child) .select2-selection { + border-top-right-radius: 0; + border-bottom-right-radius: 0; } + .select2-container--bootstrap4 .select2-selection { + width: 100%; + min-height: calc(1.5em + 0.75rem + 2px); + padding: 0.375rem 1.75rem 0.375rem 0.75rem; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-size: 1rem; + font-weight: 400; + line-height: 1.5; + color: #495057; + vertical-align: middle; + background-color: #fff; + border: 1px solid #ced4da; + border-radius: 0.25rem; + transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; } + @media (prefers-reduced-motion: reduce) { + .select2-container--bootstrap4 .select2-selection { + transition: none; } } + .select2-container--bootstrap4.select2-container--focus .select2-selection { + border-color: #80bdff; + box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); } + .select2-container--bootstrap4.select2-container--open.select2-container--above .select2-selection { + border-top-left-radius: 0; + border-top-right-radius: 0; } + .select2-container--bootstrap4.select2-container--open.select2-container--below .select2-selection { + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; } + .select2-container--bootstrap4.select2-container--disabled .select2-selection, + .select2-container--bootstrap4.select2-container--disabled .select2-search__field { + cursor: not-allowed; + background-color: #e9ecef; + border-color: #ced4da; + box-shadow: none; } + select.is-valid ~ .select2-container--bootstrap4 .select2-selection, + form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection { + border-color: #28a745; } + select.is-valid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection, + form.was-validated select:valid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection { + border-color: #28a745; + box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25); } + select.is-invalid ~ .select2-container--bootstrap4 .select2-selection, + form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection { + border-color: #dc3545; } + select.is-invalid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection, + form.was-validated select:invalid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection { + border-color: #dc3545; + box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25); } + .select2-container--bootstrap4 .select2-dropdown { + border-color: #ced4da; + border-radius: 0; } + .select2-container--bootstrap4 .select2-dropdown.select2-dropdown--below { + border-bottom-right-radius: 0.25rem; + border-bottom-left-radius: 0.25rem; } + .select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above { + border-top-left-radius: 0.25rem; + border-top-right-radius: 0.25rem; } + .select2-container--bootstrap4 .select2-results__option { + min-height: calc(1.5em + 0.75rem); + padding: 0.375rem 0.75rem; } + .select2-container--bootstrap4 .select2-results__option--selected { + color: #212529; + background-color: #e9ecef; } + .select2-container--bootstrap4 .select2-results__option--disabled { + color: #6c757d; } + .select2-container--bootstrap4 .select2-results__option--highlighted { + color: #fff; + background-color: #007bff; } + .select2-container--bootstrap4 .select2-results__option--group { + padding: 0; } + .select2-container--bootstrap4 .select2-results__option--group .select2-results__options--nested .select2-results__option { + padding-left: 0.75rem; } + .select2-container--bootstrap4 .select2-results > .select2-results__options { + max-height: 15em; + overflow-y: auto; } + .select2-container--bootstrap4 .select2-results__group { + display: list-item; + padding: 0.375rem 0.375rem; + color: #6c757d; } + .select2-container--bootstrap4 .select2-selection__clear { + float: right; + width: 1em; + height: 1em; + padding: 0; + margin: 0.25em 0 0; + font-weight: 700; + line-height: 0.75em; + color: #495057; + background: #e6e6e6 url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 16 16'%3e%3cpath fill='%23495057' d='M1 12l4-4-4-4 3-3 4 4 4-4 3 3-4 4 4 4-3 3-4-4-4 4z'/%3e%3c/svg%3e") center no-repeat !important; + border-radius: 100%; } + .select2-container--bootstrap4 .select2-selection__clear span { + display: none; } + .select2-container--bootstrap4 .select2-selection__clear:hover { + background-color: #d9d9d9 !important; } + .select2-container--bootstrap4 .select2-results__message { + color: #6c757d; } .select2-container--bootstrap4 .select2-selection--single { - height: calc(1.5em + 0.75rem + 2px) !important; } + background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right 0.75rem center/8px 10px no-repeat; } + select.is-valid ~ .select2-container--bootstrap4 .select2-selection--single, + form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--single { + padding-right: calc(1em + 2.3125rem) !important; + background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right 0.75rem center/8px 10px no-repeat, #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") center right 1.75rem/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) no-repeat; } + select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--single, + form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--single { + padding-right: calc(1em + 2.3125rem) !important; + background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right 0.75rem center/8px 10px no-repeat, #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") center right 1.75rem/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) no-repeat; } .select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder { - line-height: calc(1.5em + 0.75rem); color: #6c757d; } - .select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow { - position: absolute; - top: 50%; - right: 3px; - width: 20px; } - .select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow b { - position: absolute; - top: 60%; - left: 50%; - width: 0; - height: 0; - margin-top: -2px; - margin-left: -4px; - border-color: #343a40 transparent transparent transparent; - border-style: solid; - border-width: 5px 4px 0; } .select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered { - padding-left: 0.75rem; - line-height: calc(1.5em + 0.75rem); + padding: 0; color: #495057; } -.select2-search--dropdown .select2-search__field { +.select2-container--bootstrap4 .select2-search--dropdown .select2-search__field { padding: 0.375rem 0.75rem; + color: #495057; border: 1px solid #ced4da; border-radius: 0.25rem; } - -.select2-results__message { - color: #6c757d; } + .select2-container--bootstrap4 .select2-search--dropdown .select2-search__field:focus { + color: #495057; + background-color: #fff; + border-color: #80bdff; + outline: 0; + box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); } .select2-container--bootstrap4 .select2-selection--multiple { - min-height: calc(1.5em + 0.75rem + 2px) !important; } + padding: 0 0.75rem; } .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__rendered { - -webkit-box-sizing: border-box; - box-sizing: border-box; - width: 100%; - padding: 0 0.375rem; - margin: 0; - list-style: none; } + margin: 0; } + .select2-container--bootstrap4 .select2-selection--multiple .select2-search--inline { + display: inline-block; } .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice { - float: left; - padding: 0; - padding-right: 0.75rem; - margin-top: calc(0.375rem - 2px); - margin-right: 0.375rem; - color: #495057; + position: relative; + display: inline-block; + padding: 0 5px 0 21px; + margin: 0.375rem 0.375rem 0.375rem 0; + color: #fff; + vertical-align: top; cursor: pointer; - border: 1px solid #bdc6d0; + background-color: #6c757d; border-radius: 0.2rem; } + .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__display { + display: inline-block; + padding: 0 5px; } .select2-container--bootstrap4 .select2-selection--multiple .select2-search__field { + height: calc(1.5em + 0.75rem); + padding-top: 0.375rem; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + line-height: 1.5; color: #495057; } - .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice + .select2-search { - width: 0; } .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove { - float: left; - padding-right: 3px; - padding-left: 3px; - margin-right: 1px; - margin-left: 3px; + position: absolute; + top: 0; + left: 0; + height: 100%; + padding: 0 5px; + margin: 0; font-weight: 700; - color: #bdc6d0; } + color: rgba(255, 255, 255, 0.75); + cursor: pointer; + background: none; + border: none; + border-right: 1px solid #a1a8ae; } .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove:hover { - color: #343a40; } + color: rgba(255, 255, 255, 0.85); } + .select2-container--bootstrap4 .select2-selection--multiple.select2-selection--clearable { + padding-right: 32px; } .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear { - position: absolute !important; - top: 0; - right: .7em; - float: none; - margin-right: 0; } + position: absolute; + top: 0.375rem; + right: 0.75rem; } + select.is-valid ~ .select2-container--bootstrap4 .select2-selection--multiple, + form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--multiple { + padding-right: calc(1.5em + 0.75rem) !important; + background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") top calc(0.375em + 0.1875rem) right calc(0.375em + 0.1875rem)/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) no-repeat; } + select.is-valid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear, + form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear { + right: calc(1.5em + 0.75rem); } + select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--multiple, + form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--multiple { + padding-right: calc(1.5em + 0.75rem) !important; + background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") top calc(0.375em + 0.1875rem) right calc(0.375em + 0.1875rem)/calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) no-repeat; } + select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear, + form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear { + right: calc(1.5em + 0.75rem); } .select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice { - padding: 0 5px; + padding-left: 5px; cursor: not-allowed; } .select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove { display: none; } diff --git a/dist/select2-bootstrap4.min.css b/dist/select2-bootstrap4.min.css index 6d36591..480d03a 100644 --- a/dist/select2-bootstrap4.min.css +++ b/dist/select2-bootstrap4.min.css @@ -1,2 +1,2 @@ -.select2-container{display:block}.select2-container *:focus{outline:0}.input-group .select2-container--bootstrap4{-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1}.input-group-prepend ~ .select2-container--bootstrap4 .select2-selection{border-top-left-radius:0;border-bottom-left-radius:0}.input-group>.select2-container--bootstrap4:not(:last-child) .select2-selection{border-top-right-radius:0;border-bottom-right-radius:0}.select2-container--bootstrap4 .select2-selection{width:100%;background-color:#fff;border:1px solid #ced4da;border-radius:.25rem;-webkit-transition:border-color 0.15s ease-in-out,-webkit-box-shadow 0.15s ease-in-out;transition:border-color 0.15s ease-in-out,-webkit-box-shadow 0.15s ease-in-out;transition:border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out;transition:border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,-webkit-box-shadow 0.15s ease-in-out}@media (prefers-reduced-motion: reduce){.select2-container--bootstrap4 .select2-selection{-webkit-transition:none;transition:none}}.select2-container--bootstrap4.select2-container--focus .select2-selection{border-color:#80bdff;-webkit-box-shadow:0 0 0 .2rem rgba(0,123,255,0.25);box-shadow:0 0 0 .2rem rgba(0,123,255,0.25)}.select2-container--bootstrap4.select2-container--focus.select2-container--open .select2-selection{border-bottom:none;border-bottom-right-radius:0;border-bottom-left-radius:0}.select2-container--bootstrap4.select2-container--open.select2-container--above .select2-selection{border-top-left-radius:0;border-top-right-radius:0}.select2-container--bootstrap4.select2-container--open.select2-container--below .select2-selection{border-bottom-right-radius:0;border-bottom-left-radius:0}.select2-container--bootstrap4.select2-container--disabled .select2-selection,.select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-selection{cursor:not-allowed;background-color:#e9ecef;border-color:#ced4da;-webkit-box-shadow:none;box-shadow:none}.select2-container--bootstrap4.select2-container--disabled .select2-search__field,.select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-search__field{background-color:transparent}select.is-invalid ~ .select2-container--bootstrap4 .select2-selection,form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection{border-color:#dc3545}select.is-valid ~ .select2-container--bootstrap4 .select2-selection,form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection{border-color:#28a745}.select2-container--bootstrap4 .select2-search{width:100%}.select2-container--bootstrap4 .select2-dropdown{border-color:#ced4da;border-radius:0}.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--below{border-top:none;border-bottom-right-radius:.25rem;border-bottom-left-radius:.25rem}.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above{border-top:1px solid #ced4da;border-top-left-radius:.25rem;border-top-right-radius:.25rem}.select2-container--bootstrap4 .select2-dropdown .select2-results__option[aria-selected="true"]{color:#212529;background-color:#f2f2f2}.select2-container--bootstrap4 .select2-results__option--highlighted,.select2-container--bootstrap4 .select2-results__option--highlighted.select2-results__option[aria-selected="true"]{color:#fff;background-color:#007bff}.select2-container--bootstrap4 .select2-results__option[role="group"]{padding:0}.select2-container--bootstrap4 .select2-results__option[role="group"] .select2-results__options--nested .select2-results__option{padding-left:1em}.select2-container--bootstrap4 .select2-results__option{padding:.375rem .75rem}.select2-container--bootstrap4 .select2-results>.select2-results__options{max-height:15em;overflow-y:auto}.select2-container--bootstrap4 .select2-results__group{display:list-item;padding:6px;color:#6c757d}.select2-container--bootstrap4 .select2-selection__clear{float:right;width:.9em;height:.9em;padding-left:.15em;margin-top:.7em;margin-right:.3em;line-height:.75em;color:#f8f9fa;background-color:#c8c8c8;border-radius:100%}.select2-container--bootstrap4 .select2-selection__clear:hover{background-color:#afafaf}.select2-container--bootstrap4 .select2-selection--single{height:calc(1.5em + .75rem + 2px) !important}.select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder{line-height:calc(1.5em + .75rem);color:#6c757d}.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow{position:absolute;top:50%;right:3px;width:20px}.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow b{position:absolute;top:60%;left:50%;width:0;height:0;margin-top:-2px;margin-left:-4px;border-color:#343a40 transparent transparent transparent;border-style:solid;border-width:5px 4px 0}.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered{padding-left:.75rem;line-height:calc(1.5em + .75rem);color:#495057}.select2-search--dropdown .select2-search__field{padding:.375rem .75rem;border:1px solid #ced4da;border-radius:.25rem}.select2-results__message{color:#6c757d}.select2-container--bootstrap4 .select2-selection--multiple{min-height:calc(1.5em + .75rem + 2px) !important}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__rendered{-webkit-box-sizing:border-box;box-sizing:border-box;width:100%;padding:0 .375rem;margin:0;list-style:none}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice{float:left;padding:0;padding-right:.75rem;margin-top:calc(.375rem - 2px);margin-right:.375rem;color:#495057;cursor:pointer;border:1px solid #bdc6d0;border-radius:.2rem}.select2-container--bootstrap4 .select2-selection--multiple .select2-search__field{color:#495057}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice+.select2-search{width:0}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove{float:left;padding-right:3px;padding-left:3px;margin-right:1px;margin-left:3px;font-weight:700;color:#bdc6d0}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove:hover{color:#343a40}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear{position:absolute !important;top:0;right:.7em;float:none;margin-right:0}.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice{padding:0 5px;cursor:not-allowed}.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove{display:none} +.select2-container--bootstrap4{display:block}.select2-container--bootstrap4 *:focus{outline:0}.input-group .select2-container--bootstrap4{-ms-flex-positive:1;flex-grow:1}.input-group-prepend ~ .select2-container--bootstrap4 .select2-selection{border-top-left-radius:0;border-bottom-left-radius:0}.input-group>.select2-container--bootstrap4:not(:last-child) .select2-selection{border-top-right-radius:0;border-bottom-right-radius:0}.select2-container--bootstrap4 .select2-selection{width:100%;min-height:calc(1.5em + .75rem + 2px);padding:.375rem 1.75rem .375rem .75rem;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#495057;vertical-align:middle;background-color:#fff;border:1px solid #ced4da;border-radius:.25rem;transition:background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out}@media (prefers-reduced-motion: reduce){.select2-container--bootstrap4 .select2-selection{transition:none}}.select2-container--bootstrap4.select2-container--focus .select2-selection{border-color:#80bdff;box-shadow:0 0 0 .2rem rgba(0,123,255,0.25)}.select2-container--bootstrap4.select2-container--open.select2-container--above .select2-selection{border-top-left-radius:0;border-top-right-radius:0}.select2-container--bootstrap4.select2-container--open.select2-container--below .select2-selection{border-bottom-right-radius:0;border-bottom-left-radius:0}.select2-container--bootstrap4.select2-container--disabled .select2-selection,.select2-container--bootstrap4.select2-container--disabled .select2-search__field{cursor:not-allowed;background-color:#e9ecef;border-color:#ced4da;box-shadow:none}select.is-valid ~ .select2-container--bootstrap4 .select2-selection,form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection{border-color:#28a745}select.is-valid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection,form.was-validated select:valid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection{border-color:#28a745;box-shadow:0 0 0 .2rem rgba(40,167,69,0.25)}select.is-invalid ~ .select2-container--bootstrap4 .select2-selection,form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection{border-color:#dc3545}select.is-invalid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection,form.was-validated select:invalid ~ .select2-container--bootstrap4.select2-container--focus .select2-selection{border-color:#dc3545;box-shadow:0 0 0 .2rem rgba(220,53,69,0.25)}.select2-container--bootstrap4 .select2-dropdown{border-color:#ced4da;border-radius:0}.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--below{border-bottom-right-radius:.25rem;border-bottom-left-radius:.25rem}.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above{border-top-left-radius:.25rem;border-top-right-radius:.25rem}.select2-container--bootstrap4 .select2-results__option{min-height:calc(1.5em + .75rem);padding:.375rem .75rem}.select2-container--bootstrap4 .select2-results__option--selected{color:#212529;background-color:#e9ecef}.select2-container--bootstrap4 .select2-results__option--disabled{color:#6c757d}.select2-container--bootstrap4 .select2-results__option--highlighted{color:#fff;background-color:#007bff}.select2-container--bootstrap4 .select2-results__option--group{padding:0}.select2-container--bootstrap4 .select2-results__option--group .select2-results__options--nested .select2-results__option{padding-left:.75rem}.select2-container--bootstrap4 .select2-results>.select2-results__options{max-height:15em;overflow-y:auto}.select2-container--bootstrap4 .select2-results__group{display:list-item;padding:.375rem .375rem;color:#6c757d}.select2-container--bootstrap4 .select2-selection__clear{float:right;width:1em;height:1em;padding:0;margin:.25em 0 0;font-weight:700;line-height:.75em;color:#495057;background:#e6e6e6 url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 16 16'%3e%3cpath fill='%23495057' d='M1 12l4-4-4-4 3-3 4 4 4-4 3 3-4 4 4 4-3 3-4-4-4 4z'/%3e%3c/svg%3e") center no-repeat !important;border-radius:100%}.select2-container--bootstrap4 .select2-selection__clear span{display:none}.select2-container--bootstrap4 .select2-selection__clear:hover{background-color:#d9d9d9 !important}.select2-container--bootstrap4 .select2-results__message{color:#6c757d}.select2-container--bootstrap4 .select2-selection--single{background:#fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right .75rem center/8px 10px no-repeat}select.is-valid ~ .select2-container--bootstrap4 .select2-selection--single,form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--single{padding-right:calc(1em + 2.3125rem) !important;background:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right .75rem center/8px 10px no-repeat,#fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") center right 1.75rem/calc(.75em + .375rem) calc(.75em + .375rem) no-repeat}select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--single,form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--single{padding-right:calc(1em + 2.3125rem) !important;background:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") right .75rem center/8px 10px no-repeat,#fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") center right 1.75rem/calc(.75em + .375rem) calc(.75em + .375rem) no-repeat}.select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder{color:#6c757d}.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered{padding:0;color:#495057}.select2-container--bootstrap4 .select2-search--dropdown .select2-search__field{padding:.375rem .75rem;color:#495057;border:1px solid #ced4da;border-radius:.25rem}.select2-container--bootstrap4 .select2-search--dropdown .select2-search__field:focus{color:#495057;background-color:#fff;border-color:#80bdff;outline:0;box-shadow:0 0 0 .2rem rgba(0,123,255,0.25)}.select2-container--bootstrap4 .select2-selection--multiple{padding:0 .75rem}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__rendered{margin:0}.select2-container--bootstrap4 .select2-selection--multiple .select2-search--inline{display:inline-block}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice{position:relative;display:inline-block;padding:0 5px 0 21px;margin:.375rem .375rem .375rem 0;color:#fff;vertical-align:top;cursor:pointer;background-color:#6c757d;border-radius:.2rem}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__display{display:inline-block;padding:0 5px}.select2-container--bootstrap4 .select2-selection--multiple .select2-search__field{height:calc(1.5em + .75rem);padding-top:.375rem;margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";line-height:1.5;color:#495057}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove{position:absolute;top:0;left:0;height:100%;padding:0 5px;margin:0;font-weight:700;color:rgba(255,255,255,0.75);cursor:pointer;background:none;border:none;border-right:1px solid #a1a8ae}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove:hover{color:rgba(255,255,255,0.85)}.select2-container--bootstrap4 .select2-selection--multiple.select2-selection--clearable{padding-right:32px}.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear{position:absolute;top:.375rem;right:.75rem}select.is-valid ~ .select2-container--bootstrap4 .select2-selection--multiple,form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--multiple{padding-right:calc(1.5em + .75rem) !important;background:#fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") top calc(.375em + .1875rem) right calc(.375em + .1875rem)/calc(.75em + .375rem) calc(.75em + .375rem) no-repeat}select.is-valid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear,form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear{right:calc(1.5em + .75rem)}select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--multiple,form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--multiple{padding-right:calc(1.5em + .75rem) !important;background:#fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") top calc(.375em + .1875rem) right calc(.375em + .1875rem)/calc(.75em + .375rem) calc(.75em + .375rem) no-repeat}select.is-invalid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear,form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection--multiple .select2-selection__clear{right:calc(1.5em + .75rem)}.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice{padding-left:5px;cursor:not-allowed}.select2-container--bootstrap4.select2-container--disabled .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove{display:none} diff --git a/docs/index.html b/docs/index.html index afb532b..f8021ed 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,17 +2,18 @@ - - + - + + + Select2 Boostrap 4 Theme @@ -22,16 +23,56 @@

Example of
+
+ + +
+
+ +
+ + + Toggle is-valid state + Toggle is-invalid state +
+ +
+ + + Toggle is-valid state + Toggle is-invalid state
+ +
+ + + Toggle is-valid state + Toggle is-invalid state +
+ +
+ + + Toggle is-valid state + Toggle is-invalid state
+
@@ -145,11 +235,11 @@

Example of - + - + diff --git a/docs/script.js b/docs/script.js index a015033..8b85bca 100644 --- a/docs/script.js +++ b/docs/script.js @@ -1,11 +1,20 @@ $(function () { - $('select').each(function () { + $('select:not(.custom-select)').each(function () { $(this).select2({ theme: 'bootstrap4', width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style', - placeholder: $(this).data('placeholder'), - allowClear: Boolean($(this).data('allow-clear')), - closeOnSelect: !$(this).attr('multiple'), - }); - }); -}); + closeOnSelect: !$(this).attr('multiple') + }) + }) +}) + +$(document).on('click', '.toggle-validation-js', function (e) { + e.preventDefault() + $this = $(this) + + $this.closest('.form-group').toggleClass('was-validated') + + $selectElement = $this.closest('.form-group').find('select') + $selectElement + .toggleClass($this.data('validationClass')) +}) diff --git a/package.json b/package.json index a3fd9eb..3b721d0 100644 --- a/package.json +++ b/package.json @@ -32,24 +32,33 @@ }, "homepage": "https://github.com/ttskch/select2-bootstrap4-theme#readme", "devDependencies": { - "autoprefixer": "^10.2.3", + "autoprefixer": "^10.2.5", "bootstrap": "^4.6.0", - "css-loader": "^5.0.1", - "mini-css-extract-plugin": "^1.3.4", + "css-loader": "^5.1.2", + "mini-css-extract-plugin": "^1.3.9", "node-sass": "^5.0.0", - "postcss": "^8.2.4", - "postcss-loader": "^4.2.0", - "sass-loader": "^10.1.1", + "postcss": "^8.2.8", + "postcss-loader": "^5.2.0", + "sass-loader": "^11.0.1", "style-loader": "^2.0.0", - "stylelint": "^13.9.0", + "stylelint": "^13.12.0", "stylelint-config-twbs-bootstrap": "^2.1.0", "stylelint-webpack-plugin": "^2.1.1", - "webpack": "^5.16.0", - "webpack-cli": "^4.4.0" + "webpack": "^5.25.0", + "webpack-cli": "^4.5.0" }, "jsdelivr": "dist/select2-bootstrap4.min.css", "browserslist": [ - "last 2 versions", - "ios >= 9" + ">= 1%", + "last 1 major version", + "not dead", + "Chrome >= 45", + "Firefox >= 38", + "Edge >= 12", + "Explorer >= 10", + "iOS >= 9", + "Safari >= 9", + "Android >= 4.4", + "Opera >= 30" ] } diff --git a/src/_layout.scss b/src/_layout.scss index 1c33c41..547ca97 100644 --- a/src/_layout.scss +++ b/src/_layout.scss @@ -1,60 +1,59 @@ -// basic -.select2-container { +.select2-container--bootstrap4 { display: block; *:focus { outline: 0; } -} -// input-group -.input-group .select2-container--bootstrap4 { - flex-grow: 1; -} -// for prepended input -.input-group-prepend ~ .select2-container--bootstrap4 .select2-selection { - border-top-left-radius: 0; - border-bottom-left-radius: 0; -} -// for appended input -.input-group > .select2-container--bootstrap4:not(:last-child) .select2-selection { - border-top-right-radius: 0; - border-bottom-right-radius: 0; -} + // input-group + .input-group & { + flex-grow: 1; + } -.select2-container--bootstrap4 { + // for prepended input + .input-group-prepend ~ & .select2-selection { + border-top-left-radius: 0; + border-bottom-left-radius: 0; + } + + // for appended input + .input-group > &:not(:last-child) .select2-selection { + border-top-right-radius: 0; + border-bottom-right-radius: 0; + } // input box .select2-selection { width: 100%; - background-color: $input-bg; - border: $input-border-width solid $input-border-color; - @include border-radius($input-border-radius); - @include box-shadow($input-box-shadow); - @include transition($input-transition); + min-height: $select2-bootstrap4-height; + padding: $select2-bootstrap4-padding-y ($select2-bootstrap4-padding-x + $select2-bootstrap4-indicator-padding) $select2-bootstrap4-padding-y $select2-bootstrap4-padding-x; + font-family: $select2-bootstrap4-font-family; + @include font-size($select2-bootstrap4-font-size); + font-weight: $select2-bootstrap4-font-weight; + line-height: $select2-bootstrap4-line-height; + color: $select2-bootstrap4-color; + vertical-align: middle; + background-color: $select2-bootstrap4-bg; + border: $select2-bootstrap4-border-width solid $select2-bootstrap4-border-color; + @include border-radius($select2-bootstrap4-border-radius, 0); + @include box-shadow($select2-bootstrap4-box-shadow); + @include transition($select2-bootstrap4-transition); } - // focused input box &.select2-container--focus { .select2-selection { - border-color: $input-focus-border-color; - box-shadow: $input-focus-box-shadow; - } - - // when open, hide bottom border - &.select2-container--open .select2-selection { - border-bottom: none; - @include border-bottom-radius(0); + border-color: $select2-bootstrap4-focus-border-color; + box-shadow: $select2-bootstrap4-focus-box-shadow; } } - // open input box &.select2-container--open { &.select2-container--above { .select2-selection { @include border-top-radius(0); } } + &.select2-container--below { .select2-selection { @include border-bottom-radius(0); @@ -62,107 +61,111 @@ } } - // disabled input box - &.select2-container--disabled, - &.select2-container--disabled.select2-container--focus { - .select2-selection { + &.select2-container--disabled { + .select2-selection, + .select2-search__field { cursor: not-allowed; - background-color: $input-disabled-bg; - border-color: $input-border-color; + background-color: $select2-bootstrap4-disabled-bg; + border-color: $select2-bootstrap4-border-color; box-shadow: none; } - .select2-search__field { - background-color: transparent; - } } // validated input box // stylelint-disable selector-no-qualifying-type - select.is-invalid ~ & .select2-selection, - form.was-validated select:invalid ~ & .select2-selection { - border-color: $danger; - } - select.is-valid ~ & .select2-selection, - form.was-validated select:valid ~ & .select2-selection { - border-color: $success; - } - // stylelint-enable selector-no-qualifying-type + @each $state, $data in $select2-bootstrap4-validation-states { + select.is-#{$state} ~ &, + form.was-validated select:#{$state} ~ & { + .select2-selection { + border-color: map-get($data, color); + } - // fixes placeholder width - .select2-search { - width: 100%; + &.select2-container--focus .select2-selection { + border-color: map-get($data, color); + box-shadow: 0 0 0 $select2-bootstrap4-focus-width rgba(map-get($data, color), .25); + } + } } + // stylelint-enable selector-no-qualifying-type - // dropdown .select2-dropdown { - border-color: $input-border-color; - border-radius: 0; // overwrite select2.css + border-color: $select2-bootstrap4-border-color; + border-radius: 0; // overload select2.css - // dropdown opened below &.select2-dropdown--below { - border-top: none; - @include border-bottom-radius($input-border-radius); + @include border-bottom-radius($select2-bootstrap4-border-radius); } - // dropdown opened above &.select2-dropdown--above { - border-top: 1px solid $input-border-color; - @include border-top-radius($input-border-radius); + @include border-top-radius($select2-bootstrap4-border-radius); } + } - // selected item - .select2-results__option[aria-selected="true"] { - color: color-yiq(darken($input-bg, 5%)); - background-color: darken($input-bg, 5%); + .select2-results__option { + min-height: $select2-bootstrap4-height-inner; + padding: $select2-bootstrap4-padding-y $select2-bootstrap4-padding-x; + + &--selected { + color: color-yiq($select2-bootstrap4-disabled-bg); + background-color: $select2-bootstrap4-disabled-bg; } - } - // mouse hovered item - .select2-results__option--highlighted, - .select2-results__option--highlighted.select2-results__option[aria-selected="true"] { - color: color-yiq($primary); - background-color: $primary; - } + &--disabled { + color: $select2-bootstrap4-disabled-color; + } - // for - .select2-results__option[role="group"] { - padding: 0; - .select2-results__options--nested .select2-results__option { - padding-left: 1em; + // hover + &--highlighted { + color: color-yiq($select2-bootstrap4-highlighted-bg); + background-color: $select2-bootstrap4-highlighted-bg; } - } - .select2-results__option { - padding: $input-padding-y $input-padding-x; + &--group { + padding: 0; + + .select2-results__options--nested .select2-results__option { + padding-left: $select2-bootstrap4-padding-x; + } + } } - // fixes vertical overflow + // vertical overflow .select2-results > .select2-results__options { - max-height: 15em; + max-height: $select2-bootstrap4-dropdown-height; overflow-y: auto; } .select2-results__group { display: list-item; - padding: 6px; - color: $secondary; + padding: $select2-bootstrap4-padding-y $select2-bootstrap4-padding-x / 2; + color: $select2-bootstrap4-disabled-color; } - // all clear button + // clear all button .select2-selection__clear { - $bg: #c8c8c8; float: right; - width: .9em; - height: .9em; - padding-left: .15em; - margin-top: .7em; - margin-right: .3em; - line-height: .75em; - color: $light; - background-color: $bg; + width: 1em; + height: 1em; + padding: 0; + margin: subtract($select2-bootstrap4-line-height * 1em, 1em) / 2 0 0; + font-weight: 700; + line-height: (12em / 16); + color: $select2-bootstrap4-color; + background: darken($select2-bootstrap4-bg, 10%) escape-svg($select2-bootstrap4-selection-clear-icon) center no-repeat !important; // stylelint-disable-line declaration-no-important border-radius: 100%; + + // hide default × entity + span { + display: none; + } + &:hover { - background-color: darken($bg, 10%); + background-color: darken($select2-bootstrap4-bg, 15%) !important; // stylelint-disable-line declaration-no-important } } + + // no results message + .select2-results__message { + color: $text-muted; + } } diff --git a/src/_multiple.scss b/src/_multiple.scss index 6531c67..483a2a5 100644 --- a/src/_multiple.scss +++ b/src/_multiple.scss @@ -1,71 +1,95 @@ .select2-container--bootstrap4 { .select2-selection--multiple { - - // height of input box - min-height: $input-height !important; // stylelint-disable-line declaration-no-important + padding: 0 $select2-bootstrap4-padding-x; // input box .select2-selection__rendered { - box-sizing: border-box; - width: 100%; - padding: 0 $input-padding-x / 2; margin: 0; - list-style: none; + } + + .select2-search--inline { + display: inline-block; } // each selected item in input box .select2-selection__choice { - float: left; - padding: 0; - padding-right: $input-padding-x; - margin-top: calc(#{$input-padding-y} - 2px); - margin-right: $input-padding-x / 2; - color: $input-color; + position: relative; + display: inline-block; + padding: 0 5px 0 21px; + margin: $select2-bootstrap4-padding-y $select2-bootstrap4-padding-x / 2 $select2-bootstrap4-padding-y 0; + color: color-yiq($select2-bootstrap4-selection-choice-bg); + vertical-align: top; cursor: pointer; - border: 1px solid darken($light, 20%); - @include border-radius($input-border-radius-sm); + background-color: $select2-bootstrap4-selection-choice-bg; + @include border-radius($select2-bootstrap4-selection-choice-border-radius); } - // search field - .select2-search__field { - color: $input-color; + .select2-selection__choice__display { + display: inline-block; + padding: 0 5px; } - // fixes placeholder width - .select2-selection__choice + .select2-search { - width: 0; + .select2-search__field { + height: add($select2-bootstrap4-line-height * 1em, $select2-bootstrap4-padding-y * 2); + padding-top: $select2-bootstrap4-padding-y; + margin: 0; + font-family: $select2-bootstrap4-font-family; + line-height: $select2-bootstrap4-line-height; + color: $select2-bootstrap4-color; } // x button of each selected item in input box .select2-selection__choice__remove { - float: left; - padding-right: 3px; - padding-left: 3px; - margin-right: 1px; - margin-left: 3px; + position: absolute; + top: 0; + left: 0; + height: 100%; + padding: 0 5px; + margin: 0; font-weight: 700; - color: darken($light, 20%); + color: fade-out(color-yiq($select2-bootstrap4-selection-choice-bg), .25); + cursor: pointer; + background: none; + border: none; + border-right: 1px solid lighten($select2-bootstrap4-selection-choice-bg, 20%); + &:hover { - color: $dark; + color: fade-out(color-yiq($select2-bootstrap4-selection-choice-bg), .15); } } - // all clear button + &.select2-selection--clearable { + padding-right: 32px; + } + .select2-selection__clear { - position: absolute !important; // stylelint-disable-line declaration-no-important - top: 0; - right: .7em; - // overwrite layout.scss - float: none; - margin-right: 0; + position: absolute; + top: $select2-bootstrap4-padding-y; + right: $select2-bootstrap4-padding-x; + } + + // stylelint-disable selector-no-qualifying-type, selector-max-compound-selectors + @if $select2-bootstrap4-enable-validation-icons { + @each $state, $data in $select2-bootstrap4-validation-states { + select.is-#{$state} ~ &, + form.was-validated select:#{$state} ~ & { + padding-right: $select2-bootstrap4-height-inner !important; // stylelint-disable-line declaration-no-important + background: $select2-bootstrap4-bg escape-svg(map-get($data, icon)) top $select2-bootstrap4-height-inner-quarter right $select2-bootstrap4-height-inner-quarter / $select2-bootstrap4-feedback-icon-size no-repeat; + + .select2-selection__clear { + right: $select2-bootstrap4-height-inner; + } + } + } } + // stylelint-enable selector-no-qualifying-type, selector-max-compound-selectors } // hide x button of each selected item in disabled input box &.select2-container--disabled { .select2-selection--multiple { .select2-selection__choice { - padding: 0 5px; + padding-left: 5px; cursor: not-allowed; // stylelint-disable selector-max-class .select2-selection__choice__remove { diff --git a/src/_single.scss b/src/_single.scss index 9e040b9..185bf7e 100644 --- a/src/_single.scss +++ b/src/_single.scss @@ -1,52 +1,38 @@ .select2-container--bootstrap4 { .select2-selection--single { + background: $select2-bootstrap4-bg $select2-bootstrap4-background; - // height of input box - height: $input-height !important; // stylelint-disable-line declaration-no-important - - // placeholder - .select2-selection__placeholder { - line-height: $input-height-inner; - color: $input-placeholder-color; + // stylelint-disable selector-no-qualifying-type + @if $select2-bootstrap4-enable-validation-icons { + @each $state, $data in $select2-bootstrap4-validation-states { + select.is-#{$state} ~ &, + form.was-validated select:#{$state} ~ & { + padding-right: $select2-bootstrap4-feedback-icon-padding-right !important; // stylelint-disable-line declaration-no-important + background: $select2-bootstrap4-background, $select2-bootstrap4-bg escape-svg(map-get($data, icon)) $select2-bootstrap4-feedback-icon-position / $select2-bootstrap4-feedback-icon-size no-repeat; + } + } } + // stylelint-enable selector-no-qualifying-type - // arrow - .select2-selection__arrow { - position: absolute; - top: 50%; - right: 3px; - width: 20px; - b { - position: absolute; - top: 60%; - left: 50%; - width: 0; - height: 0; - margin-top: -2px; - margin-left: -4px; - border-color: $dark transparent transparent transparent; - border-style: solid; - border-width: 5px 4px 0; - } + .select2-selection__placeholder { + color: $select2-bootstrap4-placeholder-color; } // selected item .select2-selection__rendered { - padding-left: $input-padding-x; - line-height: $input-height-inner; - color: $input-color; + padding: 0; + color: $select2-bootstrap4-color; } } -} - -// search box -.select2-search--dropdown .select2-search__field { - padding: $input-padding-y $input-padding-x; - border: $input-border-width solid $input-border-color; - @include border-radius($input-border-radius); -} -// no result message -.select2-results__message { - color: $secondary; + // search box + .select2-search--dropdown { + .select2-search__field { + padding: $select2-bootstrap4-padding-y $select2-bootstrap4-padding-x; + color: $select2-bootstrap4-color; + border: $select2-bootstrap4-border-width solid $select2-bootstrap4-border-color; + @include border-radius($select2-bootstrap4-border-radius); + @include form-control-focus(true); + } + } } diff --git a/src/_variables.scss b/src/_variables.scss new file mode 100644 index 0000000..ad51066 --- /dev/null +++ b/src/_variables.scss @@ -0,0 +1,54 @@ +// Inherit from Bootstrap variables +$select2-bootstrap4-enable-validation-icons: $enable-validation-icons !default; + +$select2-bootstrap4-placeholder-color: $input-placeholder-color !default; +$select2-bootstrap4-height-inner: $input-height-inner !default; +$select2-bootstrap4-height-inner-quarter: $input-height-inner-quarter !default; + +$select2-bootstrap4-transition: $custom-forms-transition !default; + +$select2-bootstrap4-focus-border-color: $custom-select-focus-border-color !default; +$select2-bootstrap4-focus-width: $custom-select-focus-width !default; +$select2-bootstrap4-focus-box-shadow: $custom-select-focus-box-shadow; + +$select2-bootstrap4-padding-y: $custom-select-padding-y !default; +$select2-bootstrap4-padding-x: $custom-select-padding-x !default; +$select2-bootstrap4-font-family: $custom-select-font-family !default; +$select2-bootstrap4-font-size: $custom-select-font-size !default; +$select2-bootstrap4-height: $custom-select-height !default; +$select2-bootstrap4-indicator-padding: $custom-select-indicator-padding !default; +$select2-bootstrap4-font-weight: $custom-select-font-weight !default; +$select2-bootstrap4-line-height: $custom-select-line-height !default; +$select2-bootstrap4-color: $custom-select-color !default; +$select2-bootstrap4-disabled-color: $custom-select-disabled-color !default; +$select2-bootstrap4-bg: $custom-select-bg !default; +$select2-bootstrap4-disabled-bg: $custom-select-disabled-bg !default; +$select2-bootstrap4-bg-size: $custom-select-bg-size !default; +$select2-bootstrap4-indicator-color: $custom-select-indicator-color !default; +$select2-bootstrap4-indicator: $custom-select-indicator !default; +$select2-bootstrap4-background: $custom-select-background !default; + +// `feedback-icon-padding-right` adds some extra space compared to Boostrap +// because of the clear button +$select2-bootstrap4-feedback-icon-padding-right: add(1em, (2 * $select2-bootstrap4-padding-y * .75) + $select2-bootstrap4-padding-x + $select2-bootstrap4-indicator-padding) !default; +$select2-bootstrap4-feedback-icon-position: $custom-select-feedback-icon-position !default; +$select2-bootstrap4-feedback-icon-size: $custom-select-feedback-icon-size !default; + +$select2-bootstrap4-border-width: $custom-select-border-width !default; +$select2-bootstrap4-border-color: $custom-select-border-color !default; +$select2-bootstrap4-border-radius: $custom-select-border-radius !default; +$select2-bootstrap4-box-shadow: $custom-select-box-shadow !default; + +$select2-bootstrap4-validation-states: $form-validation-states !default; + +// Font family fallback. Needed because `$custom-select-font-family` defaults +// to `null`, but Select2 comes with a `font-family: sans-serif` CSS rule that +// this theme needs to override +$select2-bootstrap4-font-family: $font-family-base !default; + +// New variables specific to the theme +$select2-bootstrap4-dropdown-height: 15em !default; +$select2-bootstrap4-highlighted-bg: $primary !default; +$select2-bootstrap4-selection-choice-bg: $secondary !default; +$select2-bootstrap4-selection-choice-border-radius: $border-radius-sm !default; +$select2-bootstrap4-selection-clear-icon: url("data:image/svg+xml,") !default; diff --git a/src/select2-bootstrap4.scss b/src/select2-bootstrap4.scss index 39e1a3c..86fa2e6 100644 --- a/src/select2-bootstrap4.scss +++ b/src/select2-bootstrap4.scss @@ -1,3 +1,4 @@ +@import "variables"; @import "layout"; @import "single"; @import "multiple";