Skip to content

Commit b5369e0

Browse files
CopilotChronosSF
andcommitted
Add grid-lite package and create all 13 sample components
Co-authored-by: ChronosSF <2188411+ChronosSF@users.noreply.github.com>
1 parent 57385d5 commit b5369e0

54 files changed

Lines changed: 3614 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"dompurify": "^3.3.0",
2525
"file-saver": "1.3.8",
2626
"igniteui-dockmanager": "^1.17.0",
27+
"igniteui-grid-lite": "^1.0.0-alpha.9",
2728
"igniteui-react": "^19.3.0",
2829
"igniteui-react-charts": "19.3.0-beta.0",
2930
"igniteui-react-core": "19.3.0-beta.0",

browser/src/typedecls.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
declare module JSX {
33
interface IntrinsicElements {
44
"igc-dockmanager": any;
5+
"igc-grid-lite": any;
6+
"igc-avatar": any;
7+
"igc-rating": any;
8+
"igc-checkbox": any;
9+
"igc-select": any;
10+
"igc-select-item": any;
511
}
612
}
713
/* tslint:enable */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.grid-lite-wrapper {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
6+
igc-grid-lite {
7+
min-height: 65vh;
8+
--ig-size: 2;
9+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import { GridLiteDataService, ProductInfo } from './GridLiteDataService';
4+
import './GridLiteColumnConfigBasic.css';
5+
6+
// Import the web component
7+
import { IgcGridLite } from 'igniteui-grid-lite';
8+
import {
9+
defineComponents,
10+
IgcRatingComponent
11+
} from 'igniteui-webcomponents';
12+
13+
import "igniteui-webcomponents/themes/light/bootstrap.css";
14+
15+
// Register components
16+
IgcGridLite.register();
17+
defineComponents(IgcRatingComponent);
18+
19+
export default class Sample extends React.Component<any, any> {
20+
private dataService: GridLiteDataService;
21+
private formatter: Intl.NumberFormat;
22+
private gridRef: React.RefObject<any>;
23+
24+
constructor(props: any) {
25+
super(props);
26+
this.dataService = new GridLiteDataService();
27+
this.formatter = new Intl.NumberFormat('en-EN', {
28+
style: 'currency',
29+
currency: 'EUR'
30+
});
31+
this.gridRef = React.createRef();
32+
}
33+
34+
componentDidMount() {
35+
if (this.gridRef.current) {
36+
const data: ProductInfo[] = this.dataService.generateProducts(50);
37+
38+
const columns = [
39+
{
40+
key: 'name',
41+
headerText: 'Product Name'
42+
},
43+
{
44+
key: 'price',
45+
headerText: 'Price',
46+
type: 'number',
47+
cellTemplate: (params: any) => {
48+
const span = document.createElement('span');
49+
span.textContent = this.formatter.format(params.value);
50+
return span;
51+
}
52+
},
53+
{
54+
key: 'sold',
55+
type: 'number',
56+
headerText: 'Units sold'
57+
},
58+
{
59+
key: 'total',
60+
headerText: 'Total sold',
61+
cellTemplate: (params: any) => {
62+
const span = document.createElement('span');
63+
span.textContent = this.formatter.format(params.value);
64+
return span;
65+
}
66+
},
67+
{
68+
key: 'rating',
69+
type: 'number',
70+
headerText: 'Customer rating',
71+
cellTemplate: (params: any) => {
72+
const rating = document.createElement('igc-rating');
73+
rating.setAttribute('readonly', '');
74+
rating.setAttribute('step', '0.01');
75+
rating.setAttribute('value', params.value.toString());
76+
return rating;
77+
}
78+
}
79+
];
80+
81+
this.gridRef.current.columns = columns;
82+
this.gridRef.current.data = data;
83+
}
84+
}
85+
86+
public render(): JSX.Element {
87+
return (
88+
<div className="container sample ig-typography">
89+
<div className="grid-lite-wrapper">
90+
<igc-grid-lite ref={this.gridRef} id="grid-lite"></igc-grid-lite>
91+
</div>
92+
</div>
93+
);
94+
}
95+
}
96+
97+
// rendering above component in the React DOM
98+
const root = ReactDOM.createRoot(document.getElementById('root'));
99+
root.render(<Sample/>);
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
export type UserSimple = {
2+
id: string;
3+
username: string;
4+
email: string;
5+
subscribed: boolean;
6+
};
7+
8+
export type ProductInfo = {
9+
id: string;
10+
name: string;
11+
price: number;
12+
sold: number;
13+
rating: number;
14+
total: number;
15+
};
16+
17+
export type User = {
18+
id: string;
19+
firstName: string;
20+
lastName: string;
21+
age: number;
22+
email: string;
23+
avatar: string;
24+
active: boolean;
25+
priority: 'Low' | 'Standard' | 'High';
26+
satisfaction: number;
27+
registeredAt: Date;
28+
};
29+
30+
export class GridLiteDataService {
31+
private counter = 0;
32+
33+
private firstNames = ['John', 'Jane', 'Bob', 'Alice', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace', 'Henry',
34+
'Ivy', 'Jack', 'Kate', 'Liam', 'Mia', 'Noah', 'Olivia', 'Peter', 'Quinn', 'Rachel'];
35+
private lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
36+
'Rodriguez', 'Martinez', 'Wilson', 'Anderson', 'Taylor', 'Thomas', 'Moore', 'Jackson', 'White', 'Harris'];
37+
private productNames = ['Widget', 'Gadget', 'Doohickey', 'Thingamajig', 'Gizmo', 'Contraption',
38+
'Device', 'Tool', 'Apparatus', 'Instrument', 'Machine', 'Equipment'];
39+
private priorities: ('Low' | 'Standard' | 'High')[] = ['Low', 'Standard', 'High'];
40+
41+
private randomInt(min: number, max: number): number {
42+
return Math.floor(Math.random() * (max - min + 1)) + min;
43+
}
44+
45+
private randomFloat(min: number, max: number, precision = 2): number {
46+
const array = new Uint32Array(1);
47+
window.crypto.getRandomValues(array);
48+
const random01 = array[0] / 2 ** 32;
49+
return parseFloat((random01 * (max - min) + min).toFixed(precision));
50+
}
51+
52+
private randomElement<T>(array: T[]): T {
53+
return array[this.randomInt(0, array.length - 1)];
54+
}
55+
56+
private randomBoolean(): boolean {
57+
const array = new Uint8Array(1);
58+
window.crypto.getRandomValues(array);
59+
return (array[0] & 1) === 0;
60+
}
61+
62+
private generateId(): string {
63+
return `${Date.now()}-${this.counter++}-${this.randomInt(1000, 9999)}`;
64+
}
65+
66+
createProductInfo(): ProductInfo {
67+
const price = this.randomFloat(50, 500, 2);
68+
const sold = this.randomInt(10, 100);
69+
const total = parseFloat((price * sold).toFixed(2));
70+
71+
return {
72+
price,
73+
sold,
74+
total,
75+
id: this.generateId(),
76+
name: `${this.randomElement(this.productNames)} ${this.randomElement(['Pro', 'Plus', 'Max', 'Ultra', 'Mini', 'Lite'])}`,
77+
rating: this.randomFloat(0, 5, 1)
78+
};
79+
}
80+
81+
createUserSimple(): UserSimple {
82+
const firstName = this.randomElement(this.firstNames);
83+
const lastName = this.randomElement(this.lastNames);
84+
return {
85+
id: this.generateId(),
86+
username: `${firstName.toLowerCase()}.${lastName.toLowerCase()}${this.randomInt(1, 99)}`,
87+
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
88+
subscribed: this.randomBoolean()
89+
};
90+
}
91+
92+
createUser(): User {
93+
const firstName = this.randomElement(this.firstNames);
94+
const lastName = this.randomElement(this.lastNames);
95+
const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`;
96+
97+
return {
98+
id: this.generateId(),
99+
firstName,
100+
lastName,
101+
age: this.randomInt(18, 90),
102+
email,
103+
avatar: `https://i.pravatar.cc/150?img=${this.randomInt(1, 70)}`,
104+
active: this.randomBoolean(),
105+
priority: this.randomElement(this.priorities),
106+
satisfaction: this.randomInt(0, 5),
107+
registeredAt: new Date(Date.now() - this.randomInt(0, 365 * 24 * 60 * 60 * 1000))
108+
};
109+
}
110+
111+
generateUsers(count: number): User[] {
112+
return Array.from({ length: count }, () => this.createUser());
113+
}
114+
115+
generateProducts(count: number): ProductInfo[] {
116+
return Array.from({ length: count }, () => this.createProductInfo());
117+
}
118+
119+
generateSimpleUsers(count: number): UserSimple[] {
120+
return Array.from({ length: count }, () => this.createUserSimple());
121+
}
122+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './GridLiteColumnConfigBasic';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#panel {
2+
margin: 1rem 0;
3+
display: flex;
4+
flex-flow: row nowrap;
5+
justify-content: space-between;
6+
align-items: center;
7+
}
8+
9+
.config-key {
10+
flex: 2 1 25% !important;
11+
font-weight: bold;
12+
}
13+
14+
.config {
15+
display: flex;
16+
flex-flow: row nowrap;
17+
justify-content: space-evenly;
18+
align-items: center;
19+
gap: 0.75rem;
20+
}
21+
22+
.config * {
23+
flex: 1;
24+
}
25+
26+
igc-dropdown-item {
27+
padding: 0.5rem 1rem;
28+
}
29+
30+
.grid-lite-wrapper {
31+
width: 100%;
32+
height: 100%;
33+
}
34+
35+
igc-grid-lite {
36+
min-height: 65vh;
37+
--ig-size: 2;
38+
}

0 commit comments

Comments
 (0)