Skip to content

Commit cde2336

Browse files
authored
Merge pull request #1 from WJSoftware:JP/Main_Dev
JP/Main_Dev
2 parents cf01875 + 480a116 commit cde2336

16 files changed

+603
-60
lines changed

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
engine-strict=true
2-
@wjsoft:registry=https://www.npmjs.com
2+
@wjfe:registry=https://www.npmjs.com

README.md

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @wj/dataview
1+
# @wjfe/dataview
22

33
> Svelte v5 table component suitable for examination of extensive tabular data.
44
@@ -8,6 +8,8 @@ The data view component renders a table with functionality suitable for close ex
88
provides conveniences like pinnable columns and row highlighting on hover, useful to users when following data with
99
their eyes.
1010

11+
> **[Demo Website](https://wj-dataview.vercel.app)**
12+
1113
The component tries to be as unopinionated as possible in terms of styling and tries to provide as little styling as
1214
possible. Certain features, however, impose some appearance requirements. For example, pinning columns in the grid
1315
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
2123
Install the package:
2224

2325
```powershell
24-
npm i @wj/dataview
26+
npm i @wjfe/dataview
2527
```
2628

2729
Now import the data view component and use it:
2830

2931
```typescript
30-
import { WjDataView } from '@wj/dataview';
32+
import { WjDataView } from '@wjfe/dataview';
3133
```
3234

3335
The only two required properties are `columns` and `data`. The former defines the columns in the data view; the
3436
latter provides the data that shows in each column. By default, the `key` property of each column is treated as the
3537
key to retrieve data from the data row, but this can be overridden by providing `get` functions.
3638

37-
> **[Demo Website](https://wj-dataview.vercel.app)**
38-
39-
## Props
39+
Each column must have the `key` and the `text` properties. Any other property is optional. `key` is a unique string,
40+
and by default, it is assumed to be the name of a property in the data objects given to the grid via the `data`
41+
property.
4042

41-
## Snippets (formerly slots)
43+
```html
44+
<script lang="ts">
45+
import { WjDataView } from '@wjfe/dataview';
46+
import { type MyDataModel } from 'path/to/my-model-types.js';
47+
48+
type MyDataModelGridRow = WjDvRow<MyDataModel>;
49+
type MyColumn = WjDvColumn<Record<string, any>, MyDataModelGridRow>;
50+
const columns = $state<MyColumn[]>([
51+
{
52+
key: 'id',
53+
text: 'ID'
54+
},
55+
{
56+
key: 'tagName',
57+
text: 'Tag'
58+
}
59+
]);
60+
// Obtain the data somehow. This could be part of the results of the universal or server load() SvelteKit
61+
// function, or could be obtained in non-SvelteKit projects with a fetch() call.
62+
let data: $state<MyDataModel[]> = getDataSomehow();
63+
</script>
64+
...
65+
<WjDataView {columns} {data}>
66+
<!-- snippets go here -->
67+
</WjDataView>
68+
```
4269

43-
## Events
70+
This example would render the data view with two columns, whose captions will read `ID` and `Tag`. The data shown in
71+
each column will be extracted from the `MyDataModel.id` and `MyDataModel.tagName` properties of each of the data
72+
objects in the `data` array.
4473

4574
## Theming the Data View
4675

@@ -52,8 +81,8 @@ directly defining the CSS variables.
5281
### The WjDataViewTheme Component
5382

5483
This component is a mere convenience to setting up themes for data view components. It works by defining the CSS
55-
variables at the end of the section in a `<div>` element with its CSS `display` attribute set to `contets` that wraps
56-
the target `WjDataView` component.
84+
variables in a `<div>` element with its CSS `display` attribute set to `contents` that wraps the target `WjDataView`
85+
component.
5786

5887
> **TIP**: The `WjDataViewTheme` component doesn't have to be the immediate parent of a `WjDataView`. It can be
5988
> placed higher in the hierarchy to, for example, cover more than one `WjDataView` component.
@@ -82,11 +111,13 @@ export type Theme = {
82111
Since the amount of properties are a lot to set every time, the most effective way to create a theme is to spread the
83112
stock theme (light or dark) and then modify what's needed.
84113

114+
> In the future, deep merging instead of spreading will be enabled via the `wj-merge` package.
115+
85116
For example, Bootstrap consumers might want to ensure that the data view always uses the body's background color. In
86-
this case, we could create the following theme in `dataViewThemes.ts`:
117+
this case, we could create the following theme in a `dataViewThemes.ts`:
87118

88119
```typescript
89-
import { stockLight, type Theme } from '@wj/dataview';
120+
import { stockLight, type Theme } from '@wjfe/dataview';
90121

91122
export const bootstrapTheme: Theme = {
92123
...stockLight,
@@ -106,15 +137,16 @@ export const bootstrapTheme: Theme = {
106137
};
107138
```
108139

109-
As seen, one can take advantage of CSS variables to define things. In Bootstrap that provides light and dark modes,
110-
have different definitions for these CSS variables, making the data view's theme immediately responsive to theme
111-
selection changes.
140+
As seen, one can take advantage of CSS variables to define things. Bootstrap provides light and dark modes, and these
141+
variables have different definitions depending on the mode, making the data view's theme immediately responsive to
142+
mode selection changes.
112143

113144
This is not perfect, however, because Bootstrap doesn't have `-rgb` variables for every color, so not everything goes
114145
as smoothly. Create responsive CSS variables to perfect the theme.
115146

116147
> **IMPORTANT**: All background colors are composed using the provided color and an opacity value. This is why the
117-
> color must be specified in RGB format, or with a CSS variable that defines it in RGB format.
148+
> color must be specified in RGB format, or with a CSS variable that defines it in RGB format. Formats like `#rrggbb`
149+
> simply won't work.
118150
119151
Anyway, use the `WjDataViewTheme` component as a wrapper for any `WjDataView` components that you may have. This
120152
wrapper doesn't have to be the immediate parent, so put it wherever is best according to your needs.
@@ -147,22 +179,59 @@ The complete list of CSS variables that can be set for the data view component a
147179
| `--wjdv-sticky-divider-width` | `0.1em` | `0.1em` | Width of the border that divides pinned columns from unpinned ones. |
148180
| `--wjdv-sticky-divider-style` | `solid` | `solid` | Style of the border that divides pinned columns from unpinned ones. |
149181
| `--wjdv-sticky-divider-color` | `darkgray` | `lightgray` | Color of the border that divides pinned columns from unpinned ones. |
182+
| `--wjdv-resizer-width` | `0.4em` | `0.4em` | Column resizer's width. |
183+
| `--wjdv-resizer-bg-color-rgb` | `0, 0, 0` | `255, 255, 255` | Resizer handle's background color. |
184+
| `--wjdv-resizer-bg-opacity` | `0.05` | `0.05` | Resizer handle's background's opacity. |
185+
| `--wjdv-resizer-overlay-opacity` | `0.7` | `0.7` | Opacity of the entire resizer overlay. |
186+
| `--wjdv-resizer-overlay-bg-color` | `lightblue` | `#0578ea` | Background color of the overlay section that represents the original column's size. |
187+
| `--wjdv-resizer-overlay-border-color` | `blue` | `#13aeff` | Border color of the overlay section that represents the original column's size. |
188+
| `--wjdv-resizer-deltapos-bg-color` | `lightgreen` | `lightgreen` | Background color of the overlay setion that represents the column's size increase. |
189+
| `--wjdv-resizer-deltapos-border-color` | `green` | `green` | Border color of the overlay setion that represents the column's size increase. |
190+
| `--wjdv-resizer-deltaneg-bg-color` | `pink` | `pink` | Background color of the overlay setion that represents the column's size reduction. |
191+
| `--wjdv-resizer-deltaneg-border-color` | `red` | `red` | Border color of the overlay setion that represents the column's size reduction. |
192+
193+
## Reference
194+
195+
### Props
196+
197+
| Property | Type | Default Value | Description |
198+
| - | - | - | - |
199+
| `columns` | `WjDvColumn<TCol, TRow>[]` | (none) | Defines the columns the data view component will create. |
200+
| `data` | `WjDvRow<TRow>[]` | (none) | The data that is shown by the data view component. |
201+
| `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. |
202+
| `defaultWidth` | `number` | `10` | The width for colums that don't specify its own width, in `em`'s. |
203+
| `rowHighlight` | `boolean` | `true` | Turns the row-highlighting-on-hover feature on and off. |
204+
| `striped` | `boolean` | `true` | Turns the striping of rows on and off. |
205+
| `pinnedDivider` | `boolean` | `true` | Turns the divider between pinned and unpinned columns on and off. |
206+
| `class` | `string` | `undefined` | Additional CSS classes that are applied to the data view's viewport (the top-level element). |
207+
208+
### Snippets (formerly slots)
209+
210+
| Name | Signature | Description |
211+
| - | - | - |
212+
| `headerCell` | `(col: WjDvColumn<TCol, TRow>)` | Renders header cells' content. The snippet is passed the column definition. |
213+
| `dataCell` | `(col: WjDvColumn<TCol, TRow>, row: WjDvRow<TRow>])` | Renders data cells' content. The snippet is passed the column definition and the data object for the row being rendered. |
214+
215+
### Events
216+
217+
None.
150218

151219
## Roadmap
152220

153221
- [x] Scrollable viewport
154222
- [x] Striped look
155223
- [x] Row highlighting effect on hover
156224
- [x] Column alignment
225+
- [x] Text wrap control
157226
- [x] Hideable columns
158227
- [x] Pinnable columns
159228
- [x] Customizable appearance
160229
- [x] Theme component
161230
- [x] headerCell snippet
162231
- [x] dataCell snippet
232+
- [x] Resizable columns
163233
- [ ] headerControl snippet
164234
- [ ] dataControl snippet
165235
- [ ] Expansible rows (expansionRow snippet)
166-
- [ ] Resizable columns
167236
- [ ] Make cell/row/column padding themeable
168237
- [ ] dataRow snippet

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@wj/dataview",
2+
"name": "@wjfe/dataview",
33
"version": "0.0.1",
44
"scripts": {
55
"dev": "vite dev",
@@ -31,6 +31,7 @@
3131
"@sveltejs/package": "^2.0.0",
3232
"@sveltejs/vite-plugin-svelte": "^3.0.0",
3333
"publint": "^0.1.9",
34+
"sass": "^1.77.1",
3435
"svelte": "^5.0.0-next.136",
3536
"svelte-check": "^3.6.0",
3637
"tslib": "^2.4.1",
@@ -40,10 +41,5 @@
4041
},
4142
"svelte": "./dist/index.js",
4243
"types": "./dist/index.d.ts",
43-
"type": "module",
44-
"dependencies": {
45-
"bootstrap": "^5.3.3",
46-
"bootstrap-icons": "^1.11.3",
47-
"sass": "^1.77.1"
48-
}
44+
"type": "module"
4945
}

src/app.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" class="" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
8-
<link rel="stylesheet" href="node_modules/bootstrap-icons/font/bootstrap-icons.css" crossorigin="anonymous">
8+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
99
%sveltekit.head%
1010
</head>
1111
<body data-sveltekit-preload-data="hover">
1212
<div>%sveltekit.body%</div>
13+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
1314
</body>
1415
</html>

src/index.test.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)