md.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. <span id={name?.replace(/^#/, '')} className='relative -top-28' />
  40. <div className="flex items-center gap-x-3" >
  41. <span className={`font-mono text-[0.625rem] font-semibold leading-6 rounded-lg px-1.5 ring-1 ring-inset ${style}`}>{method}</span>
  42. {/* <span className="h-0.5 w-0.5 rounded-full bg-zinc-300 dark:bg-zinc-600"></span> */}
  43. <span className="font-mono text-xs text-zinc-400">{url}</span>
  44. </div>
  45. <h2 className='mt-2 scroll-mt-32'>
  46. <a href={name} className='no-underline group text-inherit hover:text-inherit'>{title}</a>
  47. </h2>
  48. </>
  49. )
  50. }
  51. export function Row({ children }: IChildrenProps) {
  52. return (
  53. <div className="grid items-start grid-cols-1 gap-x-16 gap-y-10 xl:max-w-none xl:grid-cols-2">
  54. {children}
  55. </div>
  56. )
  57. }
  58. type IColProps = IChildrenProps & {
  59. sticky: boolean
  60. }
  61. export function Col({ children, sticky = false }: IColProps) {
  62. return (
  63. <div
  64. className={classNames(
  65. '[&>:first-child]:mt-0 [&>:last-child]:mb-0',
  66. sticky && 'xl:sticky xl:top-24',
  67. )}
  68. >
  69. {children}
  70. </div>
  71. )
  72. }
  73. export function Properties({ children }: IChildrenProps) {
  74. return (
  75. <div className="my-6">
  76. <ul
  77. role="list"
  78. 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"
  79. >
  80. {children}
  81. </ul>
  82. </div>
  83. )
  84. }
  85. type IProperty = IChildrenProps & {
  86. name: string
  87. type: string
  88. }
  89. export function Property({ name, type, children }: IProperty) {
  90. return (
  91. <li className="px-0 py-4 m-0 first:pt-0 last:pb-0">
  92. <dl className="flex flex-wrap items-center m-0 gap-x-3 gap-y-2">
  93. <dt className="sr-only">Name</dt>
  94. <dd>
  95. <code>{name}</code>
  96. </dd>
  97. <dt className="sr-only">Type</dt>
  98. <dd className="font-mono text-xs text-zinc-400 dark:text-zinc-500">
  99. {type}
  100. </dd>
  101. <dt className="sr-only">Description</dt>
  102. <dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
  103. {children}
  104. </dd>
  105. </dl>
  106. </li>
  107. )
  108. }
  109. type ISubProperty = IChildrenProps & {
  110. name: string
  111. type: string
  112. }
  113. export function SubProperty({ name, type, children }: ISubProperty) {
  114. return (
  115. <li className="px-0 py-1 m-0 last:pb-0">
  116. <dl className="flex flex-wrap items-center m-0 gap-x-3">
  117. <dt className="sr-only">Name</dt>
  118. <dd>
  119. <code>{name}</code>
  120. </dd>
  121. <dt className="sr-only">Type</dt>
  122. <dd className="font-mono text-xs text-zinc-400 dark:text-zinc-500">
  123. {type}
  124. </dd>
  125. <dt className="sr-only">Description</dt>
  126. <dd className="w-full flex-none [&>:first-child]:mt-0 [&>:last-child]:mb-0">
  127. {children}
  128. </dd>
  129. </dl>
  130. </li>
  131. )
  132. }