Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion storybook/decorators/with-global-css.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const config = {

export const WithGlobalCSS = ( Story, context ) => {
const { lazyStyles, externalStyles, classes } =
config[ context.globals.css ];
config[ context.globals.css ] ?? config.none;

useEffect( () => {
const style = document.createElement( 'style' );
Expand Down
14 changes: 9 additions & 5 deletions storybook/decorators/with-rtl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,39 @@ export const WithRTL = ( Story, context ) => {
const [ rerenderKey, setRerenderKey ] = useState( 0 );
const ref = useRef();

const direction = [ 'ltr', 'rtl' ].includes( context.globals.direction )
? context.globals.direction
: 'ltr';

useEffect( () => {
// Override the return value of i18n.isRTL()
addFilter(
'i18n.gettext_with_context',
'storybook',
( translation, text, _context ) => {
if ( text === 'ltr' && _context === 'text direction' ) {
return context.globals.direction;
return direction;
}
return translation;
}
);

ref.current.ownerDocument.documentElement.setAttribute(
'dir',
context.globals.direction
direction
);

setRerenderKey( ( prevValue ) => prevValue + 1 );

return () => removeFilter( 'i18n.gettext_with_context', 'storybook' );
}, [ context.globals.direction ] );
}, [ direction ] );

useLayoutEffect( () => {
const stylesToUse = [];

CONFIG.forEach( ( item ) => {
if ( item.componentIdMatcher.test( context.componentId ) ) {
stylesToUse.push( ...item[ context.globals.direction ] );
stylesToUse.push( ...item[ direction ] );
}
} );

Expand All @@ -57,7 +61,7 @@ export const WithRTL = ( Story, context ) => {
return () => {
document.head.removeChild( style );
};
}, [ context.componentId, context.globals.direction ] );
}, [ context.componentId, direction ] );

return (
<div ref={ ref } key={ rerenderKey }>
Expand Down
Loading