Skip to content
Snippets Groups Projects
Commit 688a219c authored by Vladimir Roudakov's avatar Vladimir Roudakov Committed by Vladimir Roudakov
Browse files

Issue #3246127 by VladimirAus: Create styleguide based on Bootstrap 5 cheat...

Issue #3246127 by VladimirAus: Create styleguide based on Bootstrap 5 cheat sheet [GlobalSprintWeekend2022]
parent 4fd189dc
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## INTRODUCTION ## INTRODUCTION
Companion module for [Bootstrap 5 theme]() Companion module for [Bootstrap 5 theme](https://www.drupal.org/project/bootstrap5)
to provide better content editor and developer experience. to provide better content editor and developer experience.
## FEATURES ## FEATURES
...@@ -11,7 +11,6 @@ to provide better content editor and developer experience. ...@@ -11,7 +11,6 @@ to provide better content editor and developer experience.
* Bootstrap 5 elements in CKEditor * Bootstrap 5 elements in CKEditor
* Drupal 9+ compatible * Drupal 9+ compatible
## INSTALLATION ## INSTALLATION
### Using composer ### Using composer
...@@ -26,4 +25,4 @@ Head to `Extend` and install `bootstrap tools` module. ...@@ -26,4 +25,4 @@ Head to `Extend` and install `bootstrap tools` module.
### Style guide ### Style guide
Head to `/admin/appearance/styleguide` Head to `/styleguide` to see elements.
This diff is collapsed.
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="408" fill="#fff"><path d="M106.342 0c-29.214 0-50.827 25.58-49.86 53.32.927 26.647-.278 61.165-8.966 89.31C38.802 170.862 24.07 188.707 0 191v26c24.069 2.293 38.802 20.138 47.516 48.37 8.688 28.145 9.893 62.663 8.965 89.311C55.515 382.42 77.128 408 106.342 408h299.353c29.214 0 50.827-25.58 49.861-53.319-.928-26.648.277-61.166 8.964-89.311 8.715-28.232 23.411-46.077 47.48-48.37v-26c-24.069-2.293-38.765-20.138-47.48-48.37-8.687-28.145-9.892-62.663-8.964-89.31C456.522 25.58 434.909 0 405.695 0H106.342zm236.559 251.102c0 38.197-28.501 61.355-75.798 61.355h-87.202a2 2 0 01-2-2v-213a2 2 0 012-2h86.74c39.439 0 65.322 21.354 65.322 54.138 0 23.008-17.409 43.61-39.594 47.219v1.203c30.196 3.309 50.532 24.212 50.532 53.085zm-84.58-128.125h-45.91v64.814h38.669c29.888 0 46.373-12.03 46.373-33.535 0-20.151-14.174-31.279-39.132-31.279zm-45.91 90.53v71.431h47.605c31.12 0 47.605-12.482 47.605-35.941 0-23.46-16.947-35.49-49.608-35.49h-45.602z"/></svg>
\ No newline at end of file
body {
scroll-behavior: smooth;
}
/**
* Bootstrap "Journal code" icon
* @link https://icons.getbootstrap.com/icons/journal-code/
*/
.bd-heading a::before {
display: inline-block;
width: 1em;
height: 1em;
margin-right: .25rem;
content: "";
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%25230d6efd' viewBox='0 0 16 16'%3E%3Cpath d='M4 1h8a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2h1a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1H2a2 2 0 0 1 2-2z'/%3E%3Cpath d='M2 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H2zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H2zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H2z'/%3E%3Cpath fill-rule='evenodd' d='M8.646 5.646a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L10.293 8 8.646 6.354a.5.5 0 0 1 0-.708zm-1.292 0a.5.5 0 0 0-.708 0l-2 2a.5.5 0 0 0 0 .708l2 2a.5.5 0 0 0 .708-.708L5.707 8l1.647-1.646a.5.5 0 0 0 0-.708z'/%3E%3C/svg%3E");
background-size: 1em;
}
/* stylelint-disable-next-line selector-max-universal */
.bd-heading + div > * + * {
margin-top: 3rem;
}
/* Table of contents */
.bd-aside a {
padding: .1875rem .5rem;
margin-top: .125rem;
margin-left: .3125rem;
color: rgba(0, 0, 0, .65);
text-decoration: none;
}
.bd-aside a:hover,
.bd-aside a:focus {
color: rgba(0, 0, 0, .85);
background-color: rgba(121, 82, 179, .1);
}
.bd-aside .active {
font-weight: 600;
color: rgba(0, 0, 0, .85);
}
.bd-aside .btn {
padding: .25rem .5rem;
font-weight: 600;
color: rgba(0, 0, 0, .65);
border: 0;
}
.bd-aside .btn:hover,
.bd-aside .btn:focus {
color: rgba(0, 0, 0, .85);
background-color: rgba(121, 82, 179, .1);
}
.bd-aside .btn:focus {
box-shadow: 0 0 0 1px rgba(121, 82, 179, .7);
}
.bd-aside .btn::before {
width: 1.25em;
line-height: 0;
content: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='rgba%280,0,0,.5%29' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M5 14l6-6-6-6'/%3e%3c/svg%3e");
transition: transform .35s ease;
/* rtl:raw:
transform: rotate(180deg) translateX(-2px);
*/
transform-origin: .5em 50%;
}
.bd-aside .btn[aria-expanded="true"]::before {
transform: rotate(90deg)/* rtl:ignore */;
}
/* Examples */
.scrollspy-example {
position: relative;
height: 200px;
margin-top: .5rem;
overflow: auto;
}
[id="modal"] .bd-example .btn,
[id="buttons"] .bd-example .btn,
[id="tooltips"] .bd-example .btn,
[id="popovers"] .bd-example .btn,
[id="dropdowns"] .bd-example .btn-group,
[id="dropdowns"] .bd-example .dropdown,
[id="dropdowns"] .bd-example .dropup,
[id="dropdowns"] .bd-example .dropend,
[id="dropdowns"] .bd-example .dropstart {
margin: 0 1rem 1rem 0;
}
/* Layout */
@media (min-width: 1200px) {
body {
display: grid;
gap: 1rem;
grid-template-columns: 1fr 4fr 1fr;
grid-template-rows: auto;
}
.bd-header {
position: fixed;
top: 0;
/* rtl:begin:ignore */
right: 0;
left: 0;
/* rtl:end:ignore */
z-index: 1030;
grid-column: 1 / span 3;
}
.bd-aside,
.bd-cheatsheet {
padding-top: 4rem;
}
/**
* 1. Too bad only Firefox supports subgrids ATM
*/
.bd-cheatsheet,
.bd-cheatsheet section,
.bd-cheatsheet article {
display: inherit; /* 1 */
gap: inherit; /* 1 */
grid-template-columns: 1fr 4fr;
grid-column: 1 / span 2;
grid-template-rows: auto;
}
.bd-aside {
grid-area: 1 / 3;
scroll-margin-top: 4rem;
}
.bd-cheatsheet section,
.bd-cheatsheet section > h2 {
top: 2rem;
scroll-margin-top: 2rem;
}
.bd-cheatsheet section > h2::before {
position: absolute;
/* rtl:begin:ignore */
top: 0;
right: 0;
bottom: -2rem;
left: 0;
/* rtl:end:ignore */
z-index: -1;
content: "";
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 1) calc(100% - 3rem), rgba(255, 255, 255, .01));
}
.bd-cheatsheet article,
.bd-cheatsheet .bd-heading {
top: 8rem;
scroll-margin-top: 8rem;
}
.bd-cheatsheet .bd-heading {
z-index: 1;
}
}
/* global bootstrap: false */
(function () {
'use strict'
// Tooltip and popover demos
document.querySelectorAll('.tooltip-demo')
.forEach(function (tooltip) {
new bootstrap.Tooltip(tooltip, {
selector: '[data-bs-toggle="tooltip"]'
})
})
document.querySelectorAll('[data-bs-toggle="popover"]')
.forEach(function (popover) {
new bootstrap.Popover(popover)
})
document.querySelectorAll('.toast')
.forEach(function (toastNode) {
var toast = new bootstrap.Toast(toastNode, {
autohide: false
})
toast.show()
})
// Disable empty links and submit buttons
document.querySelectorAll('[href="#"], [type="submit"]')
.forEach(function (link) {
link.addEventListener('click', function (event) {
event.preventDefault()
})
})
function setActiveItem() {
var hash = window.location.hash
if (hash === '') {
return
}
var link = document.querySelector('.bd-aside a[href="' + hash + '"]')
if (!link) {
return
}
var active = document.querySelector('.bd-aside .active')
var parent = link.parentNode.parentNode.previousElementSibling
link.classList.add('active')
if (parent.classList.contains('collapsed')) {
parent.click()
}
if (!active) {
return
}
var expanded = active.parentNode.parentNode.previousElementSibling
active.classList.remove('active')
if (expanded && parent !== expanded) {
expanded.click()
}
}
setActiveItem()
window.addEventListener('hashchange', setActiveItem)
})();
<?php
namespace Drupal\twbstools\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\Markup;
use Drupal\Core\StreamWrapper\PublicStream;
/**
* StyleguideController controller.
*/
class StyleguideController extends ControllerBase {
/**
* Returns a render-able array for a test page.
*/
public function render() {
$styleguide = file_get_contents(drupal_get_path('module', 'twbstools') . '/resources/cheatsheet/index.html');
$styleguide = str_replace('https://getbootstrap.com/docs/5.1/examples/cheatsheet/', '', $styleguide);
$html_dom = Html::load($styleguide);
$xpath = new \DOMXPath($html_dom);
// Body tag.
$dom_aside = $html_dom->getElementsByTagName('aside')->item(0);
$dom_cheatsheet = $html_dom->getElementsByTagName('div')->item(0);
$xpath_cheatsheet = $xpath->query("//*[contains(@class, 'bd-cheatsheet')]")->item(0);
// Remove headers.
/*if($header = $body_dom->getElementsByTagName('head')->item(0)) {
$header->parentNode->removeChild($header);
}
if($header = $body_dom->getElementsByTagName('header')->item(0)) {
$header->parentNode->removeChild($header);
}*/
//$html_styleguide = $body_dom->ownerDocument->saveXML($body_dom);
$html_aside = $dom_aside->ownerDocument->saveXML($dom_aside);
$html_cheatsheet = $xpath_cheatsheet->ownerDocument->saveXML($xpath_cheatsheet);
return [
'#markup' => Markup::create($html_aside . $html_cheatsheet),
'#attached' => [
'library' => [
'twbstools/twbstools.cheatsheet'
],
],
];
}
}
twbstools.cheatsheet:
version: VERSION
css:
component:
resources/cheatsheet/index_files/cheatsheet.css: {}
js:
resources/cheatsheet/index_files/cheatsheet.js: {}
dependencies:
- bootstrap5/bootstrap5-js-latest
twbstools.styleguide.render:
title: 'Styleguide'
description: 'Bootstrap.'
parent: system.admin_config_development
route_name: twbstools.styleguide.render
twbstools.styleguide.render:
route_name: twbstools.styleguide.render
base_route: twbstools.styleguide.render
title: 'Settings'
twbstools.styleguide.render:
path: '/styleguide'
defaults:
_controller: '\Drupal\twbstools\Controller\StyleguideController::render'
requirements:
_permission: 'access content'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment