CompactModeToggle.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact [email protected]
  14. */
  15. import React from 'react';
  16. import { Button } from '@douyinfe/semi-ui';
  17. import PropTypes from 'prop-types';
  18. import { useIsMobile } from '../../../hooks/common/useIsMobile';
  19. /**
  20. * 紧凑模式切换按钮组件
  21. * 用于在自适应列表和紧凑列表之间切换
  22. * 在移动端时自动隐藏,因为移动端使用"显示操作项"按钮来控制内容显示
  23. */
  24. const CompactModeToggle = ({
  25. compactMode,
  26. setCompactMode,
  27. t,
  28. size = 'small',
  29. type = 'tertiary',
  30. className = '',
  31. ...props
  32. }) => {
  33. const isMobile = useIsMobile();
  34. // 在移动端隐藏紧凑列表切换按钮
  35. if (isMobile) {
  36. return null;
  37. }
  38. return (
  39. <Button
  40. type={type}
  41. size={size}
  42. className={`w-full md:w-auto ${className}`}
  43. onClick={() => setCompactMode(!compactMode)}
  44. {...props}
  45. >
  46. {compactMode ? t('自适应列表') : t('紧凑列表')}
  47. </Button>
  48. );
  49. };
  50. CompactModeToggle.propTypes = {
  51. compactMode: PropTypes.bool.isRequired,
  52. setCompactMode: PropTypes.func.isRequired,
  53. t: PropTypes.func.isRequired,
  54. size: PropTypes.string,
  55. type: PropTypes.string,
  56. className: PropTypes.string,
  57. };
  58. export default CompactModeToggle;