RTLWrapper.tsx 1.1 KB

12345678910111213141516171819202122232425262728
  1. import React, { useState } from 'react';
  2. import { ButtonGroup, Button, ConfigProvider } from '../../../index';
  3. export default function RTLWrapper({ children, onDirectionChange, defaultDirection = 'ltr' }: { defaultDirection?: 'ltr' | 'rtl'; children: React.ReactNode; onDirectionChange?: (direction: 'ltr' | 'rtl') => void }) {
  4. const [direction, setDirection] = useState(defaultDirection);
  5. const handleDirectionChange = dir => {
  6. setDirection(dir);
  7. if (typeof onDirectionChange === 'function') {
  8. onDirectionChange(dir);
  9. }
  10. };
  11. return (
  12. <div style={{ width: '100%' }}>
  13. <div style={{ marginBottom: 20 }}>
  14. <ButtonGroup>
  15. <Button onClick={() => handleDirectionChange('ltr')}>LTR</Button>
  16. <Button onClick={() => handleDirectionChange('rtl')}>RTL</Button>
  17. </ButtonGroup>
  18. {`direction=${direction}`}
  19. </div>
  20. <ConfigProvider direction={direction}>
  21. {children}
  22. </ConfigProvider>
  23. </div>
  24. );
  25. }