Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Replace Select component and document it
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebrooker committed Mar 11, 2016
1 parent 8d41e12 commit eeefc39
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 5 deletions.
2 changes: 2 additions & 0 deletions frontend/src/main/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
frontend.bundle.min.js
src/styles/atomic.css
src/components/Select/index.css
src/constants/styles.json
16 changes: 11 additions & 5 deletions frontend/src/main/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
"scripts": {
"js": "webpack",
"build": "npm run build:css && npm run build:icons && npm run build:webpack && npm run build:webpackLegacy",
"build:css": "webpack --config webpack.config.js",
"build:css": "npm run build:sass && webpack --config webpack.config.js",
"build:dev": "npm run build:icons & npm run build:sass",
"build:sass": "npm run variables && node-sass src/components/Select/index.scss -o src/components/Select --include-path node_modules --importer node_modules/node-sass-json-importer/dist/node-sass-json-importer.js",
"build:icons": "npm run svg && npm run icons",
"build:webpack": "webpack -p --config webpack.prod.config.js --bail --display-error-details",
"build:webpackLegacy": "webpack -p --config webpack.legacy.config.js --bail --display-error-details",
"icons": "node scripts/createIconsComponent && node scripts/generateIconList",
"hot-dev-server": "webpack-dev-server --config webpack.dev.config.js --progress --inline --hot --port 8000",
"start": "npm run build:icons && npm run hot-dev-server",
"styleguide-server": "npm run build:icons && styleguidist server",
"styleguide-build": "npm run build:icons && styleguidist build",
"start": "npm run build:dev && npm run hot-dev-server",
"styleguide-server": "npm run build:dev && styleguidist server",
"styleguide-build": "npm run build:dev && styleguidist build",
"svg": "svg-sprite -sD src/components/Icons --symbol-dest '' --ss icons.svg --si src/components/Icons/svgs/*.svg",
"test": "echo \"Error: no test specified. Jest tests need to be migrated to tape.\" && exit 1"
"test": "echo \"Error: no test specified. Jest tests need to be migrated to tape.\" && exit 1",
"variables": "node scripts/writeVariablesJson"
},
"license": "LGPL",
"devDependencies": {
Expand All @@ -41,6 +44,8 @@
"eslint-plugin-standard": "^1.3.1",
"extract-text-webpack-plugin": "^0.9.1",
"jest-cli": "github:jamedranoa/jest",
"jsonfile": "^2.2.3",
"node-sass": "^3.4.2",
"react-addons-test-utils": "^0.14.7",
"react-transform-hmr": "^1.0.4",
"react-styleguidist": "^2.0.1",
Expand Down Expand Up @@ -78,6 +83,7 @@
"react-redux": "^4.4.0",
"react-router": "^2.0.0-rc6",
"react-router-redux": "^3.0.0",
"react-select": "^1.0.0-beta10",
"react-textarea-autosize": "^3.3.0",
"redux": "^3.3.1",
"redux-actions": "^0.9.1",
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/main/web/scripts/writeVariablesJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var jsonfile = require('jsonfile')
var variables = require('../src/constants/styles.js')
var file = './src/constants/styles.json'

jsonfile.writeFile(file, variables, {spaces: 2}, function (err) {
err && console.error(err)
})
4 changes: 4 additions & 0 deletions frontend/src/main/web/src/components/Select/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Select from 'react-select'
import './index.css'

export default Select
65 changes: 65 additions & 0 deletions frontend/src/main/web/src/components/Select/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@import '../../constants/styles.json';

// Variables
// ------------------------------

// control options
$select-input-bg: #fff !default;
$select-input-bg-disabled: map-get($colors, light);
$select-input-border-color: map-get($colors, neutral);
$select-input-border-radius: map-get($rhythmem, eq);
$select-input-border-focus: map-get($colors, pri);
$select-input-border-width: .125em !default; // 2px
$select-input-height: map-get($rhythmem, e1h);
$select-input-internal-height: ($select-input-height - ($select-input-border-width * 2));
$select-input-placeholder: map-get($colors, neutral);
$select-text-color: map-get($colors, dark);
$select-link-hover-color: map-get($colors, pri);

$select-padding-vertical: map-get($rhythmem, eq);
$select-padding-horizontal: map-get($rhythmem, eh);

// menu options
$select-menu-zindex: 1000 !default;
$select-menu-max-height: 200px !default;

$select-option-color: lighten($select-text-color, 20%) !default;
$select-option-bg: $select-input-bg !default;
$select-option-focused-color: map-get($colors, light);
$select-option-focused-bg: map-get($colors, pri);
$select-option-disabled-color: map-get($colors, muted);

$select-noresults-color: map-get($colors, muted);

// clear "x" button
$select-clear-size: 1.5em;
$select-clear-color: map-get($colors, muted);
$select-clear-hover-color: map-get($colors, danger);
$select-clear-width: ($select-input-internal-height / 1.25);

// arrow indicator
$select-arrow-color: map-get($colors, neutral);
$select-arrow-color-hover: map-get($colors, muted);
$select-arrow-width: .3125em !default; // 5px

// loading indicator
$select-loading-size: 1em;
$select-loading-color: $select-text-color !default;
$select-loading-color-bg: $select-input-border-color !default;

// multi-select item
$select-item-border-radius: map-get($rhythmem, eq);
$select-item-gutter: .3125em; // 5px
$select-item-padding-vertical: .125em; // 2px
$select-item-padding-horizontal: .3125em; // 5px
$select-item-font-size: .9em !default;
$select-item-color: map-get($colors, pri) !default;
$select-item-bg: map-get($colors, pri);
$select-item-border-color: darken($select-item-bg, 10%) !default;
$select-item-hover-color: darken($select-item-color, 5%) !default;
$select-item-hover-bg: darken($select-item-bg, 5%) !default;
$select-item-disabled-color: map-get($colors, dark) !default;
$select-item-disabled-bg: map-get($colors, light) !default;
$select-item-disabled-border-color: darken($select-item-disabled-bg, 10%) !default;

@import 'react-select/scss/default.scss';
28 changes: 28 additions & 0 deletions frontend/src/main/web/src/components/Select/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Based on [React Select](https://github.com/JedWatson/react-select), this just
adds custom styling.
See [React Select Docs](https://github.com/JedWatson/react-select) for available
option.

To adjust the size, you can change the font-size using className,
e.g. `className='Fz(ms2)'`.

var options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' },
{ value: 'three', label: 'Three' },
{ value: 'four', label: 'Four' },
{ value: 'five', label: 'Five' },
{ value: 'six', label: 'Six' }
];

function handleChange(val) {
setState({value: val})
}

<Select
name='form-field-name'
value={state.value}
placeholder='Select a value'
options={options}
onChange={handleChange}
/>
1 change: 1 addition & 0 deletions frontend/src/main/web/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export NavIcon from './NavIcon'
export Page from './Page'
export Row from './Row'
export ScrollView from './ScrollView'
export Select from './Select'
export TableCell from './TableCell'
export TableRow from './TableRow'
export TextInput from './TextInput'
Expand Down

0 comments on commit eeefc39

Please sign in to comment.