From 129130f156de1e00169d72e15fb0a6e0ee169441 Mon Sep 17 00:00:00 2001 From: NiclasNorin <103985736+NiclasNorin@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:55:31 +0100 Subject: [PATCH] feat: allow elements to be placed outside of typography context (#359) Co-authored-by: Niclas Norin --- source/php/Component/Typography/Typography.php | 9 +++++---- source/php/Component/Typography/typography.json | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/php/Component/Typography/Typography.php b/source/php/Component/Typography/Typography.php index 7d6454c3..46d9692b 100644 --- a/source/php/Component/Typography/Typography.php +++ b/source/php/Component/Typography/Typography.php @@ -14,17 +14,18 @@ public function init() { //Set default $this->data['isPromotedHeading'] = false; $this->data['originalElement'] = $element; - - if (substr($element, 0, 1) == 'h') { + $this->data['element'] = $element; + + if ($useHeadingsContext && substr($element, 0, 1) == 'h') { $this->data['element'] = $this->setMaxHeading($element); } //If this is the first heading of the page, promote it to h1 - if (!self::$hasSeenH1 && substr($this->data['element'], 0, 2) == 'h1') { + if ($useHeadingsContext && !self::$hasSeenH1 && substr($this->data['element'], 0, 2) == 'h1') { self::$hasSeenH1 = true; } - if ($autopromote === true && !self::$hasSeenH1) { + if ($useHeadingsContext && $autopromote === true && !self::$hasSeenH1) { if (in_array($element, ['h1', 'h2', 'h3'])) { $this->data['isPromotedHeading'] = true; $this->data['element'] = 'h1'; diff --git a/source/php/Component/Typography/typography.json b/source/php/Component/Typography/typography.json index f0f2dc1d..dfdd19b4 100644 --- a/source/php/Component/Typography/typography.json +++ b/source/php/Component/Typography/typography.json @@ -4,13 +4,15 @@ "variant": "p", "element": "p", "slot": "", - "autopromote" : false + "autopromote" : false, + "useHeadingsContext": true }, "description": { "variant": "What element the component should base its looks off of.", "element": "What element the markup will use.", "slot": "The content", - "autopromote" : "Upgrade element to h1 (from h3 and above), if seen first on page." + "autopromote" : "Upgrade element to h1 (from h3 and above), if seen first on page.", + "useHeadingsContext": "If a heading should be based off of the context its in." }, "view": "typography.blade.php", "dependency": {