From cc2b2060c278d116efedb61cea2e84e7e072810a Mon Sep 17 00:00:00 2001 From: Bysa Boro Date: Fri, 25 Oct 2024 20:10:09 +0100 Subject: [PATCH 1/7] Port expanding text and remove typography plugin (#740) Co-authored-by: Amitai Burstein --- robo-components/ThemeTrait.php | 3 + .../custom/server_general/src/ButtonTrait.php | 13 +- .../src/ElementTrait/CtaTrait.php | 2 +- .../src/ElementTrait/ExpandingTextTrait.php | 39 ++++++ .../src/ElementTrait/HeroTrait.php | 2 +- .../custom/server_style_guide/js/accordion.js | 2 + .../src/Controller/StyleGuideController.php | 43 +++++- .../server-style-guide-text-styles.html.twig | 129 +++++++++++------- .../custom/server_theme/package-lock.json | 64 --------- web/themes/custom/server_theme/package.json | 1 - .../server_theme/server_theme.libraries.yml | 8 ++ .../custom/server_theme/server_theme.theme | 18 ++- .../server_theme/src/js/expanding-text.js | 43 ++++++ .../custom/server_theme/src/js/toggler.js | 11 +- .../server_theme/src/pcss/typography.pcss | 122 +++++++++++++++-- .../custom/server_theme/tailwind.config.js | 6 +- .../server_theme/templates/page.html.twig | 2 +- .../templates/server-theme-button.html.twig | 6 +- ...er-theme-element--expanding-text.html.twig | 39 ++++++ .../server-theme-prose-text.html.twig | 2 +- 20 files changed, 409 insertions(+), 146 deletions(-) create mode 100644 web/modules/custom/server_general/src/ElementTrait/ExpandingTextTrait.php create mode 100644 web/themes/custom/server_theme/src/js/expanding-text.js create mode 100644 web/themes/custom/server_theme/templates/server-theme-element--expanding-text.html.twig diff --git a/robo-components/ThemeTrait.php b/robo-components/ThemeTrait.php index 72a796d05..345e7f479 100644 --- a/robo-components/ThemeTrait.php +++ b/robo-components/ThemeTrait.php @@ -71,6 +71,9 @@ private function doThemeCompile(bool $optimize = FALSE): void { $this->_copyDir(self::$themeBase . '/src/js', self::$themeBase . '/dist/js'); } + // Fonts. + $this->_copyDir(self::$themeBase . '/src/fonts', self::$themeBase . '/dist/fonts'); + // Images - Copy everything first. $this->_copyDir(self::$themeBase . '/src/images', self::$themeBase . '/dist/images'); diff --git a/web/modules/custom/server_general/src/ButtonTrait.php b/web/modules/custom/server_general/src/ButtonTrait.php index 9769b0a1c..b94eda636 100644 --- a/web/modules/custom/server_general/src/ButtonTrait.php +++ b/web/modules/custom/server_general/src/ButtonTrait.php @@ -22,8 +22,9 @@ trait ButtonTrait { * The button's title. * @param \Drupal\Core\Url $url * The button's URL as Url object. - * @param bool $is_primary - * Whether this is a primary button. Defaults to FALSE. + * @param string $button_type + * Type of button. Acceptable values: 'primary', 'secondary', 'tertiary'. + * Defaults to 'primary'. * @param string|null $icon * The name of the icon to add as prefix. Allowed values are: * - `download`. @@ -34,12 +35,16 @@ trait ButtonTrait { * @return array * The rendered button array. */ - protected function buildButton(array|string|TranslatableMarkup $title, Url $url, bool $is_primary = FALSE, ?string $icon = NULL, bool $open_new_tab = FALSE): array { + protected function buildButton(array|string|TranslatableMarkup $title, Url $url, string $button_type = 'primary', ?string $icon = NULL, bool $open_new_tab = FALSE): array { + $button_types = ['primary', 'secondary', 'tertiary']; + if (!in_array($button_type, $button_types)) { + $button_type = 'primary'; + } return [ '#theme' => 'server_theme_button', '#url' => $url, '#title' => $title, - '#is_primary' => $is_primary, + '#button_type' => $button_type, '#icon' => $icon, '#open_new_tab' => $open_new_tab, ]; diff --git a/web/modules/custom/server_general/src/ElementTrait/CtaTrait.php b/web/modules/custom/server_general/src/ElementTrait/CtaTrait.php index 8141891c1..4d17ec678 100644 --- a/web/modules/custom/server_general/src/ElementTrait/CtaTrait.php +++ b/web/modules/custom/server_general/src/ElementTrait/CtaTrait.php @@ -44,7 +44,7 @@ protected function buildElementCta(string $title, array $body, Link $link): arra $elements[] = $this->wrapProseText($body); // Button. - $elements[] = $this->buildButton($link->getText(), $link->getUrl(), TRUE, NULL, $link->getUrl()->isExternal()); + $elements[] = $this->buildButton($link->getText(), $link->getUrl(), 'primary', NULL, $link->getUrl()->isExternal()); $elements = $this->wrapContainerVerticalSpacingBig($elements, 'center'); diff --git a/web/modules/custom/server_general/src/ElementTrait/ExpandingTextTrait.php b/web/modules/custom/server_general/src/ElementTrait/ExpandingTextTrait.php new file mode 100644 index 000000000..4b53f993b --- /dev/null +++ b/web/modules/custom/server_general/src/ElementTrait/ExpandingTextTrait.php @@ -0,0 +1,39 @@ + 'server_theme_element__expanding_text', + '#text' => $text, + '#lines_to_clamp' => $lines_to_clamp, + '#button_label_more' => $button_label_more, + '#button_label_less' => $button_label_less, + ]; + } + +} diff --git a/web/modules/custom/server_general/src/ElementTrait/HeroTrait.php b/web/modules/custom/server_general/src/ElementTrait/HeroTrait.php index d04eb2b10..baf57475c 100644 --- a/web/modules/custom/server_general/src/ElementTrait/HeroTrait.php +++ b/web/modules/custom/server_general/src/ElementTrait/HeroTrait.php @@ -45,7 +45,7 @@ protected function buildElementHeroImage(array $image, string $title, string $su // Button. if ($link) { - $elements[] = $this->buildButton($link->getText(), $link->getUrl(), TRUE, NULL, $link->getUrl()->isExternal()); + $elements[] = $this->buildButton($link->getText(), $link->getUrl(), 'primary', NULL, $link->getUrl()->isExternal()); } $elements = $this->wrapContainerVerticalSpacingBig($elements); diff --git a/web/modules/custom/server_style_guide/js/accordion.js b/web/modules/custom/server_style_guide/js/accordion.js index dd3f69422..cd6b4f355 100644 --- a/web/modules/custom/server_style_guide/js/accordion.js +++ b/web/modules/custom/server_style_guide/js/accordion.js @@ -21,6 +21,8 @@ } $slick.slick('setPosition'); }); + // Trigger resize. + $(window).trigger('resize'); }); // Check if hash exist, and if so try to open its pane. diff --git a/web/modules/custom/server_style_guide/src/Controller/StyleGuideController.php b/web/modules/custom/server_style_guide/src/Controller/StyleGuideController.php index 882130c23..79237e121 100644 --- a/web/modules/custom/server_style_guide/src/Controller/StyleGuideController.php +++ b/web/modules/custom/server_style_guide/src/Controller/StyleGuideController.php @@ -15,6 +15,7 @@ use Drupal\server_general\ElementTrait\CarouselTrait; use Drupal\server_general\ElementTrait\CtaTrait; use Drupal\server_general\ElementTrait\DocumentsTrait; +use Drupal\server_general\ElementTrait\ExpandingTextTrait; use Drupal\server_general\ElementTrait\HeroTrait; use Drupal\server_general\ElementTrait\InfoCardTrait; use Drupal\server_general\ElementTrait\NewsTeasersTrait; @@ -46,6 +47,7 @@ class StyleGuideController extends ControllerBase { use ElementNodeNewsTrait; use ElementLayoutTrait; use ElementWrapTrait; + use ExpandingTextTrait; use HeroTrait; use InfoCardTrait; use LinkTrait; @@ -146,6 +148,12 @@ protected function getAllElements() : array { $element = $this->getDocuments(); $build[] = $this->wrapElementNoContainer($element, 'Element: Documents list'); + $element = $this->getExpandingText(); + $build[] = $this->wrapElementNoContainer($element, 'Element: Expanding text'); + + $element = $this->getExpandingText(3, 'More', 'Less'); + $build[] = $this->wrapElementNoContainer($element, 'Element: Expanding text - 3 lines, custom buttons'); + $element = $this->getHeroImage(); $build[] = $this->wrapElementNoContainer($element, 'Element: Hero image'); @@ -499,13 +507,17 @@ protected function getButtons(): array { $url = Url::fromRoute(''); // Primary button with icon. - $element = $this->buildButton('Download file', $url, TRUE, 'download'); + $element = $this->buildButton($this->t('Download file'), $url, 'primary', 'download'); $build[] = $this->wrapElementWideContainer($element, 'Primary button'); // Secondary button. - $element = $this->buildButton('Register', $url, FALSE); + $element = $this->buildButton($this->t('Register'), $url, 'secondary'); $build[] = $this->wrapElementWideContainer($element, 'Secondary button'); + // Tertiary button. + $element = $this->buildButton($this->t('Login'), $url, 'tertiary'); + $build[] = $this->wrapElementWideContainer($element, 'Tertiary button'); + return $build; } @@ -758,11 +770,23 @@ protected function buildImage(string $url) { * A render array. */ protected function buildProcessedText(string $text) { - return [ + // Emulate core processed text by wrapping the text in div.text-formatted. + $element = [ + '#type' => 'container', + '#attributes' => [ + 'class' => [ + 'text-formatted', + ], + ], + ]; + + $element[] = [ '#type' => 'processed_text', '#text' => $text, '#format' => filter_default_format(), ]; + + return $element; } /** @@ -855,4 +879,17 @@ protected function getRelatedContent(int $num = 5, bool $is_featured = FALSE): a return $elements; } + /** + * Get a sample Expanding Text element. + * + * @return array + * The render array. + */ + protected function getExpandingText(?int $lines_to_clamp = NULL, ?string $button_label_more = NULL, ?string $button_label_less = NULL): array { + $element = ['#theme' => 'server_style_guide_text_styles']; + $element = $this->wrapProseText($element); + + return $this->wrapContainerWide($this->buildElementExpandingText($element, $lines_to_clamp, $button_label_more, $button_label_less)); + } + } diff --git a/web/modules/custom/server_style_guide/templates/server-style-guide-text-styles.html.twig b/web/modules/custom/server_style_guide/templates/server-style-guide-text-styles.html.twig index b6ba6815f..1e9b5ba78 100644 --- a/web/modules/custom/server_style_guide/templates/server-style-guide-text-styles.html.twig +++ b/web/modules/custom/server_style_guide/templates/server-style-guide-text-styles.html.twig @@ -1,61 +1,84 @@ -

This is an example for h1

-

This is an example for h2

-

This is an example for h3

-

This is an example for h4

-
This is an example for h5
- -
    -
  • Item 1
  • -
  • Item 2
  • -
  • Item 3
  • -
- -
    -
  1. Item 1
  2. -
  3. Item 2
  4. -
  5. Item 3
  6. -
- -

- This is a long paragraph that has some text. - Opulence to into a never no unprofitable a and the much she musical someone - she turner eating I text agreed terms, higher to cache thoughts up, common - ever better work, that been a ages, behind of make one vows, shut as much - shown horses he essential loyalty. That is it an almost clean set the her so - there out throughout. And feel make mouth. In somewhere, way. Was the - intrigued sovereignty. That by he sign such, win promptness he of stiff. -

- -
- This is a blockquote. -
- -
- This is a link -
+
+

This is an example for h1

+

This is an example for h2

+

This is an example for h3

+

This is an example for h4

+
This is an example for h5
-
- This is bold text -
+
    +
  • Item 1
  • +
  • Item 2
  • +
  • Item 3
  • +
-
- This is italic text -
+
    +
  1. Item 1
  2. +
  3. Item 2
  4. +
  5. Item 3
  6. +
-
- This is deleted text -
+

+ This is a long paragraph that has some text. + Opulence to into a never no unprofitable a and the much she musical someone + she turner eating I text agreed terms, higher to cache thoughts up, common + ever better work, that been a ages, behind of make one vows, shut as much + shown horses he essential loyalty. That is it an almost clean set the her so + there out throughout. And feel make mouth. In somewhere, way. Was the + intrigued sovereignty. That by he sign such, win promptness he of stiff. +

-
- This is inserted text -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Col 1This is an example of a really long table headerColumn 3Miscellaneous
Side header 1Data 1Data 1Data 1
Side header 2Data 2Data 2Data 2
Side header 3Data 3Data 3Data 3
-
- This is superscript text -
+
+ This is a blockquote. +
-
- This is subscript text -
+

+ This is a link +

+ +

+ This is bold text +

+

+ This is italic text +

+

+ This is superscript text +

+ +

+ This is subscript text +

+
diff --git a/web/themes/custom/server_theme/package-lock.json b/web/themes/custom/server_theme/package-lock.json index 5286f3f50..ab6626ac8 100644 --- a/web/themes/custom/server_theme/package-lock.json +++ b/web/themes/custom/server_theme/package-lock.json @@ -6,7 +6,6 @@ "": { "devDependencies": { "@tailwindcss/forms": "^0.5.3", - "@tailwindcss/typography": "^0.5.7", "autoprefixer": "^10.4.12", "cssnano": "^5.1.13", "minify": "^9.1.0", @@ -407,21 +406,6 @@ "tailwindcss": ">=3.0.0 || >= 3.0.0-alpha.1" } }, - "node_modules/@tailwindcss/typography": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.7.tgz", - "integrity": "sha512-JTTSTrgZfp6Ki4svhPA4mkd9nmQ/j9EfE7SbHJ1cLtthKkpW2OxsFXzSmxbhYbEkfNIyAyhle5p4SYyKRbz/jg==", - "dev": true, - "dependencies": { - "lodash.castarray": "^4.4.0", - "lodash.isplainobject": "^4.0.6", - "lodash.merge": "^4.6.2", - "postcss-selector-parser": "6.0.10" - }, - "peerDependencies": { - "tailwindcss": ">=3.0.0 || insiders" - } - }, "node_modules/@trysound/sax": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz", @@ -1534,12 +1518,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash.castarray": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.castarray/-/lodash.castarray-4.4.0.tgz", - "integrity": "sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==", - "dev": true - }, "node_modules/lodash.difference": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", @@ -1564,24 +1542,12 @@ "integrity": "sha1-Cwih3PaDl8OXhVwyOXg4Mt90A9E=", "dev": true }, - "node_modules/lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", - "dev": true - }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true - }, "node_modules/lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", @@ -4043,18 +4009,6 @@ "mini-svg-data-uri": "^1.2.3" } }, - "@tailwindcss/typography": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.7.tgz", - "integrity": "sha512-JTTSTrgZfp6Ki4svhPA4mkd9nmQ/j9EfE7SbHJ1cLtthKkpW2OxsFXzSmxbhYbEkfNIyAyhle5p4SYyKRbz/jg==", - "dev": true, - "requires": { - "lodash.castarray": "^4.4.0", - "lodash.isplainobject": "^4.0.6", - "lodash.merge": "^4.6.2", - "postcss-selector-parser": "6.0.10" - } - }, "@trysound/sax": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz", @@ -4843,12 +4797,6 @@ "p-locate": "^6.0.0" } }, - "lodash.castarray": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.castarray/-/lodash.castarray-4.4.0.tgz", - "integrity": "sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==", - "dev": true - }, "lodash.difference": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", @@ -4873,24 +4821,12 @@ "integrity": "sha1-Cwih3PaDl8OXhVwyOXg4Mt90A9E=", "dev": true }, - "lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", - "dev": true - }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, - "lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true - }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", diff --git a/web/themes/custom/server_theme/package.json b/web/themes/custom/server_theme/package.json index f624eedd5..626cd6c95 100644 --- a/web/themes/custom/server_theme/package.json +++ b/web/themes/custom/server_theme/package.json @@ -2,7 +2,6 @@ "scripts": {}, "devDependencies": { "@tailwindcss/forms": "^0.5.3", - "@tailwindcss/typography": "^0.5.7", "autoprefixer": "^10.4.12", "cssnano": "^5.1.13", "minify": "^9.1.0", diff --git a/web/themes/custom/server_theme/server_theme.libraries.yml b/web/themes/custom/server_theme/server_theme.libraries.yml index 8594d955c..ebebd4648 100644 --- a/web/themes/custom/server_theme/server_theme.libraries.yml +++ b/web/themes/custom/server_theme/server_theme.libraries.yml @@ -80,3 +80,11 @@ messages: dist/js/messages.js: {} dependencies: - core/drupal + +expanding-text: + js: + dist/js/expanding-text.js: {} + dependencies: + - core/drupal + - core/jquery + - core/once diff --git a/web/themes/custom/server_theme/server_theme.theme b/web/themes/custom/server_theme/server_theme.theme index a284cace5..64e2bc068 100644 --- a/web/themes/custom/server_theme/server_theme.theme +++ b/web/themes/custom/server_theme/server_theme.theme @@ -271,8 +271,8 @@ function server_theme_theme() { 'url' => NULL, // The button's text. 'title' => NULL, - // Indicate if button should be primary or secondary. - 'is_primary' => NULL, + // Specify button type. One of: 'primary', 'secondary' or 'tertiary'. + 'button_type' => NULL, // Specify an icon. Any icon should be added as SVG in // `server-theme-button`. 'icon' => NULL, @@ -468,6 +468,20 @@ function server_theme_theme() { ], ]; + // An element which displays clamped text with "Read more" option. + $info['server_theme_element__expanding_text'] = [ + 'variables' => [ + // This needs to be a processed text wrapped with `text-formatted` class + // (i.e., a processed text field type). + 'text' => NULL, + // Customize the Read more/less button text if needed. + 'button_label_more' => NULL, + 'button_label_less' => NULL, + // Customize how much clamping is done. 1 to 6. Default is 6. + 'lines_to_clamp' => NULL, + ], + ]; + // Media document. $info['server_theme_media__document'] = [ 'variables' => [ diff --git a/web/themes/custom/server_theme/src/js/expanding-text.js b/web/themes/custom/server_theme/src/js/expanding-text.js new file mode 100644 index 000000000..de3dd1419 --- /dev/null +++ b/web/themes/custom/server_theme/src/js/expanding-text.js @@ -0,0 +1,43 @@ +/** + * @file + * JS for button controls. + */ +(function ($, Drupal, once) { + Drupal.behaviors.expandingText = { + attach: function(context, settings) { + const $expandingText = $(once('expanding-text', '.js-expanding-text', context)); + if (!$expandingText.length) { + return; + } + + const checkExpandingText = function() { + $expandingText.each(function () { + const $text = $(this).find('.text-formatted'); + if (!$text.length) { + return; + } + const $button = $(this).find('button'); + const $textHeight = $text.height(); + const $textScrollHeight = $text.prop('scrollHeight'); + + // If the text was clamped, the scrollHeight will be higher than the + // height. + if ($textHeight < $textScrollHeight) { + // Text is clamped, if the button's hidden, reveal it. + if ($button.hasClass('hidden')) { + $button.removeClass('hidden'); + } + return; + } + + // Text is not clamped, hide the button. + $button.addClass('hidden'); + }); + } + + checkExpandingText(); + + $(window).on('resize', checkExpandingText); + } + } +})(jQuery, Drupal, once); diff --git a/web/themes/custom/server_theme/src/js/toggler.js b/web/themes/custom/server_theme/src/js/toggler.js index 8f84f07e3..47c3dda0d 100644 --- a/web/themes/custom/server_theme/src/js/toggler.js +++ b/web/themes/custom/server_theme/src/js/toggler.js @@ -25,7 +25,16 @@ if (!$target.length) { return; } - $target.toggleClass('hidden'); + + // Sometimes we don't want to toggle .hidden class. In such cases you + // can add data-toggle-strategy="aria-expanded" to the button, and this + // will instead toggle the aria-expanded property on the target element. + if ($this.data('toggleStrategy') === 'aria-expanded') { + $target.attr('aria-expanded', $target.attr('aria-expanded') === 'true' ? 'false' : 'true') + } + else { + $target.toggleClass('hidden'); + } $this.attr('aria-expanded', $this.attr('aria-expanded') === 'true' ? 'false' : 'true'); // Handle has-scroll class. It's nice to know element has scrollbar diff --git a/web/themes/custom/server_theme/src/pcss/typography.pcss b/web/themes/custom/server_theme/src/pcss/typography.pcss index 2c813a2ed..4e1ebebd7 100644 --- a/web/themes/custom/server_theme/src/pcss/typography.pcss +++ b/web/themes/custom/server_theme/src/pcss/typography.pcss @@ -14,16 +14,118 @@ body { @apply text-gray-900; } -// Remove the top/ bottom margin from the first/ last element of a prose. -.prose .text-formatted > :first-child { - @apply mt-0; -} +.prose { + // Apply default spacing to all formatted text elements. + .text-formatted > * { + @apply my-5 md:my-6 lg:my-8; + } -.prose .text-formatted > :last-child { - @apply mb-0; -} + // Remove top margin from first element, and bottom margin from last element. + .text-formatted > :first-child { + @apply mt-0; + } + .text-formatted > :last-child { + @apply mb-0; + } + + // Remove margins from images. + figure, + img { + @apply my-0; + } + + // Styling for text elements. + h1 { + @apply text-4xl md:text-5xl lg:text-6xl font-bold; + } + + h2 { + @apply text-3xl md:text-4xl lg:text-5xl font-bold; + } + + h3 { + @apply text-2xl md:text-3xl lg:text-4xl font-bold; + } + + h4 { + @apply text-xl md:text-2xl lg:text-3xl font-bold; + } + + h5 { + @apply text-lg md:text-xl lg:text-2xl font-bold; + } + + h6 { + @apply text-lg md:text-xl lg:text-2xl; + } + + p, + ul, + ol, + blockquote { + @apply text-base lg:text-lg; + } + + ul, + ol { + @apply ps-6 md:ps-8 lg:ps-10; + + li { + @apply my-1 md:my-2 lg:my-3 marker:text-gray-500; + } + } + + ul { + @apply list-disc; + } + + ol { + @apply list-decimal; + } + + a { + @apply underline decoration-2 underline-offset-4 decoration-blue-500 hover:decoration-emerald-900 hover:underline-offset-6 focus-visible:decoration-emerald-900 focus-visible:underline-offset-6 transition-all duration-300; + } + + blockquote { + @apply ps-4 md:ps-5 lg:ps-6 border-s-4 border-slate-400; + } + + table { + @apply table-auto w-full text-sm lg:text-base; + + thead tr { + @apply border-b-2 border-gray-200 bg-gray-300; + } + + th { + @apply align-bottom font-bold; + } + + td { + @apply align-top; + } + + th, + td { + @apply py-1 md:py-2 px-1 text-start; + } + + tbody { + @apply border-b-2 border-gray-200; + } + + tbody tr { + @apply border-b border-gray-100; + + &:hover { + @apply bg-lime-100; + } + } + + } -.prose .text-formatted figure, -.prose .text-formatted img { - @apply my-0; } + + + diff --git a/web/themes/custom/server_theme/tailwind.config.js b/web/themes/custom/server_theme/tailwind.config.js index 832867be8..058a0dac5 100644 --- a/web/themes/custom/server_theme/tailwind.config.js +++ b/web/themes/custom/server_theme/tailwind.config.js @@ -4,8 +4,11 @@ module.exports = { theme: { extend: { maxWidth: { - '8xl': '90rem', + '8xl': '90rem' }, + textUnderlineOffset: { + '6': '6px' + } }, fontFamily: { 'headers': ["Roboto", 'sans-serif'], @@ -29,6 +32,5 @@ module.exports = { ], plugins: [ require('@tailwindcss/forms'), - require('@tailwindcss/typography'), ], }; diff --git a/web/themes/custom/server_theme/templates/page.html.twig b/web/themes/custom/server_theme/templates/page.html.twig index 5a864e7f7..9ed1e483b 100644 --- a/web/themes/custom/server_theme/templates/page.html.twig +++ b/web/themes/custom/server_theme/templates/page.html.twig @@ -42,7 +42,7 @@ * @see html.html.twig */ #} -
+