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

New components: DataTable + variants #103

Merged
merged 39 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
47af732
Port over DataTable code from earlier Baklava.
Nov 20, 2024
04c6f29
Add license headers.
Nov 26, 2024
7060de8
Rework basic DataTable components to be free of errors.
Nov 27, 2024
67da159
Work on MultiSearch component.
Nov 28, 2024
01e4a9d
PLAT-3985 WIP
Dec 3, 2024
4481df6
Merge branch 'master' into feature/component-data-table
Dec 5, 2024
249a0d9
Fix story paths for tables.
Dec 5, 2024
3e1891c
Merge branch 'feature/component-data-table' of github.com:fortanix/ba…
Dec 5, 2024
4a6a34f
Merge branch 'master' into feature/component-data-table
Dec 9, 2024
25d8bc0
Datatables: Clear all type errors
Dec 10, 2024
e957813
Merge branch 'master' into feature/component-data-table
Jan 6, 2025
31ac8d7
Datatables: Initial table styling (basic search, table, pagination)
Jan 14, 2025
166de08
Merge branch 'master' into feature/component-data-table
Jan 14, 2025
5bae990
Data Table: Add --legacy-peer-deps arg
Jan 14, 2025
dfb8328
Data Table: fixes
Jan 14, 2025
ec493b3
Data Table: add missing file headers
Jan 14, 2025
8d26fc0
Data Table: Fix formatting issue
Jan 14, 2025
3488d85
Data Table: Fix formatting issue
Jan 14, 2025
e322213
Data Table: Remove unused util
Jan 14, 2025
a01e673
Data Table: Remove unused util
Jan 14, 2025
ec4f386
Data Table: Fix CSS issues
Jan 14, 2025
3540382
Merge branch 'master' into feature/component-data-table
mkrause Jan 14, 2025
dad79ac
Data Table: PR Review
Jan 15, 2025
1913379
Data Table: PR Review
Jan 15, 2025
c42702d
Data Table: Replace --legacy-peer-deps with overrides
Jan 15, 2025
da555ac
Merge branch 'master' into feature/component-data-table
mkrause Jan 15, 2025
72b5a93
Trim 'Load more' button.
mkrause Jan 15, 2025
bfffc8d
Data Table: PR Review
Jan 16, 2025
af5b30f
Code cleanup.
mkrause Jan 16, 2025
ff30e9a
Fix onPress -> onClick on non-Button elements.
mkrause Jan 16, 2025
91a0a81
Clean up.
mkrause Jan 16, 2025
e5722d3
Resolve some comments.
mkrause Jan 16, 2025
fa40ec1
Refactor Pagination styling to Sass modules.
mkrause Jan 16, 2025
68aed0e
Comment out some stories that are not ready.
mkrause Jan 16, 2025
d3c3b9c
Convert some .scss files to .module.scss.
mkrause Jan 16, 2025
9d9ebaf
Convert PaginationSizeSelector.scss to .module.scss.
mkrause Jan 16, 2025
4297bbc
Data Table: Convert to DataTable.module.scss + move hooks higher.
Jan 17, 2025
5390f98
Tweak shimmer effect according to design input.
mkrause Jan 17, 2025
62c04f4
Tweak shimmer effect according to design input.
mkrause Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
"linter": {
"enabled": true,
"include": ["app/**/*", "src/**/*", "tests/**/*"],
"ignore": ["tests/installation/**/*"],

"ignore": [
"src/components/tables/MultiSearch/MultiSearch.tsx", // Ignore for now (need to focus on type errors first)
"tests/installation/**/*"
],
"rules": {
"recommended": true,
"complexity": {
Expand All @@ -33,7 +37,8 @@
},
"style": {
"useImportType": "off",
"noUnusedTemplateLiteral": "off"
"noUnusedTemplateLiteral": "off",
"noUselessElse": "off"
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"check:types": "tsc -b",
"lint:style": "stylelint 'src/**/*.scss'",
"lint:script": "biome lint",
"lint": "npm run lint:style && npm run lint:script",
"lint": "npm run lint:style; npm run lint:script",
"test": "npm run check:types && npm run lint:style",
"test-ui": "vitest --ui",
"coverage": "vitest run --coverage",
Expand Down Expand Up @@ -101,7 +101,9 @@
"sass-embedded": "^1.83.1",
"lightningcss": "^1.29.1",
"@types/react": "^19.0.4",
"@types/react-dom": "^19.0.2"
"@types/react-dom": "^19.0.2",
"@types/react-table": "^7.7.20",
"@ngneat/falso": "^6.4.0"
},
"dependencies": {
"date-fns": "^4.1.0",
Expand All @@ -112,6 +114,7 @@
"react-error-boundary": "^5.0.0",
"@floating-ui/react": "^0.26.28",
"react-toastify": "^10.0.6",
"react-table": "^7.8.0",
"react-datepicker": "^7.6.0",
"effect": "^3.12.1",
"react-hook-form": "^7.54.2",
Expand All @@ -134,6 +137,10 @@
"react-datepicker": {
"react": "$react",
"react-dom": "$react-dom"
},
"react-table": {
"react": "$react",
"react-dom": "$react-dom"
}
}
}
15 changes: 13 additions & 2 deletions package.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const packageConfig = {
'check:types': 'tsc -b',
'lint:style': `stylelint 'src/**/*.scss'`,
'lint:script': 'biome lint',
'lint': 'npm run lint:style && npm run lint:script',
'lint': 'npm run lint:style; npm run lint:script',

// Test
// Note: use `vitest run --root=. src/...` to run a single test file
Expand Down Expand Up @@ -155,6 +155,11 @@ const packageConfig = {
// React
'@types/react': '^19.0.4',
'@types/react-dom': '^19.0.2',

// Data table
'@types/react-table': '^7.7.20',
// Fake data
"@ngneat/falso": "^6.4.0",
},

// Dependencies needed when running the generated build
Expand All @@ -172,6 +177,7 @@ const packageConfig = {

'@floating-ui/react': '^0.26.28',
'react-toastify': '^10.0.6',
'react-table': '^7.8.0',
'react-datepicker': '^7.6.0',

'effect': '^3.12.1',
Expand Down Expand Up @@ -200,6 +206,11 @@ const packageConfig = {
'react': '$react',
'react-dom': '$react-dom',
},
// TODO: Revisit after updating react-table to v8
'react-table': {
'react': '$react',
'react-dom': '$react-dom',
},
},
};

Expand Down Expand Up @@ -229,4 +240,4 @@ const makePackageJson = () => {
};

// Write to `package.json`
fs.writeFileSync('./package.json', JSON.stringify(makePackageJson(), null, 2) + '\n');
fs.writeFileSync('./package.json', `${JSON.stringify(makePackageJson(), null, 2)}\n`);
14 changes: 7 additions & 7 deletions src/components/actions/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

--bk-button-color-accent: #{bk.$theme-button-primary-background-default};
--bk-button-color-contrast: #{bk.$theme-button-primary-text-default};

align-self: flex-start;


cursor: pointer;
user-select: none;

margin: 0;
padding: 0;
&:not(.bk-button--trimmed) {
padding: calc(bk.$spacing-2 - 0.125lh) bk.$spacing-3; /* Note: compensate for line-height difference with Figma */
}
padding: calc(bk.$spacing-2 - 0.125lh) bk.$spacing-3; /* Note: compensate for line-height difference with Figma */

/* Transparent border for consistency with other variants that have a border */
border: bk.$size-1 solid transparent;
border-radius: bk.$radius-s;
background: transparent;

&.bk-button--trimmed {
padding: 0;
border: none;
}

display: inline-flex;
flex-flow: row wrap;
align-items: center;
Expand Down
3 changes: 2 additions & 1 deletion src/components/actions/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ export const Button = (props: ButtonProps) => {
[cl['bk-button--trimmed']]: trimmed,
[cl['bk-button--primary']]: variant === 'primary',
[cl['bk-button--secondary']]: variant === 'secondary',
[cl['bk-button--nonactive']]: isNonactive,
[cl['bk-button--disabled']]: !isInteractive,
[cl['bk-button--nonactive']]: isNonactive,
'nonactive': isNonactive, // Global class name so that consumers can style nonactive states
}, props.className)}
onClick={handleClick}
>
Expand Down
18 changes: 8 additions & 10 deletions src/components/forms/controls/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ export const Input = ({ unstyled = false, type = 'text', ...propsRest }: InputPr
}

return (
<div>
<input
{...propsRest}
type={type}
className={cx({
bk: true,
[cl['bk-input']]: !unstyled,
}, propsRest.className)}
/>
</div>
<input
{...propsRest}
type={type}
className={cx({
bk: true,
[cl['bk-input']]: !unstyled,
}, propsRest.className)}
/>
);
};
6 changes: 4 additions & 2 deletions src/components/forms/fields/CheckboxField/CheckboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const CheckboxFieldTitle = ({ className, children, titleOptional, titleTo
</h1>
);

export type CheckboxFieldProps = ComponentProps<'div'> & {
export type CheckboxFieldProps = ComponentProps<typeof Checkbox> & {
/** Whether this component should be unstyled. */
unstyled?: undefined | boolean,

Expand Down Expand Up @@ -71,7 +71,7 @@ export type CheckboxFieldProps = ComponentProps<'div'> & {
disabled?: undefined | boolean,

/** The onChange event for the checkbox. Passed down to Checkbox component. */
onChange?: (e: React.FormEvent) => void,
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void,
};

/**
Expand All @@ -86,6 +86,7 @@ export const CheckboxField = (props: CheckboxFieldProps) => {
titleOptional,
titleTooltip,
className,
...propsRest
} = props;

return (
Expand All @@ -109,6 +110,7 @@ export const CheckboxField = (props: CheckboxFieldProps) => {
defaultChecked={props.defaultChecked}
disabled={props.disabled}
onChange={props.onChange}
{...propsRest}
/>
<span className={cl['bk-checkbox-field__label__content']}>
{label}
Expand Down
8 changes: 4 additions & 4 deletions src/components/forms/fields/CheckboxGroup/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { classNames as cx } from '../../../../util/componentUtil.ts';
import { classNames as cx, type ComponentProps } from '../../../../util/componentUtil.ts';
import * as React from 'react';

import cl from './CheckboxGroup.module.scss';
Expand All @@ -12,9 +12,9 @@ import { CheckboxField } from '../CheckboxField/CheckboxField.tsx';

export { cl as CheckboxGroupClassNames };

export type CheckboxGroupProps = React.PropsWithChildren<{
direction?: undefined | "vertical" | "horizontal";
}>;
export type CheckboxGroupProps = ComponentProps<'div'> & {
direction?: undefined | 'vertical' | 'horizontal',
};

/**
* Checkbox group component, wrapping multiple CheckboxField components vertically or horizontally.
Expand Down
7 changes: 6 additions & 1 deletion src/components/graphics/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import { icons } from '../../../assets/icons/_icons.ts';
import cl from './Icon.module.scss';


export type IconName = keyof typeof icons;
export { cl as IconClassNames };

export type IconName = keyof typeof icons;
export const iconNames = new Set(Object.keys(icons) as Array<IconName>);
export const isIconName = (iconName: string): iconName is IconName => {
return (iconNames as Set<string>).has(iconName);
};

export type Decoration = (
| { type: 'background-circle' }
);
Expand Down
34 changes: 34 additions & 0 deletions src/components/tables/DataTable/DataTableContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) Fortanix, Inc.
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react';
import type * as ReactTable from 'react-table';


export type DataTableStatus = {
ready: boolean, // Whether the data is ready to be used/shown in the UI
loading: boolean, // Whether we're (re)loading the data
error: null | Error, // Whether the last loading attempt resulted in an error
};

export type TableContextState<D extends object> = {
status: DataTableStatus,
setStatus: (status: DataTableStatus) => void,
reload: () => void,
table: ReactTable.TableInstance<D>,
};

const TableContext = React.createContext<null | TableContextState<object>>(null); // Memoized
export const createTableContext = <D extends object>() => TableContext as React.Context<null | TableContextState<D>>;


export const useTable = <D extends object>(): TableContextState<D> => {
const context = React.useContext(TableContext as React.Context<null | TableContextState<D>>);

if (context === null) {
throw new TypeError('TableContext not yet initialized');
}

return context;
};
Loading
Loading