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.

ModalHeader.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. /* eslint-disable react/no-multi-comp */
  3. import ErrorIcon from '@atlaskit/icon/glyph/error';
  4. import WarningIcon from '@atlaskit/icon/glyph/warning';
  5. import {
  6. Header,
  7. Title,
  8. titleIconWrapperStyles,
  9. TitleText
  10. } from '@atlaskit/modal-dialog/dist/es2019/styled/Content';
  11. import React from 'react';
  12. import { Icon, IconClose } from '../../../icons';
  13. const TitleIcon = ({ appearance }: { appearance?: 'danger' | 'warning' }) => {
  14. if (!appearance) {
  15. return null;
  16. }
  17. const IconSymbol = appearance === 'danger' ? ErrorIcon : WarningIcon;
  18. return (
  19. <span css = { titleIconWrapperStyles(appearance) }>
  20. <IconSymbol label = { `${appearance} icon` } />
  21. </span>
  22. );
  23. };
  24. type Props = {
  25. id: string,
  26. appearance?: 'danger' | 'warning',
  27. heading: string,
  28. hideCloseIconButton: boolean,
  29. onClose: Function,
  30. showKeyline: boolean,
  31. isHeadingMultiline: boolean,
  32. testId: string,
  33. t: Function
  34. }
  35. /**
  36. * A default header for modal-dialog components
  37. *
  38. * @export
  39. * @class ModalHeader
  40. * @extends {React.Component<Props>}
  41. */
  42. export default class ModalHeader extends React.Component<Props> {
  43. static defaultProps = {
  44. isHeadingMultiline: true
  45. };
  46. /**
  47. * Implements React's {@link Component#render()}.
  48. *
  49. * @inheritdoc
  50. * @returns {ReactElement}
  51. */
  52. render() {
  53. const {
  54. id,
  55. appearance,
  56. heading,
  57. hideCloseIconButton,
  58. onClose,
  59. showKeyline,
  60. isHeadingMultiline,
  61. testId
  62. } = this.props;
  63. if (!heading) {
  64. return null;
  65. }
  66. return (
  67. <Header showKeyline = { showKeyline }>
  68. <Title>
  69. <TitleIcon appearance = { appearance } />
  70. <TitleText
  71. data-testid = { testId && `${testId}-heading` }
  72. id = { id }
  73. isHeadingMultiline = { isHeadingMultiline }>
  74. {heading}
  75. </TitleText>
  76. </Title>
  77. {
  78. !hideCloseIconButton && <Icon
  79. onClick = { onClose }
  80. src = { IconClose } />
  81. }
  82. </Header>
  83. );
  84. }
  85. }