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.

Namespace collision between grid areas components and custom component

See original GitHub issue

What:

When using render prop of Composition component it generates areas components based on grid-template-areas. This often leads to semantic namespaces collision with corresponding custom React components:

import { Composition } from 'atomic-layout'
import Header from './components/Header'

const Page = () => (
  <Composition areas="header footer">
    {({ Header }) => (
      <>
        <Header><Header /></Header> // oops, collision!
      </>
    )}
  </Composition>
)

Why:

  • It decreases the DX with the library
  • Grid areas often reflect semantics of a layout, just as actual component’s names
  • Polymorphic prop doesn’t help, as area component’s name already exists in scope in order to use polymorphic prop

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kettanaitocommented, Apr 22, 2019

Proposal: Area generic component

Atomic layout can expose a generic Area component that would act as a single domain for rendering and mapping components to grid areas.

Spec

  • Area component accepts all prop aliases as the Box component
  • Area component supports as: JSX.Element polymorphic prop.
  • Area component supports name: string prop that produces grid-area ${props.name} mapping to CSS Grid areas
  • (?) Component performs diff between responsive values of the areas props, wrapping conditional areas into <MediaQuery/> wrapper (as render prop functionality does now)

Usage

import { Area, Composition } from 'atomic-layout'
import { Header, Footer } from './components'

const Page = () => (
  <Composition areas="header footer">
    <Area name="header" as={Header} />
    <Area name="footer" as={Footer} />
  </Composition>
)

This also means that the value of name prop can be dynamic, switching the content of the area, without changing the area position. This can come in handy when combined with #132:

import { useResponsiveValue, Composition, Area } from 'atomic-layout'
import { Header } from './components'

const Page = () => {
  const areaName = useResponsiveValue({ lg: 'right' }, 'left')
  
  return (
    <Composition areas="left right">
      <Area name={areaName} as={Header} />
    </Composition>
  )
}
1reaction
MioQuispecommented, Jun 14, 2019

Proposal: Dedicated default area

Composition component exposes a hard-coded default area in the render prop. That area component can be used to render other template areas parametrically without explicitly rendering their respective components.

Usage

const { Composition } from 'atomic-layout'
import Logo from './logo.svg'

const Header = () => (
  <Composition areas="logo menu actions">
    {({ Area, Menu }) => (
      <>
        {/* Renders "logo" area parametrically */}
        <Area name="logo" marginRight={10}>
          {/* Well, looks like no namespace collision */}
          <Logo />
        </Area>

        {/* Renders "menu" area as usual */}
        <Menu>{...}</Menu>

        <Area name="actions">{...}</Area>
      </>
    )}
  </Composition>
)

Area name is a suggestion. It can be Render, or anything else.

Benefits

  • No namespace collision between custom namespaces and areas components.
  • Retaining Composition context, as the default Area component is exposed and rendered within the respective parent Composition component.

Drawbacks

  • The namespace of a default generic Area component is always taken, meaning you cannot have your custom area named areas="area".
  • Area namespace may also overlap with other custom namespaces, however this chance is rather small and would be an edge case

How about <Area.Logo></Area.Logo> typescript autocomplete potential?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to collision - Unity - Manual
Static colliders. You can add colliders to a GameObject without a Rigidbody component to create floors, walls and other motionless elements of a...
Read more >
Web Components - MDN Web Docs - Mozilla
A guide showing how to use the features of custom elements to create simple web components, as well as looking into lifecycle callbacks...
Read more >
ASP.NET Core Razor components - Microsoft Learn
Paths indicate typical folder locations. For example, Pages/ProductDetail.razor indicates that the ProductDetail component has a file name of ...
Read more >
Guide to the MUI grid system - LogRocket Blog
A grid system defines a set of measurements to place elements or components on the page based on successive columns and rows. The...
Read more >
Custom Component Builder - ServiceNow Docs
The Next Experience Design System comes with a set of customizable components that you can drag into your custom UI. Develop your own...
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