Skip to content

Margin/Padding String shorthand (Idea) #12

@eightyfive

Description

@eightyfive

Just an idea.

I find it easier and more readable to write:

<View margin="20 15 10" />

Writing the shorthand like this is one String.split / Array.map / parseInt away from the original/needed array.

But one drawback is that we loose that use case:

Shorthand Style Result
margin={[20]} {marginVertical: 20}

Writing <View margin="20" /> would end up in margin = [20] but really it should be margin = 20.

There are 2 solutions to this problem:

  1. Pass a number instead of a string when you want "full" margin/padding: <View margin={20} /> and <View margin="20" /> remains margin = [20]
  2. Or always force vertical & horizontal values in shorthand, then <View margin="20" /> becomes the full margin, and if you want vertical only: <View margin="20 0" />

I'm leaning toward solution 2 because it's in line with CSS shorthand syntax. Not to mention that solution 2 would be a clearly separated syntax choice on its own, not overlapping with original Number/Array syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions