From a3963c54f938322033077822891e1ddfae14e05d Mon Sep 17 00:00:00 2001 From: Gary Thomas Date: Tue, 8 Nov 2016 10:42:35 -0800 Subject: [PATCH] gt - Add Select2 equivalent --- package.json | 1 + src/components/Address.js | 376 +++++++++++++++++++++++++++------ src/components/Select.js | 27 +++ src/components/Select.scss | 6 + test/components/Select.spec.js | 13 ++ 5 files changed, 362 insertions(+), 61 deletions(-) create mode 100644 src/components/Select.js create mode 100644 src/components/Select.scss create mode 100644 test/components/Select.spec.js diff --git a/package.json b/package.json index cae01c8be..14e887ffe 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "react-addons-test-utils": "~15.3.0", "react-addons-transition-group": "^15.3.2", "react-fontawesome": "^1.2.0", + "react-select": "^1.0.0-rc.2", "sass-loader": "~4.0.0", "sinon": "^1.17.6", "style-loader": "~0.13.0", diff --git a/src/components/Address.js b/src/components/Address.js index ce55dda72..b8e5b4095 100644 --- a/src/components/Address.js +++ b/src/components/Address.js @@ -1,58 +1,312 @@ -import React, { PropTypes } from 'react'; +import React from 'react'; import { FormGroup, Input, Row, Col } from 'reactstrap'; +import Select from './Select.js'; -const US_STATES = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', - 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', - 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', - 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']; -const COUNTRIES = ['United States', 'Canada', 'Aaland Islands', 'Afghanistan', 'Albania', - 'Algeria', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua & Barbuda', - 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', - 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', - 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia & Herzegovina', 'Botswana', - 'Bouvet Island', 'Brazil', 'Britain (UK)', 'British Indian Ocean Territory', - 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', - 'Cape Verde', 'Caribbean Netherlands', 'Cayman Islands', 'Central African Rep.', - 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', - 'Colombia', 'Comoros', 'Congo (Dem. Rep.)', 'Congo (Rep.)', 'Cook Islands', - 'Costa Rica', 'Cote d\'Ivoire', 'Croatia', 'Cuba', 'Curacao', 'Cyprus', - 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', - 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', - 'Estonia', 'Ethiopia', 'Falkland Islands', 'Faroe Islands', 'Fiji', 'Finland', - 'France', 'French Guiana', 'French Polynesia', - 'French Southern & Antarctic Lands', 'Gabon', 'Gambia', 'Georgia', 'Germany', - 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', - 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', - 'Heard Island & McDonald Islands', 'Honduras', 'Hong Kong', 'Hungary', - 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', - 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', - 'Kenya', 'Kiribati', 'Korea (North)', 'Korea (South)', 'Kuwait', 'Kyrgyzstan', - 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', - 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', - 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', - 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia', 'Moldova', - 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', - 'Myanmar (Burma)', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Caledonia', - 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', - 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestine', - 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', - 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russia', - 'Rwanda', 'Samoa (American)', 'Samoa (western)', 'San Marino', - 'Sao Tome & Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', - 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', - 'Somalia', 'South Africa', 'South Georgia & the South Sandwich Islands', - 'South Sudan', 'Spain', 'Sri Lanka', 'St Barthelemy', 'St Helena', - 'St Kitts & Nevis', 'St Lucia', 'St Maarten (Dutch part)', - 'St Martin (French part)', 'St Pierre & Miquelon', 'St Vincent', 'Sudan', - 'Suriname', 'Svalbard & Jan Mayen', 'Swaziland', 'Sweden', 'Switzerland', - 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tokelau', - 'Tonga', 'Trinidad & Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', - 'Turks & Caicos Is', 'Tuvalu', 'US Minor Outlying Islands', 'Uganda', 'Ukraine', - 'United Arab Emirates', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', - 'Venezuela', 'Vietnam', 'Virgin Islands (UK)', 'Virgin Islands (US)', - 'Wallis & Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe']; +const US_STATES = [ + { label: 'AL', value: 'AL' }, + { label: 'AK', value: 'AK' }, + { label: 'AZ', value: 'AZ' }, + { label: 'AR', value: 'AR' }, + { label: 'CA', value: 'CA' }, + { label: 'CO', value: 'CO' }, + { label: 'CT', value: 'CT' }, + { label: 'DE', value: 'DE' }, + { label: 'DC', value: 'DC' }, + { label: 'FL', value: 'FL' }, + { label: 'GA', value: 'GA' }, + { label: 'HI', value: 'HI' }, + { label: 'ID', value: 'ID' }, + { label: 'IL', value: 'IL' }, + { label: 'IN', value: 'IN' }, + { label: 'IA', value: 'IA' }, + { label: 'KS', value: 'KS' }, + { label: 'KY', value: 'KY' }, + { label: 'LA', value: 'LA' }, + { label: 'ME', value: 'ME' }, + { label: 'MD', value: 'MD' }, + { label: 'MA', value: 'MA' }, + { label: 'MI', value: 'MI' }, + { label: 'MN', value: 'MN' }, + { label: 'MS', value: 'MS' }, + { label: 'MO', value: 'MO' }, + { label: 'MT', value: 'MT' }, + { label: 'NE', value: 'NE' }, + { label: 'NV', value: 'NV' }, + { label: 'NH', value: 'NH' }, + { label: 'NJ', value: 'NJ' }, + { label: 'NM', value: 'NM' }, + { label: 'NY', value: 'NY' }, + { label: 'NC', value: 'NC' }, + { label: 'ND', value: 'ND' }, + { label: 'OH', value: 'OH' }, + { label: 'OK', value: 'OK' }, + { label: 'OR', value: 'OR' }, + { label: 'PA', value: 'PA' }, + { label: 'RI', value: 'RI' }, + { label: 'SC', value: 'SC' }, + { label: 'SD', value: 'SD' }, + { label: 'TN', value: 'TN' }, + { label: 'TX', value: 'TX' }, + { label: 'UT', value: 'UT' }, + { label: 'VT', value: 'VT' }, + { label: 'VA', value: 'VA' }, + { label: 'WA', value: 'WA' }, + { label: 'WV', value: 'WV' }, + { label: 'WI', value: 'WI' }, +{ label: 'WY', value: 'WY' } +]; +const COUNTRIES = [ + { label: 'Afghanistan', value: 'AF' }, + { label: 'Åland Islands', value: 'AX' }, + { label: 'Albania', value: 'AL' }, + { label: 'Algeria', value: 'DZ' }, + { label: 'American Samoa', value: 'AS' }, + { label: 'Andorra', value: 'AD' }, + { label: 'Angola', value: 'AO' }, + { label: 'Anguilla', value: 'AI' }, + { label: 'Antarctica', value: 'AQ' }, + { label: 'Antigua and Barbuda', value: 'AG' }, + { label: 'Argentina', value: 'AR' }, + { label: 'Armenia', value: 'AM' }, + { label: 'Aruba', value: 'AW' }, + { label: 'Australia', value: 'AU' }, + { label: 'Austria', value: 'AT' }, + { label: 'Azerbaijan', value: 'AZ' }, + { label: 'Bahamas', value: 'BS' }, + { label: 'Bahrain', value: 'BH' }, + { label: 'Bangladesh', value: 'BD' }, + { label: 'Barbados', value: 'BB' }, + { label: 'Belarus', value: 'BY' }, + { label: 'Belgium', value: 'BE' }, + { label: 'Belize', value: 'BZ' }, + { label: 'Benin', value: 'BJ' }, + { label: 'Bermuda', value: 'BM' }, + { label: 'Bhutan', value: 'BT' }, + { label: 'Bolivia', value: 'BO' }, + { label: 'Bonaire, Sint Eustatius and Saba', value: 'BQ' }, + { label: 'Bosnia and Herzegovina', value: 'BA' }, + { label: 'Botswana', value: 'BW' }, + { label: 'Bouvet Island', value: 'BV' }, + { label: 'Brazil', value: 'BR' }, + { label: 'British Indian Ocean Territory', value: 'IO' }, + { label: 'Brunei Darussalam', value: 'BN' }, + { label: 'Bulgaria', value: 'BG' }, + { label: 'Burkina Faso', value: 'BF' }, + { label: 'Burundi', value: 'BI' }, + { label: 'Cabo Verde', value: 'CV' }, + { label: 'Cambodia', value: 'KH' }, + { label: 'Cameroon', value: 'CM' }, + { label: 'Canada', value: 'CA' }, + { label: 'Cayman Islands', value: 'KY' }, + { label: 'Central African Republic', value: 'CF' }, + { label: 'Chad', value: 'TD' }, + { label: 'Chile', value: 'CL' }, + { label: 'China', value: 'CN' }, + { label: 'Christmas Island', value: 'CX' }, + { label: 'Cocos (Keeling) Islands', value: 'CC' }, + { label: 'Colombia', value: 'CO' }, + { label: 'Comoros', value: 'KM' }, + { label: 'Congo', value: 'CG' }, + { label: 'Congo (Democratic Republic of the)', value: 'CD' }, + { label: 'Cook Islands', value: 'CK' }, + { label: 'Costa Rica', value: 'CR' }, + { label: 'Côte d\'Ivoire', value: 'CI' }, + { label: 'Croatia', value: 'HR' }, + { label: 'Cuba', value: 'CU' }, + { label: 'Curaçao', value: 'CW' }, + { label: 'Cyprus', value: 'CY' }, + { label: 'Czechia', value: 'CZ' }, + { label: 'Denmark', value: 'DK' }, + { label: 'Djibouti', value: 'DJ' }, + { label: 'Dominica', value: 'DM' }, + { label: 'Dominican Republic', value: 'DO' }, + { label: 'Ecuador', value: 'EC' }, + { label: 'Egypt', value: 'EG' }, + { label: 'El Salvador', value: 'SV' }, + { label: 'Equatorial Guinea', value: 'GQ' }, + { label: 'Eritrea', value: 'ER' }, + { label: 'Estonia', value: 'EE' }, + { label: 'Ethiopia', value: 'ET' }, + { label: 'Falkland Islands (Malvinas)', value: 'FK' }, + { label: 'Faroe Islands', value: 'FO' }, + { label: 'Fiji', value: 'FJ' }, + { label: 'Finland', value: 'FI' }, + { label: 'France', value: 'FR' }, + { label: 'French Guiana', value: 'GF' }, + { label: 'French Polynesia', value: 'PF' }, + { label: 'French Southern Territories', value: 'TF' }, + { label: 'Gabon', value: 'GA' }, + { label: 'Gambia', value: 'GM' }, + { label: 'Georgia', value: 'GE' }, + { label: 'Germany', value: 'DE' }, + { label: 'Ghana', value: 'GH' }, + { label: 'Gibraltar', value: 'GI' }, + { label: 'Greece', value: 'GR' }, + { label: 'Greenland', value: 'GL' }, + { label: 'Grenada', value: 'GD' }, + { label: 'Guadeloupe', value: 'GP' }, + { label: 'Guam', value: 'GU' }, + { label: 'Guatemala', value: 'GT' }, + { label: 'Guernsey', value: 'GG' }, + { label: 'Guinea', value: 'GN' }, + { label: 'Guinea-Bissau', value: 'GW' }, + { label: 'Guyana', value: 'GY' }, + { label: 'Haiti', value: 'HT' }, + { label: 'Heard Island and McDonald Islands', value: 'HM' }, + { label: 'Holy See', value: 'VA' }, + { label: 'Honduras', value: 'HN' }, + { label: 'Hong Kong', value: 'HK' }, + { label: 'Hungary', value: 'HU' }, + { label: 'Iceland', value: 'IS' }, + { label: 'India', value: 'IN' }, + { label: 'Indonesia', value: 'ID' }, + { label: 'Iran (Islamic Republic of)', value: 'IR' }, + { label: 'Iraq', value: 'IQ' }, + { label: 'Ireland', value: 'IE' }, + { label: 'Isle of Man', value: 'IM' }, + { label: 'Israel', value: 'IL' }, + { label: 'Italy', value: 'IT' }, + { label: 'Jamaica', value: 'JM' }, + { label: 'Japan', value: 'JP' }, + { label: 'Jersey', value: 'JE' }, + { label: 'Jordan', value: 'JO' }, + { label: 'Kazakhstan', value: 'KZ' }, + { label: 'Kenya', value: 'KE' }, + { label: 'Kiribati', value: 'KI' }, + { label: 'Korea (Democratic People\'s Republic of)', value: 'KP' }, + { label: 'Korea (Republic of)', value: 'KR' }, + { label: 'Kuwait', value: 'KW' }, + { label: 'Kyrgyzstan', value: 'KG' }, + { label: 'Lao People\'s Democratic Republic', value: 'LA' }, + { label: 'Latvia', value: 'LV' }, + { label: 'Lebanon', value: 'LB' }, + { label: 'Lesotho', value: 'LS' }, + { label: 'Liberia', value: 'LR' }, + { label: 'Libya', value: 'LY' }, + { label: 'Liechtenstein', value: 'LI' }, + { label: 'Lithuania', value: 'LT' }, + { label: 'Luxembourg', value: 'LU' }, + { label: 'Macao', value: 'MO' }, + { label: 'Macedonia', value: 'MK' }, + { label: 'Madagascar', value: 'MG' }, + { label: 'Malawi', value: 'MW' }, + { label: 'Malaysia', value: 'MY' }, + { label: 'Maldives', value: 'MV' }, + { label: 'Mali', value: 'ML' }, + { label: 'Malta', value: 'MT' }, + { label: 'Marshall Islands', value: 'MH' }, + { label: 'Martinique', value: 'MQ' }, + { label: 'Mauritania', value: 'MR' }, + { label: 'Mauritius', value: 'MU' }, + { label: 'Mayotte', value: 'YT' }, + { label: 'Mexico', value: 'MX' }, + { label: 'Micronesia (Federated States of)', value: 'FM' }, + { label: 'Moldova (Republic of)', value: 'MD' }, + { label: 'Monaco', value: 'MC' }, + { label: 'Mongolia', value: 'MN' }, + { label: 'Montenegro', value: 'ME' }, + { label: 'Montserrat', value: 'MS' }, + { label: 'Morocco', value: 'MA' }, + { label: 'Mozambique', value: 'MZ' }, + { label: 'Myanmar', value: 'MM' }, + { label: 'Namibia', value: 'NA' }, + { label: 'Nauru', value: 'NR' }, + { label: 'Nepal', value: 'NP' }, + { label: 'Netherlands', value: 'NL' }, + { label: 'New Caledonia', value: 'NC' }, + { label: 'New Zealand', value: 'NZ' }, + { label: 'Nicaragua', value: 'NI' }, + { label: 'Niger', value: 'NE' }, + { label: 'Nigeria', value: 'NG' }, + { label: 'Niue', value: 'NU' }, + { label: 'Norfolk Island', value: 'NF' }, + { label: 'Northern Mariana Islands', value: 'MP' }, + { label: 'Norway', value: 'NO' }, + { label: 'Oman', value: 'OM' }, + { label: 'Pakistan', value: 'PK' }, + { label: 'Palau', value: 'PW' }, + { label: 'Palestine, State of', value: 'PS' }, + { label: 'Panama', value: 'PA' }, + { label: 'Papua New Guinea', value: 'PG' }, + { label: 'Paraguay', value: 'PY' }, + { label: 'Peru', value: 'PE' }, + { label: 'Philippines', value: 'PH' }, + { label: 'Pitcairn', value: 'PN' }, + { label: 'Poland', value: 'PL' }, + { label: 'Portugal', value: 'PT' }, + { label: 'Puerto Rico', value: 'PR' }, + { label: 'Qatar', value: 'QA' }, + { label: 'Réunion', value: 'RE' }, + { label: 'Romania', value: 'RO' }, + { label: 'Russian Federation', value: 'RU' }, + { label: 'Rwanda', value: 'RW' }, + { label: 'Saint Barthélemy', value: 'BL' }, + { label: 'Saint Helena, Ascension and Tristan da Cunha', value: 'SH' }, + { label: 'Saint Kitts and Nevis', value: 'KN' }, + { label: 'Saint Lucia', value: 'LC' }, + { label: 'Saint Martin (French part)', value: 'MF' }, + { label: 'Saint Pierre and Miquelon', value: 'PM' }, + { label: 'Saint Vincent and the Grenadines', value: 'VC' }, + { label: 'Samoa', value: 'WS' }, + { label: 'San Marino', value: 'SM' }, + { label: 'Sao Tome and Principe', value: 'ST' }, + { label: 'Saudi Arabia', value: 'SA' }, + { label: 'Senegal', value: 'SN' }, + { label: 'Serbia', value: 'RS' }, + { label: 'Seychelles', value: 'SC' }, + { label: 'Sierra Leone', value: 'SL' }, + { label: 'Singapore', value: 'SG' }, + { label: 'Sint Maarten (Dutch part)', value: 'SX' }, + { label: 'Slovakia', value: 'SK' }, + { label: 'Slovenia', value: 'SI' }, + { label: 'Solomon Islands', value: 'SB' }, + { label: 'Somalia', value: 'SO' }, + { label: 'South Africa', value: 'ZA' }, + { label: 'South Georgia and the South Sandwich Islands', value: 'GS' }, + { label: 'South Sudan', value: 'SS' }, + { label: 'Spain', value: 'ES' }, + { label: 'Sri Lanka', value: 'LK' }, + { label: 'Sudan', value: 'SD' }, + { label: 'Suriname', value: 'SR' }, + { label: 'Svalbard and Jan Mayen', value: 'SJ' }, + { label: 'Swaziland', value: 'SZ' }, + { label: 'Sweden', value: 'SE' }, + { label: 'Switzerland', value: 'CH' }, + { label: 'Syrian Arab Republic', value: 'SY' }, + { label: 'Taiwan, Province of China[a]', value: 'TW' }, + { label: 'Tajikistan', value: 'TJ' }, + { label: 'Tanzania, United Republic of', value: 'TZ' }, + { label: 'Thailand', value: 'TH' }, + { label: 'Timor-Leste', value: 'TL' }, + { label: 'Togo', value: 'TG' }, + { label: 'Tokelau', value: 'TK' }, + { label: 'Tonga', value: 'TO' }, + { label: 'Trinidad and Tobago', value: 'TT' }, + { label: 'Tunisia', value: 'TN' }, + { label: 'Turkey', value: 'TR' }, + { label: 'Turkmenistan', value: 'TM' }, + { label: 'Turks and Caicos Islands', value: 'TC' }, + { label: 'Tuvalu', value: 'TV' }, + { label: 'Uganda', value: 'UG' }, + { label: 'Ukraine', value: 'UA' }, + { label: 'United Arab Emirates', value: 'AE' }, + { label: 'United Kingdom of Great Britain and Northern Ireland', value: 'GB' }, + { label: 'United States of America', value: 'US' }, + { label: 'United States Minor Outlying Islands', value: 'UM' }, + { label: 'Uruguay', value: 'UY' }, + { label: 'Uzbekistan', value: 'UZ' }, + { label: 'Vanuatu', value: 'VU' }, + { label: 'Venezuela (Bolivarian Republic of)', value: 'VE' }, + { label: 'Viet Nam', value: 'VN' }, + { label: 'Virgin Islands (British)', value: 'VG' }, + { label: 'Virgin Islands (U.S.)', value: 'VI' }, + { label: 'Wallis and Futuna', value: 'WF' }, + { label: 'Western Sahara', value: 'EH' }, + { label: 'Yemen', value: 'YE' }, + { label: 'Zambia', value: 'ZM' }, + { label: 'Zimbabwe', value: 'ZW' } +]; -// TODO use Select2, etc for States and Countries // TODO prop binding and validation const Address = (props) => ( @@ -69,9 +323,10 @@ const Address = (props) => ( - - {US_STATES.map(state => )} - + @@ -79,15 +334,14 @@ const Address = (props) => ( - - {COUNTRIES.map(country => )} - + + ); + } +} + +export default Select2; diff --git a/src/components/Select.scss b/src/components/Select.scss new file mode 100644 index 000000000..5da6f99d0 --- /dev/null +++ b/src/components/Select.scss @@ -0,0 +1,6 @@ +// Import and override react-select's SCSS variables to match BS4: +$select-input-border-width: 0.1rem; +$select-input-height: 2.4rem !default; +// TODO correct inner padding, colors to match BS styles + +@import '~react-select/scss/default.scss'; diff --git a/test/components/Select.spec.js b/test/components/Select.spec.js new file mode 100644 index 000000000..cace49ed2 --- /dev/null +++ b/test/components/Select.spec.js @@ -0,0 +1,13 @@ +/* eslint-env mocha */ + +import 'jsdom-global/register'; +//import React from 'react'; +//import assert from 'assert'; +//import { mount } from 'enzyme'; + +// import Select from '../../src/components/Select.js'; + +describe('