Skip to content

Commit ecbee50

Browse files
authored
Merge pull request #1401 from inplayer-org/feat/make-table-field-renameable
Feat/make table field renameable
2 parents 2642f64 + 6e5ad78 commit ecbee50

File tree

8 files changed

+386
-19
lines changed

8 files changed

+386
-19
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
# [2.5.21] - 24.01.2022
5+
# [2.5.22] - 04.02.2022
6+
7+
## Added
8+
9+
- Option in column table to make fields(columns) editable
10+
- onBlur function to trigger persa when input and textarea are focused-out
11+
12+
# [2.5.21] - 25.01.2022
613

714
## Change
815

index.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,17 @@ export interface RadioProps extends AnalyticsProps{
216216

217217
export declare const Radio: FunctionComponent<RadioProps>;
218218

219+
export interface EditableFields {
220+
fn: (props: ColumnFunctionProps) => void;
221+
validationSchema: ObjectSchema<any>;
222+
}
223+
219224
export interface TableColumn<T extends TableRowData> {
220225
title: string;
221226
key: string;
222227
render?: (props: TableColumn$RenderProps<T>) => ReactNode;
223228
style?: CSSProperties;
229+
editable?: EditableFields;
224230
}
225231

226232
export interface TableRowData extends Object {
@@ -232,6 +238,12 @@ export interface TableColumn$RenderProps<T extends TableRowData, V = any> {
232238
rowValues: T;
233239
}
234240

241+
export interface ColumnFunctionProps {
242+
value: string;
243+
currentValue: string;
244+
id: number;
245+
}
246+
235247
export interface RowAction<T extends TableRowData> {
236248
icon?: string;
237249
onClick?: (id: number | string) => any;
@@ -270,6 +282,7 @@ export interface TableProps<TableData extends TableRowData = TableRowData> exten
270282
options?: Partial<TableOptions<TableData>>;
271283
tableButton?: Array<TableButtonProps>;
272284
actionsRowTitle?: string;
285+
editableById?: string;
273286
}
274287

275288
interface TableState {

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@inplayer-org/inplayer-ui",
33
"sideEffects": false,
4-
"version": "2.5.20",
4+
"version": "2.5.22",
55
"author": "InPlayer",
66
"description": "InPlayer React UI Components",
77
"main": "dist/inplayer-ui.cjs.js",
@@ -102,5 +102,9 @@
102102
"stylelint-config-styled-components": "^0.1.1",
103103
"stylelint-processor-styled-components": "^1.10.0",
104104
"typescript": "^4.1.3"
105+
},
106+
"dependencies": {
107+
"formik": "^2.1.5",
108+
"yup": "^0.32.11"
105109
}
106110
}

src/components/Input/ErrorField.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { FunctionComponent } from 'react';
2+
import { ErrorMessage, ErrorMessageProps } from 'formik';
3+
import styled from 'styled-components';
4+
import colors from '../../theme/colors';
5+
6+
const ErrorMessageWrapper = styled(ErrorMessage)<ErrorMessageProps>`
7+
margin-top: 0.5rem;
8+
display: block;
9+
color: ${colors.red};
10+
`;
11+
12+
const ErrorField: FunctionComponent<ErrorMessageProps> = ({ className, ...rest }) => (
13+
<ErrorMessageWrapper component="span" className={className} {...rest} />
14+
);
15+
16+
export default ErrorField;

src/components/Input/FormikInput.tsx

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { FunctionComponent, InputHTMLAttributes } from 'react';
2+
import { FieldProps } from 'formik';
3+
import styled from 'styled-components';
4+
import { AnalyticsProps } from 'index';
5+
import Input from './Input';
6+
7+
const InputContainer = styled.div`
8+
position: relative;
9+
display: grid;
10+
align-items: center;
11+
grid-column-end: span 12;
12+
grid-row-end: span 1;
13+
flex: 1;
14+
`;
15+
16+
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, 'form'> & FieldProps & AnalyticsProps;
17+
18+
const FormikInput: FunctionComponent<Props> = ({
19+
id,
20+
field,
21+
value,
22+
form: _,
23+
placeholder = '',
24+
tag = '',
25+
...rest
26+
}) => {
27+
const { name: fieldName, ...fieldRest } = field;
28+
29+
return (
30+
<InputContainer>
31+
<Input
32+
tag={tag}
33+
type="text"
34+
id={id || fieldName}
35+
placeholder={placeholder}
36+
name={fieldName}
37+
{...fieldRest}
38+
{...rest}
39+
value={value ?? fieldRest.value}
40+
/>
41+
</InputContainer>
42+
);
43+
};
44+
45+
export default FormikInput;

0 commit comments

Comments
 (0)