public static function build($config) { $label = $config['label']; $type = $config['type']; $action = $config['action']; $method = isset($config['method']) ? strtoupper($config['method']) : 'GET'; $keywords = isset($config['keywords']) ? implode(' ', $config['keywords']) : null; $string = ''; // open form if ($type == 'big') { $string .= '<form class="usa-search usa-search-big"'; } elseif ($type == 'small') { $string .= '<form class="usa-search usa-search-small"'; } else { $string .= '<form class="usa-search"'; } $string .= 'action="' . $action . '" method="' . $method . '">'; $string .= '<div role="search">'; // label form if ($type == 'big') { $string .= '<label class="usa-sr-only" for="search-field-big">'; } elseif ($type == 'medium') { $string .= '<label class="usa-sr-only" for="search-field">'; } elseif ($type == 'small') { $string .= '<label class="usa-sr-only" for="search-field-small">'; } $string .= $label . '</label>'; // search input text box if ($type == 'big') { $string .= '<input id="search-field-big" type="search" name="search"'; } elseif ($type == 'medium') { $string .= '<input id="search-field" type="search" name="search"'; } elseif ($type == 'small') { $string .= '<input id="search-field-small" type="search" name="search"'; } $string .= strlen($keywords) > 0 ? ' value="' . $keywords . '">' : '>'; // search button $string .= '<button type="submit">'; if ($type == 'big' || $type == 'medium') { $string .= '<span class="usa-search-submit-text">Search</span>'; } elseif ($type == 'small') { $string .= '<span class="usa-sr-only">Search</span>'; } $string .= '</button>'; $string .= '</div>'; $string .= '</form>'; if (isset($config['filters'])) { // We need to remove the closure from the USWDS search bar // in order to include our filters. $string = str_replace('</div></form>', '', $string); foreach ($config['filters'] as $filter) { if ($filter['type'] == 'checkbox') { $string .= '<div class="use-with-one-whole">'; } else { $string .= '<div class="usa-width-one-half" style="margin-right: 7px;">'; } $string .= FormControls::select($filter); $string .= '</div>'; } // replace closure $string .= '</div></form>'; } return $string; }
static function build() { return FormControls::select(['label' => 'State', 'type' => 'dropdown', 'name' => 'state', 'options' => ['' => '', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District Of Columbia', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming']]); }
/** * * radio * */ public function testRadioUSWDSSample() { $expected = '<div>' . '<fieldset class="usa-fieldset-inputs">' . '<legend class="usa-sr-only">Historical figures 2</legend>' . '<ul class="usa-unstyled-list">' . '<li>' . '<input id="pea-soup-soup" type="radio" name="soup" value="pea-soup" checked="">' . '<label for="pea-soup-soup">Elizabeth Cady Stanton</label>' . '</li>' . '<li>' . '<input id="chicken-noodle-soup" type="radio" name="soup" value="chicken-noodle">' . '<label for="chicken-noodle-soup">Susan B. Anthony</label>' . '</li>' . '<li>' . '<input id="tomato-soup" type="radio" name="soup" value="tomato">' . '<label for="tomato-soup">Harriet Tubman</label>' . '</li>' . '</ul>' . '</fieldset>' . '</div>'; $result = FormControls::select(['label' => 'Historical figures 2', 'type' => 'radio', 'name' => 'soup', 'options' => ['pea-soup' => 'Elizabeth Cady Stanton', 'chicken-noodle' => 'Susan B. Anthony', 'tomato' => 'Harriet Tubman'], 'selected' => ['pea-soup'], 'srOnly' => true]); $this->assertTrue($result == $expected, $expected . "\n\n" . $result); }