Ul

An unordered list of items.

Usage

UlExample.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
<Ul>
<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>
</Ul>
<Ul>
<li>
Or just a simple grocery list
<Ul>
<li>Milk</li>
<li>
Cheese
<Ul>
<li>Blue cheese</li>
<li>Feta</li>
</Ul>
</li>
</Ul>
</li>
<li>
or a to-do list
<Ul>
<li>Buy milk</li>
<li>Walk the dog</li>
<li>Make dinner</li>
</Ul>
</li>
<li>Make all the use-cases look good</li>
</Ul>

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

  • 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.

  • 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.

  • 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.

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

Features

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

Source

ul.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 Ul = forwardRef<HTMLUListElement, HTMLAttributes<HTMLUListElement>>(({ className, ...props }, ref) => <ul ref={ref} className={cn('ul', className)} {...props} />)
Ul.displayName = 'Ul'
export { Ul }

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
.ul {
@apply my-fluid-10 pl-fluid-10 list-disc;
}
.ul > 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 */
& > .ul: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;
}
}