chooseLayout.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import CompactSelect from 'sentry/components/forms/compactSelect';
  2. import {IconPanel} from 'sentry/icons';
  3. import {t} from 'sentry/locale';
  4. import useReplayLayout, {LayoutKey} from 'sentry/utils/replays/hooks/useReplayLayout';
  5. const layoutToLabel: Record<LayoutKey, string> = {
  6. topbar: t('Player Top'),
  7. sidebar_left: t('Player Left'),
  8. sidebar_right: t('Player Right'),
  9. };
  10. const layoutToDir: Record<LayoutKey, string> = {
  11. topbar: 'up',
  12. sidebar_left: 'left',
  13. sidebar_right: 'right',
  14. };
  15. function getLayoutIcon(layout: string) {
  16. const dir = layout in layoutToDir ? layoutToDir[layout] : 'up';
  17. return <IconPanel size="sm" direction={dir} />;
  18. }
  19. type Props = {};
  20. function ChooseLayout({}: Props) {
  21. const {getLayout, setLayout} = useReplayLayout();
  22. return (
  23. <CompactSelect
  24. triggerProps={{
  25. size: 'xs',
  26. icon: getLayoutIcon(getLayout()),
  27. }}
  28. triggerLabel=""
  29. value={getLayout()}
  30. placement="bottom right"
  31. onChange={opt => setLayout(opt?.value)}
  32. options={Object.entries(layoutToLabel).map(([value, label]) => ({
  33. value,
  34. label,
  35. leadingItems: getLayoutIcon(value),
  36. }))}
  37. />
  38. );
  39. }
  40. export default ChooseLayout;