migrate select, number, and text widgets
This commit is contained in:
33
packages/netlify-cms-widget-text/package.json
Normal file
33
packages/netlify-cms-widget-text/package.json
Normal 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"
|
||||
}
|
||||
}
|
52
packages/netlify-cms-widget-text/src/TextControl.js
Normal file
52
packages/netlify-cms-widget-text/src/TextControl.js
Normal 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)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
13
packages/netlify-cms-widget-text/src/TextPreview.js
Normal file
13
packages/netlify-cms-widget-text/src/TextPreview.js
Normal 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;
|
2
packages/netlify-cms-widget-text/src/index.js
Normal file
2
packages/netlify-cms-widget-text/src/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
export TextControl from './TextControl';
|
||||
export TextPreview from './TextPreview';
|
3
packages/netlify-cms-widget-text/webpack.config.js
Normal file
3
packages/netlify-cms-widget-text/webpack.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
const { getConfig } = require('../../scripts/webpack.js');
|
||||
|
||||
module.exports = getConfig();
|
Reference in New Issue
Block a user