PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev3
Elementor Website Builder – more than just a page builder v4.0.0-dev3
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 4.0.0-dev3, at modules/atomic-widgets/styles/style-states.php

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