slackblock 0.4.0 → 1.0.0-0

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 (139) hide show
  1. package/CHANGELOG.md +33 -26
  2. package/LICENSE +21 -21
  3. package/README.md +95 -85
  4. package/dist/block.cjs +341 -0
  5. package/dist/block.cjs.map +1 -0
  6. package/dist/block.d.mts +412 -0
  7. package/dist/block.d.ts +412 -0
  8. package/dist/block.mjs +268 -0
  9. package/dist/block.mjs.map +1 -0
  10. package/dist/index.cjs +1202 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.mts +6 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.mjs +1170 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/types.d-DgQXbJte.d.mts +296 -0
  17. package/dist/types.d-DgQXbJte.d.ts +296 -0
  18. package/package.json +85 -135
  19. package/blocks.js +0 -12
  20. package/index.js +0 -7
  21. package/lib/components/block/button.js +0 -27
  22. package/lib/components/block/confirmation.js +0 -27
  23. package/lib/components/block/image.js +0 -27
  24. package/lib/components/block/text.js +0 -27
  25. package/lib/components/index.js +0 -42
  26. package/lib/components/input/date-picker.js +0 -27
  27. package/lib/components/input/option-group.js +0 -27
  28. package/lib/components/input/option.js +0 -27
  29. package/lib/components/input/overflow.js +0 -27
  30. package/lib/components/input/radio-group.js +0 -27
  31. package/lib/components/input/select.js +0 -34
  32. package/lib/components/input/text.js +0 -27
  33. package/lib/components/layout/actions.js +0 -27
  34. package/lib/components/layout/container.js +0 -27
  35. package/lib/components/layout/context.js +0 -27
  36. package/lib/components/layout/divider.js +0 -27
  37. package/lib/components/layout/file.js +0 -27
  38. package/lib/components/layout/image.js +0 -27
  39. package/lib/components/layout/input.js +0 -27
  40. package/lib/components/layout/section.js +0 -27
  41. package/lib/components/message.js +0 -27
  42. package/lib/index.js +0 -7
  43. package/lib/parser/index.js +0 -32
  44. package/lib/renderer/index.js +0 -71
  45. package/lib/transformers/block/button.js +0 -29
  46. package/lib/transformers/block/confirmation.js +0 -18
  47. package/lib/transformers/block/image.js +0 -10
  48. package/lib/transformers/block/text.js +0 -16
  49. package/lib/transformers/index.js +0 -54
  50. package/lib/transformers/input/date-picker.js +0 -30
  51. package/lib/transformers/input/option-group.js +0 -19
  52. package/lib/transformers/input/option.js +0 -19
  53. package/lib/transformers/input/overflow.js +0 -19
  54. package/lib/transformers/input/radio-group.js +0 -22
  55. package/lib/transformers/input/select.js +0 -84
  56. package/lib/transformers/input/text.js +0 -31
  57. package/lib/transformers/layout/actions.js +0 -18
  58. package/lib/transformers/layout/container.js +0 -11
  59. package/lib/transformers/layout/context.js +0 -18
  60. package/lib/transformers/layout/divider.js +0 -10
  61. package/lib/transformers/layout/file.js +0 -14
  62. package/lib/transformers/layout/image.js +0 -23
  63. package/lib/transformers/layout/input.js +0 -26
  64. package/lib/transformers/layout/section.js +0 -31
  65. package/lib/utils/get-type.js +0 -16
  66. package/lib/utils/type-helpers.js +0 -2
  67. package/src/components/block/button.tsx +0 -20
  68. package/src/components/block/confirmation.tsx +0 -19
  69. package/src/components/block/image.tsx +0 -8
  70. package/src/components/block/text.tsx +0 -10
  71. package/src/components/index.ts +0 -23
  72. package/src/components/input/date-picker.tsx +0 -11
  73. package/src/components/input/option-group.tsx +0 -9
  74. package/src/components/input/option.tsx +0 -9
  75. package/src/components/input/overflow.tsx +0 -12
  76. package/src/components/input/radio-group.tsx +0 -13
  77. package/src/components/input/select.tsx +0 -36
  78. package/src/components/input/text.tsx +0 -12
  79. package/src/components/layout/actions.tsx +0 -9
  80. package/src/components/layout/container.tsx +0 -9
  81. package/src/components/layout/context.tsx +0 -12
  82. package/src/components/layout/divider.tsx +0 -7
  83. package/src/components/layout/file.tsx +0 -8
  84. package/src/components/layout/image.tsx +0 -10
  85. package/src/components/layout/input.tsx +0 -12
  86. package/src/components/layout/section.tsx +0 -15
  87. package/src/components/message.tsx +0 -20
  88. package/src/constants/types.d.ts +0 -93
  89. package/src/index.ts +0 -3
  90. package/src/parser/index.ts +0 -32
  91. package/src/renderer/index.ts +0 -75
  92. package/src/transformers/block/button.tsx +0 -47
  93. package/src/transformers/block/confirmation.tsx +0 -26
  94. package/src/transformers/block/image.ts +0 -18
  95. package/src/transformers/block/text.ts +0 -34
  96. package/src/transformers/index.ts +0 -65
  97. package/src/transformers/input/date-picker.tsx +0 -43
  98. package/src/transformers/input/option-group.tsx +0 -26
  99. package/src/transformers/input/option.tsx +0 -27
  100. package/src/transformers/input/overflow.ts +0 -33
  101. package/src/transformers/input/radio-group.ts +0 -38
  102. package/src/transformers/input/select.tsx +0 -136
  103. package/src/transformers/input/text.tsx +0 -47
  104. package/src/transformers/layout/actions.ts +0 -29
  105. package/src/transformers/layout/container.ts +0 -16
  106. package/src/transformers/layout/context.ts +0 -35
  107. package/src/transformers/layout/divider.ts +0 -20
  108. package/src/transformers/layout/file.ts +0 -24
  109. package/src/transformers/layout/image.tsx +0 -34
  110. package/src/transformers/layout/input.tsx +0 -39
  111. package/src/transformers/layout/section.ts +0 -53
  112. package/src/tsconfig.json +0 -11
  113. package/src/utils/get-type.ts +0 -20
  114. package/src/utils/type-helpers.ts +0 -1
  115. package/test/index.test.tsx +0 -11
  116. package/test/parser/parser.test.tsx +0 -67
  117. package/test/renderer/renderer.test.tsx +0 -138
  118. package/test/transformers/block/button.test.tsx +0 -63
  119. package/test/transformers/block/confirmation.test.tsx +0 -37
  120. package/test/transformers/block/image.test.tsx +0 -20
  121. package/test/transformers/block/text.test.tsx +0 -32
  122. package/test/transformers/input/date-picker.test.tsx +0 -66
  123. package/test/transformers/input/option-group.test.tsx +0 -26
  124. package/test/transformers/input/option.test.tsx +0 -36
  125. package/test/transformers/input/overflow.test.tsx +0 -57
  126. package/test/transformers/input/radio-group.test.tsx +0 -81
  127. package/test/transformers/input/select.test.tsx +0 -249
  128. package/test/transformers/input/text.test.tsx +0 -42
  129. package/test/transformers/layout/actions.test.tsx +0 -33
  130. package/test/transformers/layout/container.test.tsx +0 -34
  131. package/test/transformers/layout/context.test.tsx +0 -43
  132. package/test/transformers/layout/divider.test.tsx +0 -20
  133. package/test/transformers/layout/file.test.tsx +0 -26
  134. package/test/transformers/layout/image.test.tsx +0 -43
  135. package/test/transformers/layout/input.test.tsx +0 -59
  136. package/test/transformers/layout/section.test.tsx +0 -89
  137. package/test/tsconfig.json +0 -9
  138. package/test/utils/get-type.test.tsx +0 -21
  139. package/tsconfig.json +0 -14
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import Confirmation from '../block/confirmation';
3
- import Option from './option';
4
- import OptionGroup from './option-group';
5
- import {SingleOrArray} from '../../utils/type-helpers';
6
-
7
- export const selectTypes = {
8
- STATIC: 'static',
9
- EXTERNAL: 'external',
10
- USER: 'user',
11
- CONVERSATION: 'conversation',
12
- CHANNEL: 'channel'
13
- };
14
-
15
- type SelectType =
16
- 'static' |
17
- 'external' |
18
- 'user' |
19
- 'conversation' |
20
- 'channel';
21
-
22
- export type Props = {
23
- placeholder: string;
24
- actionId: string;
25
- type?: SelectType;
26
- multi?: boolean;
27
- children?: SingleOrArray<React.ReactElement<Option>> | SingleOrArray<React.ReactElement<OptionGroup>>;
28
- initialOptions?: React.ReactElement<Option>[];
29
- confirm?: React.ReactElement<Confirmation>;
30
- maxSelectedItems?: number;
31
- initialUsers?: string[];
32
- initialConversations?: string[];
33
- initialChannels?: string[];
34
- }
35
-
36
- export default class Select extends React.Component<Props> {}
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
-
3
- export type Props = {
4
- actionId: string;
5
- placeholder?: string;
6
- initial?: string;
7
- multiline?: boolean;
8
- minLength?: number;
9
- maxLength?: number;
10
- };
11
-
12
- export default class TextInput extends React.Component<Props> {}
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { InteractiveBlockElement } from '../../constants/types';
3
-
4
- export type Props = {
5
- children: InteractiveBlockElement | InteractiveBlockElement[];
6
- blockId?: string;
7
- };
8
-
9
- export default class Actions extends React.Component<Props> {}
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import {SingleOrArray} from '../../utils/type-helpers';
3
- import {Child} from '../../constants/types';
4
-
5
- export type Props = {
6
- children: SingleOrArray<Child>
7
- };
8
-
9
- export default class Container extends React.Component<Props> {}
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import Text from '../block/text';
3
- import Image from '../block/image';
4
-
5
- export type ImageOrText = React.ReactElement<Text> | React.ReactElement<Image>;
6
-
7
- export type Props = {
8
- children: ImageOrText | ImageOrText[];
9
- blockId?: string;
10
- };
11
-
12
- export default class Context extends React.Component<Props> {}
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- export type Props = {
4
- blockId?: string;
5
- };
6
-
7
- export default class Divider extends React.Component<Props> {}
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
-
3
- export type Props = {
4
- externalId: string;
5
- blockId?: string;
6
- };
7
-
8
- export default class File extends React.Component<Props> {}
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
-
3
- export type Props = {
4
- url: string;
5
- alt: string;
6
- title?: string;
7
- blockId?: string;
8
- };
9
-
10
- export default class Image extends React.Component<Props> {}
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import {InputBlockElement} from '../../constants/types';
3
-
4
- export type Props = {
5
- label: string;
6
- element: InputBlockElement;
7
- hint?: string;
8
- optional?: boolean;
9
- blockId?: string;
10
- };
11
-
12
- export default class Input extends React.Component<Props> {}
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import Text from '../block/text';
3
- import {BlockElement} from '../../constants/types';
4
-
5
- type TextElem = React.ReactElement<Text>;
6
-
7
- export type Props = {
8
- text: React.ReactElement<Text>;
9
- blockId?: string;
10
- children?: TextElem | TextElem[];
11
- accessory?: BlockElement;
12
- };
13
-
14
- export default class Section extends React.Component<Props> {}
15
-
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import {Element} from '../constants/types';
3
-
4
- type Props = {
5
- children: string | Element | Element[];
6
- text?: string;
7
- asUser?: boolean;
8
- iconEmoji?: string;
9
- iconUrl?: string;
10
- markdown?: boolean;
11
- parse?: 'full' | 'none';
12
- replyBroadcast?: boolean;
13
- replyTo?: string;
14
- unfurlLinks?: boolean;
15
- unfurlMedia?: boolean;
16
- username?: string;
17
- color?: string;
18
- };
19
-
20
- export default class Message extends React.Component<Props> {}
@@ -1,93 +0,0 @@
1
- import {Component, ReactElement} from 'react';
2
-
3
- import Text from '../components/block/text';
4
- import Button from '../components/block/button';
5
- import Image from '../components/block/image';
6
- import Confirmation from '../components/block/confirmation';
7
-
8
- import Section from '../components/layout/section';
9
- import Actions from '../components/layout/actions';
10
- import Context from '../components/layout/context';
11
-
12
- import TextInput from '../components/input/text';
13
- import DatePicker from '../components/input/date-picker';
14
- import Select from '../components/input/select';
15
- import Option from '../components/input/option';
16
- import OptionGroup from '../components/input/option-group';
17
- import Overflow from '../components/input/overflow';
18
- import RadioGroup from '../components/input/radio-group';
19
-
20
- import {TextType as TextInputType} from '../transformers/input/text';
21
- import {DatePickerType} from '../transformers/input/date-picker';
22
- import {SelectType} from '../transformers/input/select';
23
- import {OptionType} from '../transformers/input/option';
24
- import {OptionGroupType} from '../transformers/input/option-group';
25
- import {OverflowType} from '../transformers/input/overflow';
26
- import {RadioGroupType} from '../transformers/input/radio-group';
27
-
28
- import {TextType} from '../transformers/block/text';
29
- import {ImageType} from '../transformers/block/image';
30
- import {ButtonType} from '../transformers/block/button';
31
- import {ConfirmationType} from '../transformers/block/confirmation';
32
-
33
- export type Block = ReactElement<Section> | ReactElement<Actions> | ReactElement<Context>;
34
- export type Attachment = {
35
- color: string;
36
- blocks: Block[];
37
- };
38
-
39
- export type InteractiveBlockElement = ReactElement<Button>;
40
- export type SerializedInteractiveBlockElement = ButtonType;
41
-
42
- export type StandardBlockElement =
43
- ReactElement<Text> |
44
- ReactElement<Image> |
45
- ReactElement<Confirmation>;
46
-
47
- export type InputBlockElement =
48
- ReactElement<TextInput> |
49
- ReactElement<DatePicker> |
50
- ReactElement<Option> |
51
- ReactElement<OptionGroup> |
52
- ReactElement<Select> |
53
- ReactElement<Overflow> |
54
- ReactElement<RadioGroup>;
55
-
56
- export type SerializedInputBlockElement =
57
- TextInputType |
58
- DatePickerType |
59
- OptionType |
60
- OptionGroupType |
61
- SelectType |
62
- OverflowType |
63
- RadioGroupType;
64
-
65
- export type BlockElement = InteractiveBlockElement & StandardBlockElement & InputBlockElement;
66
- export type SerializedBlockElement = TextType | ImageType | ConfirmationType;
67
-
68
- export type SlackMessage = {
69
- text?: string;
70
- as_user?: boolean;
71
- blocks?: Block[];
72
- attachments?: Attachment[];
73
- icon_emoji?: string;
74
- icon_url?: string;
75
- link_names?: boolean;
76
- mrkdwn?: boolean;
77
- parse?: 'full' | 'none';
78
- reply_broadcast?: boolean;
79
- thread_ts?: string;
80
- unfurl_links?: boolean;
81
- unfurl_media?: boolean;
82
- username?: string;
83
- };
84
-
85
- type AnyFunction = () => any;
86
-
87
- export type WithType = {
88
- type?: string | AnyFunction;
89
- };
90
- export type BComponent = Component & WithType;
91
- export type BElement = ReactElement & WithType;
92
- export type Element = BComponent | BElement;
93
- export type Child = string | Element | Element[];
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import render from './renderer';
2
-
3
- export default render;
@@ -1,32 +0,0 @@
1
- import {Child, Block, SlackMessage} from '../constants/types';
2
- import transformers from '../transformers';
3
- import getType from '../utils/get-type';
4
-
5
- export default (children: Child): SlackMessage => {
6
- if (typeof children === 'string') {
7
- return {text: children};
8
- }
9
-
10
- if (!Array.isArray(children)) {
11
- children = [children];
12
- }
13
-
14
- const transformedBlocks: any[] = [];
15
- for (const child of children) {
16
- const type = getType(child);
17
- const transformer = transformers[type];
18
-
19
- if (transformer) {
20
- transformedBlocks.push(transformer(child));
21
- } else if (type !== 'null') {
22
- console.warn(`No transformer for child type '${type}' exists and will be ignored.`);
23
- }
24
- }
25
-
26
- const result: {blocks?: Block[]} = {};
27
- if (transformedBlocks.length > 0) {
28
- result.blocks = transformedBlocks.concat.apply([], transformedBlocks); // Flatten 1 deep
29
- }
30
-
31
- return result;
32
- };
@@ -1,75 +0,0 @@
1
- import {SlackMessage, Element} from '../constants/types';
2
- import parser from '../parser';
3
- import getType from '../utils/get-type';
4
-
5
- const render = (element: Element): SlackMessage => {
6
- const {props = {}} = element || {};
7
-
8
- const typeName = getType(element);
9
- if (typeName !== 'Message') {
10
- throw new TypeError('Provided top-level element must be a Message type.');
11
- }
12
-
13
- if (!props.children) {
14
- throw new Error('Cannot render a Message with no children.');
15
- }
16
-
17
- const json = {...parser(props.children)};
18
-
19
- if (props.replyTo) {
20
- json.thread_ts = props.replyTo;
21
- }
22
-
23
- if (typeof props.markdown !== 'undefined') {
24
- json.mrkdwn = props.markdown;
25
- }
26
-
27
- json.text = props.text || '';
28
-
29
- if (props.iconEmoji) {
30
- json.icon_emoji = props.iconEmoji;
31
- }
32
-
33
- if (props.iconUrl) {
34
- json.icon_url = props.iconUrl;
35
- }
36
-
37
- if (props.parse) {
38
- json.parse = props.parse;
39
- }
40
-
41
- if (props.username) {
42
- json.username = props.username;
43
- }
44
-
45
- if (props.asUser) {
46
- json.as_user = props.asUser;
47
- }
48
-
49
- if (props.replyBroadcast) {
50
- json.reply_broadcast = props.replyBroadcast;
51
- }
52
-
53
- if (props.unfurlLinks) {
54
- json.unfurl_links = props.unfurlLinks;
55
- }
56
-
57
- if (typeof props.unfurlMedia !== 'undefined') {
58
- json.unfurl_media = props.unfurlMedia;
59
- }
60
-
61
- if (props.color && json.blocks) {
62
- json.attachments = [
63
- {
64
- color: props.color as string,
65
- blocks: json.blocks
66
- }
67
- ];
68
-
69
- delete json.blocks;
70
- }
71
-
72
- return json;
73
- };
74
-
75
- export default render;
@@ -1,47 +0,0 @@
1
- import React from 'react';
2
- import { Element } from "../../constants/types";
3
-
4
- import {ButtonProps} from '../../components/block/button';
5
- import { TextType } from "./text";
6
- import { ConfirmationType } from "./confirmation";
7
- import { transform } from "..";
8
- import Text from "../../components/block/text";
9
- import Confirmation from '../../components/block/confirmation';
10
-
11
- export type ButtonType = {
12
- type: 'button';
13
- text: TextType;
14
- action_id: string;
15
- url?: string;
16
- value?: string;
17
- style?: 'primary' | 'danger';
18
- confirm?: ConfirmationType;
19
- };
20
-
21
- export default (child: Element): ButtonType => {
22
- const {actionId, children, url, value, style, confirm}: ButtonProps = child.props;
23
-
24
- const res: ButtonType = {
25
- type: 'button',
26
- text: transform(<Text plainText>{children}</Text>) as TextType,
27
- action_id: actionId
28
- };
29
-
30
- if (url) {
31
- res.url = url;
32
- }
33
-
34
- if (value) {
35
- res.value = value;
36
- }
37
-
38
- if (style) {
39
- res.style = style;
40
- }
41
-
42
- if (confirm) {
43
- res.confirm = transform(confirm) as ConfirmationType;
44
- }
45
-
46
- return res;
47
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import { Element } from "../../constants/types";
3
- import { TextType } from "./text";
4
- import { transform } from "..";
5
- import { ConfirmationProps } from '../../components/block/confirmation';
6
- import Text from "../../components/block/text";
7
-
8
- export type ConfirmationType = {
9
- title: TextType;
10
- text: TextType;
11
- confirm: TextType;
12
- deny: TextType;
13
- };
14
-
15
- export default (child: Element): ConfirmationType => {
16
- const { title, confirm, deny, children }: ConfirmationProps = child.props;
17
-
18
- const res: ConfirmationType = {
19
- title: transform(<Text plainText>{title}</Text>) as TextType,
20
- text: transform(children) as TextType,
21
- confirm: transform(<Text plainText>{confirm}</Text>) as TextType,
22
- deny: transform(<Text plainText>{deny}</Text>) as TextType
23
- };
24
-
25
- return res;
26
- };
@@ -1,18 +0,0 @@
1
- import {Element} from '../../constants/types';
2
- import {Props as ImageProps} from '../../components/block/image';
3
-
4
- export type ImageType = {
5
- type: 'image';
6
- url: string;
7
- alt: string;
8
- };
9
-
10
- export default (child: Element): ImageType => {
11
- const {url, alt}: ImageProps = child.props;
12
-
13
- return {
14
- type: 'image',
15
- url,
16
- alt
17
- };
18
- };
@@ -1,34 +0,0 @@
1
- import {Element} from '../../constants/types';
2
-
3
- export type TextType = {
4
- type: 'plain_text' | 'mrkdwn';
5
- text: string;
6
- emoji?: boolean;
7
- verbatim?: boolean;
8
- };
9
-
10
- export default (elem: Element): TextType => {
11
- const {
12
- props: {
13
- plainText,
14
- children,
15
- emoji,
16
- verbatim
17
- }
18
- } = elem;
19
-
20
- const res: TextType = {
21
- type: plainText ? 'plain_text' : 'mrkdwn',
22
- text: children
23
- };
24
-
25
- if (emoji) {
26
- res.emoji = true;
27
- }
28
-
29
- if (verbatim) {
30
- res.verbatim = true;
31
- }
32
-
33
- return res;
34
- };
@@ -1,65 +0,0 @@
1
- import {Child, Element} from '../constants/types';
2
- import getType from '../utils/get-type';
3
-
4
- import Text from './block/text';
5
- import Confirmation from './block/confirmation';
6
- import Button from './block/button';
7
- import Image from './block/image';
8
-
9
- import Container from './layout/container';
10
- import Section from './layout/section';
11
- import Actions from './layout/actions';
12
- import Context from './layout/context';
13
- import Divider from './layout/divider';
14
- import File from './layout/file';
15
- import ImageLayout from './layout/image';
16
- import Input from './layout/input';
17
-
18
- import TextInput from './input/text';
19
- import DatePicker from './input/date-picker';
20
- import Select from './input/select';
21
- import Option from './input/option';
22
- import OptionGroup from './input/option-group';
23
- import Overflow from './input/overflow';
24
- import RadioGroup from './input/radio-group';
25
-
26
- type TransformersType = {
27
- [index: string]: (child: Child) => {};
28
- };
29
-
30
- const Transformers: TransformersType = {
31
- Container,
32
- Section,
33
- Actions,
34
- Context,
35
- Divider,
36
- File,
37
- ImageLayout,
38
- Input,
39
-
40
- Text,
41
- Confirmation,
42
- Button,
43
- Image,
44
-
45
- TextInput,
46
- DatePicker,
47
- Select,
48
- Overflow,
49
- RadioGroup,
50
-
51
- Option,
52
- OptionGroup
53
- };
54
-
55
- export default Transformers;
56
-
57
- export const transform = (elem: Element): {[index: string]: any} => {
58
- const type = getType(elem);
59
-
60
- if (!Transformers[type]) {
61
- throw new Error(`No transformer exists for type '${type}'`);
62
- }
63
-
64
- return Transformers[type](elem);
65
- };
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import {Props as DatePickerProps} from '../../components/input/date-picker';
3
- import {Element} from '../../constants/types';
4
- import {TextType} from '../block/text';
5
- import {ConfirmationType} from '../block/confirmation';
6
- import {transform} from '..';
7
- import Text from '../../components/block/text';
8
-
9
- export type DatePickerType = {
10
- type: 'datepicker';
11
- action_id: string;
12
- placeholder?: TextType;
13
- initial_date?: string;
14
- confirm?: ConfirmationType;
15
- };
16
-
17
- export default (child: Element): DatePickerType => {
18
- const {actionId, placeholder, initialDate, confirm}: DatePickerProps = child.props;
19
-
20
- const res: DatePickerType = {
21
- type: 'datepicker',
22
- action_id: actionId
23
- };
24
-
25
- if (placeholder) {
26
- res.placeholder = transform(<Text plainText>{placeholder}</Text>) as TextType;
27
- }
28
-
29
- if (initialDate) {
30
- const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/g;
31
- const date = new Date(initialDate);
32
- if (Number.isNaN(date.getTime()) || !dateRegex.test(initialDate)) {
33
- throw new Error('Date must be valid and in format YYY-MM-DD.');
34
- }
35
- res.initial_date = initialDate;
36
- }
37
-
38
- if (confirm) {
39
- res.confirm = transform(confirm as Element) as ConfirmationType;
40
- }
41
-
42
- return res;
43
- };
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import Text from '../../components/block/text';
3
- import {Props as OptionGroupProps} from '../../components/input/option-group';
4
- import {Element} from '../../constants/types';
5
- import {TextType} from '../block/text';
6
- import {OptionType} from './option';
7
- import {transform} from '..';
8
-
9
- export type OptionGroupType = {
10
- label: TextType;
11
- options: OptionType[];
12
- };
13
-
14
- export default (child: Element): OptionGroupType => {
15
- const {label, children}: OptionGroupProps = child.props;
16
-
17
- let options = children;
18
- if (!Array.isArray(options)) {
19
- options = [options];
20
- }
21
-
22
- return {
23
- label: transform(<Text plainText>{label}</Text>) as TextType,
24
- options: options.map(option => transform(option as Element)) as OptionType[]
25
- };
26
- };
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import {Element} from '../../constants/types';
3
- import {TextType} from '../block/text';
4
- import Text from '../../components/block/text';
5
- import {Props as OptionProps} from '../../components/input/option';
6
- import {transform} from '..';
7
-
8
- export type OptionType = {
9
- text: TextType;
10
- value: string;
11
- url?: string;
12
- };
13
-
14
- export default (child: Element): OptionType => {
15
- const {children: text, value, url}: OptionProps = child.props;
16
-
17
- const res: OptionType = {
18
- text: transform(<Text plainText>{text}</Text>) as TextType,
19
- value
20
- };
21
-
22
- if (url) {
23
- res.url = url;
24
- }
25
-
26
- return res;
27
- };