configProvider.stories.tsx 961 B

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