Skip to content

Commit

Permalink
Foundation for eventual WYSIWYG support
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Mar 18, 2019
1 parent 1b9a9fb commit d7135bd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Elements/Attributes/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ public function toHtml() : string
->implode(' ');
}

public function __toString()
{
return $this->toHtml();
}

/**
* Get a collection of all attributes (after mutation)
*
Expand Down
15 changes: 11 additions & 4 deletions src/Elements/Attributes/ClassNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class ClassNames
*/
protected $class_names = [];

/**
* Class names that have been explicitly removed
*
* @var array
*/
protected $removed_class_names = [];

/**
* The name of the element that this class list targets
*
Expand Down Expand Up @@ -109,14 +116,14 @@ public function add(...$class_names) : self
}

/**
* Remove class(es) from the class list
* Remove class(es) from the final output
*
* @param string[] ...$class_names
* @return \Galahad\Aire\Elements\Attributes\ClassNames
*/
public function remove(...$class_names) : self
{
$this->class_names = array_diff($this->class_names, $class_names);
$this->removed_class_names = array_unique(array_merge($this->removed_class_names, $class_names));

return $this;
}
Expand All @@ -128,10 +135,10 @@ public function remove(...$class_names) : self
*/
public function __toString()
{
return implode(' ', array_unique(array_merge(
return implode(' ', array_diff(array_unique(array_merge(
$this->class_names,
$this->validation()
)));
)), $this->removed_class_names));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Elements/Concerns/CreatesElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Galahad\Aire\Elements\Select;
use Galahad\Aire\Elements\Summary;
use Galahad\Aire\Elements\Textarea;
use Galahad\Aire\Elements\Wysiwyg;

trait CreatesElements
{
Expand Down Expand Up @@ -81,6 +82,21 @@ public function textArea($name = null, $label = null) : Textarea
return $textarea;
}

public function wysiwyg($name = null, $label = null) : Textarea
{
$textarea = new Wysiwyg($this->aire, $this);

if ($name) {
$textarea->name($name);
}

if ($label) {
$textarea->label($label);
}

return $textarea;
}

public function summary() : Summary
{
return new Summary($this->aire);
Expand Down
8 changes: 8 additions & 0 deletions src/Elements/Wysiwyg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Galahad\Aire\Elements;

class Wysiwyg extends Textarea
{
public $name = 'wysiwyg';
}
8 changes: 8 additions & 0 deletions views/wysiwyg.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php /** @var \Galahad\Aire\Elements\Attributes\Attributes $attributes */ ?>

<noscript>
<textarea {{ $attributes->except('value') }}>{{ $attributes->get('value') }}</textarea>
</noscript>
<script>
document.write({!! json_encode('<div style="display:none;"><textarea '.$attributes->except('value').'>'.$attributes->get('value').'</textarea></div>') !!});
</script>

0 comments on commit d7135bd

Please sign in to comment.