Skip to content

Commit ab18e1c

Browse files
author
Maxim Vanhove
committed
Add new styles
1 parent 8672076 commit ab18e1c

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

src/FontAwesomeSVG.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public function get_icon_details($id) {
175175
$icon = array();
176176

177177
$id = explode(' ', $id);
178-
$dir = $this->get_icon_dir($id[0]);
179-
$filename = $this->get_icon_filename($id[1]);
178+
$dir = $this->get_icon_dir($id);
179+
$filename = $this->get_icon_filename(end($id));
180180

181181
$icon['dir'] = $dir;
182182
$icon['filename'] = $filename;
@@ -198,30 +198,33 @@ public function get_icon_details($id) {
198198
* @param string $style
199199
* @return string
200200
*/
201-
public function get_icon_dir($style) {
202-
switch($style) {
203-
case 'far':
204-
$dir = 'regular';
205-
break;
201+
public function get_icon_dir($classes) {
202+
if (in_array('fa-sharp', $classes)) {
203+
if (in_array('fa-regular', $classes)) return 'sharp-regular';
204+
if (in_array('fa-light', $classes)) return 'sharp-light';
205+
if (in_array('fa-solid', $classes)) return 'sharp-solid';
206+
}
206207

207-
case 'fal':
208-
$dir = 'light';
209-
break;
208+
if (in_array('fasr', $classes)) return 'sharp-regular';
209+
if (in_array('fasl', $classes)) return 'sharp-light';
210+
if (in_array('fass', $classes)) return 'sharp-solid';
210211

211-
case 'fab':
212-
$dir = 'brands';
213-
break;
212+
if (in_array('far', $classes)) return 'regular';
213+
if (in_array('fa-regular', $classes)) return 'regular';
214214

215-
case 'fad':
216-
$dir = 'duotone';
217-
break;
215+
if (in_array('fal', $classes)) return 'light';
216+
if (in_array('fa-light', $classes)) return 'light';
218217

219-
case 'fas':
220-
default:
221-
$dir = 'solid';
222-
}
218+
if (in_array('fab', $classes)) return 'brands';
219+
if (in_array('fa-brands', $classes)) return 'brands';
220+
221+
if (in_array('fad', $classes)) return 'duotone';
222+
if (in_array('fa-duotone', $classes)) return 'duotone';
223+
224+
if (in_array('fat', $classes)) return 'thin';
225+
if (in_array('fa-thin', $classes)) return 'thin';
223226

224-
return $dir;
227+
return 'solid';
225228
}
226229

227230

@@ -236,4 +239,4 @@ public function get_icon_dir($style) {
236239
public function get_icon_filename($icon_name) {
237240
return str_replace('fa-', '', $icon_name);
238241
}
239-
}
242+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

tests/Fixtures/icons/thin/test.svg

Lines changed: 1 addition & 0 deletions
Loading

tests/Unit/FontAwesomeSVGTest.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ final class FontAwesomeSVGTest extends TestCase
1111
static public function icons(): array
1212
{
1313
return [
14-
['fab fa-test'],
15-
['fad fa-test'],
16-
['fal fa-test'],
17-
['far fa-test'],
18-
['fas fa-test'],
14+
['fab fa-test', 'brands', 'test'],
15+
['fad fa-test', 'duotone', 'test'],
16+
['fal fa-test', 'light', 'test'],
17+
['far fa-test', 'regular', 'test'],
18+
['fas fa-test', 'solid', 'test'],
19+
['fat fa-test', 'thin', 'test'],
20+
['fa-brands fa-test', 'brands', 'test'],
21+
['fa-duotone fa-test', 'duotone', 'test'],
22+
['fa-light fa-test', 'light', 'test'],
23+
['fa-regular fa-test', 'regular', 'test'],
24+
['fa-solid fa-test', 'solid', 'test'],
25+
['fa-thin fa-test', 'thin', 'test'],
26+
['fa-sharp fa-light fa-test', 'sharp-light', 'test'],
27+
['fa-sharp fa-regular fa-test', 'sharp-regular', 'test'],
28+
['fa-sharp fa-solid fa-test', 'sharp-solid', 'test'],
29+
['fasl fa-test', 'sharp-light', 'test'],
30+
['fasr fa-test', 'sharp-regular', 'test'],
31+
['fass fa-test', 'sharp-solid', 'test'],
1932
];
2033
}
2134

@@ -173,4 +186,17 @@ public function test_it_can_remove_duotone_inline_styles(): void
173186
$this->assertStringNotContainsString('--fa-secondary-color', $svg);
174187
$this->assertStringNotContainsString('--fa-secondary-opacity', $svg);
175188
}
189+
190+
/**
191+
* @dataProvider icons
192+
*/
193+
public function test_it_can_get_the_icons($icon, $dir, $filename): void
194+
{
195+
$fa = $this->createInstance();
196+
197+
$details = $fa->get_icon_details($icon);
198+
199+
$this->assertStringContainsString($dir, $details['dir']);
200+
$this->assertStringContainsString($filename, $details['filename']);
201+
}
176202
}

0 commit comments

Comments
 (0)