0.1.6 • Published 2 years ago

@salesforce-ux/c360-grid v0.1.6

Weekly downloads
-
License
See LICENSE.txt
Repository
-
Last release
2 years ago

@salesforce-ux/c360-grid

npm (custom registry)

About

The C360 grid system provides a flexible, mobile-first, device-agnostic layout system. It has features to control alignment, flow, and gaps.

Getting Started

Let's start by installing c360-grid as a dependency of your project with npm.

npm i @salesforce-ux/c360-grid

Distributable

After installation, all the distributables for the C360 Grid are found under @salesforce-ux/c360-grid/dist/ folder. |File Name |Description | |- |- | |index.css | The Compiled CSS file for c360-grid package|

c360-grid Integration

There are different ways to include c360-grid to a web application depending on the requirement.It can be used in both light DOM and shadow DOM Below are the styles to include the package -

Add C360 Grid in HTML

You can use the HTML <link> to link to C360 Grid as an external resource.

<html>
  <head>
    <!-- Dependencies go here -->
    <link rel="stylesheet" href="...">
    
    <link rel="stylesheet" href="/node_modules/@salesforce-ux/c360-grid/dist/index.css">
    <!-- Your application's stylesheets go below -->
    <link rel="stylesheet" href="...">
  </head>
  <body>
    <!-- Your application -->
  </body>
</html>

Add C360 Grid in CSS

You can use CSS @imports to pull in C360 Grid.

@import "@salesforce-ux/c360-grid/dist/index.css";

Add C360 Grid in JS

You can use JS import to pull in C360 Grid directly in the JS file.

import "@salesforce-ux/c360-grid/dist/index.css";

Example

Below are a few examples of grid layout which is part of c360-grid.

<div grid axis="row">...</div>
<div grid>
  <div>Grid item</div>
  <div>Grid item</div>
</div>

Interactive Demo

To see more examples with interactive demo, please visit c360 Subsytem's Storybook Environment

API

The C360 grid features a mobile-first, responsive layout system; built on flexbox.

Table of Contents

Initialize a grid container

To initialize a grid container, set the grid attribute to your element.

<div grid>...</div>

Define the grid axis

By default, a grid flows left-to-right on a horizontal or x-axis. This behavior can be changed to flow right-to-left, top-to-bottom, and bottom-to-top.

Left to right

<div grid axis="row">...</div>

Right to left

<div grid axis="row-reverse">...</div>

Top to bottom

<div grid axis="vertical">...</div>

Bottom to top

<div grid axis="vertical-reverse">...</div>

Grid items

A grid container will have 1 or more grid items to make up your layout. The direct descendants of a grid container are considered grid items. By being a grid item, you can modify its attributes independently or by the container.

<div grid>
  <div>Grid item</div>
  <div>Grid item</div>
</div>

A grid container is required to change the attributes of a grid item.

Defining widths

A benefit of using flexbox for your layout is things will automatically adjust inflow based on its flex properties and the size of its children's content.

There are times (most the time) when you want to explicitly define a width on a grid item. You can accomplish this by adding a size attribute and a value to determines its width.

<div grid>
  <div size="1:2">item</div>
  <!-- 50% -->
  <div size="1:2">item</div>
  <!-- 50% -->
</div>

The size attribute accepts a range of human-friendly values, you may choose to use 6:12 or 1:2, both outcomes are 50%. The second value should be based off the number of grid columns you have set for your parent container.

Available Widths

SizeValue
autoauto
1:1100%
1:250%
1:333.333%
2:366.667%
1:425%
2:450%
3:475%
1:520%
2:540%
3:560%
4:580%
1:616.667%
2:633.333%
3:650%
4:666.667%
5:683.333%
1:714.28%
2:728.57%
3:742.85%
4:757.14%
5:771.42%
6:785.71%
1:812.5%
2:825%
3:837.5%
4:850%
5:862.5%
6:875%
7:887.5%
1:128.333%
2:1216.667%
3:1225%
4:1233.333%
5:1241.667%
6:1250%
7:1258.333%
8:1266.667%
9:1275%
10:1283.333%
11:1291.667%

Implementation Note

Be sure to stick within the available widths based on the grid columns you choose to use. For example, if you have established a 12 column grid, the grid items that are direct descendants should refer to the size associated to 12.

Good

<!-- 12 column grid -->
<div grid>
  <div size="8:12"></div>
  <div size="4:12"></div>
</div>

Bad

<!-- unknown column grid -->
<div grid>
  <div size="2:3"></div>
  <div size="4:12"></div>
</div>

Responsive widths

Additionally, you can easily modify the width of an item at a defined breakpoint depending on the width of the viewport.

This can be done by appending @ then the breakpoint definition of x-small, small, medium, large, or x-large. For example, 1:2@medium would cause the grid item to take up 50% of its available width when the browsers viewport is larger than 768px.

Breakpoints

T-shirt size nameBreakpoint width
x-small320px
small480px
medium768px
large1024px
x-large1280px

Add gaps between grid items

To add space between your grid items, you can add a gap attribute to your grid container. The gap attribute takes a t-shirt size name:

Implementation Note

For a child grid item to pick up the gap size set on the parent, the element is required to have a size attribute set. If you don't need an explicit width, i.e., 50%, you can add size="auto".

Gap Sizes

T-shirt size nameValue
xxx-small2px
xx-small4px
x-small8px
small12px
medium16px
large24px
x-large32px
xx-large48px

Force multiple rows

When setting widths to your grid items, once a row of items exceed a total width of 100% you can force them to wrap to multiple rows by adding flow="wrap" to your grid container.

By default, the grid items will not wrap.

<div grid flow="wrap">
  <!-- Row 1 - 66.667% | 33.333% -->
  <div size="8:12"></div>
  <div size="4:12"></div>
  <!-- Row 2 - 50% | 50% -->
  <div size="6:12"></div>
  <div size="6:12"></div>
</div>

Defining grid container alignment

Since the grids are built on flexbox, they allow us to do some interesting things with alignment on both a horizontal axis and vertical axis. You can add an alignment value to the grid attribute.

Start of axis

<div grid="align-start">...</div>
|-----------------|
|[ ][ ][ ]        |
|-----------------|

Center of axis

<div grid="align-center">...</div>
|-----------------|
|    [ ][ ][ ]    |
|-----------------|

End of axis

<div grid="align-end">...</div>
|-----------------|
|        [ ][ ][ ]|
|-----------------|

Evenly spaced along axis

<div grid="align-spread">...</div>
|-----------------|
|[ ]    [ ]    [ ]|
|-----------------|

Equally spaced along axis

<div grid="align-space">...</div>
|-----------------|
|  [ ]  [ ]  [ ]  |
|-----------------|

Vertical alignment

Implementation Note

To vertically align elements on a cross-axis of a grid container, the elements need available vertical white space. This is usually achieved by having a height applied to the grid container.

Start of vertical axis

<div grid="align-space" axis="vertical">...</div>
|-----------------|
|  [ ]  [ ]  [ ]  |
|                 |
|                 |
|-----------------|

Center of vertical axis

<div grid="align-center" axis="vertical">...</div>
|-----------------|
|                 |
|  [ ]  [ ]  [ ]  |
|                 |
|-----------------|

End of vertical axis

<div grid="align-end" axis="vertical">...</div>
|-----------------|
|                 |
|                 |
|  [ ]  [ ]  [ ]  |
|-----------------|

Defining grid item alignment

Implementation Note

To vertically align elements on a cross-axis of a grid container, the elements need available vertical white space. This is usually achieved by having a height applied to the grid container.

To specify the vertical placement of grid items on the cross axis, add the value of align-start, align-center, and align-end to the grid-item attribute.

<div grid>
  <div grid-item="align-start"></div>
  <div grid-item="align-center"></div>
  <div grid-item="align-end"></div>
</div>
|-----------------|
|[ ]              |
|       [ ]       |
|              [ ]|
|-----------------|
0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago