Skip to content

Commit

Permalink
feat: allow elements to be placed outside of typography context (#359)
Browse files Browse the repository at this point in the history
Co-authored-by: Niclas Norin <niclas.norin@helsingborg.se>
  • Loading branch information
NiclasNorin and Niclas Norin authored Feb 13, 2024
1 parent 52423c4 commit 129130f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions source/php/Component/Typography/Typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 4 additions & 2 deletions source/php/Component/Typography/typography.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 129130f

Please sign in to comment.