Skip to content

Commit f649426

Browse files
committed
Fix #93: Add a clickable link on url format inputs
1 parent 5cd8a74 commit f649426

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

src/components/form.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import Button from './buttons';
33
import Loader from './loaders';
44
import {TimePicker} from './widgets';
5+
import Icon from './icons';
56
import {EditorContext, getCsrfCookie, capitalize, convertType, getCoordsFromName, choicesValueTitleMap} from '../util';
67

78

@@ -804,3 +805,27 @@ export class FormDateTimeInput extends React.Component {
804805
);
805806
}
806807
}
808+
809+
810+
export function FormURLInput(props) {
811+
return (
812+
<div className={props.label ? 'rjf-url-field has-label' : 'rjf-url-field'}>
813+
<FormInput
814+
{...props}
815+
type="url"
816+
className="rjf-url-field-input"
817+
/>
818+
{props.value &&
819+
<a
820+
href={props.value}
821+
target="_blank"
822+
rel="noopener noreferrer"
823+
className="rjf-url-field-link"
824+
title="Open in new tab"
825+
>
826+
<Icon name="box-arrow-up-right" /> <span>Open link</span>
827+
</a>
828+
}
829+
</div>
830+
);
831+
}

src/components/icons.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export default function Icon(props) {
2323
case 'three-dots-vertical':
2424
icon = <ThreeDotsVertical />;
2525
break;
26+
case 'box-arrow-up-right':
27+
icon = <BoxArrowUpRight />;
28+
break;
2629
}
2730

2831
return (
@@ -70,3 +73,12 @@ function ThreeDotsVertical(props) {
7073
<path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
7174
);
7275
}
76+
77+
function BoxArrowUpRight(props) {
78+
return (
79+
<React.Fragment>
80+
<path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5"/>
81+
<path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0z"/>
82+
</React.Fragment>
83+
);
84+
}

src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Button from './buttons';
22
import {FormInput, FormCheckInput, FormRadioInput, FormSelectInput, FormFileInput,
3-
FormTextareaInput, FormDateTimeInput, FormMultiSelectInput} from './form';
3+
FormTextareaInput, FormDateTimeInput, FormMultiSelectInput, FormURLInput} from './form';
44
import AutoCompleteInput from './autocomplete';
55
import {FormRow, FormGroup, FormRowControls, GroupTitle, GroupDescription} from './containers';
66
import Loader from './loaders';
@@ -11,7 +11,7 @@ export {
1111
Button,
1212
FormInput, FormCheckInput, FormRadioInput, FormSelectInput, FormFileInput,
1313
FormTextareaInput, FormDateTimeInput, FormMultiSelectInput,
14-
AutoCompleteInput,
14+
AutoCompleteInput, FormURLInput,
1515
FormRow, FormGroup, FormRowControls, GroupTitle, GroupDescription,
1616
Loader,
1717
Icon,

src/ui.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {getBlankData, findMatchingSubschemaIndex, dataObjectMatchesSchema,
33
dataArrayMatchesSchema} from './data';
44
import {Button, FormInput, FormCheckInput, FormRadioInput, FormSelectInput,
55
FormFileInput, FormRow, FormGroup, GroupTitle, GroupDescription, FormRowControls, FormTextareaInput,
6-
FormDateTimeInput, FormMultiSelectInput, FileUploader, AutoCompleteInput} from './components';
6+
FormDateTimeInput, FormMultiSelectInput, FileUploader, AutoCompleteInput, FormURLInput} from './components';
77
import {getVerboseName, convertType, getCoordsFromName, getKeyword, normalizeKeyword,
88
joinCoords, splitCoords, actualType, getSchemaType, isEqualset, isSubset} from './util';
99

@@ -81,14 +81,18 @@ function FormField(props) {
8181
InputField = FormInput;
8282

8383
if (props.schema.format) {
84-
if (props.schema.format === 'data-url') {
84+
let format = props.schema.format;
85+
86+
if (format === 'data-url') {
8587
InputField = FormFileInput;
86-
} else if (props.schema.format === 'file-url') {
88+
} else if (format === 'file-url') {
8789
InputField = FileUploader;
88-
} else if (normalizeKeyword(props.schema.format) === 'date-time') {
90+
} else if (normalizeKeyword(format) === 'date-time') {
8991
InputField = FormDateTimeInput;
92+
} else if (format === 'uri' || format === 'uri-reference') {
93+
InputField = FormURLInput;
9094
}
91-
inputProps.type = props.schema.format;
95+
inputProps.type = format;
9296
} else if (props.schema.widget === 'hidden') {
9397
inputProps.type = 'hidden';
9498
} else {

0 commit comments

Comments
 (0)