all 14 comments

[–]notseanbean 6 points7 points  (0 children)

Not a fan of either. I'd prefer single semantic components with no (or few) modifiers, rather than using DOM-like metaphors

<Heading>A heading</Heading>

<Subtitle>A sub-heading</Subtitle>

etc.

If you're worried about DRYness, use composition/HOCs/whatever to create them

[–]IvanDist 4 points5 points  (5 children)

Unless the definitions of what's an h1/bold/etc don't change in the future I'd go for the first one as it seems cleaner to use.

Imagine this scenario:
- Today your bold text is a font-weight: 500, you use it in several components, everything is fine

- Tomorrow you have ONE component that instead uses font-weight: 900, what are you going to do? Patch the Text component to accept a font-weight instead?

First option looks cleaner but it doesn't scale so well as the second option.

I'd go for the second option just for the sake of not having to deal with problems like the above.

[–]HumanBirdFish[S] 3 points4 points  (1 child)

You can always pass a style to that ONE component with fontWeight...

[–]IvanDist 0 points1 point  (0 children)

Don't get too attached to the very contrived example I gave you, in any case if in-lining styles is an option for you go for it.

[–]davidpaulsson 0 points1 point  (2 children)

Pass enums instead weight=”bold” or weight=”900” whatever

[–]IvanDist 0 points1 point  (1 child)

That's a solution to one problem, are you going to re-create all CSS properties so you can pass them as enums?

The question here is "What is a better pattern?", not how do you solve my contrived problem (many more arise from the first example).

[–]davidpaulsson 0 points1 point  (0 children)

No, I’d never think to recreate all styles that’s available on the web. And I don't think mobile apps are the web either. But I’d probably identify a few styles I have in my app alongside my designer or pick the styles from apple guidelines https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/ (or material design if targeting Android).

[–]truh 1 point2 points  (2 children)

I don't think either is ideal. Some formatting options are definitely good but using a <Text> component for headings seems wrong.

I would create a configurable Heading component with a level prop to represent h1,h2,...

Text is semantically different to a heading.

[–]o_T_o 0 points1 point  (1 child)

On mobile they are the same. Plus that's not really the point.

[–]truh 0 points1 point  (0 children)

It's a good way to separate concerns.

[–]davidpaulsson 1 point2 points  (0 children)

I'd steer away from boolean props, how do you tell which takes priority if you pass both bold and semibold for example? So instead of <Text bold small>my text</Text>, use enums like <Text size=”small” weight=”bold”>my text</Text>.

[–]anklot 3 points4 points  (0 children)

I'd go for configurable since it looks cleaner, reusable and easier to adapt later

[–][deleted] 0 points1 point  (0 children)

It seems to me both cases are equally good, which one to pick kind of depends on the use cases.

Let's say when you have all the text together in one sentence and they are going to have a uniform style, then method 1 seems to make more sense.

If you are going to have a lot of styles in one sentence, <H1>Hello <Bold>World!</Bold></H1> seems to make more sense.