• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import m from 'mithril';
16
17export interface EmptyStateAttrs {
18  // Which material icon to show.
19  // Defaults to 'search'.
20  icon?: string;
21  // Some text to show under the icon. No text shown if omitted.
22  header?: string;
23}
24
25// Something to show when there's nothing else to show!
26// Features a large icon, followed by some text explaining what went wrong, and
27// some optional content passed as children elements, usually containing common
28// actions for things you might want to do next (e.g. clear a search box).
29export class EmptyState implements m.ClassComponent<EmptyStateAttrs> {
30  view({attrs, children}: m.Vnode<EmptyStateAttrs, this>): void|m.Children {
31    const {
32      icon = 'search',  // Icon defaults to the search symbol
33      header,
34    } = attrs;
35    return m(
36        '.pf-empty-state',
37        m('i.material-icons', icon),
38        header && m('span.pf-empty-state-header', header),
39        m('div.pf-empty-state-content', children),
40    );
41  }
42}
43