Skip to content

Commit

Permalink
fix: update unused vars in component
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMooree committed Aug 12, 2022
1 parent b6bd15b commit 25141ba
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
1 change: 0 additions & 1 deletion tools/ui-components/src/table/index.ts
@@ -1,3 +1,2 @@

export { Table } from './table';
export type { TableProps } from './types';
6 changes: 2 additions & 4 deletions tools/ui-components/src/table/table.stories.tsx
Expand Up @@ -61,16 +61,14 @@ const story = {
},
borderless: {
options: [true, false],
control: { type: 'radio'},
control: { type: 'radio' },
// Used to avoid conflict with borders
if: {arg: 'bordered', truthy: false}
if: { arg: 'bordered', truthy: false }
},
size: {
options: ['small', 'medium', 'large']
}

}

};

const Template: Story<TableProps> = args => (
Expand Down
10 changes: 0 additions & 10 deletions tools/ui-components/src/table/table.test.tsx

This file was deleted.

64 changes: 39 additions & 25 deletions tools/ui-components/src/table/table.tsx
@@ -1,59 +1,73 @@
import React from 'react';
import '../../../../client/src/components/layouts/global.css'
import '../../../../client/src/components/layouts/global.css';

import { TableProps, TableVariant } from './types';
import { TableProps } from './types';

const defaultClassNames = ['table','table-auto', 'w-full', 'border-collapse',
'text-left', 'bg-transparent'];
const defaultClassNames = [
'table',
'table-auto',
'w-full',
'border-collapse',
'text-left',
'bg-transparent'
];
const MAX_MOBILE_WIDTH = 767;

const computeWindowSize = window.innerWidth <= MAX_MOBILE_WIDTH
const computeWindowSize = window.innerWidth <= MAX_MOBILE_WIDTH;

const variantClasses: Record<TableVariant, string> = {
light: 'bg-light-theme-background',
dark: 'bg-dark-theme-background text-gray-0'
}
// const variantClasses: Record<TableVariant, string> = {
// light: 'bg-light-theme-background',
// dark: 'bg-dark-theme-background text-gray-0'
// }

const computeClassNames = (size: string) => {
switch (size) {
case 'large':
return 'text-lg'
return 'text-lg';
case 'small':
return 'text-sm'
return 'text-sm';
// default is medium
default:
return 'text-md'
return 'text-md';
}
}
};

export const Table = React.forwardRef<HTMLTableElement, TableProps>(
(
{ borderless, bordered, className, hover, striped, responsive, variant, size, ...props },
{ borderless, bordered, hover, striped, responsive, size, ...props },
ref
) => {
props.cellPadding = 10 // Default cell padding for visual clarity in Storybook

if (borderless && bordered) bordered = false;
props.cellPadding = 10; // Default cell padding for visual clarity in Storybook

const borderClass = bordered ? "bordered" : ""
const stripedClass = striped ? "table-striped" : ""
const hoverClass = hover ? "table-hover" : ""
if (borderless && bordered) bordered = false;

const classes = [...defaultClassNames, borderClass, stripedClass, computeClassNames(size || ''), hoverClass].join(' ');
const borderClass = bordered ? 'bordered' : '';
const stripedClass = striped ? 'table-striped' : '';
const hoverClass = hover ? 'table-hover' : '';

const classes = [
...defaultClassNames,
borderClass,
stripedClass,
computeClassNames(size || ''),
hoverClass
].join(' ');

const table = <table {...props} ref={ref} className={classes}/>;
const table = <table {...props} ref={ref} className={classes} />;

if (responsive) {
let responsiveClass = computeWindowSize ? 'sm' : 'lg';
return <div className={responsiveClass}>{table}</div>
const responsiveClass = computeWindowSize ? 'sm' : 'lg';
return <div className={responsiveClass}>{table}</div>;
}

// For storybook use cases. Table should remain transparent to the background color
// For storybook use cases. Table should remain transparent to the background color add @param of 'variant'

// if (variant == 'light') {
// return <div className={variantClasses[variant]}>{table}</div>
// } else return <div className={variantClasses[variant]}>{table}</div>

return table;
}
);

Table.displayName = 'Table';
5 changes: 3 additions & 2 deletions tools/ui-components/src/table/types.ts
@@ -1,8 +1,9 @@
import React from "react";
import React from 'react';

export type TableVariant = 'light' | 'dark';

export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement> {
export interface TableProps
extends React.TableHTMLAttributes<HTMLTableElement> {
bordered?: boolean;
borderless?: boolean;
className?: string;
Expand Down

0 comments on commit 25141ba

Please sign in to comment.