-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1701 from bgoonz/preview
- Loading branch information
Showing
38 changed files
with
1,987 additions
and
1,259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
|
||
import { Link, withPrefix } from '../utils'; | ||
|
||
export default class Action extends React.Component { | ||
render() { | ||
const action = _.get(this.props, 'action'); | ||
const url = _.get(action, 'url'); | ||
const label = _.get(action, 'label'); | ||
const newWindow = _.get(action, 'new_window'); | ||
const noFollow = _.get(action, 'no_follow'); | ||
const attrs = {}; | ||
if (newWindow) { | ||
attrs.target = '_blank'; | ||
} | ||
if (newWindow || noFollow) { | ||
attrs.rel = [(newWindow ? 'noopener' : '') + (noFollow ? 'nofollow' : '')].join(' '); | ||
} | ||
|
||
return ( | ||
<Link href={withPrefix(url)} {...attrs}> | ||
{label} | ||
</Link> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
|
||
import { Link, withPrefix, classNames } from '../utils'; | ||
import Icon from './Icon'; | ||
|
||
export default class ActionIcon extends React.Component { | ||
render() { | ||
const action = _.get(this.props, 'action'); | ||
const url = _.get(action, 'url'); | ||
const label = _.get(action, 'label'); | ||
const style = _.get(action, 'style', 'link'); | ||
const icon = _.get(action, 'icon_class', 'dev'); | ||
const classes = classNames({ | ||
'button-circle': style === 'icon' | ||
}); | ||
const newWindow = _.get(action, 'new_window'); | ||
const noFollow = _.get(action, 'no_follow'); | ||
const attrs = {}; | ||
if (newWindow) { | ||
attrs.target = '_blank'; | ||
} | ||
if (newWindow || noFollow) { | ||
attrs.rel = [(newWindow ? 'noopener' : '') + (noFollow ? 'nofollow' : '')].join(' '); | ||
} | ||
|
||
return ( | ||
<Link href={withPrefix(url)} {...attrs} className={classes}> | ||
{style === 'icon' && icon ? ( | ||
<React.Fragment> | ||
<Icon icon={icon} /> | ||
<span className="screen-reader-text">{label}</span> | ||
</React.Fragment> | ||
) : ( | ||
label | ||
)} | ||
</Link> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import _ from 'lodash'; | ||
|
||
export default class FormField extends React.Component { | ||
render() { | ||
const field = _.get(this.props, 'field'); | ||
const inputType = _.get(field, 'input_type'); | ||
const name = _.get(field, 'name'); | ||
const defaultValue = _.get(field, 'default_value'); | ||
const options = _.get(field, 'options'); | ||
const required = _.get(field, 'is_required'); | ||
const label = _.get(field, 'label'); | ||
const labelId = `${name}-label`; | ||
const attr = {}; | ||
if (label) { | ||
attr['aria-labelledby'] = labelId; | ||
} | ||
if (required) { | ||
attr.required = true; | ||
} | ||
|
||
switch (inputType) { | ||
case 'checkbox': | ||
return ( | ||
<div className="form-group form-checkbox"> | ||
<input type="checkbox" id={name} name={name} {...attr} /> | ||
{label && <label htmlFor={name}>{label}</label>} | ||
</div> | ||
); | ||
case 'select': | ||
return ( | ||
<div className="form-group"> | ||
{label && <label htmlFor={name}>{label}</label>} | ||
<div className="form-select-wrap"> | ||
<select id={name} name={name} {...attr}> | ||
{defaultValue && <option value="">{defaultValue}</option>} | ||
{_.map(options, (option, index) => ( | ||
<option key={index} value={option}> | ||
{option} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
</div> | ||
); | ||
case 'textarea': | ||
return ( | ||
<div className="form-group"> | ||
{label && <label htmlFor={name}>{label}</label>} | ||
<textarea name={name} id={name} rows="7" {...(defaultValue ? { placeholder: defaultValue } : null)} {...attr} /> | ||
</div> | ||
); | ||
default: | ||
return ( | ||
<div className="form-group"> | ||
{label && <label htmlFor={name}>{label}</label>} | ||
<input type={inputType} name={name} id={name} {...(defaultValue ? { placeholder: defaultValue } : null)} {...attr} /> | ||
</div> | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.