add_individual_icon_styles( $css_generator, $attributes ); return $css_generator->generate_css(); } /** * Individual mode (Change Icon): this item's icon setup, size and colours. * One class stronger than the timeline's All mode rules, which they * override; empty values inherit the timeline's. Mirrors edit.js. */ private function add_individual_icon_styles( $css_generator, $attributes ) { if ( empty( $attributes['changeChildIcon'] ) ) { return; } $marker = '{{WRAPPER}}.ablocks-block-content-timeline-child .ablocks-icon-maker.ablocks__in-view-icon'; $parent = isset( $attributes['parentAttribute'] ) && is_array( $attributes['parentAttribute'] ) ? $attributes['parentAttribute'] : []; $color = ! empty( $attributes['individualIconColor'] ) ? $attributes['individualIconColor'] : ( $parent['iconColor'] ?? '' ); $css_generator->add_class_styles( $marker, $this->get_individual_marker_css( $attributes, $parent ) ); // Scroll animation colour on whichever element is this item's visible // background, when that differs from the timeline's. Stronger than the // stylesheet's and the timeline's active rules. $has_view = ContentTimelineBlock::has_icon_view( $attributes, 'icon' ); if ( ContentTimelineBlock::has_icon_view( $parent, 'contentTimeLineIcon' ) !== $has_view ) { $active_marker = '{{WRAPPER}}.ablocks-block-content-timeline-child.ablocks-block-content-timeline-child--field.ablocks-block--content-timeline-child .ablocks-icon-maker.ablocks__in-view-icon.ablocks-block-content-timeline__marker--active'; $css_generator->add_class_styles( $active_marker, ContentTimelineBlock::get_active_marker_css( $has_view ) ); $css_generator->add_class_styles( $active_marker . ' .ablocks-icon-wrap', ContentTimelineBlock::get_active_wrap_css( $has_view ) ); } // Default View item inside a timeline with a View: undo the timeline's // wrapper background / padding / border. Added first so this item's // own wrapper values still win. if ( ! $has_view && ContentTimelineBlock::has_icon_view( $parent, 'contentTimeLineIcon' ) ) { $css_generator->add_class_styles( $marker . ' .ablocks-icon-wrap', [ 'background' => 'transparent', 'padding' => '0', 'border' => 'none', 'border-radius' => '0', 'box-shadow' => 'none', ] ); } ContentTimelineBlock::add_icon_setup_styles( $css_generator, $marker, $attributes, 'icon', $color, function ( $device, $is_image ) use ( $attributes, $color ) { return $this->get_individual_icon_css( $attributes, $device, $is_image, $color ); }, // An empty Individual size keeps the timeline's (inherited rule). $attributes['individualIconSize'] ?? [], '' ); } // Individual mode marker. With its own View it has no Icon Background; // with the Default View it keeps one (its own colour, else the // timeline's), and when the timeline's View removed the marker background // it restores the timeline's colour and size. Mirrors styling.js. private function get_individual_marker_css( $attributes, $parent ) { if ( ContentTimelineBlock::has_icon_view( $attributes, 'icon' ) ) { return ContentTimelineBlock::MARKER_WITHOUT_BACKGROUND; } $own = Color::get_css( $attributes['individualIconBackgroundColor'] ?? '' ); if ( ! ContentTimelineBlock::has_icon_view( $parent, 'contentTimeLineIcon' ) ) { return $own ? [ 'background' => $own ] : []; } $inherited = Color::get_css( $parent['iconBackgroundColor'] ?? '' ); $size = ( ! empty( $parent['iconBackgroundSize'] ) ? $parent['iconBackgroundSize'] : 48 ) . 'px'; $css = [ 'min-width' => $size, 'min-height' => $size, ]; $background = $own ? $own : $inherited; if ( $background ) { $css['background'] = $background; } return $css; } private function get_individual_icon_css($attributes, $device, $is_image, $color ) { $size_args = [ 'attributeValue' => $attributes['individualIconSize'] ?? [], 'attributeObjectKey' => 'value', 'isResponsive' => true, 'hasUnit' => true, 'defaultValue' => '', 'unitDefaultValue' => 'px', 'device' => $device, ]; $fill = $is_image ? '' : Color::get_css( $attributes['individualIconColor'] ?? '' ); return array_merge( $fill ? [ 'fill' => $fill ] : [], Range::get_css( array_merge( $size_args, [ 'property' => 'width' ] ) ), Range::get_css( array_merge( $size_args, [ 'property' => 'height' ] ) ), ContentTimelineBlock::get_icon_glyph_css( $attributes, $device, 'icon', $is_image, $color ) ); } }