Foundation Buttons

This namespace contains Foundation buttons and buttongroups. They are convenient tools when a centralized style for customized button links and form buttons etc. isneeded.

The ButtonInterface For Foundation styled button

Interface defines required minimun implementation for all Foundation styled Buttons. Buttons support predefined Foundation color and size classes and can also use custom made classes. Colors can be set by calling ButtonInterface::setColor() instance method whereas size can be set by calling ButtonInterface::setSize() instance method with the CSS class name as a parameter value:

Predefined color classes:

  • NULL unsets all special button styles (default)
  • 'alert' for alert/error buttons
  • 'success' for ok/success buttons
  • 'info' for information buttons
  • 'secondary' for alternatively styled buttons
  • 'disabled' for disabled buttons

Predefined size classes:

  • 'tiny' for tiny buttons
  • 'small' for small buttons
  • NULL for medium buttons (default)
  • 'large' for large buttons
  • 'extend' for extended buttons (takes the full width of the container) "

Button Converts anything to button style

This adapter can transform most Component objects to Foundation styled buttons.

  • PHP code
    1. <?php
    2.  
    3. namespace Sphp\Html\Foundation\Sites\Buttons;
    4.  
    5. $b1 = Button::hyperlink("http://www.google.com/", "Google", "engine")
    6.         ->setSize("small")
    7.         ->setColor("alert");
    8. $b2 = Button::hyperlink("http://www.bing.com", "Bing", "engine")
    9.         ->setSize("medium")
    10.         ->setColor("warning")
    11.         ->disable(true);
    12. $b3 = Button::hyperlink("http://www.ask.com/", "ask.com", "engine")
    13.         ->setSize("large")
    14.         ->setColor("success")
    15.         ->isHollow(true);
    16. $b4 = Button::submitter("Submit!", "submit", "foo")
    17.         ->setColor("secondary")
    18.         ->isDropdown(true);
    19.  
    20. echo "$b1 $b2 $b3 $b4";
    21.  
    Highlighted with GeSHi 1.0.9.1
  • Execution result as HTML5 flow

The ButtonGroup class

A ButtonGroup component is a container for ButtonInterface components. A ButtonGroup component is effective for displaying a group of actions in a bar. ButtonGroup component works perfectly with the grid component.

The orientation of a button group can be changed with method ButtonGroup::stackFor() that uses Foundation stack classes for button groups. Stacking can be removed by using ButtonGroup::unStackFor() method.

  • PHP code
    1. <?php
    2.  
    3. namespace Sphp\Html\Foundation\Sites\Buttons;
    4.  
    5. $buttonGroup = new ButtonGroup();
    6. $buttonGroup->appendButton(new \Sphp\Html\Span("foo button"));
    7. $buttonGroup->appendButton(Button::hyperlink("http://www.google.com/", "google", "engine"));
    8. $buttonGroup->appendButton(Button::hyperlink("http://www.bing.com", "Bing", "engine"));
    9. $buttonGroup->appendHyperlink("https://www.yahoo.com/", "Yahoo!", "engine");
    10. $buttonGroup->setSize("tiny");
    11.  
    12. $buttonGroup->printHtml();
    13.  
    14. $buttonGroup->setExtended(true);
    15. $buttonGroup->printHtml();
    16.  
    17. use Sphp\Html\Foundation\Sites\Containers\Dropdown;
    18.  
    19. $split = (new ButtonGroup())->setSize('small');
    20. $split->appendPushButton('Push button')->setColor('alert');
    21. $opener = $split->appendArrowOnlyButton('Dropdownopener');
    22.  
    23. $dd = new Dropdown($opener, "Hello! I'm a dropdown");
    24.  
    25. echo "$split {$dd->getDropdown()}";
    26.  
    27. $buttonGroup->setColor("success");
    28. $buttonGroup->printHtml();
    29.  
    30. $buttonGroup->stackFor("all")
    31.         ->printHtml();
    32.  
    Highlighted with GeSHi 1.0.9.1
  • Execution result as HTML5 flow