PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / atomic-widgets / styles / style-states.php

style-states.php in Elementor Website Builder – more than just a page builder 3.35.0-dev4, at modules/atomic-widgets/styles/style-states.php

97 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\Styles;
4
5 class Style_States {
6 const HOVER = 'hover';
7 const ACTIVE = 'active';
8 const FOCUS = 'focus';
9 const FOCUS_VISIBLE = 'focus-visible';
10
11 const SELECTED = 'e--selected';
12
13 private static function get_pseudo_states(): array {
14 return [
15 self::HOVER,
16 self::ACTIVE,
17 self::FOCUS,
18 self::FOCUS_VISIBLE,
19 ];
20 }
21
22 private static function get_class_states(): array {
23 return [
24 self::SELECTED,
25 ];
26 }
27
28 private static function get_additional_states_map(): array {
29 return [
30 self::HOVER => [ self::FOCUS_VISIBLE ],
31 ];
32 }
33
34 public static function get_selector_with_state( string $base_selector, string $state ): string {
35 $additional_states = self::get_additional_states( $state );
36 $all_states = [ $state, ...$additional_states ];
37
38 foreach ( $all_states as $current_state ) {
39 $selector_strings[] = $base_selector . self::get_state_selector( $current_state );
40 }
41
42 return implode( ',', $selector_strings );
43 }
44
45 public static function get_additional_states( string $state ): array {
46 return self::get_additional_states_map()[ $state ] ?? [];
47 }
48
49 public static function get_state_selector( string $state ): string {
50 if ( self::is_class_state( $state ) ) {
51 return '.' . $state;
52 }
53
54 if ( self::is_pseudo_state( $state ) ) {
55 return ':' . $state;
56 }
57
58 return $state;
59 }
60
61
62 public static function get_valid_states(): array {
63 return [
64 ...array_filter( self::get_pseudo_states(), function ( $state ) {
65 return ! in_array( $state, self::get_additional_states_map()[ $state ] ?? [], true );
66 } ),
67 ...self::get_class_states(),
68 null,
69 ];
70 }
71
72 public static function is_pseudo_state( string $state ): bool {
73 return in_array( $state, self::get_pseudo_states(), true );
74 }
75
76 public static function is_class_state( string $state ): bool {
77 return in_array( $state, self::get_class_states(), true );
78 }
79
80 public static function is_valid_state( $state ): bool {
81 if ( null === $state ) {
82 return true;
83 }
84
85 return is_string( $state ) && in_array( $state, self::get_valid_states(), true );
86 }
87
88 public static function get_class_states_map(): array {
89 return [
90 'selected' => [
91 'name' => 'selected',
92 'value' => self::SELECTED,
93 ],
94 ];
95 }
96 }
97