From b5f1b34bdb565835e580ab0714d63bd5ab3b674d Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Sat, 1 Aug 2015 22:52:15 -0700 Subject: [PATCH] Add a couple of dynamic fields --- src/App.js | 11 +++++++ src/DynamicField.react.js | 60 +++++++++++++++++++++++++++++++++++++++ src/Field.react.js | 4 +-- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/DynamicField.react.js diff --git a/src/App.js b/src/App.js index cfaa589..7009c03 100644 --- a/src/App.js +++ b/src/App.js @@ -7,6 +7,7 @@ 'use strict'; +import DynamicField from './DynamicField.react'; import React from 'react'; import type Value from './Field.react'; import Field from './Field.react'; @@ -57,6 +58,16 @@ export default class App extends React.Component { value={this.state.value} /> + + ); } diff --git a/src/DynamicField.react.js b/src/DynamicField.react.js new file mode 100644 index 0000000..673cc2d --- /dev/null +++ b/src/DynamicField.react.js @@ -0,0 +1,60 @@ +/** + * Copyright 2015-present Greg Hurrell. All rights reserved. + * Licensed under the terms of the MIT license. + * + * @flow + */ + +'use strict'; + +import React from 'react'; +import { + default as Field, + ValuePropType, +} from './Field.react'; + +export default class DynamicField extends React.Component { + static propTypes = { + initialBase: React.PropTypes.number, + onValueChange: React.PropTypes.func.required, + value: ValuePropType, + }; + + constructor(props) { + super(props); + this.state = {base: props.initialBase}; + } + + _onChange = event => { + const base = parseInt(event.target.value, 10); + this.setState({base}); + } + + _renderOptions() { + const options = []; + for (let i = 2; i <= 36; i++) { + options.push( + + ); + } + return options; + } + + render() { + return ( + + ); + } +} diff --git a/src/Field.react.js b/src/Field.react.js index 5ff4be7..6331cc4 100644 --- a/src/Field.react.js +++ b/src/Field.react.js @@ -19,7 +19,7 @@ export const ValuePropType = React.PropTypes.shape({ value: React.PropTypes.string, }); -const DIGITS = '0123456789abcdef'; +const DIGITS = '0123456789abcdefghijklmnopqrstuvwxyz'; /** * Convert from `value` to `base`. @@ -80,7 +80,7 @@ export default class Field extends React.Component { } } - _copyLink = () => { + _copyLink() { // Would check `document.queryCommandSupported('copy')` here, but that // doesn't work; see: // - https://code.google.com/p/chromium/issues/detail?id=476508 -- 2.37.1