migrate select, number, and text widgets

This commit is contained in:
Shawn Erquhart
2018-07-24 22:36:41 -04:00
parent f1a2eb33b4
commit c54605be85
21 changed files with 157 additions and 52 deletions

View File

@ -0,0 +1,33 @@
{
"name": "netlify-cms-widget-text",
"description": "Widget for editing multiline plain string values in Netlify CMS.",
"version": "2.0.0-alpha.0",
"main": "dist/netlify-cms-widget-text.js",
"license": "MIT",
"keywords": [
"netlify",
"netlify-cms",
"widget",
"string",
"text",
"textarea",
"mulitiline"
],
"sideEffects": false,
"scripts": {
"watch": "webpack -w",
"build": "webpack"
},
"dependencies": {
"react-textarea-autosize": "^5.2.0"
},
"devDependencies": {
"webpack": "^4.16.1",
"webpack-cli": "^3.1.0"
},
"peerDependencies": {
"netlify-cms-ui-default": "^2.0.0-alpha.0",
"prop-types": "^15.5.10",
"react": "^16.4.1"
}
}

View File

@ -0,0 +1,52 @@
import React from 'react';
import PropTypes from 'prop-types';
import Textarea from 'react-textarea-autosize';
export default class TextControl extends React.Component {
static propTypes = {
onChange: PropTypes.func.isRequired,
forID: PropTypes.string,
value: PropTypes.node,
classNameWrapper: PropTypes.string.isRequired,
setActiveStyle: PropTypes.func.isRequired,
setInactiveStyle: PropTypes.func.isRequired,
};
static defaultProps = {
value: '',
};
/**
* Always update to ensure `react-textarea-autosize` properly calculates
* height. Certain situations, such as this widget being nested in a list
* item that gets rearranged, can leave the textarea in a minimal height
* state. Always updating this particular widget should generally be low cost,
* but this should be optimized in the future.
*/
shouldComponentUpdate(nextProps) {
return true;
}
render() {
const {
forID,
value,
onChange,
classNameWrapper,
setActiveStyle,
setInactiveStyle,
} = this.props;
return (
<Textarea
id={forID}
value={value || ''}
className={classNameWrapper}
onFocus={setActiveStyle}
onBlur={setInactiveStyle}
style={{ minHeight: '140px' }}
onChange={e => onChange(e.target.value)}
/>
);
}
}

View File

@ -0,0 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
const TextPreview = ({ value }) => (
<WidgetPreviewContainer>{ value }</WidgetPreviewContainer>
)
TextPreview.propTypes = {
value: PropTypes.node,
};
export default TextPreview;

View File

@ -0,0 +1,2 @@
export TextControl from './TextControl';
export TextPreview from './TextPreview';

View File

@ -0,0 +1,3 @@
const { getConfig } = require('../../scripts/webpack.js');
module.exports = getConfig();