question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider Size component

See original GitHub issue

I’m wondering if there should be a Size component, whose explicit role is to let us size items consistently without using webContainerSx. I made something like it in my app, and I’m wondering if it should be included in Dripsy directly.

Examples

For flex columns:

import { Size } from 'dripsy'

<Row>
  <Size flex={[null, 1]}>
    <Column />
  </Size>
  <Size flex={[null, 1]}>
    <Column />
  </Size>
</Row>

For widths:

<Size width={['50%', '33%']} />

Why

At the moment, the same thing is achieved by passing a webContainerSx prop. It’s a bit cumersome and repetitive. I think it’s a nice escape hatch prop to have, but for sizing, it makes more sense to have a specific solution.

Since the entire sx prop would not be supported, style props would be inlined on the Size component.

Code

On native, it would export a View from dripsy, like normal (with added props.) Nothing special happening on native.

size.tsx

import View from './view'

type SizeProps = Pick<SxStyleProp, 'flex' | 'width' | ...etc>

const Size = (props: SizeProps) => {
  return <View sx={props} />
}

On web, however, we can render a native div, and use sx with the JSX pragma from theme-ui.

size.web.tsx

/** @jsx jsx */
import { jsx } from 'theme-ui'

const RNWStyleReset = {...}

const Size = (props: SizeProps) => {
  return <div sx={{ ...RNWStyleReset, ...props }} />
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nandorojocommented, May 18, 2021

While I’m using this my app, I’m still not sure if I’m convinced by it. I think getting rid of SSR (and thus fresnel) would be a better idea than entirely circumventing RNW altogether 😕

0reactions
nandorojocommented, May 18, 2021

Yeah, that’s true. Although I would recommend returning null (or a placeholder) and then rendering the app after it’s mounted if you ever plan on using responsive styles. I’ll probably do this with an ssr prop on the provider.

Ultimately, we’re dealing with constraints of RNW.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to determine the size of a component in ReactJS
The size of a component is determined by the height and width of the container. It can be determined if we assign a...
Read more >
Size in Design Systems. Tuning Type & Space With an Eye on…
This article describes how consider density using component size and height. Next, it describes how to unify size across components ...
Read more >
How to get a react component's size (height/width) before ...
Show activity on this post. A React hook that measure an element's size and handle responsive components with highly-performant way, using ResizeObserver. It's ......
Read more >
Determining the dimensions of elements - Web APIs | MDN
If you need to know the actual size of the content, regardless of how much of it is currently visible, you need to...
Read more >
Size Classes and Core Components - WWDC17 - Videos
Designing for multiple screen sizes can seem complicated, difficult, and time-consuming. Learn how size classes, dynamic type, and UIKit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found