mirror of
https://github.com/maputnik/editor.git
synced 2026-07-28 08:47:27 +00:00
Migrate block and field doc label
This commit is contained in:
@@ -1,40 +1,41 @@
|
|||||||
import React from 'react'
|
import React, {SyntheticEvent} from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import FieldDocLabel from './FieldDocLabel'
|
import FieldDocLabel from './FieldDocLabel'
|
||||||
import Doc from './Doc'
|
import Doc from './Doc'
|
||||||
|
|
||||||
|
|
||||||
/** Wrap a component with a label */
|
type BlockProps = {
|
||||||
export default class Block extends React.Component {
|
"data-wd-key"?: string
|
||||||
static propTypes = {
|
label?: string
|
||||||
"data-wd-key": PropTypes.string,
|
action?: React.ReactElement
|
||||||
label: PropTypes.oneOfType([
|
style?: object
|
||||||
PropTypes.string,
|
onChange(...args: unknown[]): unknown
|
||||||
PropTypes.element,
|
fieldSpec?: object
|
||||||
]),
|
wideMode?: boolean
|
||||||
action: PropTypes.element,
|
error?: unknown[]
|
||||||
children: PropTypes.node.isRequired,
|
};
|
||||||
style: PropTypes.object,
|
|
||||||
onChange: PropTypes.func,
|
|
||||||
fieldSpec: PropTypes.object,
|
|
||||||
wideMode: PropTypes.bool,
|
|
||||||
error: PropTypes.array,
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor (props) {
|
type BlockState = {
|
||||||
|
showDoc: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Wrap a component with a label */
|
||||||
|
export default class Block extends React.Component<BlockProps, BlockState> {
|
||||||
|
_blockEl: HTMLDivElement | null = null;
|
||||||
|
|
||||||
|
constructor (props: BlockProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
showDoc: false,
|
showDoc: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange(e) {
|
onChange(e: React.BaseSyntheticEvent<Event, HTMLInputElement, HTMLInputElement>) {
|
||||||
const value = e.target.value
|
const value = e.target.value
|
||||||
return this.props.onChange(value === "" ? undefined : value)
|
return this.props.onChange(value === "" ? undefined : value)
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggleDoc = (val) => {
|
onToggleDoc = (val: boolean) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
showDoc: val
|
showDoc: val
|
||||||
});
|
});
|
||||||
@@ -46,20 +47,17 @@ export default class Block extends React.Component {
|
|||||||
* causing the picker to reopen. This causes a scenario where the picker can
|
* causing the picker to reopen. This causes a scenario where the picker can
|
||||||
* never be closed once open.
|
* never be closed once open.
|
||||||
*/
|
*/
|
||||||
onLabelClick = (event) => {
|
onLabelClick = (event: SyntheticEvent<any, any>) => {
|
||||||
const el = event.nativeEvent.target;
|
const el = event.nativeEvent.target;
|
||||||
const nativeEvent = event.nativeEvent;
|
const contains = this._blockEl?.contains(el);
|
||||||
const contains = this._blockEl.contains(el);
|
|
||||||
|
|
||||||
if (event.nativeEvent.target.nodeName !== "INPUT" && !contains) {
|
if (event.nativeEvent.target.nodeName !== "INPUT" && !contains) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const errors = [].concat(this.props.error || []);
|
|
||||||
|
|
||||||
return <label style={this.props.style}
|
return <label style={this.props.style}
|
||||||
data-wd-key={this.props["data-wd-key"]}
|
data-wd-key={this.props["data-wd-key"]}
|
||||||
className={classnames({
|
className={classnames({
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import {MdInfoOutline, MdHighlightOff} from 'react-icons/md'
|
import {MdInfoOutline, MdHighlightOff} from 'react-icons/md'
|
||||||
|
|
||||||
type FieldDocLabelProps = {
|
type FieldDocLabelProps = {
|
||||||
label: object | string
|
label: object | string | undefined
|
||||||
fieldSpec?: {
|
fieldSpec?: {
|
||||||
doc?: string
|
doc?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user