@prioticket/design-system-react 1.8.1-beta.1 → 1.8.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/dist/components/pd-table.d.ts +22 -12
- package/dist/components/pd-table.js +8 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -63,15 +63,31 @@ await initialize({ theme: { colorPrimary: '#4caf50' } });
|
|
|
63
63
|
|
|
64
64
|
## TypeScript Support
|
|
65
65
|
|
|
66
|
-
Every wrapper
|
|
66
|
+
Every wrapper is typed from its element class (`ReactWebComponent<Element, Events>`): properties become props, an unknown prop is a compile error, and each event prop takes a handler that receives the `CustomEvent` the component dispatches, so `event.detail` needs no cast:
|
|
67
67
|
|
|
68
68
|
```tsx
|
|
69
|
-
|
|
70
|
-
import { PdTextField, PdTextFieldElement } from '@prioticket/design-system-react';
|
|
71
|
-
|
|
72
|
-
const ref = useRef<PdTextFieldElement>(null);
|
|
69
|
+
<PdTextField label="Name" value={value} onInput={(e) => setValue(e.detail.value)} />
|
|
73
70
|
```
|
|
74
71
|
|
|
72
|
+
Two rules that the types make visible:
|
|
73
|
+
|
|
74
|
+
- **ARIA.** Standard ARIA is written as the attribute, because `@lit/react` strips a camelCase `ariaLabel`; a component's own property that merely looks like ARIA stays camelCase: `<PdIconButton aria-label="Close" ariaLabelSelected="Selected" />`.
|
|
75
|
+
- **pd-table is generic over its row type**, like the element class. Pass the type argument, or let TypeScript infer it from `columns`:
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { PdTable, type PdTableProps } from '@prioticket/design-system-react';
|
|
79
|
+
import type { PdTableColumn } from '@prioticket/design-system-web/components/pd-table';
|
|
80
|
+
|
|
81
|
+
type Booking = { id: string; guest: string; [key: string]: unknown };
|
|
82
|
+
const columns: PdTableColumn<Booking>[] = [{ id: 'guest', header: 'Guest', cellTemplate: (row) => row.guest }];
|
|
83
|
+
|
|
84
|
+
<PdTable<Booking> columns={columns} rowKey={(row) => row.id} onPdTableSort={(e) => console.log(e.detail)} />
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Row types must satisfy `Record<string, unknown>`, so add an index signature to your row interface.
|
|
88
|
+
|
|
89
|
+
The element types are exported alongside each wrapper (`PdTextFieldElement`, `PdTableElement`, …) for refs: `const ref = useRef<PdTableElement<Booking>>(null)`.
|
|
90
|
+
|
|
75
91
|
## Component Reference
|
|
76
92
|
|
|
77
93
|
The React entry point (`@prioticket/design-system-react`) exports all Prioticket components. Refer to `COMPONENT-DOCUMENTATION.md` in the root of the design system repository for behavior, slots, and properties—they apply equally to the React wrappers.
|
|
@@ -82,6 +98,8 @@ The wrappers are thin `@lit/react` adapters and support server-side rendering. R
|
|
|
82
98
|
|
|
83
99
|
## Troubleshooting
|
|
84
100
|
|
|
101
|
+
**The upgrade seems to have changed nothing.** A reused Vite or Next.js dev server keeps serving its pre-bundle of the old package. Stop the server, delete `node_modules/.vite`, start again, then re-test.
|
|
102
|
+
|
|
85
103
|
- Ensure the core package is loaded exactly once (e.g. do not register components via multiple versions of the bundle).
|
|
86
104
|
- Import the CSS theme before rendering components to avoid flashes of unstyled content.
|
|
87
105
|
- If you tree-shake aggressively, keep the side-effect flag for `@prioticket/design-system-react` enabled so the custom elements are defined.
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { PdTable as PdTableElementType } from '@prioticket/design-system-web/components/pd-table';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type WebComponentProps } from '@lit/react';
|
|
3
|
+
import type { PdTable as PdTableElementType, PdTableRowData } from '@prioticket/design-system-web/components/pd-table';
|
|
4
|
+
/** Handler props for the events pd-table dispatches. */
|
|
5
|
+
export interface PdTableEventProps {
|
|
6
|
+
onPdTableSort?: (event: CustomEvent) => void;
|
|
7
|
+
onPdTableSelectionChange?: (event: CustomEvent) => void;
|
|
8
|
+
onPdTableRowClick?: (event: CustomEvent) => void;
|
|
9
|
+
onPdTableCellChange?: (event: CustomEvent) => void;
|
|
10
|
+
onPdTableRowReorder?: (event: CustomEvent) => void;
|
|
11
|
+
onPdTableColumnReorder?: (event: CustomEvent) => void;
|
|
12
|
+
onPdTablePageChange?: (event: CustomEvent) => void;
|
|
13
|
+
}
|
|
14
|
+
/** Props of PdTable, generic exactly like the element class. */
|
|
15
|
+
export type PdTableProps<T extends PdTableRowData = PdTableRowData> = WebComponentProps<PdTableElementType<T>> & PdTableEventProps;
|
|
16
|
+
/**
|
|
17
|
+
* pd-table's element class is generic<T extends PdTableRowData = PdTableRowData>. createComponent() can only return a
|
|
18
|
+
* concrete component, so the wrapper is re-typed as a generic function component: pass the type
|
|
19
|
+
* argument explicitly, `<PdTable<YourType> …/>`, or let TypeScript infer it from the props.
|
|
20
|
+
* Same runtime object as createComponent() returned; only the type changes.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PdTable: <T extends PdTableRowData = PdTableRowData>(props: PdTableProps<T>) => React.ReactElement | null;
|
|
13
23
|
export type { PdTableElementType as PdTableElement };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createComponent } from '@lit/react';
|
|
3
3
|
import { PdTable as PdTableElementClass } from '@prioticket/design-system-web/components/pd-table';
|
|
4
|
-
|
|
4
|
+
const PdTableComponent = createComponent({
|
|
5
5
|
displayName: 'PdTable',
|
|
6
6
|
react: React,
|
|
7
7
|
tagName: 'pd-table',
|
|
@@ -16,3 +16,10 @@ export const PdTable = createComponent({
|
|
|
16
16
|
onPdTablePageChange: 'pd-table-page-change'
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
/**
|
|
20
|
+
* pd-table's element class is generic<T extends PdTableRowData = PdTableRowData>. createComponent() can only return a
|
|
21
|
+
* concrete component, so the wrapper is re-typed as a generic function component: pass the type
|
|
22
|
+
* argument explicitly, `<PdTable<YourType> …/>`, or let TypeScript infer it from the props.
|
|
23
|
+
* Same runtime object as createComponent() returned; only the type changes.
|
|
24
|
+
*/
|
|
25
|
+
export const PdTable = PdTableComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prioticket/design-system-react",
|
|
3
|
-
"version": "1.8.1-beta.
|
|
3
|
+
"version": "1.8.1-beta.2",
|
|
4
4
|
"description": "React wrappers for the Prioticket Design System web components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"clean": "rimraf dist"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@prioticket/design-system-web": "^1.8.1-beta.
|
|
34
|
+
"@prioticket/design-system-web": "^1.8.1-beta.2",
|
|
35
35
|
"react": ">=17",
|
|
36
36
|
"react-dom": ">=17"
|
|
37
37
|
},
|