Skip to content

Commit

Permalink
fix: Hex input check after enter or blur. Close #52
Browse files Browse the repository at this point in the history
  • Loading branch information
noyobo committed Nov 10, 2017
1 parent 0c34153 commit b780e4d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions assets/index/Board.less
Expand Up @@ -4,7 +4,7 @@
position: relative;
font-size: 0;
user-select: none;

margin: 8px 8px 0px;
span {
position: absolute;
border-radius: 10px;
Expand Down Expand Up @@ -45,7 +45,7 @@
.background-image(linear-gradient(to right, #ffffff 0%, transparent 100%));
}
&-handler {
box-shadow: 0 0 2px #808080 inset;
box-shadow: 0 0 2px #808080 inset;
border-radius: 2px;
cursor: crosshair;
user-select: none;
Expand Down
12 changes: 6 additions & 6 deletions assets/index/Layout.less
Expand Up @@ -5,7 +5,7 @@
border-radius: 4px;
box-shadow: 0 1px 5px #ccc;
border: 1px solid #ccc;
padding: 8px;
padding-bottom: 8px;
}

.@{prefixClassName}-wrap{
Expand All @@ -15,19 +15,19 @@
position: relative;
&-preview{
position: absolute;
right: 0px;
right: 8px;
}
&-ribbon{
position: absolute;
left: 0px;
left: 8px;
top: 0;
right: 35px;
right: 43px;
height: 30px;
}
&-alpha{
position: absolute;
left: 0px;
right: 35px;
left: 8px;
right: 43px;
bottom: 0;
height: (30px - 5px) / 2;
}
Expand Down
4 changes: 2 additions & 2 deletions assets/index/Params.less
Expand Up @@ -2,7 +2,7 @@
font-size: 12px;
&-input{
overflow: hidden;
padding: 2px 0;
padding: 2px 8px;
}
input{
user-select: text;
Expand All @@ -26,7 +26,7 @@
}

&-lable{
padding: 2px 0;
padding: 2px 8px;
height: 22px;
line-height: 18px;
user-select: none;
Expand Down
49 changes: 38 additions & 11 deletions src/Params.jsx
Expand Up @@ -48,8 +48,9 @@ export default class Params extends React.Component {
return `${this.props.rootPrefixCls}-params`;
};

handleHexHandler = event => {
const hex = event.target.value;
handleHexBlur = () => {
const hex = this.state.hex;

let color = null;

if (Color.isValidHex(hex)) {
Expand All @@ -62,13 +63,36 @@ export default class Params extends React.Component {
hex,
});
this.props.onChange(color, false);
} else {
this.setState({
hex,
});
}
};

handleHexPress = event => {
const hex = this.state.hex;
if (event.nativeEvent.which === 13) {
let color = null;

if (Color.isValidHex(hex)) {
color = new Color(hex);
}

if (color !== null) {
this.setState({
color,
hex,
});
this.props.onChange(color, false);
}
}
};

handleHexChange = event => {
const hex = event.target.value;

this.setState({
hex,
});
};

handleModeChange = () => {
let mode = this.state.mode;

Expand Down Expand Up @@ -132,7 +156,7 @@ export default class Params extends React.Component {
},
() => {
this.props.onChange(color, false);
},
}
);
};

Expand Down Expand Up @@ -161,8 +185,10 @@ export default class Params extends React.Component {
className={`${prefixCls}-hex`}
type="text"
maxLength="6"
onChange={this.handleHexHandler}
value={this.state.hex.toUpperCase()}
onKeyPress={this.handleHexPress}
onBlur={this.handleHexBlur}
onChange={this.handleHexChange}
value={this.state.hex.toLowerCase()}
/>
<input
type="number"
Expand All @@ -182,12 +208,13 @@ export default class Params extends React.Component {
value={colorChannel[2]}
onChange={this.handleColorChannelChange.bind(null, 2)}
/>
{enableAlpha &&
{enableAlpha && (
<input
type="number"
value={Math.round(this.props.alpha)}
onChange={this.handleAlphaHandler}
/>}
/>
)}
</div>
<div className={`${prefixCls}-lable`}>
<label className={`${prefixCls}-lable-hex`}>Hex</label>
Expand Down

0 comments on commit b780e4d

Please sign in to comment.