-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add view transitions in WP Admin #10699
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
017ad4d
291cba6
8fe35f3
1a3bf36
8ff0383
ee75b33
8bd1633
d2b3437
53f9405
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| @view-transition { | ||
| navigation: auto; | ||
| } | ||
|
|
||
| #adminmenu > .menu-top { | ||
| view-transition-name: attr(id type(<custom-ident>), none); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||
| <?php | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * View Transitions API. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @package WordPress | ||||||||||||||||||||
| * @subpackage View Transitions | ||||||||||||||||||||
| * @since 7.0.0 | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Enqueues View Transitions CSS for the admin. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @since 7.0.0 | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| function wp_enqueue_view_transitions_admin_css(): void { | ||||||||||||||||||||
| wp_enqueue_style( 'wp-view-transitions-admin' ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Gets the CSS for View Transitions in the admin. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @since 7.0.0 | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @return string The CSS. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| function wp_get_view_transitions_admin_css(): string { | ||||||||||||||||||||
| $affix = SCRIPT_DEBUG ? '' : '.min'; | ||||||||||||||||||||
| $path = ABSPATH . "wp-admin/css/view-transitions{$affix}.css"; | ||||||||||||||||||||
| return file_get_contents( $path ); | ||||||||||||||||||||
|
||||||||||||||||||||
| return file_get_contents( $path ); | |
| $contents = ''; | |
| if ( is_readable( $path ) ) { | |
| $contents = file_get_contents( $path ); | |
| } | |
| return is_string( $contents ) ? $contents : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file will always exist. So this isn't necessary.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
| /** | ||
| * Tests for the wp_enqueue_view_transitions_admin_css() function. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage View Transitions | ||
| */ | ||
|
|
||
| /** | ||
| * @group view-transitions | ||
| * @covers ::wp_enqueue_view_transitions_admin_css | ||
| */ | ||
| class Tests_View_Transitions_wpEnqueueViewTransitionsAdminCss extends WP_UnitTestCase { | ||
|
|
||
| private ?WP_Styles $original_wp_styles = null; | ||
|
|
||
| public function set_up() { | ||
| global $wp_styles; | ||
|
|
||
| parent::set_up(); | ||
| $this->original_wp_styles = $wp_styles; | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| global $wp_styles; | ||
|
|
||
| $wp_styles = $this->original_wp_styles; | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the hook for enqueuing admin view transitions CSS is set up. | ||
| * | ||
| * @ticket 64470 | ||
| */ | ||
| public function test_hook() { | ||
| $this->assertSame( 10, has_action( 'admin_enqueue_scripts', 'wp_enqueue_view_transitions_admin_css' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the admin view transitions style handle includes the inline CSS. | ||
| * | ||
| * @ticket 64470 | ||
| * | ||
| * @covers ::wp_get_view_transitions_admin_css | ||
| */ | ||
| public function test_inline_css_included() { | ||
| $after_data = wp_styles()->get_data( 'wp-view-transitions-admin', 'after' ); | ||
| $this->assertIsArray( $after_data, 'Expected `after` data to be an array.' ); | ||
| $css = wp_get_view_transitions_admin_css(); | ||
| $this->assertStringContainsString( '@view-transition', $css ); | ||
| $this->assertContains( $css, $after_data ); | ||
|
Comment on lines
+47
to
+52
|
||
| } | ||
|
|
||
| /** | ||
| * Tests enqueuing admin view transitions CSS. | ||
| * | ||
| * @ticket 64470 | ||
| */ | ||
| public function test_wp_enqueue_view_transitions_admin_css() { | ||
| $this->assertFalse( wp_style_is( 'wp-view-transitions-admin' ) ); | ||
|
|
||
| wp_enqueue_view_transitions_admin_css(); | ||
| $this->assertTrue( wp_style_is( 'wp-view-transitions-admin' ) ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check whether the file exists and return an empty string if it doesn’t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we needs to add filter so we can extend the CSS? Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should exist. If not, it's an error. We don't do a
file_exists()check in_print_emoji_detection_script(), for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha.