xref: /aosp_15_r20/external/perfetto/ui/src/widgets/empty_state.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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
22  // Some text to show under the icon. No text shown if omitted.
23  title?: string;
24
25  // Additional class name applied to our container.
26  className?: string;
27}
28
29// Something to show when there's nothing else to show!
30// Features a large icon, followed by some text explaining what went wrong, and
31// some optional content passed as children elements, usually containing common
32// actions for things you might want to do next (e.g. clear a search box).
33export class EmptyState implements m.ClassComponent<EmptyStateAttrs> {
34  view({attrs, children}: m.Vnode<EmptyStateAttrs, this>): void | m.Children {
35    const {
36      icon = 'search', // Icon defaults to the search symbol
37      title,
38      className,
39    } = attrs;
40    return m(
41      '.pf-empty-state',
42      {className},
43      m('i.material-icons', icon),
44      title && m('.pf-empty-state-title', title),
45      m('.pf-empty-state-content', children),
46    );
47  }
48}
49