Skip to content

Commit 2c6c128

Browse files
qili26nstepien
authored andcommitted
tsfy all features example (#1852)
* chores: tsfy all features examples * chores: minor polish * chores: change class component to functional component * chores: add redirect, fix propTypes issue * chores: polish DropdownEditor in demo * chores: address PR comments * chores: tweak url; remove proptypes * chores: address PR comment
1 parent 7a479df commit 2c6c128

19 files changed

+396
-493
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
2+
import { Column, Editor } from '../../../../src';
3+
4+
interface Option {
5+
id: string;
6+
title: string;
7+
value: string;
8+
text: string;
9+
}
10+
11+
interface DropDownEditorProps<TRow> {
12+
column: Column<TRow>;
13+
options: Array<Option | string>;
14+
value?: string;
15+
onBlur(): void;
16+
}
17+
18+
type DropDownEditorHandle = Pick<Editor<{[key: string]: string | undefined}>, 'getInputNode' | 'getValue'>;
19+
20+
function DropDownEditorWithRef<TRow>({ column, value, onBlur, options }: DropDownEditorProps<TRow>, ref: React.Ref<DropDownEditorHandle>): JSX.Element {
21+
const selectRef = useRef<HTMLSelectElement>(null);
22+
23+
useImperativeHandle(ref, () => ({
24+
getInputNode() {
25+
return selectRef.current;
26+
},
27+
getValue() {
28+
return {
29+
[column.key]: selectRef.current?.value
30+
};
31+
}
32+
}));
33+
34+
return (
35+
<select
36+
ref={selectRef}
37+
className="rdg-select-editor"
38+
defaultValue={value}
39+
onBlur={onBlur}
40+
size={options.length}
41+
style={{ maxHeight: 200, height: 'auto', overflowY: 'auto' }}
42+
>
43+
{options.map(name => typeof name === 'string' ? (
44+
<option
45+
key={name}
46+
value={name}
47+
onClick={onBlur}
48+
>
49+
{name}
50+
</option>
51+
) : (
52+
<option
53+
key={name.id}
54+
value={name.value}
55+
title={name.title}
56+
onClick={onBlur}
57+
>
58+
{name.text || name.value}
59+
</option>
60+
))}
61+
</select>
62+
);
63+
}
64+
65+
export default forwardRef(
66+
DropDownEditorWithRef as React.RefForwardingComponent<DropDownEditorHandle, DropDownEditorProps<{ [key: string]: unknown }>>
67+
) as <R>(props: DropDownEditorProps<R> & { ref?: React.Ref<DropDownEditorHandle> }) => JSX.Element;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import './rdg-image.less';
3+
4+
interface Props {
5+
/** image url, used as background-image */
6+
value: string;
7+
}
8+
9+
export default function ImageFormatter({ value }: Props) {
10+
return (
11+
<div className="rdg-image-cell-wrapper">
12+
<div className="rdg-image-cell" style={{ backgroundImage: `url(${value})` }} />
13+
</div>
14+
);
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.rdg-image-cell {
2+
background: #efefef;
3+
background-size: 100%;
4+
display: inline-block;
5+
height: 28px;
6+
width: 28px;
7+
vertical-align: middle;
8+
background-position: center;
9+
}
10+
11+
.rdg-image-cell-wrapper {
12+
display: flex;
13+
justify-content: space-around;
14+
}

packages/react-data-grid-addons/src/toolbars/Toolbar.tsx renamed to examples/demos/components/Toolbar/Toolbar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from 'react';
1+
import React, { PropsWithChildren } from 'react';
2+
import './rdg-toolbar.less';
23

34
interface Props {
45
onAddRow?(arg: { newRowIndex: number }): void;
@@ -7,16 +8,15 @@ interface Props {
78
numberOfRows: number;
89
addRowButtonText?: string;
910
filterRowsButtonText?: string;
10-
children: React.ReactNode;
1111
}
1212

13-
export default function Toolbar(props: Props) {
13+
export default function Toolbar(props: PropsWithChildren<Props>) {
1414
function onAddRow() {
15-
props.onAddRow!({ newRowIndex: props.numberOfRows });
15+
props.onAddRow?.({ newRowIndex: props.numberOfRows });
1616
}
1717

1818
return (
19-
<div className="react-grid-Toolbar">
19+
<div className="rdg-toolbar">
2020
<div className="tools">
2121
{props.onAddRow && (
2222
<button type="button" className="btn" onClick={onAddRow}>

packages/react-data-grid-addons/style/rdg-toolbar.less renamed to examples/demos/components/Toolbar/rdg-toolbar.less

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.react-grid-Toolbar {
1+
.rdg-toolbar {
22
background-color: #ffffff;
33
border-color: #e7eaec;
44
border-image: none;
@@ -7,9 +7,9 @@
77
color: inherit;
88
margin-bottom: 0;
99
padding: 14px 15px 7px;
10-
height: 48px;
1110
}
12-
.react-grid-Toolbar .btn {
11+
12+
.rdg-toolbar .btn {
1313
display: inline-block;
1414
padding: 6px 12px;
1515
margin-bottom: 0;
@@ -27,20 +27,24 @@
2727
background: white;
2828
border: 1px solid #e7eaec;
2929
}
30-
.react-grid-Toolbar .btn:hover {
30+
31+
.rdg-toolbar .btn:hover {
3132
color: inherit;
3233
border: 1px solid #d2d2d2;
3334
}
34-
.react-grid-Toolbar .grouped-col-btn {
35+
36+
.rdg-toolbar .grouped-col-btn {
3537
background-color: #428bca;
3638
color: white;
3739
border-color: #2b669a;
3840
}
39-
.react-grid-Toolbar .grouped-col-btn:hover {
41+
42+
.rdg-toolbar .grouped-col-btn:hover {
4043
color: white;
4144
border-color: #2b669a;
4245
}
43-
.react-grid-Toolbar .grouped-col-btn + .grouped-col-btn {
46+
47+
.rdg-toolbar .grouped-col-btn + .grouped-col-btn {
4448
margin-left: 5px;
4549
}
4650

@@ -49,7 +53,7 @@
4953
vertical-align: middle;
5054
}
5155

52-
.react-grid-Toolbar .tools {
56+
.rdg-toolbar .tools {
5357
float: right;
5458
position: relative;
5559
padding: 0;

0 commit comments

Comments
 (0)