mapbox / mapbox/mr-ui

Extend `theme*` props to accept functions that receive the default class list

Open
#26 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

estimate-4 icebox jira-sync-complete p2
Dominant language
TypeScript
Stars
90
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Having experimented with a few different options, here's the outline of a styling pattern that I think could fit our purposes:

  • Opinionated defaults.
  • Standard variants are easy to implement, with either boolean or keyword props. The current MbxButton component illustrates this approach with the variant, size, and width props.
  • Non-standard variants are possible to implement, with theme* props. This is the pattern established by the bulk of existing components and has proven useful. The main problem with it is that it requires a lot of the user — so it makes sense for advanced users, but not for the average user. We should continue to use these but indicate in the docs that they are advanced props and most people should not need to use them.

One major annoyance with the theme* props is that you need to replace every class that you don't want to override. A common use case is to just append a class to the end of the list, but to do this you actually need to copy-paste the default class list and add your own to the end — and that's not very robust or cheery. So I'm thinking that instead of theme* props accepting only strings, they'll also accept functions that receive the default class list and return a modified one. Appending would be very easy, then.

cc @danswick

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/components/mbx-button/mbx-button.js and its existing variant, size, and width props to understand the component pattern. Trace how theme* props are handled in the surrounding components, then verify that they can accept functions receiving the default class list and that the returned classes are used.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.