From 2f8cb76778cacab4cc9c334ac4327029c99dc4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Garn=C3=A6s?= Date: Tue, 30 Apr 2024 00:06:08 +0200 Subject: [PATCH 1/8] Encode inline SVGs When using an inline SVG it must be encoded. Otherwise browsers may choke on it due to unescaped characters like < and ". At the moment problem can be seen when the Chromatic/Cypress integration tries to generate pages with inline CSS. Without this process fails and CSS is never loaded. To address this we encode the inline CSS using https://yoksel.github.io/url-encoder/. A proper SCSS function to address this would be preferable but I could not find such a thing. We only have two actual instances of inline SVGs to for now it should be OK to just change these. The fact that this is a nice change is also indicated by the fact that we no longer have stylelint issues that has to be ignored. --- .../material-header/material-periodical-select.scss | 2 +- src/styles/scss/tools/placeholder.scss | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/stories/Library/material-header/material-periodical-select.scss b/src/stories/Library/material-header/material-periodical-select.scss index 0fa7e677b..1c0dd8ae1 100644 --- a/src/stories/Library/material-header/material-periodical-select.scss +++ b/src/stories/Library/material-header/material-periodical-select.scss @@ -20,7 +20,7 @@ $icon-position: 10px; background-repeat: no-repeat; background-size: 6px; // This is a copy from icons/basic/icon-select-arrow - background-image: url('data:image/svg+xml;utf8, '); + background-image: url("data:image/svg+xml;utf8,%3Csvg width='6' height='5' viewBox='0 0 6 5' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.75821 0.708313L3 3.95101L1.24179 0.708313L4.75821 0.708313Z' fill='black' stroke='black'/%3E%3C/svg%3E"); background-position: 100%; padding-right: $icon-position; } diff --git a/src/styles/scss/tools/placeholder.scss b/src/styles/scss/tools/placeholder.scss index ee28135c3..cae1fd237 100644 --- a/src/styles/scss/tools/placeholder.scss +++ b/src/styles/scss/tools/placeholder.scss @@ -28,9 +28,7 @@ background-repeat: no-repeat; background-size: cover; background-position: center; - // stylelint-disable -- Stylelint really does not enjoy embedded IMGs. - background-image: url('data:image/svg+xml,'); - // stylelint-enable + background-image: url("data:image/svg+xml,%3Csvg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 852.2 17' style='enable-background:new 0 0 852.2 17;' xml:space='preserve'%3E%3Cstyle type='text/css'%3E.st0%7Bfill:none;stroke:%2523000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;%7D%3C/style%3E%3Cpath class='st0' d='M7.9,8.7c52-1.3,131.1-3,227.7-4.3c83.7-1.1,243.5,1.2,325.2,4.3c43.3,1.6,166.2-4.9,284.4-2.7'/%3E%3C/svg%3E"); } } @@ -40,9 +38,7 @@ &::before { width: 80px; right: auto; - // stylelint-disable -- Stylelint really does not enjoy embedded IMGs. - background-image: url('data:image/svg+xml,'); - // stylelint-enable + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='81' height='16' viewBox='0 0 81 16' fill='none'%3E%3Cpath d='M3 10C29.8561 3.71312 50.1886 4.9889 78 5.35819' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); } } From e56846d94dafff626b788eb37c1bba8f62c12585 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Wed, 10 Jul 2024 11:47:07 +0200 Subject: [PATCH 2/8] Refactored Underlined Title for `Slider` This commit refactors the underlined title for the `Slider` component. Related pull request: [#1364](https://github.com/danskernesdigitalebibliotek/dpl-cms/pull/1364) --- src/stories/Library/slider/Slider.stories.tsx | 2 +- src/stories/Library/slider/Slider.tsx | 9 ++++++++- src/stories/Library/slider/slider.scss | 4 +--- src/styles/scss/tools/placeholder.scss | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/stories/Library/slider/Slider.stories.tsx b/src/stories/Library/slider/Slider.stories.tsx index bedd4b10d..cc880dab2 100644 --- a/src/stories/Library/slider/Slider.stories.tsx +++ b/src/stories/Library/slider/Slider.stories.tsx @@ -17,7 +17,7 @@ export default { }, argTypes: { title: { - defaultValue: "Inspiration", + defaultValue: "Get new Inspiration", type: "string", }, items: { diff --git a/src/stories/Library/slider/Slider.tsx b/src/stories/Library/slider/Slider.tsx index 2049b48a5..b70bfad10 100644 --- a/src/stories/Library/slider/Slider.tsx +++ b/src/stories/Library/slider/Slider.tsx @@ -24,7 +24,14 @@ const Slider: FC = ({ title, items }) => {
- {title ?

{title}

: ""} + {title && ( +

) words. + // eslint-disable-next-line react/no-danger + dangerouslySetInnerHTML={{ __html: title }} + /> + )}