Skip to content

Commit

Permalink
adding configuration information to avoid hardcoding data
Browse files Browse the repository at this point in the history
  • Loading branch information
celdia committed Jun 10, 2024
1 parent d5ec8f0 commit 3607ba4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function overview() {
],
];
}

return $build;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ uswsd:
- '/libraries/uswds/packages/usa-icon/src/img/usa-icons-bg'
- '/libraries/uswds/packages/usa-icon/src/img/uswds-icons'

material_icons:
label: 'Material icons'
material_icons_outlined:
label: 'Material icons Outlined'
plugin: 'codepoints'
config:
template : '<span class="material-icons-outlined">{{ icon_id }}</span>'
library: 'ui_icons_test/material'
assets:
- 'https://raw.githubusercontent.com/google/material-design-icons/master/font/MaterialIconsOutlined-Regular.codepoints'

material_icons_round:
label: 'Material Icon Round'
plugin: 'codepoints'
config:
template: '<span class="material-icons-round">{{ icon_id }}</span>'
library: 'ui_icons_test/material'
assets:
- 'https://raw.githubusercontent.com/google/material-design-icons/master/font/MaterialIconsRound-Regular.codepoints'


44 changes: 19 additions & 25 deletions src/Plugin/Iconset/CodepointsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,27 @@
*/
class CodepointsHandler extends PluginBase implements IconHandlerInterface {

/**
* URL to the codepoints file.
*/
const CODEPOINTS_URL = 'https://raw.githubusercontent.com/google/material-design-icons/master/font/MaterialIconsOutlined-Regular.codepoints';

/**
* {@inheritdoc}
*/
public function createAssets($asset_info, IconsetInterface $iconset) {
// @todo get url from $asset_info,
return new CodepointsAsset(static::CODEPOINTS_URL);
}

/**
* {@inheritdoc}
*/
public function supports(IconsetInterface $iconset) {
// Check if the iconset supports this handler.
return $iconset->getType() === 'codepoints';
return new CodepointsAsset($asset_info);
}

/**
*
*/
public function build($icon_id, AssetInterface $iconset, array $options = []) {
// @todo don't hardcode this here
$config = $this->configuration;
return [
"#type" => "html_tag",
"#tag" => "span",
"#value" => $icon_id,
"#attributes" => [
"class" => [
"material-icons-outlined",
],
'#type' => 'inline_template',
"#template" => $config['template'],
"#context" => [
'icon_id' => $icon_id,
],
"#attached" => [
"library" => [
"ui_icons_test/material",
$config['library'],
],
],
];
Expand All @@ -74,7 +57,18 @@ public function getJsSettings() {
*/
public function formatJson(AssetInterface $asset) {
// @todo Implement formatJson() method.
return [];
// return [];
$icons = $asset->getIcons();
$formatted_icons = [];

foreach ($icons as $icon_id => $icon_data) {
$formatted_icons[] = [
'id' => $icon_id,
'label' => $icon_data['label'],
];
}

return json_encode($formatted_icons);
}

}

0 comments on commit 3607ba4

Please sign in to comment.