Skip to content

Commit c9d7c47

Browse files
committed
Refactor custom icons implementation to use SCSS and improve font-face handling
1 parent 0b31cb9 commit c9d7c47

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

src/styles/icons/custom/custom-icons-def.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,18 @@ const customIconsMeta = document.querySelector('meta[name="gtt-font-custom-icons
1313
const customIconsUrl = customIconsMeta ? customIconsMeta.getAttribute('content') : 'data:application/font-woff2;base64,'; // Provide a data URL for an empty font
1414

1515
// Dynamically create the @font-face rule
16-
if (customIconsUrl) {
17-
// Remove the existing @font-face rule
18-
const styleSheets = document.styleSheets;
19-
for (let i = 0; i < styleSheets.length; i++) {
20-
const cssRules = styleSheets[i].cssRules || styleSheets[i].rules;
21-
for (let j = 0; j < cssRules.length; j++) {
22-
const rule = cssRules[j];
23-
if (rule instanceof CSSFontFaceRule && rule.style.fontFamily === 'custom-icons') {
24-
styleSheets[i].deleteRule(j);
25-
break;
26-
}
27-
}
16+
const style = document.createElement('style');
17+
style.type = 'text/css';
18+
style.innerHTML = `
19+
@font-face {
20+
font-family: 'custom-icons';
21+
font-style: normal;
22+
font-weight: 400;
23+
font-display: block;
24+
src: url(${customIconsUrl}) format('woff2');
2825
}
29-
30-
const style = document.createElement('style');
31-
style.innerHTML = `
32-
@font-face {
33-
font-family: 'custom-icons';
34-
font-style: normal;
35-
font-weight: 400;
36-
font-display: block;
37-
src: url(${customIconsUrl}) format('woff2');
38-
}
39-
`;
40-
document.head.appendChild(style);
41-
}
26+
`;
27+
document.head.appendChild(style);
4228

4329
// Define the font face
4430
let customFont: FontFace;

src/styles/icons/custom/custom-icons.css renamed to src/styles/icons/custom/custom-icons.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
$custom-icons-path: unquote('RAILS_ASSET_URL("custom-icons.woff2")');
2+
13
@font-face {
24
font-family: "custom-icons";
35
font-style: normal;
46
font-weight: 400;
57
font-display: block;
6-
src: url("./custom-icons.woff2") format("woff2");
8+
src: url(#{$custom-icons-path}) format("woff2");
79
}
810

911
.custom-icons {

src/styles/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'ol-ext/dist/ol-ext.min.css';
88
import './scss/app.scss';
99

1010
// Import custom icons CSS file for adding custom icon designs in the application
11-
import './icons/custom/custom-icons.css';
11+
import './icons/custom/custom-icons.scss';
1212

1313
// Import custom icons definition JS file to define icon names, sizes, and variations
1414
import './icons/custom/custom-icons-def';

webpack.config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ const path = require('path');
33
// Define loaders
44
// Loaders for processing Sass files
55
const sassLoaders = [
6-
'style-loader', // Creates `style` nodes from JS strings
7-
'css-loader', // Translates CSS into CommonJS
8-
'sass-loader', // Compiles Sass to CSS
6+
'style-loader',
7+
{
8+
loader: 'css-loader',
9+
options: {
10+
url: false, // Prevent css-loader from interpreting URLs
11+
},
12+
},
13+
'sass-loader',
914
];
1015

1116
// Loaders for processing CSS files

0 commit comments

Comments
 (0)