Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar Block: Add color supports and polish styles #42029

Merged
merged 16 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ A calendar of your site’s posts. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/calendar
- **Category:** widgets
- **Supports:** align, typography (fontSize, lineHeight)
- **Supports:** align, color (background, link, text), typography (fontSize, lineHeight)
- **Attributes:** month, year

## Categories List
Expand Down
9 changes: 9 additions & 0 deletions packages/block-library/src/calendar/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
},
"supports": {
"align": true,
"color": {
"link": true,
"__experimentalSkipSerialization": [ "text", "background" ],
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
"__experimentalDefaultControls": {
"background": true,
"text": true
},
"__experimentalSelector": "table, th"
},
"typography": {
"fontSize": true,
"lineHeight": true,
Expand Down
23 changes: 22 additions & 1 deletion packages/block-library/src/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,32 @@ function render_block_core_calendar( $attributes ) {
}
}

$color_block_styles = array();

// Text color.
$preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null;
$custom_text_color = _wp_array_get( $attributes, array( 'style', 'color', 'text' ), null );
$color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;

// Background Color.
$preset_background_color = array_key_exists( 'backgroundColor', $attributes ) ? "var:preset|color|{$attributes['backgroundColor']}" : null;
$custom_background_color = _wp_array_get( $attributes, array( 'style', 'color', 'background' ), null );
$color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;

// Generate color styles and classes.
$styles = gutenberg_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) );
$inline_styles = empty( $styles['css'] ) ? '' : sprintf( ' style="%s"', esc_attr( $styles['css'] ) );
$classnames = empty( $styles['classnames'] ) ? '' : ' ' . esc_attr( $styles['classnames'] );

// Apply color classes and styles to the calendar.
$calendar = str_replace( '<table', '<table' . $inline_styles, get_calendar( true, false ) );
$calendar = str_replace( 'class="wp-calendar-table', 'class="wp-calendar-table' . $classnames, $calendar );

$wrapper_attributes = get_block_wrapper_attributes();
$output = sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
get_calendar( true, false )
$calendar
);

// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
Expand Down
43 changes: 28 additions & 15 deletions packages/block-library/src/calendar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@
text-align: center;

th,
tbody td {
td {
padding: 0.25em;
border: 1px solid $gray-300;
border: 1px solid;
}

tfoot td {
border: none;
th {
font-weight: 400;
}

caption {
background-color: inherit;
}

table {
width: 100%;
border-collapse: collapse;
}

table th {
font-weight: 400;
background: $gray-300;
}
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
&:where(:not(.has-text-color)) {
color: #40464d;

a {
text-decoration: underline;
}
// Keep the hard-coded border color for backward compatibility.
th,
td {
border-color: $gray-300;
}
}

&.has-background th {
background-color: inherit;
}

table tbody,
table caption {
color: #40464d;
&.has-text-color th {
color: inherit;
}
}
}

// Keep the hard-coded header background color for backward compatibility.
:where(.wp-block-calendar table:not(.has-background) th) {
background: $gray-300;
}