1<?php
2
3
4namespace ComboStrap;
5
6
7use syntax_plugin_combo_text;
8
9class LineSpacing
10{
11
12    const CANONICAL = syntax_plugin_combo_text::TAG;
13
14
15    /**
16     * Process the line-spacing attribute
17     * https://getbootstrap.com/docs/5.0/utilities/text/#line-height
18     * @param TagAttributes $attributes
19     */
20    public static function processLineSpacingAttributes(&$attributes)
21    {
22
23        // Spacing is just a class
24        $lineSpacing = "line-spacing";
25        if ($attributes->hasComponentAttribute($lineSpacing)) {
26
27            $bootstrapVersion = Bootstrap::getBootStrapMajorVersion();
28            if ($bootstrapVersion != Bootstrap::BootStrapFiveMajorVersion) {
29                LogUtility::msg("The line-spacing attribute is only implemented with Bootstrap 5. If you want to use this attribute, you should " . PluginUtility::getDocumentationHyperLink(Bootstrap::CANONICAL, "change the Bootstrap version") . ".", self::CANONICAL);
30                return;
31            }
32
33            $lineSpacingValue = trim(strtolower($attributes->getValueAndRemove($lineSpacing)));
34            switch ($lineSpacingValue) {
35                case "xs":
36                case "extra-small":
37                    $attributes->addClassName("lh-1");
38                    break;
39                case "sm":
40                case "small":
41                    $attributes->addClassName("lh-sm");
42                    break;
43                case "md":
44                case "medium":
45                    $attributes->addClassName("lh-base");
46                    break;
47                case "lg":
48                case "large":
49                    $attributes->addClassName("lh-lg");
50                    break;
51                default:
52                    LogUtility::msg("The line-spacing value ($lineSpacingValue) is not a valid value.", LogUtility::LVL_MSG_ERROR, self::CANONICAL);
53                    break;
54            }
55        }
56    }
57
58}
59