Skip to content

Commit

Permalink
icon block fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seothemes committed Dec 23, 2023
1 parent 48f3496 commit e614806
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion assets/css/blocks/button.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/blocks/template-part.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/components/site-blocks.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/editor.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions includes/blocks/paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function render_paragraph_block( string $html, array $block ): string {
$html = render_curved_text( $html, $block, $svg_string );
}

if ( str_contains( $html, 'http://http' ) ) {
$html = str_replace( 'http://http', 'http', $html );
}

return $html;
}

Expand Down
29 changes: 25 additions & 4 deletions includes/extensions/icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ function get_icon_html( string $content, array $block ): string {
$figure_classes[] = "has-{$text_color}-color";
}

$figure->setAttribute( 'class', implode( ' ', $figure_classes ) );
$span->setAttribute( 'class', implode( ' ', $span_classes ) );

$aria_label = $img->getAttribute( 'alt' ) ? $img->getAttribute( 'alt' ) : str_replace( '-', ' ', $icon_name ) . __( ' icon', 'blockify' );

$span->setAttribute( 'title', $attrs['title'] ?? $aria_label );
Expand Down Expand Up @@ -189,10 +186,28 @@ function get_icon_html( string $content, array $block ): string {
$figure_styles['--wp--custom--icon--color'] = $custom_text_color;
}

$background_color = $attrs['backgroundColor'] ?? null;

if ( $background_color ) {
$figure_styles['--wp--custom--icon--background'] = "var(--wp--preset--color--{$background_color})";
}

if ( $gradient ) {
$figure_styles['--wp--custom--icon--color'] = "var(--wp--preset--gradient--{$gradient})";
}

$border_radius = $attrs['style']['border']['radius'] ?? null;

if ( $border_radius ) {
$span_styles['border-radius'] = $border_radius;
}

$padding = $attrs['style']['spacing']['padding'] ?? null;

if ( $padding ) {
$span_styles = add_shorthand_property( $span_styles, 'padding', $padding );
}

$transform = $attrs['style']['transform'] ?? [];
$transform_units = [
'rotate' => 'deg',
Expand All @@ -214,6 +229,8 @@ function get_icon_html( string $content, array $block ): string {
}
}

$figure->setAttribute( 'class', implode( ' ', $figure_classes ) );
$span->setAttribute( 'class', implode( ' ', $span_classes ) );
$figure->setAttribute( 'style', css_array_to_string( $figure_styles ) );
$span->setAttribute( 'style', css_array_to_string( $span_styles ) );

Expand All @@ -236,7 +253,11 @@ function get_icon_html( string $content, array $block ): string {
}
}

return $dom->saveHTML();
$html = $dom->saveHTML();
$html = add_position_classes( $html, $block );
$html = add_position_styles( $html, $block );

return $html;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions includes/extensions/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use function shortcode_exists;
use function str_contains;
use function str_replace;
use function strtolower;

add_filter( 'render_block', NS . 'render_template_tags', 8, 3 );
/**
Expand Down Expand Up @@ -82,6 +83,7 @@ function render_template_tags( string $html, array $block, WP_Block $object ): s
$replacements = [];

foreach ( $without_brackets as $tag ) {
$tag = strtolower( $tag );
$replacement = '';

if ( shortcode_exists( $tag ) ) {
Expand Down
7 changes: 5 additions & 2 deletions includes/utility/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ function format_custom_property( string $custom_property ): string {
(array) ( $global_settings['color']['palette']['theme'] ?? [] ),
(array) $theme_json->settings->color->palette
);

$color_slugs = wp_list_pluck( $colors, 'slug' );

$color_slugs = array_diff(
wp_list_pluck( $colors, 'slug' ),
get_system_colors()
);

if ( in_array( $custom_property, $color_slugs, true ) ) {
return "var(--wp--preset--color--{$custom_property})";
Expand Down
7 changes: 7 additions & 0 deletions src/scss/blocks/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
justify-content: flex-start;
}
}

&[style*="font-weight:"] {

.wp-element-button {
font-weight: inherit;
}
}
}

2 changes: 1 addition & 1 deletion src/scss/blocks/template-part.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ header.wp-block-template-part {
}

&:not([class*="has-display-"]) {
display: initial; // Required for nested sticky elements to work.
// display: initial; // Required for nested sticky elements to work.
}

&:not([class*="has-position-"]) {
Expand Down
4 changes: 4 additions & 0 deletions src/scss/components/site-blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
align-self: stretch;
}

.vertical-align-top {
vertical-align: top;
}

.object-fit {
object-fit: cover;
object-position: center;
Expand Down
2 changes: 1 addition & 1 deletion src/scss/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ div:has(> .blockify-icon-settings) {
min-height: 0;
}

.editor-styles-wrapper div .is-style-icon {
.editor-styles-wrapper div [style*="--wp--custom--icon--url:"] {
background: transparent !important;
float: none !important;
padding: 0 !important;
Expand Down
8 changes: 7 additions & 1 deletion src/utility/types.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CustomSelectControl } from '@wordpress/components';
import { CSSProperties } from 'react';
import { BlockAttributes } from '@wordpress/blocks';
import { BlockAttributes, TemplateArray } from '@wordpress/blocks';
import {
AlignmentToolbar,
BlockAlignmentToolbar,
BlockControls,
EditorTemplateLock,
} from '@wordpress/block-editor';
import { Value } from '@wordpress/rich-text';
import Option = CustomSelectControl.Option;
Expand Down Expand Up @@ -59,6 +60,8 @@ declare global {
post_types?: string[];
uses_context?: string[];
enabled?: boolean;
template?: TemplateArray | undefined;
template_lock?: EditorTemplateLock | undefined;
}

interface CustomField {
Expand All @@ -70,6 +73,9 @@ declare global {
default?: string | number | boolean | object | null | undefined;
subfields?: CustomField[];
placeholder?: string;
columns?: number;
control?: string; // Used by blocks.
onChange?: ( newValue: string | number | boolean | object | null | undefined ) => void; // Used by blocks.
}

interface blockify {
Expand Down

0 comments on commit e614806

Please sign in to comment.