UNPKG

@wordpress/components

Version:
8 lines (7 loc) 2.77 kB
{ "version": 3, "sources": ["../../src/color-picker/hex-input.tsx"], "sourcesContent": ["/**\n * External dependencies\n */\nimport { colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { InputControl } from '../input-control';\nimport { Text } from '../text';\nimport { COLORS } from '../utils/colors-values';\nimport InputControlPrefixWrapper from '../input-control/input-prefix-wrapper';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport const HexInput = ({\n color,\n onChange,\n enableAlpha\n}) => {\n const handleChange = nextValue => {\n if (!nextValue) {\n return;\n }\n const hexValue = nextValue.startsWith('#') ? nextValue : '#' + nextValue;\n onChange(colord(hexValue));\n };\n const stateReducer = (state, action) => {\n const nativeEvent = action.payload?.event?.nativeEvent;\n if ('insertFromPaste' !== nativeEvent?.inputType) {\n return {\n ...state\n };\n }\n const value = state.value?.startsWith('#') ? state.value.slice(1).toUpperCase() : state.value?.toUpperCase();\n return {\n ...state,\n value\n };\n };\n return /*#__PURE__*/_jsx(InputControl, {\n prefix: /*#__PURE__*/_jsx(InputControlPrefixWrapper, {\n children: /*#__PURE__*/_jsx(Text, {\n color: COLORS.theme.accent,\n lineHeight: 1,\n children: \"#\"\n })\n }),\n value: color.toHex().slice(1).toUpperCase(),\n onChange: handleChange,\n maxLength: enableAlpha ? 9 : 7,\n label: __('Hex color'),\n hideLabelFromVision: true,\n size: \"__unstable-large\",\n __unstableStateReducer: stateReducer,\n __unstableInputWidth: \"9em\"\n });\n};"], "mappings": ";AAGA,SAAS,cAAc;AAKvB,SAAS,UAAU;AAKnB,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,OAAO,+BAA+B;AACtC,SAAS,OAAO,YAAY;AACrB,IAAM,WAAW,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,eAAe,eAAa;AAChC,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AACA,UAAM,WAAW,UAAU,WAAW,GAAG,IAAI,YAAY,MAAM;AAC/D,aAAS,OAAO,QAAQ,CAAC;AAAA,EAC3B;AACA,QAAM,eAAe,CAAC,OAAO,WAAW;AACtC,UAAM,cAAc,OAAO,SAAS,OAAO;AAC3C,QAAI,sBAAsB,aAAa,WAAW;AAChD,aAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,IACF;AACA,UAAM,QAAQ,MAAM,OAAO,WAAW,GAAG,IAAI,MAAM,MAAM,MAAM,CAAC,EAAE,YAAY,IAAI,MAAM,OAAO,YAAY;AAC3G,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACA,SAAoB,qBAAK,cAAc;AAAA,IACrC,QAAqB,qBAAK,2BAA2B;AAAA,MACnD,UAAuB,qBAAK,MAAM;AAAA,QAChC,OAAO,OAAO,MAAM;AAAA,QACpB,YAAY;AAAA,QACZ,UAAU;AAAA,MACZ,CAAC;AAAA,IACH,CAAC;AAAA,IACD,OAAO,MAAM,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY;AAAA,IAC1C,UAAU;AAAA,IACV,WAAW,cAAc,IAAI;AAAA,IAC7B,OAAO,GAAG,WAAW;AAAA,IACrB,qBAAqB;AAAA,IACrB,MAAM;AAAA,IACN,wBAAwB;AAAA,IACxB,sBAAsB;AAAA,EACxB,CAAC;AACH;", "names": [] }