You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RadioCard.tsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import classNames from 'classnames';
  21. import * as React from 'react';
  22. import { FormattedMessage } from 'react-intl';
  23. import { translate } from '../../helpers/l10n';
  24. import RecommendedIcon from '../icons/RecommendedIcon';
  25. import './Radio.css';
  26. import './RadioCard.css';
  27. export interface RadioCardProps {
  28. className?: string;
  29. disabled?: boolean;
  30. onClick?: () => void;
  31. selected?: boolean;
  32. }
  33. interface Props extends RadioCardProps {
  34. children: React.ReactNode;
  35. recommended?: string;
  36. title: React.ReactNode;
  37. titleInfo?: React.ReactNode;
  38. vertical?: boolean;
  39. }
  40. export default function RadioCard(props: Props) {
  41. const {
  42. className,
  43. disabled,
  44. onClick,
  45. recommended,
  46. selected,
  47. titleInfo,
  48. vertical = false
  49. } = props;
  50. const isActionable = Boolean(onClick);
  51. return (
  52. <div
  53. aria-checked={selected}
  54. className={classNames(
  55. 'radio-card',
  56. {
  57. 'radio-card-actionable': isActionable,
  58. 'radio-card-vertical': vertical,
  59. disabled,
  60. selected
  61. },
  62. className
  63. )}
  64. onClick={isActionable && !disabled ? onClick : undefined}
  65. role="radio"
  66. tabIndex={0}>
  67. <h2 className="radio-card-header big-spacer-bottom">
  68. <span className="display-flex-center link-radio">
  69. {isActionable && (
  70. <i className={classNames('icon-radio', 'spacer-right', { 'is-checked': selected })} />
  71. )}
  72. {props.title}
  73. </span>
  74. {titleInfo}
  75. </h2>
  76. <div className="radio-card-body">{props.children}</div>
  77. {recommended && (
  78. <div className="radio-card-recommended">
  79. <RecommendedIcon className="spacer-right" />
  80. <FormattedMessage
  81. defaultMessage={recommended}
  82. id={recommended}
  83. values={{ recommended: <strong>{translate('recommended')}</strong> }}
  84. />
  85. </div>
  86. )}
  87. </div>
  88. );
  89. }