0.25.3-1 • Published 2 years ago

@maicol07/mwc-layout-grid v0.25.3-1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

<mwc-layout-grid> Published on npm

Material design’s responsive UI is based on a column-variate grid layout. It has 12 columns on desktop, 8 columns on tablet and 4 columns on phone.

Layout Grid Web Component encapsulates the Layout Grid component.

Installation

npm install @maicol07/mwc-layout-grid

NOTE: The Material Web Components are distributed as ES2017 JavaScript Modules, and use the Custom Elements API. They are compatible with all modern browsers including Chrome, Firefox, Safari, Edge, and IE11, but an additional tooling step is required to resolve bare module specifiers, as well as transpilation and polyfills for Edge and IE11. See here for detailed instructions.

Example Usage

Standard

<mwc-layout-grid>
  <div>Content</div>
  <div>Content</div>
  <div>Content...</div>
</mwc-layout-grid>

Each element inside of mwc-layout-grid will beplaced into a single cell. Default span size for cell is 4 columns.

Custom span size

<mwc-layout-grid>
  <mwc-layout-grid-cell span="2">Content</mwc-layout-grid-cell>
    <div>Content</div>
    <mwc-layout-grid-cell span-tablet="3">Content...</mwc-layout-grid-cell>
</mwc-layout-grid>

Use mwc-layout-grid-cell to define custom value for span size.

Nested grid

When your contents need extra structure that cannot be supported by single layout grid, you can nest layout grid within each other. To nest layout grid, add a new mwc-layout-grid with attribute inner to wrap around nested content.

The nested layout grid behaves exactly like when they are not nested, e.g, they have 12 columns on desktop, 8 columns on tablet and 4 columns on phone. They also use the same gutter size as their parents, but margins are not re-introduced since they are living within another cell.

However, the Material Design guidelines do not recommend having a deeply nested grid as it might mean an over complicated UX.

<mwc-layout-grid>
  <mwc-layout-grid inner>
    <div>Second level</div>
      <div>Second level</div>
  </mwc-layout-grid>
    <div>First level</div>
    <div>First level</div>
</mwc-layout-grid>

API

Slots

NameDescription
defaultComponent will place its children into appropriate slots at runtime.

Properties/Attributes

mwc-layout-grid

NameTypeDefaultDescription
innerbooleanfalseIndicates whetherthis component is inner or outer one.
fixedColumnWidthbooleanfalseYou can designate each column to have a certain width. The column width can be specified through SASS variable$mdc-layout-grid-column-width or CSS custom properties --mdc-layout-grid-column-width-{screen_size}. The column width is set to 72px on all devices by default.
positionstringThe grid is by default center aligned. You can set this attribute toleft or right to change this behavior. Note, these modifiers will have no effect when the grid already fills its container.

mwc-layout-grid-cell

NameTypeDefaultDescription
spannumber*This value is applied to all the devices
span-destopnumber*This value is applied only to desktops
span-tabletnumber*This value is applied only to tablets
span-phonenumber*This value is applied only to phones
ordernumberBy default, items are positioned in the source order. However, you can reorder them by using theorder attributes, where value is an integer between 1 and 12. Please bear in mind that this may have an impact on accessibility, since screen readers and other tools tend to follow source order.
alignstringItems are defined to stretch, by default, taking up the height of their corresponding row. You can switch to a different behavior by using one oftop, middle or bottom.

*You can set the cells span by applying span attribute, where value is an integer between 1 and 12. If the chosen span size is larger than the available number of columns at the current screen size, the cell behaves as if its chosen span size were equal to the available number of columns at that screen size. If the span classes are not set, value will fallback to a default span size of 4 columns.

Methods

None

Events

None

CSS Custom Properties

NameDefaultDescription
--mdc-layout-grid-margin-desktop24pxSpecifies the space between the edge of the grid and the edge of the first cell fordesktop device.
--mdc-layout-grid-gutter-desktop24pxSpecifies the space between edges of adjacent cells fordesktop device.
--mdc-layout-grid-column-width-desktop72pxSpecifies column width fordesktop device.
--mdc-layout-grid-margin-tablet16pxSpecifies the space between the edge of the grid and the edge of the first cell fortablet device.
--mdc-layout-grid-gutter-tablet16pxSpecifies the space between edges of adjacent cells fortablet device.
--mdc-layout-grid-column-width-tablet72pxSpecifies column width fortablet device.
--mdc-layout-grid-margin-phone16pxSpecifies the space between the edge of the grid and the edge of the first cell forphone device.
--mdc-layout-grid-gutter-phone16pxSpecifies the space between edges of adjacent cells forphone device.
--mdc-layout-grid-column-width-phone72pxSpecifies column width forphone device.
--mwc-layout-grid-backgroundnoneSpecifies background of grid.
--mwc-layout-grid-bordernoneSpecifies border of grid.
--mwc-layout-grid-min-heightnoneSpecifies minimal grid height.
--mwc-layout-grid-heightnoneSpecifies grid height.
--mwc-layout-grid-max-heightnoneSpecifies maximum grid height.

Additional references