Files
gerrit/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.html
Becky Siegel 5444bad21a Introduce gr-dropdown-list element
This element will replace some existing gr-select (beginning with the
patch range selector) and most likely the file dropdown in
gr-diff-view.

On wider/desktop screens, a custom dropdown appears, and on
smaller/mobile devices, a native select appears. This element handles
determining which to display and when.

This element requires an array of 'items'.
Items must contain a value and text. They can also include the
following:
- bottomText: (a second, more subtle row of text)
- date: (a date to get displayed/formatted on the top row/right side)
- triggerText: The text to display on the dropdown trigger when
  the particular option is selected.
- mobileText: the text to use as the option text on mobile devices.

When mobileText or triggerText are not set, they fall back to text.

Change-Id: Ie8842d8833a1ecf7c260b88c389d3f3a4f93944b
2017-09-22 13:12:19 -07:00

175 lines
4.9 KiB
HTML

<!--
Copyright (C) 2017 The Android Open Source Project
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.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-dropdown/iron-dropdown.html">
<link rel="import" href="../../../bower_components/paper-item/paper-item.html">
<link rel="import" href="../../../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
<link rel="import" href="../../shared/gr-select/gr-select.html">
<dom-module id="gr-dropdown-list">
<template>
<style include="shared-styles">
:host {
display: inline-block;
}
#trigger {
-moz-user-select: text;
-ms-user-select: text;
-webkit-user-select: text;
user-select: text;
}
.downArrow {
display: inline-block;
font-size: .6em;
user-select: none;
vertical-align: middle;
}
.dropdown-trigger {
cursor: pointer;
padding: 0;
}
.dropdown-content {
background-color: #fff;
box-shadow: 0 1px 5px rgba(0, 0, 0, .3);
max-height: 70vh;
margin-top: 1.5em;
width: 266px;
}
paper-listbox {
--paper-listbox: {
padding: 0;
}
}
paper-item {
cursor: pointer;
flex-direction: column;
--paper-item: {
min-height: 0;
padding: 10px 16px;
}
--paper-item-selected: {
background-color: rgba(161,194,250,.12);
}
--paper-item-focused-before: {
background-color: #f2f2f2;
}
--paper-item-focused: {
background-color: #f2f2f2;
}
}
paper-item:not(:last-of-type) {
border-bottom: 1px solid #ddd;
}
gr-button {
color: black;
font: inherit;
padding: .3em 0;
text-decoration: none;
}
.bottomContent {
color: rgba(0,0,0,.54);
font-size: .85em;
line-height: 16px;
}
.bottomContent,
.topContent {
display: flex;
line-height: 16px;
justify-content: space-between;
flex-direction: row;
width: 100%;
}
gr-date-formatter {
color: rgba(0,0,0,.54);
margin-left: 2em;
}
gr-select {
display: none;
}
@media only screen and (max-width: 50em) {
gr-select {
display: inline;
}
gr-button,
iron-dropdown {
display: none;
}
select {
max-width: 5.25em;
}
}
</style>
<gr-button
link
id="trigger"
class="dropdown-trigger"
on-tap="_showDropdownTapHandler">
<span>[[text]]</span>
<span
class="downArrow"
on-tap="_showDropdownTapHandler">&#9660;</span>
</gr-button>
<iron-dropdown
id="dropdown"
vertical-align="top"
allow-outside-scroll="true">
<paper-listbox
class="dropdown-content"
slot="dropdown-content"
attr-for-selected="value"
on-tap="_handleDropdownTap"
selected="{{value}}">
<template is="dom-repeat" items="[[items]]">
<paper-item
disabled="[[item.disabled]]"
value="[[item.value]]">
<div class="topContent">
<div>[[item.text]]</div>
<template is="dom-if" if="[[item.date]]">
<gr-date-formatter
date-str="[[item.date]]"></gr-date-formatter>
</template>
</div>
<template is="dom-if" if="[[item.bottomText]]">
<div class="bottomContent">
<div>[[item.bottomText]]</div>
</div>
</template>
</paper-item>
</template>
</paper-listbox>
</iron-dropdown>
<gr-select bind-value="{{value}}">
<select>
<template is="dom-repeat" items="[[items]]">
<option
disabled$="[[item.disabled]]"
value="[[item.value]]">
[[_computeMobileText(item)]]
</option>
</template>
</select>
</gr-select>
</template>
<script src="gr-dropdown-list.js"></script>
</dom-module>