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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. onClose: Function,
  29. showKeyline: boolean,
  30. isHeadingMultiline: boolean,
  31. testId: string,
  32. t: Function
  33. }
  34. /**
  35. * A default header for modal-dialog components
  36. *
  37. * @export
  38. * @class ModalHeader
  39. * @extends {React.Component<Props>}
  40. */
  41. export default class ModalHeader extends React.Component<Props> {
  42. static defaultProps = {
  43. isHeadingMultiline: true
  44. };
  45. /**
  46. * Implements React's {@link Component#render()}.
  47. *
  48. * @inheritdoc
  49. * @returns {ReactElement}
  50. */
  51. render() {
  52. const {
  53. id,
  54. appearance,
  55. heading,
  56. onClose,
  57. showKeyline,
  58. isHeadingMultiline,
  59. testId
  60. } = this.props;
  61. if (!heading) {
  62. return null;
  63. }
  64. return (
  65. <Header showKeyline = { showKeyline }>
  66. <Title>
  67. <TitleIcon appearance = { appearance } />
  68. <TitleText
  69. data-testid = { testId && `${testId}-heading` }
  70. id = { id }
  71. isHeadingMultiline = { isHeadingMultiline }>
  72. {heading}
  73. </TitleText>
  74. </Title>
  75. <Icon
  76. onClick = { onClose }
  77. src = { IconClose } />
  78. </Header>
  79. );
  80. }
  81. }