@wordpress/block-editor
Version:
8 lines (7 loc) • 2.67 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/hooks/use-border-props.js"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getInlineStyles } from './style';\nimport { getBorderClasses, getMultiOriginColor } from './border';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\n\n// This utility is intended to assist where the serialization of the border\n// block support is being skipped for a block but the border related CSS classes\n// & styles still need to be generated so they can be applied to inner elements.\n\n/**\n * Provides the CSS class names and inline styles for a block's border support\n * attributes.\n *\n * @param {Object} attributes Block attributes.\n * @return {Object} Border block support derived CSS classes & styles.\n */\nexport function getBorderClassesAndStyles( attributes ) {\n\tconst border = attributes.style?.border || {};\n\tconst className = getBorderClasses( attributes );\n\n\treturn {\n\t\tclassName: className || undefined,\n\t\tstyle: getInlineStyles( { border } ),\n\t};\n}\n\n/**\n * Derives the border related props for a block from its border block support\n * attributes.\n *\n * Inline styles are forced for named colors to ensure these selections are\n * reflected when themes do not load their color stylesheets in the editor.\n *\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} ClassName & style props from border block support.\n */\nexport function useBorderProps( attributes ) {\n\tconst { colors } = useMultipleOriginColorsAndGradients();\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\tconst { borderColor } = attributes;\n\n\t// Force inline styles to apply named border colors when themes do not load\n\t// their color stylesheets in the editor.\n\tif ( borderColor ) {\n\t\tconst borderColorObject = getMultiOriginColor( {\n\t\t\tcolors,\n\t\t\tnamedColor: borderColor,\n\t\t} );\n\n\t\tborderProps.style.borderColor = borderColorObject.color;\n\t}\n\n\treturn borderProps;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAgC;AAChC,oBAAsD;AACtD,sDAAgD;AAazC,SAAS,0BAA2B,YAAa;AACvD,QAAM,SAAS,WAAW,OAAO,UAAU,CAAC;AAC5C,QAAM,gBAAY,gCAAkB,UAAW;AAE/C,SAAO;AAAA,IACN,WAAW,aAAa;AAAA,IACxB,WAAO,8BAAiB,EAAE,OAAO,CAAE;AAAA,EACpC;AACD;AAaO,SAAS,eAAgB,YAAa;AAC5C,QAAM,EAAE,OAAO,QAAI,gDAAAA,SAAoC;AACvD,QAAM,cAAc,0BAA2B,UAAW;AAC1D,QAAM,EAAE,YAAY,IAAI;AAIxB,MAAK,aAAc;AAClB,UAAM,wBAAoB,mCAAqB;AAAA,MAC9C;AAAA,MACA,YAAY;AAAA,IACb,CAAE;AAEF,gBAAY,MAAM,cAAc,kBAAkB;AAAA,EACnD;AAEA,SAAO;AACR;",
"names": ["useMultipleOriginColorsAndGradients"]
}