Ol

An ordered list of items.

Usage

OlExample.tsx
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
<Ol>
<li>
<P>
<Strong>I often do this thing where list items have headings.</Strong>
</P>
<P>For some reason I think this looks cool which is unfortunate because it's pretty annoying to get the styles right.</P>
<P>
I often have two or three paragraphs in these list items, too, so the hard part is getting the spacing between the paragraphs, list item heading, and separate list items to
all make sense. Pretty tough honestly, you could make a strong argument that you just shouldn't write this way.
</P>
</li>
<li>
<P>
<Strong>Since this is a list, I need at least two items.</Strong>
</P>
<P>
I explained what I'm doing already in the previous list item, but a list wouldn't be a list if it only had one item, and we really want this to look realistic. That's why
I've added this second list item so I actually have something to look at when writing the styles.
</P>
</li>
<li>
<P>
<Strong>It's not a bad idea to add a third item either.</Strong>
</P>
<P>
I think it probably would've been fine to just use two items but three is definitely not worse, and since I seem to be having no trouble making up arbitrary things to type,
I might as well include it.
</P>
</li>
</Ol>
<Ol>
<li>
Or just a simple grocery list
<Ol>
<li>Milk</li>
<li>
Cheese
<Ol>
<li>Blue cheese</li>
<li>Feta</li>
</Ol>
</li>
</Ol>
</li>
<li>
or a to-do list
<Ol>
<li>Buy milk</li>
<li>Walk the dog</li>
<li>Make dinner</li>
</Ol>
</li>
<li>Make all the use-cases look good</li>
</Ol>

Here's the <Ol /> component in action.

  1. I often do this thing where list items have headings.

    For some reason I think this looks cool which is unfortunate because it's pretty annoying to get the styles right.

    I often have two or three paragraphs in these list items, too, so the hard part is getting the spacing between the paragraphs, list item heading, and separate list items to all make sense. Pretty tough honestly, you could make a strong argument that you just shouldn't write this way.

  2. Since this is a list, I need at least two items.

    I explained what I'm doing already in the previous list item, but a list wouldn't be a list if it only had one item, and we really want this to look realistic. That's why I've added this second list item so I actually have something to look at when writing the styles.

  3. It's not a bad idea to add a third item either.

    I think it probably would've been fine to just use two items but three is definitely not worse, and since I seem to be having no trouble making up arbitrary things to type, I might as well include it.

  1. Or just a simple grocery list
    1. Milk
    2. Cheese
      1. Blue cheese
      2. Feta
  2. or a to-do list
    1. Buy milk
    2. Walk the dog
    3. Make dinner
  3. Make all the use-cases look good

Features

  • Drop-in replacement for the native <ol> element.
  • Opts-in to your design system's typographic styles.

Source

ol.tsx
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
import { forwardRef, type HTMLAttributes } from 'react'
import { cn } from '#app/utils/tailwind-merge.ts'
const Ol = forwardRef<HTMLOListElement, HTMLAttributes<HTMLOListElement>>(({ className, ...props }, ref) => <ol ref={ref} className={cn('ol', className)} {...props} />)
Ol.displayName = 'Ol'
export { Ol }

Styling

tailwind.css
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
.ol {
@apply my-fluid-10 pl-fluid-10 list-decimal;
}
.ol > li {
@apply text-muted-600 text-fluid-md my-fluid-2 max-w-prose;
/* Bullet point */
&::marker {
@apply text-muted-400 font-normal;
}
/* Nested lists */
& > .ol:first-child {
@apply my-0;
}
/* Nested paragraphs */
& > *:first-child {
@apply mt-fluid-10 mb-fluid-6;
}
& > * {
@apply mt-fluid-6 mb-fluid-6;
}
& > *:last-child {
@apply mt-fluid-6 mb-fluid-10;
}
}