600,
+ 'is-button': !! onClick,
} ) }
style={ {
color: textColor,
@@ -206,53 +217,118 @@ function StyleBook( { isSelected, onSelect } ) {
} }
>
{ resizeObserver }
-
- { ( tab ) => (
-
- ) }
-
+ ) }
+
+ ) : (
+
+ ) }
);
}
+const StyleBookBody = ( {
+ category,
+ examples,
+ isSelected,
+ onClick,
+ onSelect,
+ settings,
+ sizes,
+ title,
+} ) => {
+ const [ isFocused, setIsFocused ] = useState( false );
+
+ // The presence of an `onClick` prop indicates that the Style Book is being used
+ // as a button. In this case, we need to add additional props to the iframe to
+ // make it behave like a button.
+ const buttonModeProps = {
+ role: 'button',
+ onFocus: () => setIsFocused( true ),
+ onBlur: () => setIsFocused( false ),
+ onKeyDown: ( event ) => {
+ const { keyCode } = event;
+ if ( onClick && ( keyCode === ENTER || keyCode === SPACE ) ) {
+ onClick( event );
+ }
+ },
+ onClick: ( event ) => {
+ if ( onClick ) {
+ onClick( event );
+ }
+ },
+ readonly: true,
+ };
+
+ const buttonModeStyles = onClick
+ ? 'body { cursor: pointer; } body * { pointer-events: none; }'
+ : '';
+
+ return (
+