UNPKG

@wordpress/components

Version:
1 lines • 4.91 kB
{"version":3,"file":"component.mjs","names":[],"sources":["../../../src/border-box-control/border-box-control-split-controls/component.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { useMergeRefs } from '@wordpress/compose';\nimport BorderBoxControlVisualizer from '../border-box-control-visualizer';\nimport { BorderControl } from '../../border-control';\nimport { Grid } from '../../grid';\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect } from '../../context';\nimport { useBorderBoxControlSplitControls } from './hook';\nimport type { BorderControlProps } from '../../border-control/types';\nimport type { SplitControlsProps } from '../types';\n\nconst BorderBoxControlSplitControls = (\n\tprops: WordPressComponentProps< SplitControlsProps, 'div' >,\n\tforwardedRef: React.ForwardedRef< any >\n) => {\n\tconst {\n\t\tcenteredClassName,\n\t\tcolors,\n\t\tdisableCustomColors,\n\t\tenableAlpha,\n\t\tenableStyle,\n\t\tonChange,\n\t\tpopoverPlacement,\n\t\tpopoverOffset,\n\t\trightAlignedClassName,\n\t\tvalue,\n\t\t__experimentalIsRenderedInSidebar,\n\t\t...otherProps\n\t} = useBorderBoxControlSplitControls( props );\n\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState< Element | null >(\n\t\tnull\n\t);\n\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps: BorderControlProps[ '__unstablePopoverProps' ] =\n\t\tuseMemo(\n\t\t\t() =>\n\t\t\t\tpopoverPlacement\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tplacement: popoverPlacement,\n\t\t\t\t\t\t\toffset: popoverOffset,\n\t\t\t\t\t\t\tanchor: popoverAnchor,\n\t\t\t\t\t\t\tshift: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t[ popoverPlacement, popoverOffset, popoverAnchor ]\n\t\t);\n\n\tconst sharedBorderControlProps = {\n\t\tcolors,\n\t\tdisableCustomColors,\n\t\tenableAlpha,\n\t\tenableStyle,\n\t\tisCompact: true,\n\t\t__experimentalIsRenderedInSidebar,\n\t};\n\n\tconst mergedRef = useMergeRefs( [ setPopoverAnchor, forwardedRef ] );\n\n\treturn (\n\t\t<Grid { ...otherProps } ref={ mergedRef } gap={ 3 }>\n\t\t\t<BorderBoxControlVisualizer value={ value } />\n\n\t\t\t<BorderControl\n\t\t\t\tclassName={ centeredClassName }\n\t\t\t\thideLabelFromVision\n\t\t\t\tlabel={ __( 'Top border' ) }\n\t\t\t\tonChange={ ( newBorder ) => onChange( newBorder, 'top' ) }\n\t\t\t\t__unstablePopoverProps={ popoverProps }\n\t\t\t\tvalue={ value?.top }\n\t\t\t\t{ ...sharedBorderControlProps }\n\t\t\t/>\n\t\t\t<BorderControl\n\t\t\t\thideLabelFromVision\n\t\t\t\tlabel={ __( 'Left border' ) }\n\t\t\t\tonChange={ ( newBorder ) => onChange( newBorder, 'left' ) }\n\t\t\t\t__unstablePopoverProps={ popoverProps }\n\t\t\t\tvalue={ value?.left }\n\t\t\t\t{ ...sharedBorderControlProps }\n\t\t\t/>\n\t\t\t<BorderControl\n\t\t\t\tclassName={ rightAlignedClassName }\n\t\t\t\thideLabelFromVision\n\t\t\t\tlabel={ __( 'Right border' ) }\n\t\t\t\tonChange={ ( newBorder ) => onChange( newBorder, 'right' ) }\n\t\t\t\t__unstablePopoverProps={ popoverProps }\n\t\t\t\tvalue={ value?.right }\n\t\t\t\t{ ...sharedBorderControlProps }\n\t\t\t/>\n\t\t\t<BorderControl\n\t\t\t\tclassName={ centeredClassName }\n\t\t\t\thideLabelFromVision\n\t\t\t\tlabel={ __( 'Bottom border' ) }\n\t\t\t\tonChange={ ( newBorder ) => onChange( newBorder, 'bottom' ) }\n\t\t\t\t__unstablePopoverProps={ popoverProps }\n\t\t\t\tvalue={ value?.bottom }\n\t\t\t\t{ ...sharedBorderControlProps }\n\t\t\t/>\n\t\t</Grid>\n\t);\n};\n\nconst ConnectedBorderBoxControlSplitControls = contextConnect(\n\tBorderBoxControlSplitControls,\n\t'BorderBoxControlSplitControls'\n);\nexport default ConnectedBorderBoxControlSplitControls;\n"],"mappings":";;;;;;;;;;AAYA,MAAM,iCACL,OACA,iBACI;CACJ,MAAM,EACL,mBACA,QACA,qBACA,aACA,aACA,UACA,kBACA,eACA,uBACA,OACA,mCACA,GAAG,eACA,iCAAkC,KAAM;CAI5C,MAAM,CAAE,eAAe,oBAAqB,SAC3C,IACD;CAGA,MAAM,eACL,cAEE,mBACG;EACA,WAAW;EACX,QAAQ;EACR,QAAQ;EACR,OAAO;CACR,IACC,KAAA,GACJ;EAAE;EAAkB;EAAe;CAAc,CAClD;CAED,MAAM,2BAA2B;EAChC;EACA;EACA;EACA;EACA,WAAW;EACX;CACD;CAEA,MAAM,YAAY,aAAc,CAAE,kBAAkB,YAAa,CAAE;CAEnE,OACC,qBAAC,MAAD;EAAM,GAAK;EAAa,KAAM;EAAY,KAAM;EAAhD,UAAA;GACC,oBAAC,4BAAD,EAAoC,MAAS,CAAA;GAE7C,oBAAC,eAAD;IACC,WAAY;IACZ,qBAAA;IACA,OAAQ,GAAI,YAAa;IACzB,WAAa,cAAe,SAAU,WAAW,KAAM;IACvD,wBAAyB;IACzB,OAAQ,OAAO;IACf,GAAK;GACL,CAAA;GACD,oBAAC,eAAD;IACC,qBAAA;IACA,OAAQ,GAAI,aAAc;IAC1B,WAAa,cAAe,SAAU,WAAW,MAAO;IACxD,wBAAyB;IACzB,OAAQ,OAAO;IACf,GAAK;GACL,CAAA;GACD,oBAAC,eAAD;IACC,WAAY;IACZ,qBAAA;IACA,OAAQ,GAAI,cAAe;IAC3B,WAAa,cAAe,SAAU,WAAW,OAAQ;IACzD,wBAAyB;IACzB,OAAQ,OAAO;IACf,GAAK;GACL,CAAA;GACD,oBAAC,eAAD;IACC,WAAY;IACZ,qBAAA;IACA,OAAQ,GAAI,eAAgB;IAC5B,WAAa,cAAe,SAAU,WAAW,QAAS;IAC1D,wBAAyB;IACzB,OAAQ,OAAO;IACf,GAAK;GACL,CAAA;EACI;;AAER;AAEA,MAAM,yCAAyC,eAC9C,+BACA,+BACD"}