From 84064ce4eee6a33cf12cde6abb4af4904e585dbc Mon Sep 17 00:00:00 2001 From: daguilarm Date: Mon, 16 Jan 2017 19:45:02 +0100 Subject: [PATCH 1/5] New option to customize the css inside the addon component If we want to add a custom css to the input-group-addon:
@domain.com
Using something like this: $input->afterAddon('@domain.com')->addAddonCss('newCss1')->addAddonCss(' newCss2'); --- build/logs/clover.xml | 572 ++++++++++++++++++ .../BootForms/Elements/InputGroup.php | 24 +- tests/InputGroupTest.php | 17 + 3 files changed, 609 insertions(+), 4 deletions(-) create mode 100644 build/logs/clover.xml diff --git a/build/logs/clover.xml b/build/logs/clover.xml new file mode 100644 index 0000000..0649d0f --- /dev/null +++ b/build/logs/clover.xml @@ -0,0 +1,572 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index 6cadad8..1489039 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -5,8 +5,8 @@ class InputGroup extends Text { protected $beforeAddon = []; - protected $afterAddon = []; + protected $cssAddons = []; public function beforeAddon($addon) { @@ -33,14 +33,30 @@ protected function renderAddons($addons) $html = ''; foreach ($addons as $addon) { - $html .= ''; - $html .= $addon; - $html .= ''; + $html .= sprintf('%s', $this->renderAddonCss(), $addon); } return $html; } + public function addAddonCss($css) + { + $this->cssAddons[] = $css; + + return $this; + } + + protected function renderAddonCss() + { + $class = ''; + + foreach ($this->cssAddons as $css) { + $class .= ' ' . $css; + } + + return $class; + } + public function render() { $html = '
'; diff --git a/tests/InputGroupTest.php b/tests/InputGroupTest.php index 6a15ef4..3444e0c 100644 --- a/tests/InputGroupTest.php +++ b/tests/InputGroupTest.php @@ -67,4 +67,21 @@ public function testDefaultValue() $result = $input->defaultValue('abc')->value('xyz')->render(); $this->assertEquals($expected, $result); } + + public function testCustomCssAddons() + { + $input = new InputGroup('example1'); + $input->afterAddon('@domain.com')->addAddonCss('newCss'); + + $expected = '
@domain.com
'; + $result = $input->render(); + $this->assertEquals($expected, $result); + + $input = new InputGroup('example2'); + $input->afterAddon('@domain.com')->addAddonCss('newCss1')->addAddonCss('newCss2'); + + $expected = '
@domain.com
'; + $result = $input->render(); + $this->assertEquals($expected, $result); + } } From 252a83e4675ebd2b8d193426c51a23e19d0c3fd2 Mon Sep 17 00:00:00 2001 From: daguilarm Date: Mon, 23 Jan 2017 08:11:28 +0100 Subject: [PATCH 2/5] Names update --- src/AdamWathan/BootForms/Elements/InputGroup.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index 1489039..ab63f73 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -6,7 +6,7 @@ class InputGroup extends Text { protected $beforeAddon = []; protected $afterAddon = []; - protected $cssAddons = []; + protected $addonClass = []; public function beforeAddon($addon) { @@ -33,7 +33,7 @@ protected function renderAddons($addons) $html = ''; foreach ($addons as $addon) { - $html .= sprintf('%s', $this->renderAddonCss(), $addon); + $html .= sprintf('%s', $this->renderAddonClass(), $addon); } return $html; @@ -41,16 +41,16 @@ protected function renderAddons($addons) public function addAddonCss($css) { - $this->cssAddons[] = $css; + $this->addonClass[] = $css; return $this; } - protected function renderAddonCss() + protected function renderAddonClass() { $class = ''; - foreach ($this->cssAddons as $css) { + foreach ($this->addonClass as $css) { $class .= ' ' . $css; } From 3eeb7d113046a9767600bff9552dc60876745e37 Mon Sep 17 00:00:00 2001 From: daguilarm Date: Mon, 23 Jan 2017 08:38:41 +0100 Subject: [PATCH 3/5] Add addon ID attribute!!! --- .../BootForms/Elements/InputGroup.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index ab63f73..5dead6c 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -6,7 +6,8 @@ class InputGroup extends Text { protected $beforeAddon = []; protected $afterAddon = []; - protected $addonClass = []; + protected $classAddon; + protected $addonID; public function beforeAddon($addon) { @@ -22,6 +23,20 @@ public function afterAddon($addon) return $this; } + public function addAddonClass($class) + { + $this->classAddon = $class; + + return $this; + } + + public function addAddonId($id) + { + $this->addonID = $id; + + return $this; + } + public function type($type) { $this->attributes['type'] = $type; @@ -33,28 +48,17 @@ protected function renderAddons($addons) $html = ''; foreach ($addons as $addon) { - $html .= sprintf('%s', $this->renderAddonClass(), $addon); + $html .= sprintf('%s', $this->renderAddonsId(), $this->classAddon, $addon); } return $html; } - public function addAddonCss($css) - { - $this->addonClass[] = $css; - - return $this; - } - - protected function renderAddonClass() + protected function renderAddonsId() { - $class = ''; - - foreach ($this->addonClass as $css) { - $class .= ' ' . $css; + if($this->addonID) { + return sprintf('id = "%s"', $this->addonID); } - - return $class; } public function render() From 5070a98670c0b444c65d5d67596a4cda0d00c0b0 Mon Sep 17 00:00:00 2001 From: daguilarm Date: Mon, 23 Jan 2017 08:56:33 +0100 Subject: [PATCH 4/5] Fix problem --- src/AdamWathan/BootForms/Elements/InputGroup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index 5dead6c..cfbb8dc 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -48,7 +48,7 @@ protected function renderAddons($addons) $html = ''; foreach ($addons as $addon) { - $html .= sprintf('%s', $this->renderAddonsId(), $this->classAddon, $addon); + $html .= sprintf('%s', $this->renderAddonsId(), $this->classAddon, $addon); } return $html; @@ -57,7 +57,7 @@ protected function renderAddons($addons) protected function renderAddonsId() { if($this->addonID) { - return sprintf('id = "%s"', $this->addonID); + return sprintf(' ' . 'id = "%s"', $this->addonID); } } From 6e0e54472a9f6f6e7a552cf8f87052f392d7599c Mon Sep 17 00:00:00 2001 From: daguilarm Date: Mon, 23 Jan 2017 09:19:52 +0100 Subject: [PATCH 5/5] Update tests --- build/logs/clover.xml | 850 ++++++++---------- .../BootForms/Elements/InputGroup.php | 19 +- tests/InputGroupTest.php | 16 +- 3 files changed, 381 insertions(+), 504 deletions(-) diff --git a/build/logs/clover.xml b/build/logs/clover.xml index 0649d0f..3e4d3e9 100644 --- a/build/logs/clover.xml +++ b/build/logs/clover.xml @@ -1,139 +1,92 @@ - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -163,410 +116,313 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + - - - - - - - - + + + + + - + diff --git a/src/AdamWathan/BootForms/Elements/InputGroup.php b/src/AdamWathan/BootForms/Elements/InputGroup.php index cfbb8dc..f9896f3 100644 --- a/src/AdamWathan/BootForms/Elements/InputGroup.php +++ b/src/AdamWathan/BootForms/Elements/InputGroup.php @@ -6,7 +6,7 @@ class InputGroup extends Text { protected $beforeAddon = []; protected $afterAddon = []; - protected $classAddon; + protected $classAddon = []; protected $addonID; public function beforeAddon($addon) @@ -25,7 +25,7 @@ public function afterAddon($addon) public function addAddonClass($class) { - $this->classAddon = $class; + $this->classAddon[] = $class; return $this; } @@ -48,7 +48,7 @@ protected function renderAddons($addons) $html = ''; foreach ($addons as $addon) { - $html .= sprintf('%s', $this->renderAddonsId(), $this->classAddon, $addon); + $html .= sprintf('%s', $this->renderAddonsId(), $this->renderAddonsClass(), $addon); } return $html; @@ -57,10 +57,21 @@ protected function renderAddons($addons) protected function renderAddonsId() { if($this->addonID) { - return sprintf(' ' . 'id = "%s"', $this->addonID); + return sprintf('id="%s"' . ' ', $this->addonID); } } + protected function renderAddonsClass() + { + $html = ''; + + foreach($this->classAddon as $class) { + $html .= ' ' . $class; + } + + return $html; + } + public function render() { $html = '
'; diff --git a/tests/InputGroupTest.php b/tests/InputGroupTest.php index 3444e0c..f62d2ce 100644 --- a/tests/InputGroupTest.php +++ b/tests/InputGroupTest.php @@ -68,20 +68,30 @@ public function testDefaultValue() $this->assertEquals($expected, $result); } - public function testCustomCssAddons() + public function testCustomClassAddons() { $input = new InputGroup('example1'); - $input->afterAddon('@domain.com')->addAddonCss('newCss'); + $input->afterAddon('@domain.com')->addAddonClass('newCss'); $expected = '
@domain.com
'; $result = $input->render(); $this->assertEquals($expected, $result); $input = new InputGroup('example2'); - $input->afterAddon('@domain.com')->addAddonCss('newCss1')->addAddonCss('newCss2'); + $input->afterAddon('@domain.com')->addAddonClass('newCss1')->addAddonClass('newCss2'); $expected = '
@domain.com
'; $result = $input->render(); $this->assertEquals($expected, $result); } + + public function testCustomIdAddons() + { + $input = new InputGroup('example1'); + $input->afterAddon('@domain.com')->addAddonId('myID'); + + $expected = '
@domain.com
'; + $result = $input->render(); + $this->assertEquals($expected, $result); + } }