aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components
diff options
context:
space:
mode:
authorFred Carlsen <fred@sjelfull.no>2018-12-15 06:24:08 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-15 06:24:08 +0800
commite53f28c5705ad6dc5afeb672ef7491c15a682018 (patch)
treec8f946751f4fa88cfadbe621349f7f30b447e000 /packages/instant/src/components
parent5c083ba16bb5db4e3b74035b73c0307b7f8db65e (diff)
parent6d45beccad44e86ddd692d0cf54c09c29c5d9daf (diff)
downloaddexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar.gz
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar.bz2
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar.lz
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar.xz
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.tar.zst
dexon-sol-tools-e53f28c5705ad6dc5afeb672ef7491c15a682018.zip
Merge remote-tracking branch 'upstream/development' into website
# Conflicts: # .gitignore # README.md # contracts/core/CHANGELOG.json # contracts/examples/package.json # contracts/extensions/package.json # contracts/interfaces/package.json # contracts/libs/package.json # contracts/multisig/package.json # contracts/protocol/CHANGELOG.json # contracts/protocol/DEPLOYS.json # contracts/protocol/package.json # contracts/test-utils/CHANGELOG.json # contracts/test-utils/CHANGELOG.md # contracts/test-utils/package.json # contracts/tokens/CHANGELOG.json # contracts/tokens/package.json # contracts/utils/package.json # packages/0x.js/CHANGELOG.json # packages/0x.js/CHANGELOG.md # packages/0x.js/package.json # packages/abi-gen-wrappers/CHANGELOG.json # packages/abi-gen-wrappers/CHANGELOG.md # packages/abi-gen-wrappers/package.json # packages/abi-gen/CHANGELOG.json # packages/abi-gen/CHANGELOG.md # packages/abi-gen/package.json # packages/assert/CHANGELOG.json # packages/assert/CHANGELOG.md # packages/assert/package.json # packages/asset-buyer/CHANGELOG.md # packages/asset-buyer/package.json # packages/base-contract/CHANGELOG.json # packages/base-contract/CHANGELOG.md # packages/base-contract/package.json # packages/connect/CHANGELOG.json # packages/connect/CHANGELOG.md # packages/connect/package.json # packages/contract-wrappers/CHANGELOG.json # packages/contract-wrappers/CHANGELOG.md # packages/contract-wrappers/package.json # packages/dev-tools-pages/package.json # packages/dev-utils/CHANGELOG.json # packages/dev-utils/CHANGELOG.md # packages/dev-utils/package.json # packages/ethereum-types/CHANGELOG.json # packages/ethereum-types/CHANGELOG.md # packages/ethereum-types/package.json # packages/fill-scenarios/CHANGELOG.json # packages/fill-scenarios/CHANGELOG.md # packages/fill-scenarios/package.json # packages/instant/package.json # packages/instant/src/types.ts # packages/json-schemas/CHANGELOG.json # packages/json-schemas/CHANGELOG.md # packages/json-schemas/package.json # packages/metacoin/package.json # packages/migrations/CHANGELOG.json # packages/migrations/CHANGELOG.md # packages/migrations/package.json # packages/order-utils/CHANGELOG.json # packages/order-utils/CHANGELOG.md # packages/order-utils/package.json # packages/order-watcher/CHANGELOG.json # packages/order-watcher/CHANGELOG.md # packages/order-watcher/package.json # packages/pipeline/package.json # packages/pipeline/src/ormconfig.ts # packages/pipeline/src/parsers/ddex_orders/index.ts # packages/pipeline/src/parsers/oasis_orders/index.ts # packages/pipeline/src/parsers/paradex_orders/index.ts # packages/pipeline/src/parsers/token_metadata/index.ts # packages/pipeline/src/scripts/pull_competing_dex_trades.ts # packages/pipeline/src/scripts/pull_ddex_orderbook_snapshots.ts # packages/pipeline/src/scripts/pull_idex_orderbook_snapshots.ts # packages/pipeline/src/scripts/pull_missing_blocks.ts # packages/pipeline/src/scripts/pull_oasis_orderbook_snapshots.ts # packages/pipeline/src/scripts/pull_paradex_orderbook_snapshots.ts # packages/pipeline/src/scripts/pull_trusted_tokens.ts # packages/pipeline/src/scripts/update_relayer_info.ts # packages/pipeline/src/utils/get_ohlcv_trading_pairs.ts # packages/pipeline/src/utils/index.ts # packages/pipeline/test/parsers/ddex_orders/index_test.ts # packages/pipeline/test/parsers/oasis_orders/index_test.ts # packages/pipeline/test/parsers/paradex_orders/index_test.ts # packages/react-docs/CHANGELOG.json # packages/react-docs/CHANGELOG.md # packages/react-docs/package.json # packages/react-shared/CHANGELOG.json # packages/react-shared/CHANGELOG.md # packages/react-shared/package.json # packages/sol-compiler/CHANGELOG.md # packages/sol-compiler/package.json # packages/sol-cov/CHANGELOG.json # packages/sol-cov/CHANGELOG.md # packages/sol-cov/package.json # packages/sol-doc/CHANGELOG.json # packages/sol-doc/CHANGELOG.md # packages/sol-doc/package.json # packages/sol-resolver/CHANGELOG.md # packages/sol-resolver/package.json # packages/sra-spec/CHANGELOG.json # packages/sra-spec/CHANGELOG.md # packages/sra-spec/package.json # packages/subproviders/CHANGELOG.json # packages/subproviders/CHANGELOG.md # packages/subproviders/package.json # packages/testnet-faucets/package.json # packages/types/CHANGELOG.md # packages/types/package.json # packages/typescript-typings/CHANGELOG.json # packages/typescript-typings/CHANGELOG.md # packages/typescript-typings/package.json # packages/utils/CHANGELOG.json # packages/utils/CHANGELOG.md # packages/utils/package.json # packages/web3-wrapper/CHANGELOG.json # packages/web3-wrapper/CHANGELOG.md # packages/web3-wrapper/package.json # packages/website/package.json # packages/website/public/index.html # packages/website/ts/pages/instant/fee_percentage_slider.tsx # yarn.lock
Diffstat (limited to 'packages/instant/src/components')
-rw-r--r--packages/instant/src/components/scaling_amount_input.tsx1
-rw-r--r--packages/instant/src/components/scaling_input.tsx93
-rw-r--r--packages/instant/src/components/ui/input.tsx6
3 files changed, 45 insertions, 55 deletions
diff --git a/packages/instant/src/components/scaling_amount_input.tsx b/packages/instant/src/components/scaling_amount_input.tsx
index 86aca5a65..4feb0502d 100644
--- a/packages/instant/src/components/scaling_amount_input.tsx
+++ b/packages/instant/src/components/scaling_amount_input.tsx
@@ -58,6 +58,7 @@ export class ScalingAmountInput extends React.Component<ScalingAmountInputProps,
const { textLengthThreshold, fontColor, maxFontSizePx, onFontSizeChange } = this.props;
return (
<ScalingInput
+ type="number"
maxFontSizePx={maxFontSizePx}
textLengthThreshold={textLengthThreshold}
onFontSizeChange={onFontSizeChange}
diff --git a/packages/instant/src/components/scaling_input.tsx b/packages/instant/src/components/scaling_input.tsx
index 791692257..00aea37da 100644
--- a/packages/instant/src/components/scaling_input.tsx
+++ b/packages/instant/src/components/scaling_input.tsx
@@ -1,3 +1,4 @@
+import { ObjectMap } from '@0x/types';
import * as _ from 'lodash';
import * as React from 'react';
@@ -13,10 +14,15 @@ export enum ScalingInputPhase {
export interface ScalingSettings {
percentageToReduceFontSizePerCharacter: number;
- constantPxToIncreaseWidthPerCharacter: number;
+ // 1ch = the width of the 0 chararacter.
+ // Allow to customize 'char' length for different characters.
+ characterWidthOverrides: ObjectMap<number>;
+ // How much room to leave to the right of the scaling input.
+ additionalInputSpaceInCh: number;
}
export interface ScalingInputProps {
+ type?: string;
textLengthThreshold: number;
maxFontSizePx: number;
value: string;
@@ -31,32 +37,29 @@ export interface ScalingInputProps {
hasAutofocus: boolean;
}
-export interface ScalingInputState {
- inputWidthPxAtPhaseChange?: number;
-}
-
export interface ScalingInputSnapshot {
inputWidthPx: number;
}
// These are magic numbers that were determined experimentally.
const defaultScalingSettings: ScalingSettings = {
- percentageToReduceFontSizePerCharacter: 0.125,
- constantPxToIncreaseWidthPerCharacter: 4,
+ percentageToReduceFontSizePerCharacter: 0.1,
+ characterWidthOverrides: {
+ '1': 0.7,
+ '.': 0.4,
+ },
+ additionalInputSpaceInCh: 0.4,
};
-export class ScalingInput extends React.Component<ScalingInputProps, ScalingInputState> {
+export class ScalingInput extends React.Component<ScalingInputProps> {
public static defaultProps = {
onChange: util.boundNoop,
onFontSizeChange: util.boundNoop,
- maxLength: 7,
+ maxLength: 9,
scalingSettings: defaultScalingSettings,
isDisabled: false,
hasAutofocus: false,
};
- public state: ScalingInputState = {
- inputWidthPxAtPhaseChange: undefined,
- };
private readonly _inputRef = React.createRef<HTMLInputElement>();
public static getPhase(textLengthThreshold: number, value: string): ScalingInputPhase {
if (value.length <= textLengthThreshold) {
@@ -93,36 +96,15 @@ export class ScalingInput extends React.Component<ScalingInputProps, ScalingInpu
scalingSettings.percentageToReduceFontSizePerCharacter,
);
}
- public getSnapshotBeforeUpdate(): ScalingInputSnapshot {
- return {
- inputWidthPx: this._getInputWidthInPx(),
- };
- }
public componentDidMount(): void {
// Trigger an initial notification of the calculated fontSize.
const currentPhase = ScalingInput.getPhaseFromProps(this.props);
const currentFontSize = ScalingInput.calculateFontSizeFromProps(this.props, currentPhase);
this.props.onFontSizeChange(currentFontSize);
}
- public componentDidUpdate(
- prevProps: ScalingInputProps,
- prevState: ScalingInputState,
- snapshot: ScalingInputSnapshot,
- ): void {
+ public componentDidUpdate(prevProps: ScalingInputProps): void {
const prevPhase = ScalingInput.getPhaseFromProps(prevProps);
const curPhase = ScalingInput.getPhaseFromProps(this.props);
- // if we went from fixed to scaling, save the width from the transition
- if (prevPhase !== ScalingInputPhase.ScalingFontSize && curPhase === ScalingInputPhase.ScalingFontSize) {
- this.setState({
- inputWidthPxAtPhaseChange: snapshot.inputWidthPx,
- });
- }
- // if we went from scaling to fixed, revert back to scaling using `ch`
- if (prevPhase === ScalingInputPhase.ScalingFontSize && curPhase !== ScalingInputPhase.ScalingFontSize) {
- this.setState({
- inputWidthPxAtPhaseChange: undefined,
- });
- }
const prevFontSize = ScalingInput.calculateFontSizeFromProps(prevProps, prevPhase);
const curFontSize = ScalingInput.calculateFontSizeFromProps(this.props, curPhase);
// If font size has changed, notify.
@@ -131,13 +113,14 @@ export class ScalingInput extends React.Component<ScalingInputProps, ScalingInpu
}
}
public render(): React.ReactNode {
- const { hasAutofocus, isDisabled, fontColor, onChange, placeholder, value, maxLength } = this.props;
+ const { type, hasAutofocus, isDisabled, fontColor, placeholder, value, maxLength } = this.props;
const phase = ScalingInput.getPhaseFromProps(this.props);
return (
<Input
+ type={type}
ref={this._inputRef as any}
fontColor={fontColor}
- onChange={onChange}
+ onChange={this._handleChange}
value={value}
placeholder={placeholder}
fontSize={`${this._calculateFontSize(phase)}px`}
@@ -149,32 +132,34 @@ export class ScalingInput extends React.Component<ScalingInputProps, ScalingInpu
);
}
private readonly _calculateWidth = (phase: ScalingInputPhase): string => {
- const { value, textLengthThreshold, scalingSettings } = this.props;
+ const { value, scalingSettings } = this.props;
if (_.isEmpty(value)) {
return `${this.props.emptyInputWidthCh}ch`;
}
- switch (phase) {
- case ScalingInputPhase.FixedFontSize:
- return `${value.length}ch`;
- case ScalingInputPhase.ScalingFontSize:
- const { inputWidthPxAtPhaseChange } = this.state;
- if (!_.isUndefined(inputWidthPxAtPhaseChange)) {
- const charactersOverMax = value.length - textLengthThreshold;
- const scalingAmount = scalingSettings.constantPxToIncreaseWidthPerCharacter * charactersOverMax;
- const width = inputWidthPxAtPhaseChange + scalingAmount;
- return `${width}px`;
+ const lengthInCh = _.reduce(
+ value.split(''),
+ (sum, char) => {
+ const widthOverride = scalingSettings.characterWidthOverrides[char];
+ if (!_.isUndefined(widthOverride)) {
+ // tslint is confused
+ // tslint:disable-next-line:restrict-plus-operands
+ return sum + widthOverride;
}
- return `${textLengthThreshold}ch`;
- }
+ return sum + 1;
+ },
+ scalingSettings.additionalInputSpaceInCh,
+ );
+ return `${lengthInCh}ch`;
};
private readonly _calculateFontSize = (phase: ScalingInputPhase): number => {
return ScalingInput.calculateFontSizeFromProps(this.props, phase);
};
- private readonly _getInputWidthInPx = (): number => {
- const ref = this._inputRef.current;
- if (!ref) {
- return 0;
+ private readonly _handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
+ const value = event.target.value;
+ const { maxLength } = this.props;
+ if (!_.isUndefined(value) && !_.isUndefined(maxLength) && value.length > maxLength) {
+ return;
}
- return ref.getBoundingClientRect().width;
+ this.props.onChange(event);
};
}
diff --git a/packages/instant/src/components/ui/input.tsx b/packages/instant/src/components/ui/input.tsx
index 62c70f9e1..53c43ea0b 100644
--- a/packages/instant/src/components/ui/input.tsx
+++ b/packages/instant/src/components/ui/input.tsx
@@ -2,7 +2,7 @@ import * as React from 'react';
import { ColorOption, styled } from '../../style/theme';
-export interface InputProps {
+export interface InputProps extends React.HTMLAttributes<HTMLInputElement> {
tabIndex?: number;
className?: string;
value?: string;
@@ -32,6 +32,10 @@ export const Input =
color: ${props => props.theme[props.fontColor || 'white']} !important;
opacity: 0.5 !important;
}
+ &::-webkit-outer-spin-button, &::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+ }
}
`;