• 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
17import {
18  ColumnDescriptor,
19  numberColumn,
20  stringColumn,
21  Table,
22  TableData,
23} from './table';
24
25// This file serves as an example of a table component present in the widgets
26// showcase. Since table is somewhat complicated component that requires some
27// setup spread across several declarations, all the necessary code resides in a
28// separate file (this one) and provides a no-argument wrapper component that
29// can be used in the widgets showcase directly.
30
31interface ProgrammingLanguage {
32  id: number;
33  name: string;
34  year: number;
35}
36
37const languagesList: ProgrammingLanguage[] = [
38  {
39    id: 1,
40    name: 'TypeScript',
41    year: 2012,
42  },
43  {
44    id: 2,
45    name: 'JavaScript',
46    year: 1995,
47  },
48  {
49    id: 3,
50    name: 'Lean',
51    year: 2013,
52  },
53];
54
55const columns: ColumnDescriptor<ProgrammingLanguage>[] = [
56  numberColumn('ID', (x) => x.id),
57  stringColumn('Name', (x) => x.name),
58  numberColumn('Year', (x) => x.year),
59];
60
61export class TableShowcase implements m.ClassComponent {
62  data = new TableData(languagesList);
63
64  view(): m.Child {
65    return m(Table, {
66      data: this.data,
67      columns,
68    });
69  }
70}
71