Skip to content

Commit

Permalink
Wrap icon in div
Browse files Browse the repository at this point in the history
  • Loading branch information
yuijim committed May 9, 2024
1 parent 44b7310 commit b9d79cf
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 34 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 1 addition & 4 deletions build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<?php return array(
'dependencies' => array( 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-primitives' ),
'version' => 'df4685a6c835056e0af6',
);
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-primitives'), 'version' => '66740de567073eb52bf2');
4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

39 changes: 27 additions & 12 deletions build/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @package WI\AcademicSocialLink
*/


/**
* Renders the `wielgosz-info/wi-academic-social-link` block on server.
*
Expand Down Expand Up @@ -45,7 +44,7 @@ function wi_academic_social_link_render_block( $attributes, $content, $block ) {
* Prepend URL with https:// if it doesn't appear to contain a scheme
* and it's not a relative link starting with //.
*/
if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) ) {
if ( ! wp_parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) ) {
$url = 'https://' . $url;
}

Expand All @@ -57,7 +56,7 @@ function wi_academic_social_link_render_block( $attributes, $content, $block ) {
)
);

$link = '<li ' . $wrapper_attributes . '>';
$link = '<li ' . $wrapper_attributes . '>';
$link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">';
$link .= $icon;
$link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">' . esc_html( $label ) . '</span>';
Expand All @@ -80,6 +79,7 @@ function wi_academic_social_link_render_block( $attributes, $content, $block ) {
* @since 0.1.0
*
* @param string $service The service icon.
* @param array $context The block context.
*
* @return string DIV Element for service icon.
*/
Expand All @@ -89,12 +89,23 @@ function wi_academic_social_link_get_icon( $service, $context ) {
$color = isset( $context['iconColor'] ) ? $context['iconColor'] : null;
$color_value = isset( $context['iconColorValue'] ) ? $context['iconColorValue'] : null;

$icon = null;
if ( isset( $services[ $service ]['icon'][ $color ] ) ) {
return $services[ $service ]['icon'][ $color ];
$icon = $services[ $service ]['icon'][ $color ];
} elseif ( isset( $services[ $service ]['icon'][ $color_value ] ) ) {
return $services[ $service ]['icon'][ $color_value ];
$icon = $services[ $service ]['icon'][ $color_value ];
} else {
return $services[ $service ]['icon']['original'];
$icon = $services[ $service ]['icon']['original'];
}

if ( $icon ) {
return sprintf( '<div class="wp-block-academic-social-link__icon">
<img
class="wp-block-academic-social-link__icon-img"
src="%s"
alt=""
/>
</div>', $icon );
}
}

Expand Down Expand Up @@ -131,17 +142,21 @@ function wi_academic_social_link_services() {
'orcid-id' => array(
'name' => 'ORCID iD',
'icon' => array(
'original' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCIDiD_iconvector.svg' ),
'var(--wp--preset--color--black)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCIDiD_iconbwvector.svg' ),
'var(--wp--preset--color--white)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCID-iD_icon_reversed_vector.svg' ),
'original' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconvector.svg',
'var(--wp--preset--color--black)' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconbwvector.svg',
'var(--wp--preset--color--white)' => plugin_dir_url( __DIR__ ) . 'assets/ORCID-iD_icon_reversed_vector.svg',
'black' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconbwvector.svg',
'white' => plugin_dir_url( __DIR__ ) . 'assets/ORCID-iD_icon_reversed_vector.svg',
),
),
'arxiv-profile' => array(
'name' => 'arXiv Profile',
'icon' => array(
'original' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small.svg' ),
'var(--wp--preset--color--black)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small-black.svg' ),
'var(--wp--preset--color--white)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small-white.svg' ),
'original' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small.svg',
'var(--wp--preset--color--black)' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-black.svg',
'var(--wp--preset--color--white)' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-white.svg',
'black' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-black.svg',
'white' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-white.svg',
),
),
);
Expand Down
12 changes: 6 additions & 6 deletions src/icons/index.js → src/icons.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// We're importing original, unmodified SVGs, since that what brand guidelines usually require.
import ORCIDiDIconDefault from './ORCIDiD_iconvector.svg';
import ORCIDiDIconBlack from './ORCIDiD_iconbwvector.svg';
import ORCIDiDIconWhite from './ORCID-iD_icon_reversed_vector.svg';
import arXivProfileIconDefault from './arxiv-logomark-small.svg';
import arXivProfileIconBlack from './arxiv-logomark-small-black.svg';
import arXivProfileIconWhite from './arxiv-logomark-small-white.svg';
import ORCIDiDIconDefault from '../assets/ORCIDiD_iconvector.svg';
import ORCIDiDIconBlack from '../assets/ORCIDiD_iconbwvector.svg';
import ORCIDiDIconWhite from '../assets/ORCID-iD_icon_reversed_vector.svg';
import arXivProfileIconDefault from '../assets/arxiv-logomark-small.svg';
import arXivProfileIconBlack from '../assets/arxiv-logomark-small-black.svg';
import arXivProfileIconWhite from '../assets/arxiv-logomark-small-white.svg';

const ORCIDiDIcon = {
original: ORCIDiDIconDefault,
Expand Down
35 changes: 25 additions & 10 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function wi_academic_social_link_render_block( $attributes, $content, $block ) {
)
);

$link = '<li ' . $wrapper_attributes . '>';
$link = '<li ' . $wrapper_attributes . '>';
$link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">';
$link .= $icon;
$link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">' . esc_html( $label ) . '</span>';
Expand Down Expand Up @@ -89,12 +89,23 @@ function wi_academic_social_link_get_icon( $service, $context ) {
$color = isset( $context['iconColor'] ) ? $context['iconColor'] : null;
$color_value = isset( $context['iconColorValue'] ) ? $context['iconColorValue'] : null;

$icon = null;
if ( isset( $services[ $service ]['icon'][ $color ] ) ) {
return $services[ $service ]['icon'][ $color ];
$icon = $services[ $service ]['icon'][ $color ];
} elseif ( isset( $services[ $service ]['icon'][ $color_value ] ) ) {
return $services[ $service ]['icon'][ $color_value ];
$icon = $services[ $service ]['icon'][ $color_value ];
} else {
return $services[ $service ]['icon']['original'];
$icon = $services[ $service ]['icon']['original'];
}

if ( $icon ) {
return sprintf( '<div class="wp-block-academic-social-link__icon">

Check failure on line 102 in src/index.php

View workflow job for this annotation

GitHub Actions / WPCS check

Opening parenthesis of a multi-line function call must be the last content on the line
<img
class="wp-block-academic-social-link__icon-img"
src="%s"
alt=""
/>
</div>', $icon );

Check failure on line 108 in src/index.php

View workflow job for this annotation

GitHub Actions / WPCS check

Only one argument is allowed per line in a multi-line function call

Check failure on line 108 in src/index.php

View workflow job for this annotation

GitHub Actions / WPCS check

Closing parenthesis of a multi-line function call must be on a line by itself
}
}

Expand Down Expand Up @@ -131,17 +142,21 @@ function wi_academic_social_link_services() {
'orcid-id' => array(
'name' => 'ORCID iD',
'icon' => array(
'original' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCIDiD_iconvector.svg' ),
'var(--wp--preset--color--black)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCIDiD_iconbwvector.svg' ),
'var(--wp--preset--color--white)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/ORCID-iD_icon_reversed_vector.svg' ),
'original' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconvector.svg',
'var(--wp--preset--color--black)' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconbwvector.svg',
'var(--wp--preset--color--white)' => plugin_dir_url( __DIR__ ) . 'assets/ORCID-iD_icon_reversed_vector.svg',
'black' => plugin_dir_url( __DIR__ ) . 'assets/ORCIDiD_iconbwvector.svg',
'white' => plugin_dir_url( __DIR__ ) . 'assets/ORCID-iD_icon_reversed_vector.svg',
),
),
'arxiv-profile' => array(
'name' => 'arXiv Profile',
'icon' => array(
'original' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small.svg' ),
'var(--wp--preset--color--black)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small-black.svg' ),
'var(--wp--preset--color--white)' => file_get_contents( plugin_dir_path( __FILE__ ) . '../src/icons/arxiv-logomark-small-white.svg' ),
'original' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small.svg',
'var(--wp--preset--color--black)' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-black.svg',
'var(--wp--preset--color--white)' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-white.svg',
'black' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-black.svg',
'white' => plugin_dir_url( __DIR__ ) . 'assets/arxiv-logomark-small-white.svg',
),
),
);
Expand Down

0 comments on commit b9d79cf

Please sign in to comment.