0.12.1 • Published 4 years ago

material-web-components-layout-grid v0.12.1

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

<mwc-layout-grid> Published on npm

IMPORTANT: This is just a humble implementation of the MDC Layout Grid for Material Compenents Web Components AKA MWC. It's based off of the 0.12 release.

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 Layout Grid component.

Installation

npm install material-web-components-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>
  <div>Content...</div>
</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 whether this component is inner or outer one.
fixedColumnWidthbooleanfalseYou can designate each column to have a certain width. The column width can be specified through sass map $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 values left 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
spanobjectYou 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. It is also possible to set span value for a specific type of device (desktop, tablet or phone). In that case value must be specified as an object in the JSON form with attribute names corresponding to device type, e.g. {"desktop":"12", "tablet":"8", "phone":"4"}.
ordernumberBy default, items are positioned in the source order. However, you can reorder them by using the order 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 of top, middle or bottom.

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 for desktop device.
--mdc-layout-grid-gutter-desktop24pxSpecifies the space between edges of adjacent cells for desktop device.
--mdc-layout-grid-column-width-desktop72pxSpecifies column width for desktop device.
--mdc-layout-grid-margin-tablet16pxSpecifies the space between the edge of the grid and the edge of the first cell for tablet device.
--mdc-layout-grid-gutter-tablet16pxSpecifies the space between edges of adjacent cells for tablet device.
--mdc-layout-grid-column-width-tablet72pxSpecifies column width for tablet device.
--mdc-layout-grid-margin-phone16pxSpecifies the space between the edge of the grid and the edge of the first cell for phone device.
--mdc-layout-grid-gutter-phone16pxSpecifies the space between edges of adjacent cells for phone device.
--mdc-layout-grid-column-width-phone72pxSpecifies column width for phone 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

0.12.1

4 years ago

0.12.0

4 years ago