使用法

  1. import { withFallbackStyles, Button } from '@wordpress/components';
  2. const { getComputedStyle } = window;
  3. const MyComponentWithFallbackStyles = withFallbackStyles(
  4. ( node, ownProps ) => {
  5. const buttonNode = node.querySelector( 'button' );
  6. return {
  7. fallbackBackgroundColor: getComputedStyle( buttonNode )
  8. .backgroundColor,
  9. fallbackTextColor: getComputedStyle( buttonNode ).color,
  10. };
  11. }
  12. )( ( { fallbackTextColor, fallbackBackgroundColor } ) => (
  13. <div>
  14. <Button variant="primary">My button</Button>
  15. <div>Text color: { fallbackTextColor }</div>
  16. <div>Background color: { fallbackBackgroundColor }</div>
  17. </div>
  18. ) );