Skip to content

Commit

Permalink
fix(full package): fixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
susanta96 committed Jun 12, 2023
1 parent e0ef1d6 commit 0dc302a
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 100 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ yarn add react-xlsx-wrapper@latest

- [Simple Excel Export](examples/simple_excel_export_01.md)
- [Excel Export with Dataset](examples/simple_excel_export_02.md)
- [Excel Export with Custom Download Button](examples/with_custom_download_element.md)
- [Excel Export with custom cells style](examples/styled_excel_sheet.md)

## Excel Props
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExcelColumn = exports.ExcelSheet = void 0;
var ExcelFileNew_1 = __importDefault(require("./ExcelPlugin/components/ExcelFileNew"));
var ExcelFile_1 = __importDefault(require("./ExcelPlugin/components/ExcelFile"));
var ExcelSheet_1 = __importDefault(require("./ExcelPlugin/elements/ExcelSheet"));
exports.ExcelSheet = ExcelSheet_1.default;
var ExcelColumn_1 = __importDefault(require("./ExcelPlugin/elements/ExcelColumn"));
exports.ExcelColumn = ExcelColumn_1.default;
ExcelFileNew_1.default.ExcelSheet = ExcelSheet_1.default;
ExcelFileNew_1.default.ExcelColumn = ExcelColumn_1.default;
exports.default = ExcelFileNew_1.default;
ExcelFile_1.default.ExcelSheet = ExcelSheet_1.default;
ExcelFile_1.default.ExcelColumn = ExcelColumn_1.default;
exports.default = ExcelFile_1.default;
65 changes: 0 additions & 65 deletions examples/with_custom_download_element.md

This file was deleted.

File renamed without changes.
8 changes: 4 additions & 4 deletions src-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExcelColumn = exports.ExcelSheet = void 0;
const ExcelFileNew_1 = __importDefault(require("./ExcelPlugin/components/ExcelFileNew"));
const ExcelFile_1 = __importDefault(require("./ExcelPlugin/components/ExcelFile"));
const ExcelSheet_1 = __importDefault(require("./ExcelPlugin/elements/ExcelSheet"));
exports.ExcelSheet = ExcelSheet_1.default;
const ExcelColumn_1 = __importDefault(require("./ExcelPlugin/elements/ExcelColumn"));
exports.ExcelColumn = ExcelColumn_1.default;
ExcelFileNew_1.default.ExcelSheet = ExcelSheet_1.default;
ExcelFileNew_1.default.ExcelColumn = ExcelColumn_1.default;
exports.default = ExcelFileNew_1.default;
ExcelFile_1.default.ExcelSheet = ExcelSheet_1.default;
ExcelFile_1.default.ExcelColumn = ExcelColumn_1.default;
exports.default = ExcelFile_1.default;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { utils, writeFile } from "xlsx-js-style";
import type { BookType, WorkSheet } from "xlsx-js-style";
import { excelSheetFromAoA, excelSheetFromDataSet } from "../utils/DataUtil";
import type {
DataProps,
ExcelColumnProps,
ExcelSheetData,
ExcelSheetProps,
ExcelValue,
} from "react-xlsx-wrapper";
Expand All @@ -15,7 +13,7 @@ interface ExcelFileProps {
filename?: string;
fileExtension?: BookType;
element?: React.ReactNode;
children: React.ReactElement<ExcelSheetProps<DataProps, ExcelSheetData>>[];
children: React.ReactElement<ExcelSheetProps>[];
}

class ExcelFile extends React.Component<ExcelFileProps> {
Expand All @@ -39,9 +37,7 @@ class ExcelFile extends React.Component<ExcelFileProps> {
}
}

createSheetData = (
sheet: React.ReactElement<ExcelSheetProps<DataProps, ExcelSheetData>>
) => {
createSheetData = (sheet: React.ReactElement<ExcelSheetProps>) => {
const columns = sheet.props.children;
const sheetData = [
React.Children.map(
Expand All @@ -52,14 +48,13 @@ class ExcelFile extends React.Component<ExcelFileProps> {

const data = sheet.props.data;
if (!data) throw new Error("No data provided");
data.forEach((row: DataProps) => {
data.forEach((row: any) => {
let sheetRow: ExcelValue[] = [];

React.Children.forEach(
columns,
(column: React.ReactElement<ExcelColumnProps>) => {
const getValue = (row: DataProps) =>
row[column.props.value as string];
const getValue = (row: any) => row[column.props.value as string];
const itemValue = getValue(row);
sheetRow.push(isNaN(Number(itemValue)) ? itemValue || "" : itemValue);
}
Expand Down
14 changes: 6 additions & 8 deletions src/ExcelPlugin/elements/ExcelSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React, { Component } from "react";
import ExcelColumn from "./ExcelColumn";
import type { DataProps, ExcelValue, ExcelSheetData } from "react-xlsx-wrapper";
import type { ExcelValue, ExcelSheetData } from "react-xlsx-wrapper";

export interface ExcelSheetProps<D, DS> {
export interface ExcelSheetProps {
name: string;
data?: D[];
dataSet?: DS[];
data?: any[];
dataSet?: ExcelSheetData[];
value: ExcelValue[] | (() => void);
children: React.ReactElement<typeof ExcelColumn>[];
}
export default class ExcelSheet extends Component<
ExcelSheetProps<DataProps, ExcelSheetData>
> {
constructor(props: ExcelSheetProps<DataProps, ExcelSheetData>) {
export default class ExcelSheet extends Component<ExcelSheetProps> {
constructor(props: ExcelSheetProps) {
super(props);

if (!props.children.every((child) => child.type === ExcelColumn)) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ExcelFile from "./ExcelPlugin/components/ExcelFileNew";
import ExcelFile from "./ExcelPlugin/components/ExcelFile";
import ExcelSheet from "./ExcelPlugin/elements/ExcelSheet";
import ExcelColumn from "./ExcelPlugin/elements/ExcelColumn";

Expand Down
12 changes: 4 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
declare module 'react-xlsx-wrapper' {
import * as React from 'react';

export type DataProps = {
[key: string]: ExcelValue;
};

export interface ExcelFileProps {
filename?: string;
Expand All @@ -12,10 +8,10 @@ declare module 'react-xlsx-wrapper' {
children?: Array<React.ReactElement> | React.ReactElement; // Array<ExcelSheetProps>;
}

export interface ExcelSheetProps<D, DS> {
export interface ExcelSheetProps {
name: string;
data?: D[];
dataSet?: DS[];
data?: any[];
dataSet?: ExcelSheetData[];
value: ExcelValue[] | (() => void);
children: React.ReactElement | Array<React.ReactElement>;
}
Expand Down Expand Up @@ -140,7 +136,7 @@ declare module 'react-xlsx-wrapper' {
export class ExcelColumn extends React.Component<ExcelColumnProps, any> {
}

export class ExcelSheet extends React.Component<ExcelSheetProps<DataProps|undefined, ExcelSheetData|undefined>, any> {
export class ExcelSheet extends React.Component<ExcelSheetProps, any> {
}

export class ExcelFile extends React.Component<ExcelFileProps, any> {
Expand Down

0 comments on commit 0dc302a

Please sign in to comment.