Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom state persistence samples. #583

Merged
merged 10 commits into from
Dec 12, 2023
11 changes: 11 additions & 0 deletions samples/grids/grid/state-persistence-about/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 250,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"fluid": false
}
51 changes: 51 additions & 0 deletions samples/grids/grid/state-persistence-about/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!-- NOTE: do not change this file because it's auto re-generated from template: -->
<!-- https://github.com/IgniteUI/igniteui-wc-examples/tree/vnext/templates/browser/sample/ReadMe.md -->

This folder contains implementation of Web Components application with example of State Persistence About feature using [Grid](https://infragistics.com/webcomponentssite/components/general-getting-started.html) component.


<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body>
<a target="_blank" href="https://infragistics.com/webcomponentssite/components/general-getting-started.html" rel="noopener noreferrer">
<img height="40px" style="border-radius: 0rem" alt="View Docs" src="https://github.com/IgniteUI/igniteui-blazor-examples/raw/vnext/templates/sample/images/button-docs.png"/>
</a>
<a target="_blank" href="./src/index.ts" rel="noopener noreferrer">
<img height="40px" style="border-radius: 0rem; max-width: 100%;" alt="View Code" src="https://github.com/IgniteUI/igniteui-blazor-examples/raw/vnext/templates/sample/images/button-code.png"/>
</a>
<a target="_blank" href="https://www.infragistics.com/webcomponents-demos/samples/grids/grid/state-persistence-about" rel="noopener noreferrer">
<img height="40px" style="border-radius: 0rem; max-width: 100%;" alt="Run Sample" src="https://github.com/IgniteUI/igniteui-blazor-examples/raw/vnext/templates/sample/images/button-run.png"/>
</a>
<a target="_blank" href="https://codesandbox.io/s/github/IgniteUI/igniteui-wc-examples/tree/master/samples/grids/grid/state-persistence-about?fontsize=14&hidenavigation=1&theme=dark&view=preview&file=/src/{SampleFile}" rel="noopener noreferrer">
<img height="40px" style="border-radius: 0rem; max-width: 100%;" alt="Run Sample" src="https://github.com/IgniteUI/igniteui-blazor-examples/raw/vnext/templates/sample/images/button-sandbox.png"/>
</a>
</body>
</html>

## Instructions

To set up this project locally, execute these commands:

```
git clone https://github.com/IgniteUI/igniteui-wc-examples.git
cd ./igniteui-wc-examples
cd ./samples/grids/grid/state-persistence-about
```

open above folder in VS Code or type:
```
code .
```

In terminal window, run:

```
npm install
npm run start
```

Then open http://localhost:4200/ in your browser


## Learn More

To learn more about **Ignite UI for Web Components**, check out the [Web Components documentation](https://infragistics.com/webcomponentssite/components/general-getting-started.html).
31 changes: 31 additions & 0 deletions samples/grids/grid/state-persistence-about/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Sample | Ignite UI | Web Components | infragistics</title>
<meta charset="UTF-8" />

<link rel="shortcut icon" href="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel="stylesheet" href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel="stylesheet" href="./about.css" type="text/css" />
</head>

<body>
<div id="root">
<div class="container sample">
<div style="text-align: center; width: 900px">
<br />
<span>By default navigating to the previous page, components will reinitialize as per their initial configuration, therefore the igcGrid will lose its state.</span>
<br />
<span>What our Sample Component does is reading the state from the `window.localStorage` object and applying the corresponding state in the `onload` window lifecycle.</span><br />
MayaKirova marked this conversation as resolved.
Show resolved Hide resolved
<igc-button id="backBtn" variant="contained">Go Back</igc-button>
</div>
</div>
</div>

<!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><script src="src/index.ts"></script><% } %>
</body>
</html>
62 changes: 62 additions & 0 deletions samples/grids/grid/state-persistence-about/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "example-ignite-ui-web-components",
"description": "This project provides example of using Ignite UI for Web Components",
"author": "Infragistics",
"version": "1.0.0",
"license": "",
"private": true,
"homepage": ".",
"main": "src/index.ts",
"scripts": {
"build": "npm run build:prod",
"build:dev": "webpack --mode development --config ./webpack.config.js --progress --color --display-error-details",
"build:prod": "webpack --env.NODE_ENV=production --mode production --config ./webpack.config.js --progress --color --display-error-details --bail",
"serve:dev": "node --max-old-space-size=8192 node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode development --config ./webpack.config.js --hot --progress --open",
"serve:prod": "webpack-dev-server --env.NODE_ENV=production --mode production --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --progress --open --content-base dist/",
"start": "npm run serve:dev",
"build:legacy": "npm run build:prod:legacy",
"build:dev:legacy": "webpack --env.legacy=true --mode development --config ./webpack.config.js --progress --color --display-error-details",
"build:prod:legacy": "webpack --env.NODE_ENV=production --env.legacy=true --mode production --config ./webpack.config.js --progress --color --display-error-details --bail",
"serve:dev:legacy": "node --max-old-space-size=8192 node_modules/webpack-dev-server/bin/webpack-dev-server.js --env.legacy=true --mode development --config ./webpack.config.js --hot --progress --open",
"serve:prod:legacy": "webpack-dev-server --env.NODE_ENV=production --env.legacy=true --mode production --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --progress --open --content-base dist/",
"start:legacy": "npm run serve:dev:legacy"
},
"dependencies": {
"@webcomponents/custom-elements": "^1.4.1",
"@webcomponents/template": "^1.4.2",
"babel-runtime": "^6.26.0",
"core-js": "^3.6.5",
"igniteui-webcomponents-core": "4.3.1",
"igniteui-webcomponents-grids": "4.3.1",
"igniteui-webcomponents-inputs": "4.3.1",
"igniteui-webcomponents-layouts": "4.3.1",
"lit-html": "^2.2.0",
"tslib": "^2.0.0"
},
"devDependencies": {
"@babel/cli": "^7.8.3",
"@babel/core": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.10.0",
"@babel/preset-env": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
"@types/source-map": "^0.5.7",
"babel-loader": "^8.1.0",
"babel-plugin-transform-custom-element-classes": "^0.1.0",
"css-loader": "^1.0.0",
"csv-loader": "^3.0.2",
"file-loader": "^4.2.0",
"fork-ts-checker-webpack-plugin": "^4.1.5",
"html-webpack-plugin": "^4.3.0",
"parcel-bundler": "^1.6.1",
"source-map": "^0.7.3",
"style-loader": "^0.22.1",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"typescript": "^4.4.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1",
"worker-loader": "^3.0.8",
"xml-loader": "^1.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"infiniteLoopProtection": false,
"hardReloadOnChange": false,
"view": "browser",
"template": "parcel"
}

2 changes: 2 additions & 0 deletions samples/grids/grid/state-persistence-about/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
19 changes: 19 additions & 0 deletions samples/grids/grid/state-persistence-about/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'igniteui-webcomponents-grids/grids/combined';
import { defineAllComponents, IgcButtonComponent } from 'igniteui-webcomponents';
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
defineAllComponents();

export class Sample {
private _bind: () => void;

constructor() {
var backBtn = document.getElementById("backBtn") as IgcButtonComponent;

this._bind = () => {
backBtn.addEventListener("click", () => { window.location.replace("./grids/grid/state-persistence-main");});
}
this._bind();
}
}

new Sample();
40 changes: 40 additions & 0 deletions samples/grids/grid/state-persistence-about/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"compilerOptions": {
"noImplicitReturns": true,
"esModuleInterop": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"declarationDir": "dist/types",
"moduleResolution": "node",
"declaration": true,
"target": "es2015",
"module": "es2015",
"strict": true,
"strictNullChecks": false,
"baseUrl": ".",
"paths": {
"igniteui-webcomponents-core": [ "node_modules/igniteui-webcomponents-core", "node_modules/@infragistics/igniteui-webcomponents-core" ],
"igniteui-webcomponents-charts": [ "node_modules/igniteui-webcomponents-charts", "node_modules/@infragistics/igniteui-webcomponents-charts" ],
"igniteui-webcomponents-gauges": [ "node_modules/igniteui-webcomponents-gauges", "node_modules/@infragistics/igniteui-webcomponents-gauges" ],
"igniteui-webcomponents-datasources": [ "node_modules/igniteui-webcomponents-datasources", "node_modules/@infragistics/igniteui-webcomponents-datasources" ],
"igniteui-webcomponents-excel": [ "node_modules/igniteui-webcomponents-excel", "node_modules/@infragistics/igniteui-webcomponents-excel" ],
"igniteui-webcomponents-inputs": [ "node_modules/igniteui-webcomponents-inputs", "node_modules/@infragistics/igniteui-webcomponents-inputs" ],
"igniteui-webcomponents-grids": [ "node_modules/igniteui-webcomponents-grids", "node_modules/@infragistics/igniteui-webcomponents-grids" ],
"igniteui-webcomponents-maps": [ "node_modules/igniteui-webcomponents-maps", "node_modules/@infragistics/igniteui-webcomponents-maps" ],
"igniteui-webcomponents-spreadsheet": [ "node_modules/igniteui-webcomponents-spreadsheet", "node_modules/@infragistics/igniteui-webcomponents-spreadsheet" ],
"igniteui-webcomponents-spreadsheet-chart-adapter": [ "node_modules/igniteui-webcomponents-spreadsheet-chart-adapter", "node_modules/@infragistics/igniteui-webcomponents-spreadsheet-chart-adapter" ],
"igniteui-webcomponents-grids/*": [ "node_modules/igniteui-webcomponents-grids/*", "node_modules/@infragistics/igniteui-webcomponents-grids/*" ],
"igniteui-webcomponents-grids/grids": [ "node_modules/igniteui-webcomponents-grids/grids", "node_modules/@infragistics/igniteui-webcomponents-grids/grids" ],
"igniteui-webcomponents-grids/grids/*": [ "node_modules/igniteui-webcomponents-grids/grids/*", "node_modules/@infragistics/igniteui-webcomponents-grids/grids/*" ],
"igniteui-webcomponents-grids/grids/combined": [ "node_modules/igniteui-webcomponents-grids/grids/combined", "node_modules/@infragistics/igniteui-webcomponents-grids/grids/combined" ],
"igniteui-webcomponents-layouts": [ "node_modules/igniteui-webcomponents-layouts", "node_modules/@infragistics/igniteui-webcomponents-layouts" ]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}
53 changes: 53 additions & 0 deletions samples/grids/grid/state-persistence-about/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": [
"node_modules/**/*.ts",
"**/odatajs-4.0.0.js",
"src/images/*.*"
]
},
"rules": {
"only-arrow-functions": false,
"jsx-self-close": false,
"jsx-wrap-multiline": false,
"no-var-requires": false,
"no-var": false,
"no-var-keyword": false,
"no-console": false,
"no-string-literal": false,
"no-unused-vars": false,
"@typescript-eslint/no-unused-vars": "off",
"jsx-no-lambda": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"member-ordering": false,
"curly": [false, "ignore-same-line"],
"max-classes-per-file": [true, 10],
"prefer-const": false,
"prefer-for-of": false,
"no-useless-constructor": false,
"@typescript-eslint/no-useless-constructor": "off",
"@typescript-eslint/type-annotation-spacing": "off"
},
"jsRules": {
"only-arrow-functions": false,
"jsx-self-close": false,
"jsx-wrap-multiline": false,
"no-var-requires": false,
"no-console": false,
"no-unused-vars": false,
"@typescript-eslint/no-unused-vars": "off",
"jsx-no-lambda": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"curly": [false, "ignore-same-line"],
"max-classes-per-file": [true, 10],
"prefer-const": false,
"prefer-for-of": false,
"no-useless-constructor": false,
"@typescript-eslint/no-useless-constructor": "off"
}
}
105 changes: 105 additions & 0 deletions samples/grids/grid/state-persistence-about/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const path = require('path');
const webpack = require('webpack');

module.exports = env => {
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
const isLegacy = !!process.env.legacy && !(process.env.legacy == "false");
console.log(">> webpack nodeEnv=" + nodeEnv);
console.log(">> webpack isProd=" + isProd);
console.log(">> webpack isLegacy=" + isLegacy);
const presets = [
["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": 3,
"targets": {
"browsers": isLegacy ? ["defaults"] : [
"last 2 Chrome versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 Firefox versions",
"last 2 Edge versions"]
}
}],
"@babel/preset-typescript"
];

return {
entry: isLegacy ? [
path.resolve(__dirname, 'node_modules/@webcomponents/custom-elements'),
path.resolve(__dirname, 'node_modules/@webcomponents/template'),
path.resolve(__dirname, 'src')
] : path.resolve(__dirname, 'src'),
devtool: isProd ? false : 'source-map',
output: {
filename: '[name].[fullhash].bundle.js',
globalObject: 'this',
path: path.resolve(__dirname, 'dist'),
},

resolve: {
mainFields: ['esm2015', 'module', 'main'],
extensions: ['.ts', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({
configFile: './tsconfig.json',
extensions: ['.ts', '.js'],
mainFields: ['esm2015', 'module', 'main']
})]
},

module: {
rules: [
{ test: /\.(png|svg|jpg|gif)$/, use: ['file-loader'] },
{ test: /\.(csv|tsv)$/, use: ['csv-loader'] },
{ test: /\.xml$/, use: ['xml-loader'] },
{ test: /\.css$/, sideEffects: true, use: ['style-loader', 'css-loader'] },
{
test: /worker\.(ts|js)$/,
use: [
{ loader: 'worker-loader' },
{
loader: 'babel-loader', options: {
"compact": isProd ? true : false,
"presets": presets,
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
]
}
}
]
},
{
test: /\.(ts|js)$/, loader: 'babel-loader',
options: {
"compact": isProd ? true : false,
"presets": presets,
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
]
},
exclude:
function (modulePath) {
return /node_modules/.test(modulePath) &&
!/igniteui-webcomponents/.test(modulePath) &&
!/lit-html/.test(modulePath);
}
}],
},

plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(nodeEnv)
}),
new HtmlWebpackPlugin({
title: 'index-cs',
template: 'index.html',
}),
new ForkTsCheckerWebpackPlugin()
]
};
};
Loading