diff --git a/.npmrc b/.npmrc index 2b249b1..9844771 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ engine-strict=true -@wjsoft:registry=https://www.npmjs.com +@wjfe:registry=https://www.npmjs.com diff --git a/README.md b/README.md index 6398c14..e4430db 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# @wj/dataview +# @wjfe/dataview > Svelte v5 table component suitable for examination of extensive tabular data. @@ -8,6 +8,8 @@ The data view component renders a table with functionality suitable for close ex provides conveniences like pinnable columns and row highlighting on hover, useful to users when following data with their eyes. +> **[Demo Website](https://wj-dataview.vercel.app)** + The component tries to be as unopinionated as possible in terms of styling and tries to provide as little styling as possible. Certain features, however, impose some appearance requirements. For example, pinning columns in the grid requires opaque background colors or else the data from other columns will be seen through the pinned columns when @@ -21,26 +23,53 @@ Tailwind CSS, Bulma, etc.), you may style it in accordance to what is shown in t Install the package: ```powershell -npm i @wj/dataview +npm i @wjfe/dataview ``` Now import the data view component and use it: ```typescript -import { WjDataView } from '@wj/dataview'; +import { WjDataView } from '@wjfe/dataview'; ``` The only two required properties are `columns` and `data`. The former defines the columns in the data view; the latter provides the data that shows in each column. By default, the `key` property of each column is treated as the key to retrieve data from the data row, but this can be overridden by providing `get` functions. -> **[Demo Website](https://wj-dataview.vercel.app)** - -## Props +Each column must have the `key` and the `text` properties. Any other property is optional. `key` is a unique string, +and by default, it is assumed to be the name of a property in the data objects given to the grid via the `data` +property. -## Snippets (formerly slots) +```html + +... + + + +``` -## Events +This example would render the data view with two columns, whose captions will read `ID` and `Tag`. The data shown in +each column will be extracted from the `MyDataModel.id` and `MyDataModel.tagName` properties of each of the data +objects in the `data` array. ## Theming the Data View @@ -52,8 +81,8 @@ directly defining the CSS variables. ### The WjDataViewTheme Component This component is a mere convenience to setting up themes for data view components. It works by defining the CSS -variables at the end of the section in a `
` element with its CSS `display` attribute set to `contets` that wraps -the target `WjDataView` component. +variables in a `
` element with its CSS `display` attribute set to `contents` that wraps the target `WjDataView` +component. > **TIP**: The `WjDataViewTheme` component doesn't have to be the immediate parent of a `WjDataView`. It can be > placed higher in the hierarchy to, for example, cover more than one `WjDataView` component. @@ -82,11 +111,13 @@ export type Theme = { Since the amount of properties are a lot to set every time, the most effective way to create a theme is to spread the stock theme (light or dark) and then modify what's needed. +> In the future, deep merging instead of spreading will be enabled via the `wj-merge` package. + For example, Bootstrap consumers might want to ensure that the data view always uses the body's background color. In -this case, we could create the following theme in `dataViewThemes.ts`: +this case, we could create the following theme in a `dataViewThemes.ts`: ```typescript -import { stockLight, type Theme } from '@wj/dataview'; +import { stockLight, type Theme } from '@wjfe/dataview'; export const bootstrapTheme: Theme = { ...stockLight, @@ -106,15 +137,16 @@ export const bootstrapTheme: Theme = { }; ``` -As seen, one can take advantage of CSS variables to define things. In Bootstrap that provides light and dark modes, -have different definitions for these CSS variables, making the data view's theme immediately responsive to theme -selection changes. +As seen, one can take advantage of CSS variables to define things. Bootstrap provides light and dark modes, and these +variables have different definitions depending on the mode, making the data view's theme immediately responsive to +mode selection changes. This is not perfect, however, because Bootstrap doesn't have `-rgb` variables for every color, so not everything goes as smoothly. Create responsive CSS variables to perfect the theme. > **IMPORTANT**: All background colors are composed using the provided color and an opacity value. This is why the -> color must be specified in RGB format, or with a CSS variable that defines it in RGB format. +> color must be specified in RGB format, or with a CSS variable that defines it in RGB format. Formats like `#rrggbb` +> simply won't work. Anyway, use the `WjDataViewTheme` component as a wrapper for any `WjDataView` components that you may have. This wrapper doesn't have to be the immediate parent, so put it wherever is best according to your needs. @@ -147,6 +179,42 @@ The complete list of CSS variables that can be set for the data view component a | `--wjdv-sticky-divider-width` | `0.1em` | `0.1em` | Width of the border that divides pinned columns from unpinned ones. | | `--wjdv-sticky-divider-style` | `solid` | `solid` | Style of the border that divides pinned columns from unpinned ones. | | `--wjdv-sticky-divider-color` | `darkgray` | `lightgray` | Color of the border that divides pinned columns from unpinned ones. | +| `--wjdv-resizer-width` | `0.4em` | `0.4em` | Column resizer's width. | +| `--wjdv-resizer-bg-color-rgb` | `0, 0, 0` | `255, 255, 255` | Resizer handle's background color. | +| `--wjdv-resizer-bg-opacity` | `0.05` | `0.05` | Resizer handle's background's opacity. | +| `--wjdv-resizer-overlay-opacity` | `0.7` | `0.7` | Opacity of the entire resizer overlay. | +| `--wjdv-resizer-overlay-bg-color` | `lightblue` | `#0578ea` | Background color of the overlay section that represents the original column's size. | +| `--wjdv-resizer-overlay-border-color` | `blue` | `#13aeff` | Border color of the overlay section that represents the original column's size. | +| `--wjdv-resizer-deltapos-bg-color` | `lightgreen` | `lightgreen` | Background color of the overlay setion that represents the column's size increase. | +| `--wjdv-resizer-deltapos-border-color` | `green` | `green` | Border color of the overlay setion that represents the column's size increase. | +| `--wjdv-resizer-deltaneg-bg-color` | `pink` | `pink` | Background color of the overlay setion that represents the column's size reduction. | +| `--wjdv-resizer-deltaneg-border-color` | `red` | `red` | Border color of the overlay setion that represents the column's size reduction. | + +## Reference + +### Props + +| Property | Type | Default Value | Description | +| - | - | - | - | +| `columns` | `WjDvColumn[]` | (none) | Defines the columns the data view component will create. | +| `data` | `WjDvRow[]` | (none) | The data that is shown by the data view component. | +| `get` | `(row: TRow, key: string) => any` | (function) | Function that retrieves a column's value using the row and provided key for columns that don't provide one. | +| `defaultWidth` | `number` | `10` | The width for colums that don't specify its own width, in `em`'s. | +| `rowHighlight` | `boolean` | `true` | Turns the row-highlighting-on-hover feature on and off. | +| `striped` | `boolean` | `true` | Turns the striping of rows on and off. | +| `pinnedDivider` | `boolean` | `true` | Turns the divider between pinned and unpinned columns on and off. | +| `class` | `string` | `undefined` | Additional CSS classes that are applied to the data view's viewport (the top-level element). | + +### Snippets (formerly slots) + +| Name | Signature | Description | +| - | - | - | +| `headerCell` | `(col: WjDvColumn)` | Renders header cells' content. The snippet is passed the column definition. | +| `dataCell` | `(col: WjDvColumn, row: WjDvRow])` | Renders data cells' content. The snippet is passed the column definition and the data object for the row being rendered. | + +### Events + +None. ## Roadmap @@ -154,15 +222,16 @@ The complete list of CSS variables that can be set for the data view component a - [x] Striped look - [x] Row highlighting effect on hover - [x] Column alignment +- [x] Text wrap control - [x] Hideable columns - [x] Pinnable columns - [x] Customizable appearance - [x] Theme component - [x] headerCell snippet - [x] dataCell snippet +- [x] Resizable columns - [ ] headerControl snippet - [ ] dataControl snippet - [ ] Expansible rows (expansionRow snippet) -- [ ] Resizable columns - [ ] Make cell/row/column padding themeable - [ ] dataRow snippet diff --git a/package.json b/package.json index 0834fc4..d12bb56 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@wj/dataview", + "name": "@wjfe/dataview", "version": "0.0.1", "scripts": { "dev": "vite dev", @@ -31,6 +31,7 @@ "@sveltejs/package": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "publint": "^0.1.9", + "sass": "^1.77.1", "svelte": "^5.0.0-next.136", "svelte-check": "^3.6.0", "tslib": "^2.4.1", @@ -40,10 +41,5 @@ }, "svelte": "./dist/index.js", "types": "./dist/index.d.ts", - "type": "module", - "dependencies": { - "bootstrap": "^5.3.3", - "bootstrap-icons": "^1.11.3", - "sass": "^1.77.1" - } + "type": "module" } diff --git a/src/app.html b/src/app.html index a88224c..be7e4cb 100644 --- a/src/app.html +++ b/src/app.html @@ -5,10 +5,11 @@ - + %sveltekit.head%
%sveltekit.body%
+ diff --git a/src/index.test.ts b/src/index.test.ts deleted file mode 100644 index e07cbbd..0000000 --- a/src/index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, it, expect } from 'vitest'; - -describe('sum test', () => { - it('adds 1 + 2 to equal 3', () => { - expect(1 + 2).toBe(3); - }); -}); diff --git a/src/lib/Resizer.svelte b/src/lib/Resizer.svelte new file mode 100644 index 0000000..a63e954 --- /dev/null +++ b/src/lib/Resizer.svelte @@ -0,0 +1,185 @@ + + + + +{#if dragStart !== null} +
+
+
0 })} + style:width="{deltaOverlayWidth}px" + >
+
+{/if} +
+ + + + diff --git a/src/lib/WjDataView.svelte b/src/lib/WjDataView.svelte index 1bb814c..26b7dbe 100644 --- a/src/lib/WjDataView.svelte +++ b/src/lib/WjDataView.svelte @@ -3,24 +3,25 @@ export type WjDvRow = Record> = TRow & { id: string | number; - selected?: boolean; expanded?: boolean; - } + }; export type WjDvColumn = Record, TRow extends Record = Record> = TCol & { key: string; text: string; width?: number; - pinnable?: boolean; + minWidth?: number; + resizable?: boolean; pinned?: boolean; hidden?: boolean; alignment?: ColAlignment; noTextWrap?: boolean; get?: (row: TRow) => any; - } + }; + +
+ +
+ + diff --git a/src/routes/themes.ts b/src/routes/themes.ts index 2b50840..7b8b6e7 100644 --- a/src/routes/themes.ts +++ b/src/routes/themes.ts @@ -1,4 +1,4 @@ -import { stockLight, type Theme } from "$lib/stockTheme.js"; +import { stockLight, stockDark, type Theme } from "$lib/stockTheme.js"; export const bootstrapTheme: Theme = { ...stockLight, @@ -14,6 +14,9 @@ export const bootstrapTheme: Theme = { ...stockLight.rowHighlight, backgroundColor: 'var(--bs-primary-rgb)', opacity: 0.2 + }, + resizer: { + ...stockLight.resizer } };