Skip to content

Commit

Permalink
Urlfield enahancement (keystonejs#4856)
Browse files Browse the repository at this point in the history
* add thumb option support to url type

* do not fix the height of form input since it the value can be out of bound
  • Loading branch information
gemscng authored and autoboxer committed Dec 19, 2018
1 parent 0260bc5 commit 359b451
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
1 change: 0 additions & 1 deletion admin/client/App/elemental/FormInput/noedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const classes = {
borderWidth: theme.input.border.width,
color: theme.color.gray80,
display: 'inline-block',
height: theme.input.height,
lineHeight: theme.input.lineHeight,
padding: `0 ${theme.input.paddingHorizontal}`,
transition: 'border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s',
Expand Down
61 changes: 29 additions & 32 deletions fields/types/url/UrlField.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Field from '../Field';
import { GlyphButton, FormInput } from '../../../admin/client/App/elemental';
import { FormInput } from '../../../admin/client/App/elemental';

module.exports = Field.create({
displayName: 'URLField',
Expand All @@ -15,45 +15,42 @@ module.exports = Field.create({
}
window.open(href);
},
renderLink () {
if (!this.props.value) return null;

return (
<GlyphButton
className="keystone-relational-button"
glyph="link"
onClick={this.openValue}
title={'Open ' + this.props.value + ' in a new tab'}
variant="link"
/>
);
},
renderField () {
const { value } = this.props;
return (
<FormInput
autoComplete="off"
name={this.getInputName(this.props.path)}
onChange={this.valueChanged}
ref="focusTarget"
type="url"
value={this.props.value}
/>
);
},
wrapField () {
return (
<div style={{ position: 'relative' }}>
{this.renderField()}
{this.renderLink()}
<div>
<FormInput
autoComplete="off"
name={this.getInputName(this.props.path)}
onChange={this.valueChanged}
ref="focusTarget"
type="url"
value={value}
/>
{ this.renderThumb() }
</div>
);
},
renderValue () {
const { value } = this.props;
return (
<FormInput noedit onClick={value && this.openValue}>
{value}
</FormInput>
<div>
<FormInput
noedit
onClick={value && this.openValue}
value={value}
/>
{ this.renderThumb() }
</div>
);
},
renderThumb () {
const { thumb, value } = this.props;
if (thumb === true) {
return (
<img src={value}/>
);
}
return ('');
},
});

0 comments on commit 359b451

Please sign in to comment.