Skip to content

Commit e80db22

Browse files
committed
Initial commit
0 parents  commit e80db22

File tree

167 files changed

+13644
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+13644
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
js/node_modules
2+
.sass-cache

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Mergado UI Library
2+
3+
## Styles
4+
5+
Stylesheet is available as both SASS source and compiled/minified CSS.
6+
We included basics like css reset, typography, icons and of course styles for individual UI components.
7+
8+
## Images / Icons
9+
10+
All (two) images needed are inlined into CSS. Only icons are as extra files.
11+
12+
We use technique called SVG sprite. That means all icons are in a single svg file. We included this file, source svg files for each icons and script which will generate sprite file from source icons, it's in `bin` folder.
13+
14+
## Javascript
15+
16+
Checkboxes and radiobuttons are notoriously hard to style.
17+
We use some JS magic, to help us with that and decided to share it with you.
18+
Just put `script` tag pointing to this JS script this in your HTML and you're good to go.
19+
20+
Unless you're using React or similar framework. In that case, you are better of writing your own component in your framework style.
21+
22+
## Docs
23+
24+
[Mergado Docs](https://mergado.github.io/docs/design/intro.html)

bin/crateSvgSprite.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* For icons, we're using SVG sprite technique. This big svg would be PITA to
6+
* maintain, so source icons are in single files. This script takes all .svg
7+
* files from given folder (recursively) and combines them into that svg sprite.
8+
*/
9+
10+
// Some setup.
11+
$inputPath = __DIR__ . '/../icons';
12+
$outputPath = realpath(__DIR__ . '/../build') . '/muil.icons.svg';
13+
14+
15+
/**
16+
* Read directory recursively and return it's content in array filename => file content.
17+
*
18+
* @param string Icon directory location.
19+
* @param string Icon prefix (directory name) - used when called recursively.
20+
* @return array<iconName, svgCode>
21+
*/
22+
function readIcons(string $path, string $prefix = ''): array {
23+
$icons = [];
24+
25+
foreach (new FilesystemIterator($path) as $fileInfo) {
26+
if ($fileInfo->getExtension() === 'svg') {
27+
$id = $fileInfo->getBasename('.svg');
28+
$id = $prefix ? $prefix . '-' . $id : $id;
29+
$icons[$id] = file_get_contents($fileInfo->getPathname());
30+
} elseif ($fileInfo->isDir()) {
31+
$dirName = $fileInfo->getFilename();
32+
$icons = array_merge($icons, readIcons($fileInfo->getRealPath(), $dirName));
33+
}
34+
}
35+
36+
return $icons;
37+
}
38+
39+
/**
40+
* Convert SVG file into SVG symbol tag.
41+
*
42+
* @param string Icon SVG source.
43+
* @param string Icon name
44+
* @return string
45+
*/
46+
function fileToSymbol(string $svg, string $id): string {
47+
$svg = str_replace(' ', null, $svg);
48+
$svg = str_replace("\n", null, $svg);
49+
$svg = str_replace(' xmlns="http://www.w3.org/2000/svg"', null, $svg);
50+
$svg = str_replace('<svg ', sprintf('<symbol id="%s" ', $id), $svg);
51+
$svg = str_replace('</svg>', '</symbol>', $svg);
52+
53+
// Unfuck firefox.
54+
$svg = preg_replace('/ width="[0-9]+"/', null, $svg);
55+
$svg = preg_replace('/ height="[0-9]+"/', null, $svg);
56+
57+
return trim($svg) . PHP_EOL;
58+
}
59+
60+
61+
// Read symbols.
62+
$symbols = [];
63+
$icons = readIcons($inputPath);
64+
$count = count($icons);
65+
echo "Processing $count files \n";
66+
foreach ($icons as $id => $svg) {
67+
$symbols[$id] = fileToSymbol($svg, $id);
68+
echo ".";
69+
}
70+
71+
ksort($symbols);
72+
73+
echo "\n";
74+
echo "Exporting sprite: $outputPath";
75+
76+
// Write sprite.
77+
file_put_contents($outputPath, sprintf(
78+
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">%s</svg>%s',
79+
implode('', $symbols), PHP_EOL
80+
));
81+
echo "\n";
82+

0 commit comments

Comments
 (0)