Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Carbon columns are cumbersome to write out long hand e.g. for web components #17909

Open
1 task done
lee-chase opened this issue Oct 29, 2024 · 1 comment · May be fixed by #18034
Open
1 task done

Comments

@lee-chase
Copy link
Member

The problem

When not using a library or framework that includes a Column component it can be cumbersome and overly verbose to use the Carbon grid.

For example the Carbon tutorial the following for @carbon/react

  <Grid>
    <Column md={4} lg={7} sm={4}>
      7/16
    </Column>
    <Column md={4} lg={{ span: 8, offset: 8 }} sm={4}>
      8/16
    </Column>
  </Grid>

To achieve the same without the grid component requires the following.

<div class="cds--grid">
  <div
    class="cds--css-grid-column cds--sm:col-span-4 cds--md:col-span-4 cds--lg:col-span-7">
    7/16
  </div>
  <div
    class="cds--sm:col-span-4 cds--md:col-span-4 cds--lg:col-start-9 cds--lg:col-span-8 cds--css-grid-column">
    8/16
  </div>
</div>

The solution

The addition of a relatively utility could make this much simpler.

const processDataCols = () => {
  const dataCols = document.querySelectorAll(['data-cols']);
  
  /* for each data col split out sizes, spans and starts then apply Carbon column classes */

  [...dataCols].forEach((dataColEl) => {
    const attr = dataColEl.getAttribute('data-cols');
    const colSizes = attr.split(',');
    colSizes.forEach((colSize) => {
      const [size, value] = colSize.split(' ');
      const parts = value.split['s'];
      const span = parts.pop();
      if (parts.length > 0) {
        const start = parts.pop();
        dataColEl.classList.add(`cds--${size}:col-start-${start}`);
      }
      dataColEl.classList.add(`cds--${size}:col-span-${span}`);
    });
  });
}

Reducing the above html to

<div class="cds--grid">
  <div class="cds--css-grid-column" data-cols="sm 4, md 4, lg 7">
    7/16
  </div>
  <div class="cds--css-grid-column" data-cols="sm 4, md 4, lg 8s9">
    8/16
  </div>
</div>

Examples

No response

Application/PAL

No response

Business priority

None

Available extra resources

No response

Code of Conduct

Copy link
Contributor

Thank you for submitting a feature request. Your proposal is open and will soon be triaged by the Carbon team.

If your proposal is accepted and the Carbon team has bandwidth they will take on the issue, or else request you or other volunteers from the community to work on this issue.

@lee-chase lee-chase linked a pull request Nov 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Triage
Development

Successfully merging a pull request may close this issue.

1 participant