2 * Copyright 2015-present Greg Hurrell. All rights reserved.
3 * Licensed under the terms of the MIT license.
10 import DIGITS from './DIGITS';
11 import DynamicField from './DynamicField.react';
12 import React from 'react';
13 import type Value from './Field.react';
14 import Field from './Field.react';
15 import Label from './Label.react';
16 import Size from './Size.react';
17 import convert from './convert';
21 const SERIALIZATION_BASE = DIGITS.length;
23 function getInitialValue() {
24 // Extract value from URL fragment, if present.
25 const value = window.location.hash.replace(/^#/, '');
26 const validator = new RegExp(`^[${DIGITS}]+$`);
27 if (!validator.test(value)) {
31 base: SERIALIZATION_BASE,
37 export default class App extends React.Component {
41 value: getInitialValue(),
45 _onValueChange = (value: Value) => {
46 this.setState({value});
47 window.history.replaceState(
50 '#' + convert(value.value, value.base, SERIALIZATION_BASE)
55 this._firstInput.focus();
59 const {value} = this.state;
62 <div className="hextrapolate">
64 Hextrapolate — <Size value={value} />
66 <Label text="Hexadecimal">
69 onValueChange={this._onValueChange}
70 ref={ref => this._firstInput = ref}
74 <Label text="Decimal">
76 onValueChange={this._onValueChange}
83 onValueChange={this._onValueChange}
90 onValueChange={this._onValueChange}
97 onValueChange={this._onValueChange}
102 onValueChange={this._onValueChange}
104 <footer className="hextrapolate-footer">
105 <a href="mailto:greg@hurrell.net">Contact</a>
107 <a href="https://github.com/wincent/hextrapolate">Source</a>