- Issue created by @asherry
- Assigned to asherry
- 🇦🇹Austria hudri Austria
Given the popularity of TailwindCSS and other utility class approaches, I think prefix and suffix are not sufficent. Prefix and suffix will cover many use cases, but taking the Tailwind syntax as an example, I would propose using a full regex to cover the following common use-cases:
Arbitrary values in Tailwind:
[100px,200px,300px] ==> min-h-[100px] or min-h-[200px] min-h-[300px]
Max or range breakpoints in Tailwind:
[sm,md,lg] ==> max-sm:hidden or max-md:hidden or max-lg:hiddenI've done something similar in my own custom style option plugin. Would love to see something similar in the module itself:
/** * Defines the HTML attribute style option plugin. * * @code * my_example_style_option: * plugin: html_attribute * # Preprocess the value with PHP's preg_place before rendering. E.g. massage an number input field * # to a Tailwind CSS class. In the following example an input "1700" will be rendered as "max-w-[1700px]". * value_preg_replace: * pattern: '/^(\d+)$/' * replacement: 'max-w-[${0}px]' * @endcode * * @StyleOption( * id = "html_attribute", * label = @Translation("Html attribute") * ) */ class HtmlAttribute extends StyleOptionPluginBase { /* ... */ public function build(array $build, string $region_id = NULL) { /* ... */ if ($preg_replace = $this->getConfiguration('value_preg_replace')) { $value = preg_replace($preg_replace['pattern'], $preg_replace['replacement'], $value, $preg_replace['limit'] ?? -1); } if (empty($value)) { $value = 'INVALID_PREG_REPLACE_SUBJECT'; } /* ... */ } }
Full code here:
https://bitbucket.org/webtourismus/designsystem/src/master/src/Plugin/St...