Skip to content

Commit d7135bd

Browse files
committed
Foundation for eventual WYSIWYG support
1 parent 1b9a9fb commit d7135bd

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

src/Elements/Attributes/Attributes.php

+5
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ public function toHtml() : string
330330
->implode(' ');
331331
}
332332

333+
public function __toString()
334+
{
335+
return $this->toHtml();
336+
}
337+
333338
/**
334339
* Get a collection of all attributes (after mutation)
335340
*

src/Elements/Attributes/ClassNames.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class ClassNames
2828
*/
2929
protected $class_names = [];
3030

31+
/**
32+
* Class names that have been explicitly removed
33+
*
34+
* @var array
35+
*/
36+
protected $removed_class_names = [];
37+
3138
/**
3239
* The name of the element that this class list targets
3340
*
@@ -109,14 +116,14 @@ public function add(...$class_names) : self
109116
}
110117

111118
/**
112-
* Remove class(es) from the class list
119+
* Remove class(es) from the final output
113120
*
114121
* @param string[] ...$class_names
115122
* @return \Galahad\Aire\Elements\Attributes\ClassNames
116123
*/
117124
public function remove(...$class_names) : self
118125
{
119-
$this->class_names = array_diff($this->class_names, $class_names);
126+
$this->removed_class_names = array_unique(array_merge($this->removed_class_names, $class_names));
120127

121128
return $this;
122129
}
@@ -128,10 +135,10 @@ public function remove(...$class_names) : self
128135
*/
129136
public function __toString()
130137
{
131-
return implode(' ', array_unique(array_merge(
138+
return implode(' ', array_diff(array_unique(array_merge(
132139
$this->class_names,
133140
$this->validation()
134-
)));
141+
)), $this->removed_class_names));
135142
}
136143

137144
/**

src/Elements/Concerns/CreatesElements.php

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Galahad\Aire\Elements\Select;
1313
use Galahad\Aire\Elements\Summary;
1414
use Galahad\Aire\Elements\Textarea;
15+
use Galahad\Aire\Elements\Wysiwyg;
1516

1617
trait CreatesElements
1718
{
@@ -81,6 +82,21 @@ public function textArea($name = null, $label = null) : Textarea
8182
return $textarea;
8283
}
8384

85+
public function wysiwyg($name = null, $label = null) : Textarea
86+
{
87+
$textarea = new Wysiwyg($this->aire, $this);
88+
89+
if ($name) {
90+
$textarea->name($name);
91+
}
92+
93+
if ($label) {
94+
$textarea->label($label);
95+
}
96+
97+
return $textarea;
98+
}
99+
84100
public function summary() : Summary
85101
{
86102
return new Summary($this->aire);

src/Elements/Wysiwyg.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Galahad\Aire\Elements;
4+
5+
class Wysiwyg extends Textarea
6+
{
7+
public $name = 'wysiwyg';
8+
}

views/wysiwyg.blade.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php /** @var \Galahad\Aire\Elements\Attributes\Attributes $attributes */ ?>
2+
3+
<noscript>
4+
<textarea {{ $attributes->except('value') }}>{{ $attributes->get('value') }}</textarea>
5+
</noscript>
6+
<script>
7+
document.write({!! json_encode('<div style="display:none;"><textarea '.$attributes->except('value').'>'.$attributes->get('value').'</textarea></div>') !!});
8+
</script>

0 commit comments

Comments
 (0)