amis-rpc-design/dist/630.b0f60bcc.bundle.js

1 line
5.9 KiB
JavaScript
Raw Permalink Normal View History

2023-10-07 19:42:30 +08:00
"use strict";(self.webpackChunkamis_rpc_design=self.webpackChunkamis_rpc_design||[]).push([[630],{10630:(e,t,n)=>{n.r(t),n.d(t,{ColorControl:()=>p,default:()=>h});var o=n(14320),r=n(90375),a=(n(44001),n(2731)),l=n(15878),s=n(44495),i=n(4987),c=n(41338),p=function(e){function t(t){var n=e.call(this,t)||this;return n.state={isOpened:!1,isFocused:!1,inputValue:n.props.value||"",tempValue:n.props.value||""},n.open=n.open.bind(n),n.close=n.close.bind(n),n.focus=n.focus.bind(n),n.blur=n.blur.bind(n),n.handleChange=n.handleChange.bind(n),n.handleTempChange=n.handleTempChange.bind(n),n.handleConfirm=n.handleConfirm.bind(n),n.handleFocus=n.handleFocus.bind(n),n.handleBlur=n.handleBlur.bind(n),n.clearValue=n.clearValue.bind(n),n.handleInputChange=n.handleInputChange.bind(n),n.handleClick=n.handleClick.bind(n),n.preview=r.Z.createRef(),n.input=r.Z.createRef(),n}return(0,o.ZT)(t,e),t.prototype.componentDidUpdate=function(e){var t=this.props;e.value!==t.value&&this.setState({inputValue:t.value||""})},t.prototype.handleFocus=function(){this.setState({isFocused:!0})},t.prototype.handleBlur=function(){this.setState({isFocused:!1,inputValue:this.props.value})},t.prototype.focus=function(){this.input.current&&this.input.current.focus()},t.prototype.blur=function(){this.input.current&&this.input.current.blur()},t.prototype.open=function(e){this.props.disabled||this.setState({isOpened:!0},e)},t.prototype.close=function(){this.setState({isOpened:!1})},t.prototype.clearValue=function(){var e=this.props;(0,e.onChange)(e.resetValue||"")},t.prototype.handleClick=function(){this.state.isOpened?this.close():this.open(this.focus)},t.prototype.handleInputChange=function(e){var t=this;if(this.props.allowCustomColor){var n=this.props.onChange;this.setState({inputValue:e.currentTarget.value},(function(){t.validateColor(t.state.inputValue)&&n(t.state.inputValue)}))}},t.prototype.validateColor=function(e){if(""===e)return!1;if("inherit"===e)return!1;if("transparent"===e)return!1;var t=document.createElement("img");return t.style.color="rgb(0, 0, 0)",t.style.color=e,"rgb(0, 0, 0)"!==t.style.color||(t.style.color="rgb(255, 255, 255)",t.style.color=e,"rgb(255, 255, 255)"!==t.style.color)},t.prototype.handleChange=function(e){var t=this.props,n=t.onChange,o=t.format;n("rgba"===o?"rgba(".concat(e.rgb.r,", ").concat(e.rgb.g,", ").concat(e.rgb.b,", ").concat(e.rgb.a,")"):"rgb"===o?"rgb(".concat(e.rgb.r,", ").concat(e.rgb.g,", ").concat(e.rgb.b,")"):"hsl"===o?"hsl(".concat(Math.round(e.hsl.h),", ").concat(Math.round(100*e.hsl.s),"%, ").concat(Math.round(100*e.hsl.l),"%)"):e.hex)},t.prototype.handleTempChange=function(e){var t=this.state.tempValue,n=this.props.format;t="rgba"===n?"rgba(".concat(e.rgb.r,", ").concat(e.rgb.g,", ").concat(e.rgb.b,", ").concat(e.rgb.a,")"):"rgb"===n?"rgb(".concat(e.rgb.r,", ").concat(e.rgb.g,", ").concat(e.rgb.b,")"):"hsl"===n?"hsl(".concat(Math.round(e.hsl.h),", ").concat(Math.round(100*e.hsl.s),"%, ").concat(Math.round(100*e.hsl.l),"%)"):e.hex,this.setState({tempValue:t})},t.prototype.handleConfirm=function(){(0,this.props.onChange)(this.state.tempValue),this.close()},t.prototype.render=function(){var e=this,t=this.props,n=t.classPrefix,o=t.className,p=t.popoverClassName,h=t.value,u=t.placeholder,d=t.disabled,C=t.popOverContainer,g=t.format,m=t.clearable,f=t.placement,b=t.classnames,y=t.presetColors,v=t.allowCustomColor,k=t.mobileUI,Z=this.props.translate,V=this.state.isOpened,w=this.state.isFocused,E=this.state.tempValue;return r.Z.createElement("div",{className:b("ColorPicker",{"is-disabled":d,"is-focused":w,"is-opened":V},o)},r.Z.createElement("span",{onClick:this.handleClick,className:b("ColorPicker-preview")},r.Z.createElement("i",{ref:this.preview,className:"".concat(n,"ColorPicker-previewIcon"),style:{background:this.state.inputValue||"#ccc"}})),r.Z.createElement("input",{ref:this.input,type:"text",autoComplete:"off",size:10,className:b("ColorPicker-input"),value:this.state.inputValue||"",placeholder:Z(u),disabled:d,onChange:this.handleInputChange,onFocus:this.handleFocus,onBlur:this.handleBlur,onClick:this.handleClick,read