-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid-list): Implement mdc-grid-list (#47)
- Loading branch information
1 parent
bfac404
commit d5a199c
Showing
12 changed files
with
1,133 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# MDC Toolbar | ||
|
||
MDC Toolbar provides a RTL-aware Material Design toolbar component adhering to the | ||
[Material Design toolbar spec](https://www.google.com/design/spec/components/toolbars.html) | ||
Toolbars scroll with content by default, but supports fixed on | ||
top as well. Currently, this component does not yet support the "Waterfall" or | ||
"Flexible Header" patterns. | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
npm install --save @material/toolbar | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
Wrap the items with `mdc-toolbar` class in following way: | ||
|
||
```html | ||
<header class="mdc-toolbar"> | ||
<section class="mdc-toolbar__section mdc-toolbar__section--align-start"> | ||
<a class="material-icons">menu</a> | ||
<span class="mdc-toolbar__title">Title</span> | ||
</section> | ||
</header> | ||
``` | ||
|
||
### Fixed toolbars | ||
|
||
By default, toolbars scroll with the page content. To keep the toolbar fixed to | ||
the top of the screen, add an `mdc-toolbar--fixed` class to the toolbar element. | ||
|
||
**Adjusting sibling elements of fixed toolbars** | ||
|
||
When using `mdc-toolbar--fixed`, you can add the `mdc-toolbar-fixed-adjust` | ||
helper class to the toolbar's adjacent sibling element, which will ensure that | ||
the sibling element's top margin will be large enough such that the fixed | ||
toolbar will not overlay any of the element's content. | ||
|
||
```html | ||
<header class="mdc-toolbar mdc-toolbar--fixed"> | ||
<section class="mdc-toolbar__section mdc-toolbar__section--align-start"> | ||
<span class="mdc-toolbar__title">Title</span> | ||
</section> | ||
</header> | ||
<main class="mdc-toolbar-fixed-adjust"> | ||
<p class="demo-paragraph"> | ||
A demo paragraph here. | ||
</p> | ||
</main> | ||
``` | ||
|
||
### Sections | ||
|
||
Toolbar sections are aligned to the toolbar's center. You can change this | ||
behavior by applying `mdc-toolbar__section--align-start` or | ||
`mdc-toolbar__section--align-end` to align the sections to the start or the end | ||
of the toolbar (respectively). | ||
|
||
```html | ||
<header class="mdc-toolbar"> | ||
<section class="mdc-toolbar__section mdc-toolbar__section--align-start"> | ||
Section aligns to start. | ||
</section> | ||
<section class="mdc-toolbar__section"> | ||
Section aligns to center. | ||
</section> | ||
<section class="mdc-toolbar__section mdc-toolbar__section--align-end"> | ||
Section aligns to end. | ||
</section> | ||
</header> | ||
``` | ||
|
||
Toolbar sections are laid out using flexbox. Each section will take up an equal | ||
amount of space within the toolbar. | ||
|
||
### Toolbar title | ||
|
||
You can use the `mdc-toolbar__title` element to style toolbar text representing | ||
a page's title, or an application name. | ||
|
||
```html | ||
<header class="mdc-toolbar"> | ||
<section class="mdc-toolbar__section"> | ||
<span class="mdc-toolbar__title">Title</span> | ||
</section> | ||
</header> | ||
``` | ||
|
||
### RTL Support | ||
|
||
`mdc-toolbar` is automatically RTL-aware, and will re-position elements whenever | ||
it, or its ancestors, has a `dir="rtl"` attribute. | ||
|
||
|
||
## Classes | ||
|
||
### Block | ||
|
||
The block class is `mdc-toolbar`. This defines the top-level toolbar element. | ||
|
||
### Element | ||
The component has `mdc-toolbar__section` and `mdc-toolbar__title` elements. You | ||
can add multiple sections to toolbar. Refer to Sections and Toolbar title for | ||
further details. | ||
|
||
### Modifier | ||
|
||
The provided modifiers are: | ||
|
||
| Class | Description | | ||
| -------------------------------------| --------------------------------------- | | ||
| `mdc-toolbar--fixed` | Make toolbar fixed to top of screen. | | ||
| `mdc-toolbar__section--align-start` | Makes section aligns to the start. | | ||
| `mdc-toolbar__section--align-end` | Makes section aligns to the end. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export const strings = { | ||
TILES_SELECTOR: '.mdc-grid-list__tiles', | ||
TILE_SELECTOR: '.mdc-grid-tile', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {MDCFoundation} from '@material/base'; | ||
import {strings} from './constants'; | ||
|
||
export default class MDCGridListFoundation extends MDCFoundation { | ||
static get strings() { | ||
return strings; | ||
} | ||
|
||
static get defaultAdapter() { | ||
return { | ||
getOffsetWidth: () => /* number */ 0, | ||
getTileOffsetWidthAtIndex: (/* index: number | null */) => /* number */ 0, | ||
setTilesWidth: (/* value: number | null */) => {}, | ||
registerInteractionHandler: (/* type: string, handler: EventListener */) => {}, | ||
deregisterInteractionHandler: (/* type: string, handler: EventListener */) => {}, | ||
}; | ||
} | ||
constructor(adapter) { | ||
super(Object.assign(MDCGridListFoundation.defaultAdapter, adapter)); | ||
this.resizeHandler_ = () => this.alignCenter(); | ||
} | ||
init() { | ||
this.alignCenter(); | ||
this.adapter_.registerInteractionHandler('resize', this.resizeHandler_); | ||
} | ||
destroy() { | ||
this.adapter_.deregisterInteractionHandler('resize', this.resizeHandler_); | ||
} | ||
alignCenter() { | ||
const gridWidth = this.adapter_.getOffsetWidth(); | ||
const itemWidth = this.adapter_.getTileOffsetWidthAtIndex(0); | ||
this.adapter_.setTilesWidth(itemWidth * Math.floor(gridWidth / itemWidth)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {MDCComponent} from '@material/base'; | ||
|
||
import MDCGridListFoundation from './foundation'; | ||
|
||
export {MDCGridListFoundation}; | ||
|
||
export class MDCGridList extends MDCComponent { | ||
static attachTo(root) { | ||
return new MDCGridList(root); | ||
} | ||
|
||
getDefaultFoundation() { | ||
return new MDCGridListFoundation({ | ||
getOffsetWidth: () => this.root_.offsetWidth, | ||
getTileOffsetWidthAtIndex: (index) => { | ||
this.root_.querySelectorAll(MDCGridListFoundation.strings.TILE_SELECTOR)[index].offsetWidth; | ||
}, | ||
setTilesWidth: (value) => { | ||
this.root_.querySelector(MDCGridListFoundation.strings.TILES_SELECTOR).style.width = value; | ||
}, | ||
registerInteractionHandler: (type, handler) => this.root_.addEventListener(type, handler), | ||
deregisterInteractionHandler: (type, handler) => this.root_.removeEventListener(type, handler), | ||
}); | ||
} | ||
} |
Oops, something went wrong.