panelProvider.tsx 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import {useMemo} from 'react';
  2. import {ThemeProvider, useTheme} from '@emotion/react';
  3. /**
  4. * Smaller border radii for descendants of panel-like elements. For most
  5. * elements, the default border radius is 6px. However, for descendants of
  6. * panel-like elements (e.g. menu items inside overlays), the border radius
  7. * should be 4px. `smallerBorderRadii` overrides the default 6px and enforces
  8. * the 4px version on these panel descendants.
  9. */
  10. const smallerBorderRadii = {
  11. borderRadius: '4px',
  12. borderRadiusBottom: '0 0 4px 4px',
  13. borderRadiusTop: '4px 4px 0 0',
  14. borderRadiusLeft: '4px 0 0 4px',
  15. borderRadiusRight: '0 4px 4px 0',
  16. };
  17. /**
  18. * Nested theme provider that automatically adjusts the styles of descendants
  19. * of panel-like elements. See `panel.tsx` for usage example.
  20. */
  21. const PanelProvider = ({children}: {children: React.ReactNode}) => {
  22. const theme = useTheme();
  23. const modifiedTheme = useMemo(() => ({...theme, ...smallerBorderRadii}), [theme]);
  24. return <ThemeProvider theme={modifiedTheme}>{children}</ThemeProvider>;
  25. };
  26. export default PanelProvider;