alertLink.stories.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import {Fragment, useState} from 'react';
  2. import AlertLink from 'sentry/components/alertLink';
  3. import JSXNode from 'sentry/components/stories/jsxNode';
  4. import JSXProperty from 'sentry/components/stories/jsxProperty';
  5. import {IconSentry} from 'sentry/icons';
  6. import storyBook from 'sentry/stories/storyBook';
  7. export default storyBook(AlertLink, story => {
  8. story('Default', () => {
  9. return (
  10. <Fragment>
  11. <p>
  12. The <JSXNode name="AlertLink" /> component is a highlighted banner that links to
  13. some other page (or component). Depending on the{' '}
  14. <JSXProperty name="priority" value /> prop specified, it can be used as a
  15. success alert, an error or warning alert, and for various other use cases.
  16. </p>
  17. <p>
  18. The default <JSXNode name="AlertLink" /> looks like this:
  19. </p>
  20. <AlertLink href="https://sentry.io/welcome">
  21. Clicking this link will not open in a new tab!
  22. </AlertLink>
  23. <p>
  24. The default props are <JSXProperty name="size" value="normal" />,{' '}
  25. <JSXProperty name="priority" value="warning" />,{' '}
  26. <JSXProperty name="withoutMarginBottom" value="false" />, and{' '}
  27. <JSXProperty name="openInNewTab" value="false" />.
  28. </p>
  29. <p>
  30. This alert below has <JSXProperty name="openInNewTab" value="true" />:
  31. </p>
  32. <AlertLink href="https://sentry.io/welcome" openInNewTab>
  33. Clicking this link WILL open in a new tab!
  34. </AlertLink>
  35. </Fragment>
  36. );
  37. });
  38. story('priority', () => {
  39. return (
  40. <Fragment>
  41. <p>
  42. The <JSXProperty name="priority" value /> prop specifies the alert category, and
  43. changes the color of the alert.
  44. </p>
  45. <AlertLink priority="error">
  46. This is an error alert. Something went wrong.
  47. </AlertLink>
  48. <AlertLink priority="info">Info alert. Put some exciting info here.</AlertLink>
  49. <AlertLink priority="muted">Muted alerts look like this.</AlertLink>
  50. <AlertLink priority="success">Success alert. Yay!</AlertLink>
  51. <AlertLink priority="warning">
  52. Warning alert. Something is about to go wrong, probably.
  53. </AlertLink>
  54. </Fragment>
  55. );
  56. });
  57. story('icon', () => {
  58. return (
  59. <Fragment>
  60. <p>
  61. The <JSXProperty name="icon" value /> prop can be specified if you want to add
  62. an icon to the alert. Just directly pass in the icon, like{' '}
  63. <JSXNode name="IconSentry" /> for example, to the prop.
  64. </p>
  65. <AlertLink priority="warning" icon={<IconSentry />}>
  66. Read the docs.
  67. </AlertLink>
  68. </Fragment>
  69. );
  70. });
  71. story('withoutMarginBottom', () => {
  72. return (
  73. <Fragment>
  74. <p>
  75. The <JSXProperty name="withoutMarginBottom" value /> prop is a boolean that's{' '}
  76. <code>false</code> by default.
  77. </p>
  78. <AlertLink withoutMarginBottom>This one has no bottom margin.</AlertLink>
  79. <AlertLink>This one has bottom margin by default.</AlertLink>
  80. <AlertLink withoutMarginBottom>This one has no margin bottom.</AlertLink>
  81. </Fragment>
  82. );
  83. });
  84. story('size', () => {
  85. return (
  86. <Fragment>
  87. <p>
  88. The <JSXProperty name="size" value /> prop can be either <code>"small"</code> or{' '}
  89. <code>"normal"</code>.{' '}
  90. </p>
  91. <AlertLink priority="info" size="normal">
  92. Normal
  93. </AlertLink>
  94. <AlertLink priority="info" size="small">
  95. Small
  96. </AlertLink>
  97. </Fragment>
  98. );
  99. });
  100. story('to vs href vs onClick', () => {
  101. const [count, setCount] = useState(0);
  102. return (
  103. <Fragment>
  104. <p>
  105. There are three ways to specify what should happen when the{' '}
  106. <JSXNode name="AlertLink" /> is clicked.{' '}
  107. </p>
  108. <p>
  109. The <JSXProperty name="to" value /> prop should be used for internal links.
  110. Note: links specified with this prop will never open in a new tab, even if you
  111. set
  112. <JSXProperty name="openInNewTab" value="true" /> .
  113. </p>
  114. <AlertLink
  115. priority="info"
  116. size="normal"
  117. to="/stories/?name=app/components/badge.stories.tsx"
  118. >
  119. View the badge story page
  120. </AlertLink>
  121. <p>
  122. The <JSXProperty name="href" value /> prop should be used for external links.
  123. </p>
  124. <AlertLink
  125. priority="info"
  126. size="normal"
  127. href="https://sentry.io/for/session-replay/"
  128. openInNewTab
  129. >
  130. Learn more about Session Replay
  131. </AlertLink>
  132. <p>
  133. Lastly, you can get creative with the <JSXProperty name="onClick" value /> prop.
  134. </p>
  135. <AlertLink priority="info" size="normal" onClick={() => setCount(count + 1)}>
  136. You clicked this {count} times.
  137. </AlertLink>
  138. </Fragment>
  139. );
  140. });
  141. });