UNPKG

@gravel-form/blueprintjs

Version:

A flexible middlewares driven json schema form with Blueprintjs

1 lines 1.1 kB
{"version":3,"sources":["middlewares/ChangeToBlueMw.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAoBnE,CAAC;AACF,eAAe,cAAc,CAAC","file":"ChangeToBlueMw.d.ts","sourcesContent":["import * as React from 'react';\nimport { FormMiddlewareProps } from '../core';\n\nexport const ChangeToBlurMw: React.ComponentType<FormMiddlewareProps> = (props) => {\n const { schema, next, data, onChange } = props;\n const focus = React.useRef(false);\n const [value, setValue] = React.useState<unknown>(null);\n\n if (typeof schema === 'boolean' || schema.type === 'object' || schema.type === 'array') return next(props);\n return (\n <div\n onFocus={() => {\n focus.current = true;\n setValue(data);\n }}\n onBlur={() => {\n focus.current = false;\n onChange(value);\n }}\n >\n {next({ ...props, data: focus.current ? value : data, onChange: focus.current ? setValue : onChange })}\n </div>\n );\n};\nexport default ChangeToBlurMw;\n"]}