md.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. 'use client'
  2. import classNames from '@/utils/classnames'
  3. type IChildrenProps = {
  4. children: React.ReactNode
  5. id?: string
  6. tag?: any
  7. label?: any
  8. anchor: boolean
  9. }
  10. type IHeaderingProps = {
  11. url: string
  12. method: 'PUT' | 'DELETE' | 'GET' | 'POST'
  13. title: string
  14. name: string
  15. }
  16. export const Heading = function H2({
  17. url,
  18. method,
  19. title,
  20. name,
  21. }: IHeaderingProps) {
  22. let style = ''
  23. switch (method) {
  24. case 'PUT':
  25. style = 'ring-amber-300 bg-amber-400/10 text-amber-500 dark:ring-amber-400/30 dark:bg-amber-400/10 dark:text-amber-400'
  26. break
  27. case 'DELETE':
  28. style = 'ring-rose-200 bg-rose-50 text-red-500 dark:ring-rose-500/20 dark:bg-rose-400/10 dark:text-rose-400'
  29. break
  30. case 'POST':
  31. style = 'ring-sky-300 bg-sky-400/10 text-sky-500 dark:ring-sky-400/30 dark:bg-sky-400/10 dark:text-sky-400'
  32. break
  33. default:
  34. style = 'ring-emerald-300 dark:ring-emerald-400/30 bg-emerald-400/10 text-emerald-500 dark:text-emerald-400'
  35. break
  36. }
  37. return (
  38. <>
  39. <div className="flex items-center gap-x-3" >
  40. <span className={`font-mono text-[0.625rem] font-semibold leading-6 rounded-lg px-1.5 ring-1 ring-inset ${style}`}>{method}</span>
  41. {/* <span className="h-0.5 w-0.5 rounded-full bg-zinc-300 dark:bg-zinc-600"></span> */}
  42. <span className="font-mono text-xs text-zinc-400">{url}</span>
  43. </div>
  44. <h2 className='mt-2 scroll-mt-32'>
  45. <a href={name} className='no-underline group text-inherit hover:text-inherit'>{title}</a>
  46. </h2>
  47. </>
  48. )
  49. }
  50. export function Row({ children }: IChildrenProps) {
  51. return (
  52. <div className="grid items-start grid-cols-1 gap-x-16 gap-y-10 xl:max-w-none xl:grid-cols-2">
  53. {children}
  54. </div>
  55. )
  56. }
  57. type IColProps = IChildrenProps & {
  58. sticky: boolean
  59. }
  60. export function Col({ children, sticky = false }: IColProps) {
  61. return (
  62. <div
  63. className={classNames(
  64. '[&>:first-child]:mt-0 [&>:last-child]:mb-0',
  65. sticky && 'xl:sticky xl:top-24',
  66. )}
  67. >
  68. {children}
  69. </div>
  70. )
  71. }
  72. export function Properties({ children }: IChildrenProps) {
  73. return (
  74. <div className="my-6">
  75. <ul
  76. role="list"
  77. className="m-0 max-w-[calc(theme(maxWidth.lg)-theme(spacing.8))] list-none divide-y divide-zinc-900/5 p-0 dark:divide-white/5"
  78. >
  79. {children}
  80. </ul>
  81. </div>
  82. )
  83. }
  84. type IProperty = IChildrenProps & {
  85. name: string
  86. type: string
  87. }
  88. export function Property({ name, type, children }: IProperty) {
  89. return (
  90. <li className="px-0 py-4 m-0 first:pt-0 last:pb-0">
  91. <dl className="flex flex-wrap items-center m-0 gap-x-3 gap-y-2">
  92. <dt className="sr-only">Name</dt>
  93. <dd>
  94. <code>{name}</code>
  95. </dd>
  96. <dt className="sr-only">Type</dt>
  97. <dd className="font-mono text-xs text-zinc-400 dark:text-zinc-500">
  98. {type}
  99. </dd>
  100. <dt className="sr-only">Description</dt>
  101. <dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
  102. {children}
  103. </dd>
  104. </dl>
  105. </li>
  106. )
  107. }
  108. type ISubProperty = IChildrenProps & {
  109. name: string
  110. type: string
  111. }
  112. export function SubProperty({ name, type, children }: ISubProperty) {
  113. return (
  114. <li className="px-0 py-1 m-0 last:pb-0">
  115. <dl className="flex flex-wrap items-center m-0 gap-x-3">
  116. <dt className="sr-only">Name</dt>
  117. <dd>
  118. <code>{name}</code>
  119. </dd>
  120. <dt className="sr-only">Type</dt>
  121. <dd className="font-mono text-xs text-zinc-400 dark:text-zinc-500">
  122. {type}
  123. </dd>
  124. <dt className="sr-only">Description</dt>
  125. <dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
  126. {children}
  127. </dd>
  128. </dl>
  129. </li>
  130. )
  131. }