PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 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 All 452 releases
elementor / modules / atomic-widgets / styles / style-states.php

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

126 lines 2.8 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 const CHECKED = 'checked';
11
12 const SELECTED = 'e--selected';
13 const DISABLED = 'e--disabled';
14 const PLAYING = 'e--playing';
15 const PAUSED = 'e--paused';
16
17 private static function get_pseudo_states(): array {
18 return [
19 self::HOVER,
20 self::ACTIVE,
21 self::FOCUS,
22 self::FOCUS_VISIBLE,
23 self::CHECKED,
24 ];
25 }
26
27 private static function get_class_states(): array {
28 return [
29 self::SELECTED,
30 self::DISABLED,
31 self::PLAYING,
32 self::PAUSED,
33 ];
34 }
35
36 private static function get_additional_states_map(): array {
37 return [
38 self::HOVER => [ self::FOCUS_VISIBLE ],
39 ];
40 }
41
42 public static function get_selector_with_state( string $base_selector, string $state ): string {
43 $additional_states = self::get_additional_states( $state );
44 $all_states = [ $state, ...$additional_states ];
45
46 foreach ( $all_states as $current_state ) {
47 $selector_strings[] = $base_selector . self::get_state_selector( $current_state );
48 }
49
50 return implode( ',', $selector_strings );
51 }
52
53 public static function get_additional_states( string $state ): array {
54 return self::get_additional_states_map()[ $state ] ?? [];
55 }
56
57 public static function get_state_selector( string $state ): string {
58 if ( self::is_class_state( $state ) ) {
59 return '.' . $state;
60 }
61
62 if ( self::is_pseudo_state( $state ) ) {
63 return ':' . $state;
64 }
65
66 return $state;
67 }
68
69
70 public static function get_valid_states(): array {
71 return [
72 ...array_filter( self::get_pseudo_states(), function ( $state ) {
73 return ! in_array( $state, self::get_additional_states_map()[ $state ] ?? [], true );
74 } ),
75 ...self::get_class_states(),
76 null,
77 ];
78 }
79
80 public static function is_pseudo_state( string $state ): bool {
81 return in_array( $state, self::get_pseudo_states(), true );
82 }
83
84 public static function is_class_state( string $state ): bool {
85 return in_array( $state, self::get_class_states(), true );
86 }
87
88 public static function is_valid_state( $state ): bool {
89 if ( null === $state ) {
90 return true;
91 }
92
93 return is_string( $state ) && in_array( $state, self::get_valid_states(), true );
94 }
95
96 public static function get_class_states_map(): array {
97 return [
98 'selected' => [
99 'name' => 'selected',
100 'value' => self::SELECTED,
101 ],
102 'disabled' => [
103 'name' => 'disabled',
104 'value' => self::DISABLED,
105 ],
106 'playing' => [
107 'name' => 'playing',
108 'value' => self::PLAYING,
109 ],
110 'paused' => [
111 'name' => 'paused',
112 'value' => self::PAUSED,
113 ],
114 ];
115 }
116
117 public static function get_pseudo_states_map(): array {
118 return [
119 'checked' => [
120 'name' => 'checked',
121 'value' => self::CHECKED,
122 ],
123 ];
124 }
125 }
126