@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 2.12 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/separator/use-deprecated-opacity.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { usePrevious } from '@wordpress/compose';\n\nexport default function useDeprecatedOpacity(\n\topacity,\n\tcurrentColor,\n\tsetAttributes\n) {\n\tconst [ deprecatedOpacityWithNoColor, setDeprecatedOpacityWithNoColor ] =\n\t\tuseState( false );\n\tconst previousColor = usePrevious( currentColor );\n\n\t// A separator with no color set will always have previousColor set to undefined,\n\t// and we need to differentiate these from those with color set that will return\n\t// previousColor as undefined on the first render.\n\tuseEffect( () => {\n\t\tif ( opacity === 'css' && ! currentColor && ! previousColor ) {\n\t\t\tsetDeprecatedOpacityWithNoColor( true );\n\t\t}\n\t}, [ currentColor, previousColor, opacity ] );\n\n\t// For deprecated blocks, that have a default 0.4 css opacity set, we\n\t// need to remove this if the current color is changed, or a color is added.\n\t// In these instances the opacity attribute is set back to the default of\n\t// alpha-channel which allows a new custom opacity to be set via the color picker.\n\tuseEffect( () => {\n\t\tif (\n\t\t\topacity === 'css' &&\n\t\t\t( ( deprecatedOpacityWithNoColor && currentColor ) ||\n\t\t\t\t( previousColor && currentColor !== previousColor ) )\n\t\t) {\n\t\t\tsetAttributes( { opacity: 'alpha-channel' } );\n\t\t\tsetDeprecatedOpacityWithNoColor( false );\n\t\t}\n\t}, [ deprecatedOpacityWithNoColor, currentColor, previousColor ] );\n}\n"],
"mappings": ";AAGA,SAAS,WAAW,gBAAgB;AACpC,SAAS,mBAAmB;AAEb,SAAR,qBACN,SACA,cACA,eACC;AACD,QAAM,CAAE,8BAA8B,+BAAgC,IACrE,SAAU,KAAM;AACjB,QAAM,gBAAgB,YAAa,YAAa;AAKhD,YAAW,MAAM;AAChB,QAAK,YAAY,SAAS,CAAE,gBAAgB,CAAE,eAAgB;AAC7D,sCAAiC,IAAK;AAAA,IACvC;AAAA,EACD,GAAG,CAAE,cAAc,eAAe,OAAQ,CAAE;AAM5C,YAAW,MAAM;AAChB,QACC,YAAY,UACR,gCAAgC,gBACjC,iBAAiB,iBAAiB,gBACpC;AACD,oBAAe,EAAE,SAAS,gBAAgB,CAAE;AAC5C,sCAAiC,KAAM;AAAA,IACxC;AAAA,EACD,GAAG,CAAE,8BAA8B,cAAc,aAAc,CAAE;AAClE;",
"names": []
}