summaryrefslogtreecommitdiffstats
path: root/toolkit/content/widgets/panel-list/panel-list.stories.mjs
blob: db0ab7597c0a05f10378f4aef47aeadc8c9b8d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// eslint-disable-next-line import/no-unassigned-import
import "./panel-list.js";
import { html, ifDefined } from "../vendor/lit.all.mjs";

export default {
  title: "UI Widgets/Panel List",
  component: "panel-list",
  parameters: {
    status: "in-development",
    actions: {
      handles: ["showing", "shown", "hidden", "click"],
    },
    fluent: `
panel-list-item-one = Item One
panel-list-item-two = Item Two (accesskey w)
panel-list-item-three = Item Three
panel-list-checked = Checked
panel-list-badged = Badged, look at me
panel-list-passwords = Passwords
panel-list-settings = Settings
submenu-item-one = Submenu Item One
submenu-item-two = Submenu Item Two
submenu-item-three = Submenu Item Three
    `,
  },
};

function openMenu(event) {
  if (
    event.type == "mousedown" ||
    event.inputSource == MouseEvent.MOZ_SOURCE_KEYBOARD ||
    !event.detail
  ) {
    event.target.getRootNode().querySelector("panel-list").toggle(event);
  }
}

const Template = ({ isOpen, items, wideAnchor, hasSubMenu }) =>
  html`
    <style>
      panel-item[icon="passwords"]::part(button) {
        background-image: url("chrome://browser/skin/login.svg");
      }
      panel-item[icon="settings"]::part(button) {
        background-image: url("chrome://global/skin/icons/settings.svg");
      }
      button {
        position: absolute;
        background-image: url("chrome://global/skin/icons/more.svg");
      }
      button[wide] {
        width: 400px !important;
      }
      .end {
        inset-inline-end: 30px;
      }

      .bottom {
        inset-block-end: 30px;
      }
    </style>
    ${isOpen
      ? ""
      : html`
          <button
            class="ghost-button icon-button"
            @click=${openMenu}
            @mousedown=${openMenu}
            ?wide="${wideAnchor}"
          ></button>
          <button
            class="ghost-button icon-button end"
            @click=${openMenu}
            @mousedown=${openMenu}
            ?wide="${wideAnchor}"
          ></button>
          <button
            class="ghost-button icon-button bottom"
            @click=${openMenu}
            @mousedown=${openMenu}
            ?wide="${wideAnchor}"
          ></button>
          <button
            class="ghost-button icon-button bottom end"
            @click=${openMenu}
            @mousedown=${openMenu}
            ?wide="${wideAnchor}"
          ></button>
        `}
    <panel-list
      ?stay-open=${isOpen}
      ?open=${isOpen}
      ?min-width-from-anchor=${wideAnchor}
    >
      ${items.map((item, index) => {
        // Always showing submenu on the first item for simplicity.
        let showSubMenu = hasSubMenu && index == 0;
        let subMenuId = showSubMenu ? "example-sub-menu" : undefined;
        return item == "<hr>"
          ? html` <hr /> `
          : html`
              <panel-item
                icon=${item.icon ?? ""}
                ?checked=${item.checked}
                ?badged=${item.badged}
                accesskey=${ifDefined(item.accesskey)}
                data-l10n-id=${item.l10nId ?? item}
                submenu=${ifDefined(subMenuId)}
              >
                ${showSubMenu ? subMenuTemplate() : ""}
              </panel-item>
            `;
      })}
    </panel-list>
  `;

const subMenuTemplate = () => html`
  <panel-list slot="submenu" id="example-sub-menu">
    <panel-item data-l10n-id="submenu-item-one"></panel-item>
    <panel-item data-l10n-id="submenu-item-two"></panel-item>
    <panel-item data-l10n-id="submenu-item-three"></panel-item>
  </panel-list>
`;

export const Simple = Template.bind({});
Simple.args = {
  isOpen: false,
  wideAnchor: false,
  items: [
    "panel-list-item-one",
    { l10nId: "panel-list-item-two", accesskey: "w" },
    "panel-list-item-three",
    "<hr>",
    { l10nId: "panel-list-checked", checked: true },
    { l10nId: "panel-list-badged", badged: true, icon: "settings" },
  ],
};

export const Icons = Template.bind({});
Icons.args = {
  isOpen: false,
  wideAnchor: false,
  items: [
    { l10nId: "panel-list-passwords", icon: "passwords" },
    { l10nId: "panel-list-settings", icon: "settings" },
  ],
};

export const Open = Template.bind({});
Open.args = {
  ...Simple.args,
  wideAnchor: false,
  isOpen: true,
};

export const Wide = Template.bind({});
Wide.args = {
  ...Simple.args,
  wideAnchor: true,
};

export const SubMenu = Template.bind({});
SubMenu.args = {
  ...Simple.args,
  hasSubMenu: true,
};