onekijs-ui 0.19.2 → 0.19.4

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.
Files changed (80) hide show
  1. package/dist/components/card/FormCardDisplayer.d.ts +3 -0
  2. package/dist/components/card/components/FormCardDisplayerComponent.d.ts +4 -0
  3. package/dist/components/card/style.d.ts +2 -0
  4. package/dist/components/field/FieldDisplayer.d.ts +3 -0
  5. package/dist/components/field/FieldHelp.d.ts +2 -2
  6. package/dist/components/field/components/FieldDisplayerComponent.d.ts +4 -0
  7. package/dist/components/field/hoc/defaultFIeldDisplayer.d.ts +4 -0
  8. package/dist/components/field/style.d.ts +2 -1
  9. package/dist/components/field/typings.d.ts +10 -2
  10. package/dist/components/icon/HideIcon.d.ts +4 -0
  11. package/dist/components/icon/ShowIcon.d.ts +4 -0
  12. package/dist/components/input/typings.d.ts +3 -2
  13. package/dist/components/password/Password.d.ts +3 -0
  14. package/dist/components/password/components/PasswordComponent.d.ts +4 -0
  15. package/dist/components/password/style.d.ts +4 -0
  16. package/dist/components/password/typings.d.ts +4 -0
  17. package/dist/components/select/SelectService.d.ts +3 -3
  18. package/dist/components/table/columns/enumColumn.d.ts +1 -1
  19. package/dist/components/table/columns/inputColumn.d.ts +1 -1
  20. package/dist/components/table/displayers/DefaultCellDisplayer.d.ts +4 -0
  21. package/dist/components/table/displayers/FormTableItemDisplayer.d.ts +4 -0
  22. package/dist/components/table/displayers/FormTableValueDisplayer.d.ts +4 -0
  23. package/dist/components/table/typings.d.ts +37 -2
  24. package/dist/components/wizard/WizardSummary.d.ts +3 -0
  25. package/dist/components/wizard/components/FormStep.d.ts +2 -2
  26. package/dist/components/wizard/components/WizardSummaryComponent.d.ts +4 -0
  27. package/dist/components/wizard/style.d.ts +1 -0
  28. package/dist/components/wizard/typings.d.ts +1 -0
  29. package/dist/index.d.ts +23 -9
  30. package/dist/index.js +592 -132
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.module.js +573 -131
  33. package/dist/index.module.js.map +1 -1
  34. package/dist/styles/border.d.ts +1 -1
  35. package/dist/styles/typography.d.ts +2 -2
  36. package/dist/utils/misc.d.ts +1 -0
  37. package/package.json +3 -3
  38. package/src/components/card/FormCard.tsx +40 -8
  39. package/src/components/card/FormCardDisplayer.tsx +9 -0
  40. package/src/components/card/components/FormCardDisplayerComponent.tsx +18 -0
  41. package/src/components/card/style.ts +17 -2
  42. package/src/components/checkbox/FormCheckbox.tsx +30 -3
  43. package/src/components/field/FieldDisplayer.tsx +9 -0
  44. package/src/components/field/FieldHelp.tsx +2 -2
  45. package/src/components/field/components/FieldDisplayerComponent.tsx +36 -0
  46. package/src/components/field/hoc/defaultFIeldDisplayer.tsx +25 -0
  47. package/src/components/field/style.ts +50 -3
  48. package/src/components/field/typings.ts +11 -1
  49. package/src/components/field/util.ts +20 -4
  50. package/src/components/icon/HideIcon.tsx +31 -0
  51. package/src/components/icon/ShowIcon.tsx +30 -0
  52. package/src/components/input/FormInput.tsx +35 -10
  53. package/src/components/input/typings.ts +3 -1
  54. package/src/components/password/Password.tsx +9 -0
  55. package/src/components/password/components/PasswordComponent.tsx +26 -0
  56. package/src/components/password/style.ts +26 -0
  57. package/src/components/password/typings.ts +5 -0
  58. package/src/components/select/FormSelect.tsx +63 -4
  59. package/src/components/select/components/ControlledTreeSelectComponent.tsx +1 -1
  60. package/src/components/table/FormTable.tsx +40 -7
  61. package/src/components/table/columns/checkboxColumn.ts +2 -0
  62. package/src/components/table/columns/enumColumn.tsx +3 -1
  63. package/src/components/table/columns/inputColumn.ts +3 -1
  64. package/src/components/table/columns/numberColumn.ts +2 -0
  65. package/src/components/table/columns/selectColumn.ts +2 -0
  66. package/src/components/table/columns/textColumn.ts +2 -0
  67. package/src/components/table/columns/textareaColumn.ts +2 -0
  68. package/src/components/table/displayers/DefaultCellDisplayer.tsx +29 -0
  69. package/src/components/table/displayers/FormTableItemDisplayer.tsx +49 -0
  70. package/src/components/table/displayers/FormTableValueDisplayer.tsx +43 -0
  71. package/src/components/table/typings.ts +41 -1
  72. package/src/components/textarea/FormTextarea.tsx +33 -9
  73. package/src/components/wizard/WizardSummary.tsx +9 -0
  74. package/src/components/wizard/components/FormStep.tsx +77 -11
  75. package/src/components/wizard/components/Step.tsx +11 -23
  76. package/src/components/wizard/components/WizardSummaryComponent.tsx +19 -0
  77. package/src/components/wizard/style.ts +16 -1
  78. package/src/components/wizard/typings.ts +1 -0
  79. package/src/index.ts +31 -11
  80. package/src/utils/misc.ts +5 -0
@@ -0,0 +1,26 @@
1
+ import { css } from 'styled-components'
2
+ import { ComponentStyle } from '../../styles/typings'
3
+ import { PasswordProps } from './typings'
4
+ import { display } from '../../styles/display'
5
+ import { alignItems } from '../../styles/alignment'
6
+ import { color, fontSize } from '../../styles/typography'
7
+ import { marginBottom, marginLeft } from '../../styles/spacing'
8
+ import { cursor } from '../../styles/interactivity'
9
+
10
+ const passwordStyle: ComponentStyle<PasswordProps> = () => {
11
+ return css`
12
+ ${display('flex')}
13
+ ${alignItems('center')}
14
+ .g-icon-obfuscated-password {
15
+ ${fontSize('xl')}
16
+ ${marginBottom('-8px')}
17
+ }
18
+ .g-icon-show-password {
19
+ ${color('primary')}
20
+ ${marginLeft('sm')}
21
+ ${cursor('pointer')}
22
+ }
23
+ `
24
+ }
25
+
26
+ export default passwordStyle
@@ -0,0 +1,5 @@
1
+ import { StylableProps } from '../../styles/typings';
2
+
3
+ export type PasswordProps = StylableProps & {
4
+ value: string;
5
+ };
@@ -1,16 +1,75 @@
1
+ import { FormDisplayerProps, FormFieldValueDisplayerProps, useForm } from 'onekijs-framework';
1
2
  import React from 'react';
2
3
  import Select from '.';
4
+ import { titlelize } from '../../utils/misc';
5
+ import FieldDisplayer from '../field/FieldDisplayer';
3
6
  import FieldLayout from '../field/FieldLayout';
4
7
  import useFieldLayout from '../field/hooks/useFieldLayout';
5
8
  import { FormSelectProps, SelectItem, SelectProps } from './typings';
6
9
 
7
- const FormSelect = <T extends any = any, I extends SelectItem<T> = SelectItem<T>>(props: FormSelectProps<T, I>) => {
10
+ const FormSelectValueDisplayer: React.FC<FormFieldValueDisplayerProps> = ({ value }) => {
11
+ if (Array.isArray(value)) {
12
+ return (
13
+ <>
14
+ {value.map((v, index) => <div key={`item-${index}`} className="o-select-displayer-value">{v ?? ''}</div>)}
15
+ </>
16
+ )
17
+ }
18
+ return <span className="o-select-displayer-value">{value ?? ''}</span>;
19
+ };
20
+
8
21
 
22
+
23
+ const FormSelect = <T extends any = any, I extends SelectItem<T> = SelectItem<T>>(props: FormSelectProps<T, I>) => {
24
+ const service = props.controller ? props.controller.asService() : undefined;
9
25
  const defaultValue = props.defaultValue === undefined ? (props.multiple ? [] : null) : props.defaultValue;
10
26
  const [fieldLayoutProps, fieldComponentProps] = useFieldLayout<SelectProps<T, I>>(
11
- Object.assign({}, props, {
12
- defaultValue,
13
- }),
27
+ Object.assign(
28
+ {},
29
+ props,
30
+ {
31
+ defaultValue,
32
+ Displayer: props.Displayer ?? ((displayerProps: FormDisplayerProps) => {
33
+ const form = useForm();
34
+ let value = form.getValue(displayerProps.name) ?? '';
35
+ const adapter = props.adapter;
36
+ if (value === undefined || value === null) {
37
+ value = '';
38
+ } else if (service) {
39
+ if (Array.isArray(value)) {
40
+ value = value.map((v) => {
41
+ const adaptee = service.adapt(v);
42
+ return adaptee.text ?? `${value}`;
43
+ })
44
+ } else {
45
+ const adaptee = service.adapt(value);
46
+ value = adaptee.text ?? `${value}`;
47
+ }
48
+ } else if (adapter) {
49
+ if (Array.isArray(value)) {
50
+ value = value.map((v) => {
51
+ const adaptee = adapter(v);
52
+ return adaptee.text ?? `${value}`;
53
+ })
54
+ } else {
55
+ const adaptee = adapter(value);
56
+ value = adaptee.text ?? `${value}`;
57
+ }
58
+ }
59
+ const ValueDisplayer = props.ValueDisplayer ?? FormSelectValueDisplayer;
60
+ return (
61
+ <FieldDisplayer
62
+ label={displayerProps.label ?? titlelize(displayerProps.name)}
63
+ help={props.help}
64
+ first={displayerProps.first}
65
+ last={displayerProps.last}
66
+ value={<ValueDisplayer value={value} />}
67
+ format={displayerProps.format}
68
+ />
69
+ );
70
+ }),
71
+ },
72
+ ),
14
73
  );
15
74
  const Component = props.FieldComponent || Select;
16
75
 
@@ -24,7 +24,7 @@ export const useTreeSelectPropsContext = <
24
24
  return useContext(TreeSelectPropsContext);
25
25
  };
26
26
 
27
- const TreeSelectListComponent = <T = any, I extends TreeSelectItem<T> = TreeSelectItem<T>>(
27
+ const TreeSelectListComponent = <T extends any = any, I extends TreeSelectItem<T> = TreeSelectItem<T>>(
28
28
  props: SelectListComponentProps<T, I>,
29
29
  ) => {
30
30
  const treeProps = useTreeSelectPropsContext<T, I>();
@@ -1,8 +1,12 @@
1
+ import { FormContext, FormDisplayerProps, useFieldContainer, useForm } from 'onekijs-framework';
1
2
  import React, { FC } from 'react';
2
3
  import styled from 'styled-components';
4
+ import { titlelize } from '../../utils/misc';
5
+ import FieldDisplayer from '../field/FieldDisplayer';
3
6
  import FieldLayout from '../field/FieldLayout';
4
7
  import useFieldLayout from '../field/hooks/useFieldLayout';
5
8
  import FormTableComponent from './components/FormTableComponent';
9
+ import FormTableValueDisplayer from './displayers/FormTableValueDisplayer';
6
10
  import { tableStyle } from './style';
7
11
  import { FormTableProps, TableItem } from './typings';
8
12
 
@@ -24,21 +28,50 @@ const FormTable: FC<FormTableProps<any, TableItem<any>>> = React.memo((props) =>
24
28
  Object.assign(
25
29
  {
26
30
  defaultValue,
31
+ Displayer: (displayerProps: FormDisplayerProps) => {
32
+ const form = useForm();
33
+ let value = form.getValue(displayerProps.name) ?? [];
34
+ const ValueDisplayer = props.ValueDisplayer ?? FormTableValueDisplayer;
35
+ return (
36
+ <FieldDisplayer
37
+ label={displayerProps.label ?? titlelize(displayerProps.name)}
38
+ help={props.help}
39
+ first={displayerProps.first}
40
+ last={displayerProps.last}
41
+ value={
42
+ <ValueDisplayer
43
+ name={displayerProps.name}
44
+ value={value}
45
+ columns={props.controller.columns}
46
+ format={displayerProps.format}
47
+ />
48
+ }
49
+ format={displayerProps.format}
50
+ />
51
+ );
52
+ },
27
53
  },
28
54
  props,
29
55
  ),
30
56
  );
57
+
58
+ const fieldContainer = useFieldContainer({
59
+ container: props.name,
60
+ });
61
+
31
62
  const Component = props.FieldComponent || StyledFormTableComponent;
32
63
 
33
64
  return (
34
65
  <FieldLayout {...fieldLayoutProps} required={props.required}>
35
- <Component
36
- {...fieldComponentProps}
37
- name={props.name}
38
- required={props.required}
39
- minLength={props.minLength ?? props.min}
40
- maxLength={props.maxLength ?? props.max}
41
- />
66
+ <FormContext.Provider value={fieldContainer.context}>
67
+ <Component
68
+ {...fieldComponentProps}
69
+ name={props.name}
70
+ required={props.required}
71
+ minLength={props.minLength ?? props.min}
72
+ maxLength={props.maxLength ?? props.max}
73
+ />
74
+ </FormContext.Provider>
42
75
  </FieldLayout>
43
76
  );
44
77
  });
@@ -1,4 +1,5 @@
1
1
  import CheckboxCellComponent from '../components/cells/CheckboxCellComponent';
2
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
2
3
  import { CheckboxColumn, CheckboxColumnOptions, TableItem } from '../typings';
3
4
 
4
5
  const checkboxColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
@@ -11,6 +12,7 @@ const checkboxColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
11
12
  filterable: false,
12
13
  sortable: false,
13
14
  className: 'o-checkbox-cell',
15
+ Displayer: DefaultCellDisplayer,
14
16
  },
15
17
  options,
16
18
  {
@@ -2,8 +2,9 @@ import React from 'react';
2
2
  import DefaultCellComponent from '../components/cells/DefaultCellComponent';
3
3
  import TableSelectFilterComponent from '../components/filters/TableSelectFilterComponent';
4
4
  import { EnumColumnOptions, TableColumn, TableHeaderCellProps, TableItem } from '../typings';
5
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
5
6
 
6
- const enumColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
7
+ const enumColumn = <T extends any = any, I extends TableItem<T> = TableItem<T>>(
7
8
  id: string,
8
9
  options: EnumColumnOptions<T, I>,
9
10
  ): TableColumn<T, I> => {
@@ -15,6 +16,7 @@ const enumColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
15
16
  <TableSelectFilterComponent {...props} dataSource={options.filterDataSource} />
16
17
  ),
17
18
  sortable: true,
19
+ Displayer: DefaultCellDisplayer,
18
20
  },
19
21
  options,
20
22
  {
@@ -1,7 +1,8 @@
1
1
  import InputCellComponent from '../components/cells/InputCellComponent';
2
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
2
3
  import { InputColumn, InputColumnOptions, TableItem } from '../typings';
3
4
 
4
- const inputColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
5
+ const inputColumn = <T extends any = any, I extends TableItem<T> = TableItem<T>>(
5
6
  id: string,
6
7
  options: InputColumnOptions<T, I>,
7
8
  ): InputColumn<T, I> => {
@@ -10,6 +11,7 @@ const inputColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
10
11
  {
11
12
  filterable: false,
12
13
  sortable: false,
14
+ Displayer: DefaultCellDisplayer,
13
15
  },
14
16
  options,
15
17
  {
@@ -1,5 +1,6 @@
1
1
  import DefaultCellComponent from '../components/cells/DefaultCellComponent';
2
2
  import TableNumberFilterComponent from '../components/filters/TableNumberFilterComponent';
3
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
3
4
  import { TableColumn, TableColumnOptions, TableItem } from '../typings';
4
5
 
5
6
  const numberColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
@@ -12,6 +13,7 @@ const numberColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
12
13
  filterable: true,
13
14
  FilterComponent: TableNumberFilterComponent,
14
15
  sortable: true,
16
+ Displayer: DefaultCellDisplayer,
15
17
  },
16
18
  options,
17
19
  {
@@ -1,6 +1,7 @@
1
1
  import DefaultSelectBroker from '../../select/SelectBroker';
2
2
  import { SelectItem, SelectItemAdapter } from '../../select/typings';
3
3
  import SelectCellComponent from '../components/cells/SelectCellComponent';
4
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
4
5
  import { SelectCell, SelectColumn, SelectColumnOptions, TableItem } from '../typings';
5
6
 
6
7
  const selectColumn = <
@@ -34,6 +35,7 @@ const selectColumn = <
34
35
  {
35
36
  filterable: false,
36
37
  sortable: false,
38
+ Displayer: DefaultCellDisplayer,
37
39
  },
38
40
  opts,
39
41
  {
@@ -1,5 +1,6 @@
1
1
  import DefaultCellComponent from '../components/cells/DefaultCellComponent';
2
2
  import TableTextFilterComponent from '../components/filters/TableTextFilterComponent';
3
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
3
4
  import { TableColumn, TableColumnOptions, TableItem } from '../typings';
4
5
 
5
6
  const textColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
@@ -12,6 +13,7 @@ const textColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
12
13
  filterable: true,
13
14
  FilterComponent: TableTextFilterComponent,
14
15
  sortable: true,
16
+ Displayer: DefaultCellDisplayer,
15
17
  },
16
18
  options,
17
19
  {
@@ -1,4 +1,5 @@
1
1
  import TextareaCellComponent from '../components/cells/TextareaCellComponent';
2
+ import DefaultCellDisplayer from '../displayers/DefaultCellDisplayer';
2
3
  import { TableItem, TextareaColumn, TextareaColumnOptions } from '../typings';
3
4
 
4
5
  const textareaColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
@@ -11,6 +12,7 @@ const textareaColumn = <T = any, I extends TableItem<T> = TableItem<T>>(
11
12
  {
12
13
  filterable: false,
13
14
  sortable: false,
15
+ Displayer: DefaultCellDisplayer,
14
16
  },
15
17
  options,
16
18
  {
@@ -0,0 +1,29 @@
1
+ import { get, useForm } from 'onekijs-framework';
2
+ import { TableCellDisplayerProps } from '../typings';
3
+ import React from 'react';
4
+
5
+ const DefaultFormCellDisplayer: React.FC<TableCellDisplayerProps<any>> = (props) => {
6
+ const form = useForm();
7
+ if (['form_summary', 'form_summary_table'].includes(props.format)) {
8
+ if (props.column) {
9
+ const name = props.column.id ? `${props.rowName}.${props.column.id}` : `${props.rowName}`;
10
+ const field = form.fields[name];
11
+ if (props.column.id === 'value') {
12
+ console.log(field);
13
+ }
14
+ if (field && field.Displayer) {
15
+ const Component = field.Displayer
16
+ return <Component name={name} label={props.column.id ? props.column.title : ''} Displayer={field.Displayer} children={{}} index={0} first={true} last={true} format={props.format} />
17
+ }
18
+ }
19
+ }
20
+ if (props.format === 'csv') {
21
+ const value = get(props.value, props.column.id, '');
22
+ if (typeof value === 'string') return value;
23
+ return JSON.stringify(value);
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ export default DefaultFormCellDisplayer;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { addClassname } from '../../../utils/style';
3
+ import { FormTableItemDisplayerProps } from '../typings';
4
+
5
+ const FormTableItemDisplayer: React.FC<FormTableItemDisplayerProps> = ({
6
+ value,
7
+ columns,
8
+ first,
9
+ last,
10
+ className,
11
+ format,
12
+ name,
13
+ index,
14
+ }) => {
15
+ const userColumns = columns.filter((c) => !c.id.startsWith('system.'));
16
+ const monoColumnTable = userColumns.length === 1 && !userColumns[0].id;
17
+ const classNames = monoColumnTable
18
+ ? 'o-form-mono-column-table-item-displayer'
19
+ : `o-form-table-item-displayer${first ? ' o-form-table-item-displayer-first' : ''}${
20
+ last ? ' o-form-table-item-displayer-last' : ''
21
+ }`;
22
+ return (
23
+ <div className={addClassname(classNames, className)}>
24
+ {userColumns.map((column, colIndex) => {
25
+ const Displayer = column.Displayer;
26
+ if (Displayer) {
27
+ return (
28
+ <Displayer
29
+ column={column}
30
+ firstRow={first}
31
+ lastRow={last}
32
+ rowIndex={index}
33
+ firstCol={colIndex === 0}
34
+ lastCol={colIndex === columns.length - 1}
35
+ colIndex={colIndex}
36
+ format={format}
37
+ value={value}
38
+ rowName={name}
39
+ key={`col-${colIndex}`}
40
+ />
41
+ );
42
+ }
43
+ return null;
44
+ })}
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export default FormTableItemDisplayer;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { FormTableValueDisplayerProps } from '../typings';
3
+ import FormTableItemDisplayer from './FormTableItemDisplayer';
4
+ import styled from 'styled-components';
5
+ import { addClassname } from '../../../utils/style';
6
+ import { borderBottomColor, borderBottomStyle, borderBottomWidth } from '../../../styles/border';
7
+ import { paddingBottom, paddingTop, paddingY } from '../../../styles/spacing';
8
+
9
+ const FormTableValueDisplayer: React.FC<FormTableValueDisplayerProps> = ({ name, columns, value, format, className }) => {
10
+ if (!Array.isArray(value)) return null;
11
+ return (
12
+ <div className={addClassname('o-form-table-displayer-value', className)}>
13
+ {value.map((v: any, index: number) => (
14
+ <FormTableItemDisplayer
15
+ key={`item-${index}`}
16
+ value={v}
17
+ columns={columns}
18
+ first={index === 0}
19
+ last={index === value.length - 1}
20
+ format={format === 'csv' ? 'csv' : 'form_summary_table'}
21
+ name={`${name}.${index}`}
22
+ index={index}
23
+ />
24
+ ))}
25
+ </div>
26
+ );
27
+ };
28
+
29
+ export default styled(FormTableValueDisplayer)`
30
+ .o-form-table-item-displayer {
31
+ ${borderBottomColor('primary')}
32
+ ${borderBottomStyle('solid')}
33
+ ${borderBottomWidth('1px')}
34
+ ${paddingY('sm')}
35
+ &.o-form-table-item-displayer-last{
36
+ ${paddingBottom(0)}
37
+ ${borderBottomWidth(0)}
38
+ }
39
+ &.o-form-table-item-displayer-first{
40
+ ${paddingTop(0)}
41
+ }
42
+ }
43
+ `;
@@ -2,6 +2,7 @@ import {
2
2
  Collection,
3
3
  CollectionBy,
4
4
  CollectionProxy,
5
+ FormDisplayerProps,
5
6
  FormFieldProps,
6
7
  Item,
7
8
  ItemAdaptee,
@@ -14,6 +15,7 @@ import {
14
15
  } from 'onekijs-framework';
15
16
  import React, { FC, ReactNode } from 'react';
16
17
  import { StylableProps, TshirtSize } from '../../styles/typings';
18
+ import { ButtonProps } from '../button/typings';
17
19
  import { CheckboxProps } from '../checkbox/typings';
18
20
  import { FieldLayoutProps } from '../field/typings';
19
21
  import { InputProps } from '../input/typings';
@@ -21,7 +23,6 @@ import { ListItemProps, ListItems, ListNotFoundProps, ListState, UseListOptions
21
23
  import { FormSelectProps, SelectBroker, SelectItem, SelectProps } from '../select/typings';
22
24
  import { TextareaProps } from '../textarea/typings';
23
25
  import TableService from './TableService';
24
- import { ButtonProps } from '../button/typings';
25
26
 
26
27
  export type ArrayTableProps<T = any, I extends TableItem<T> = TableItem<T>> = TableConfig<T, I> & {
27
28
  adapter?: TableItemAdapter<T>;
@@ -40,6 +41,12 @@ export type ControllerTableProps<
40
41
  controller: CollectionProxy<T, I, S, C>;
41
42
  };
42
43
 
44
+ export type FormCellDisplayerProps = {
45
+ Displayer: React.FC<FormDisplayerProps>;
46
+ name: string;
47
+ label?: string;
48
+ };
49
+
43
50
  export type FormTableProps<
44
51
  T = any,
45
52
  I extends TableItem<T> = TableItem<T>,
@@ -70,6 +77,25 @@ export type FormTableContext<T = any> = {
70
77
  minLength?: number;
71
78
  };
72
79
 
80
+ export type FormTableItemDisplayerProps<T = any> = {
81
+ value: T;
82
+ columns: TableColumn<T>[];
83
+ first: boolean;
84
+ last: boolean;
85
+ className?: string;
86
+ format: FormDisplayerProps['format'];
87
+ name: string;
88
+ index: number;
89
+ };
90
+
91
+ export type FormTableValueDisplayerProps<T = any> = {
92
+ columns: TableColumn<T>[];
93
+ value: T[];
94
+ format: FormDisplayerProps['format'];
95
+ name: string;
96
+ className?: string;
97
+ };
98
+
73
99
  export type TableBodyCellProps<T = any, I extends TableItem<T> = TableItem<T>> = {
74
100
  className?: string;
75
101
  colIndex: number;
@@ -177,9 +203,23 @@ export type TableColumn<T, I extends TableItem<T> = TableItem<T>> = TableColumnS
177
203
  computedWidth?: TableColumnComputedWidth;
178
204
  };
179
205
 
206
+ export type TableCellDisplayerProps<T, I extends TableItem<T> = TableItem<T>> = {
207
+ column: TableColumn<T, I>;
208
+ rowIndex: number;
209
+ colIndex: number;
210
+ firstCol: boolean;
211
+ lastCol: boolean;
212
+ firstRow: boolean;
213
+ lastRow: boolean;
214
+ rowName: string;
215
+ value: T;
216
+ format: FormDisplayerProps['format'];
217
+ };
218
+
180
219
  export type TableColumnSpec<T, I extends TableItem<T> = TableItem<T>> = {
181
220
  className?: string | ((item: I, column: TableColumn<T, I>, rowIndex: number) => string);
182
221
  CellComponent?: Cell<T, I>;
222
+ Displayer?: React.FC<TableCellDisplayerProps<T>>;
183
223
  footerClassName?: string | ((column: TableColumn<T, I>) => string);
184
224
  FooterComponent?: React.FC<TableFooterCellProps<T, I>>;
185
225
  filterable?: boolean;
@@ -1,20 +1,44 @@
1
+ import { FormDisplayerProps, FormFieldValueDisplayerProps, useForm } from 'onekijs-framework';
1
2
  import React, { FC } from 'react';
2
3
  import Textarea from '.';
4
+ import { titlelize } from '../../utils/misc';
5
+ import FieldDisplayer from '../field/FieldDisplayer';
3
6
  import FieldLayout from '../field/FieldLayout';
4
7
  import useFieldLayout from '../field/hooks/useFieldLayout';
5
8
  import { FormTextareaProps, TextareaProps } from './typings';
6
9
 
10
+ const FormTextareaValueDisplayer: React.FC<FormFieldValueDisplayerProps> = ({ value }) => {
11
+ return (
12
+ <span className="o-input-displayer-value">
13
+ {value ? value.split('\n').map((v: string, index: number) => <div key={`line-${index}`}>{v}</div>) : ''}
14
+ </span>
15
+ );
16
+ };
17
+
7
18
  const FormTextarea: FC<FormTextareaProps> = React.memo((props) => {
8
19
  const [fieldLayoutProps, fieldComponentProps] = useFieldLayout<TextareaProps>(
9
- Object.assign(
10
- {
11
- defaultValue: props.defaultValue === undefined ? '' : props.defaultValue,
12
- },
13
- props,
14
- {
15
- isUndefined: (value: any) => value === undefined || value === null,
16
- },
17
- ),
20
+ Object.assign({}, props, {
21
+ isUndefined: (value: any) => value === undefined || value === null,
22
+ defaultValue: props.defaultValue === undefined ? '' : props.defaultValue,
23
+ Displayer:
24
+ props.Displayer === undefined
25
+ ? (displayerProps: FormDisplayerProps) => {
26
+ const form = useForm();
27
+ let value = form.getValue(displayerProps.name) ?? '';
28
+ const ValueDisplayer = props.ValueDisplayer ?? FormTextareaValueDisplayer;
29
+ return (
30
+ <FieldDisplayer
31
+ label={displayerProps.label ?? titlelize(displayerProps.name)}
32
+ help={props.help}
33
+ first={displayerProps.first}
34
+ last={displayerProps.last}
35
+ value={<ValueDisplayer value={value} />}
36
+ format={displayerProps.format}
37
+ />
38
+ );
39
+ }
40
+ : props.Displayer,
41
+ }),
18
42
  );
19
43
  const Component = props.FieldComponent || Textarea;
20
44
 
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components';
2
+ import WizardSummaryComponent from './components/WizardSummaryComponent';
3
+ import { wizardSummaryStyle } from './style';
4
+
5
+ const WizardSummary = styled(WizardSummaryComponent)`
6
+ ${wizardSummaryStyle}
7
+ `;
8
+
9
+ export default WizardSummary;