@pushwoosh/smart-components-kit 0.0.4 → 0.1.1

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.
@@ -1,4 +1,4 @@
1
- import { type PushwooshSPAContextType } from './context';
1
+ import { type PushwooshSPAContextType } from '../context';
2
2
  export type ParcelResult<P> = {
3
3
  render: (props: P) => void;
4
4
  unmount: () => void;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import { Router, Route, Switch, Link } from 'react-router-dom';
4
+ import { PushwooshSPAContextProvider } from '../context';
5
+ import { Lib } from './lib';
6
+ import { TestPlace } from './test-place';
7
+ export function parcel(container) {
8
+ const root = createRoot(container);
9
+ return {
10
+ render(props) {
11
+ root.render(React.createElement(Router, {
12
+ history: props.context.history
13
+ }, React.createElement(PushwooshSPAContextProvider, {
14
+ value: props.context
15
+ }, React.createElement(Switch, null, React.createElement(Route, {
16
+ path: "/:url",
17
+ exact: true,
18
+ render: ({
19
+ match
20
+ }) => {
21
+ return React.createElement("ul", null, React.createElement("li", null, React.createElement(Link, {
22
+ to: `${match.url}/test`
23
+ }, "Test your new component")), React.createElement("li", null, React.createElement(Link, {
24
+ to: `${match.url}/lib`
25
+ }, "Components lib")));
26
+ }
27
+ }), React.createElement(Route, {
28
+ path: "/:url/test",
29
+ component: TestPlace
30
+ }), React.createElement(Route, {
31
+ path: "/:url/lib",
32
+ component: Lib
33
+ })))));
34
+ },
35
+ unmount() {
36
+ root.unmount();
37
+ }
38
+ };
39
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function DynamicContentPickerExample(): React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ import React, { useState } from 'react';
2
+ import { DynamicContentPicker } from '../../dynamic-content-picker';
3
+ import { Horizontal } from '@pushwoosh/kit-helpers';
4
+ import { Button } from '@pushwoosh/kit-button';
5
+ export function DynamicContentPickerExample() {
6
+ const [dc, setDc] = useState();
7
+ return React.createElement("div", null, React.createElement(DynamicContentPicker, {
8
+ dc: dc,
9
+ onChange: setDc
10
+ }, React.createElement(Horizontal, {
11
+ "$justifyContent": "end"
12
+ }, React.createElement(Button, {
13
+ color: "primary",
14
+ onClick: () => console.log(dc)
15
+ }, "Log to console"))));
16
+ }
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { RouteComponentProps } from 'react-router-dom';
3
+ interface MatchParams {
4
+ path: string;
5
+ url: string;
6
+ }
7
+ export declare const Lib: React.FC<RouteComponentProps<MatchParams>>;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { Route, Switch, Link } from 'react-router-dom';
3
+ import { Columns } from '@pushwoosh/kit-helpers';
4
+ import { DynamicContentPickerExample } from './dynamic-content-picker';
5
+ function Example() {
6
+ return React.createElement("div", null, React.createElement("h3", null, "component example"));
7
+ }
8
+ export const Lib = ({
9
+ match
10
+ }) => {
11
+ return React.createElement(Columns, {
12
+ "$gap": 12,
13
+ "$sizes": "200px 780px"
14
+ }, React.createElement("ul", null, React.createElement("li", null, React.createElement(Link, {
15
+ to: `${match.url}/dynamic-content-picker`
16
+ }, "Child 1")), React.createElement("li", null, React.createElement(Link, {
17
+ to: `${match.url}/example`
18
+ }, "Child 2"))), React.createElement("div", null, React.createElement(Switch, null, React.createElement(Route, {
19
+ path: `${match.path}/dynamic-content-picker`,
20
+ component: DynamicContentPickerExample
21
+ }), React.createElement(Route, {
22
+ path: `${match.path}/example`,
23
+ component: Example
24
+ }), React.createElement(Route, {
25
+ path: match.path,
26
+ exact: true,
27
+ render: () => React.createElement("div", null, "Please select a child route.")
28
+ }))));
29
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function TestPlace(): React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ // PLEASE, DON'T COMMIT THIS FILE
2
+ // I is for testing components, you can add your component here to test it
3
+ import React from 'react';
4
+ export function TestPlace() {
5
+ return React.createElement("div", null, "add your component to test please, don't commit this file");
6
+ }
@@ -1,11 +1,10 @@
1
1
  import { type FC, type PropsWithChildren, type ReactNode } from 'react';
2
2
  import type { DynamicContent } from './DynamicContentPicker.types';
3
- export declare const FieldTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
4
3
  export declare const Field: FC<PropsWithChildren<{
5
4
  title: ReactNode;
6
5
  }>>;
7
6
  type DynamicContentFormProps = {
8
- dc: DynamicContent;
7
+ dc?: DynamicContent;
9
8
  onChange: (dc: DynamicContent) => void;
10
9
  };
11
10
  export declare const DynamicContentPicker: FC<PropsWithChildren<DynamicContentFormProps>>;
@@ -1,20 +1,10 @@
1
1
  import React from 'react';
2
- import styled from 'styled-components';
3
- import { Vertical } from '@pushwoosh/kit-helpers';
2
+ import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
4
3
  import { TextInputField } from '@pushwoosh/kit-text-input';
5
4
  import { NativeSelect } from '@pushwoosh/kit-select';
5
+ import { Spinner } from '@pushwoosh/kit-spinner';
6
6
  import { useDynamicContentTags } from './hooks';
7
- const TagPickerDiv = styled(Vertical).attrs({
8
- $gap: 16,
9
- $padding: 16
10
- }).withConfig({
11
- displayName: "TagPickerDiv",
12
- componentId: "sc-j19s3d-0"
13
- })(["width:240px;border-radius:4px;background:#F7F9FA;box-shadow:0 0 4px 0 rgba(0,0,0,0.06),0 4px 6px 0 rgba(0,0,0,0.06);"]);
14
- export const FieldTitle = styled.div.withConfig({
15
- displayName: "FieldTitle",
16
- componentId: "sc-j19s3d-1"
17
- })(["font-size:12px;font-style:normal;font-weight:500;line-height:130%;"]);
7
+ import { FieldTitle, TagPickerDiv } from './styled';
18
8
  export const Field = ({
19
9
  title,
20
10
  children
@@ -23,17 +13,28 @@ export const Field = ({
23
13
  "$gap": 4
24
14
  }, React.createElement(FieldTitle, null, title), children);
25
15
  };
16
+ const defaultDynamicContent = {
17
+ tagName: '',
18
+ modifier: 'regular',
19
+ defaultValue: ''
20
+ };
26
21
  export const DynamicContentPicker = ({
27
- dc,
22
+ dc = defaultDynamicContent,
28
23
  onChange,
29
24
  children
30
25
  }) => {
31
26
  const asyncResult = useDynamicContentTags();
32
27
  if (asyncResult.loading) {
33
- return React.createElement("div", null);
28
+ return React.createElement(TagPickerDiv, null, React.createElement(Horizontal, {
29
+ "$placeItems": "center",
30
+ "$padding": 36
31
+ }, React.createElement(Spinner, {
32
+ size: "medium"
33
+ })));
34
34
  }
35
35
  const tags = asyncResult.value || [];
36
36
  const currentTag = tags.find(tag => tag.name === dc.tagName) || {
37
+ name: '',
37
38
  modifiers: ['regular']
38
39
  };
39
40
  return React.createElement(TagPickerDiv, null, React.createElement(Field, {
@@ -49,7 +50,9 @@ export const DynamicContentPicker = ({
49
50
  defaultValue: ''
50
51
  });
51
52
  }
52
- }, tags.map(tag => React.createElement("option", {
53
+ }, !currentTag.name && React.createElement("option", {
54
+ value: ""
55
+ }, "Select tag"), tags.map(tag => React.createElement("option", {
53
56
  value: tag.name,
54
57
  key: tag.name
55
58
  }, tag.name))), React.createElement(NativeSelect, {
@@ -59,7 +62,8 @@ export const DynamicContentPicker = ({
59
62
  ...dc,
60
63
  modifier: e.target.value
61
64
  });
62
- }
65
+ },
66
+ disabled: !currentTag.name
63
67
  }, currentTag.modifiers.map(modifier => React.createElement("option", {
64
68
  value: modifier,
65
69
  key: modifier
@@ -72,6 +76,7 @@ export const DynamicContentPicker = ({
72
76
  ...dc,
73
77
  defaultValue: e.target.value
74
78
  });
75
- }
79
+ },
80
+ disabled: !currentTag.name
76
81
  })), children);
77
82
  };
@@ -3,6 +3,7 @@ import { useAsync } from '@pushwoosh/kit-helpers';
3
3
  import { collectPaginatedData } from '../asyncHelpers';
4
4
  import { PushwooshSPAContext } from '../context';
5
5
  const ignoreTagTypes = ['boolean', 'list'];
6
+ const numberTypes = ['integer', 'decimal'];
6
7
  export async function fetchDynamicContentTags(context) {
7
8
  const [originalTags, modifiers] = await Promise.all([collectPaginatedData(1000, async (perPage, page) => {
8
9
  const res = await context.grpcBridge.tags.list({
@@ -14,12 +15,11 @@ export async function fetchDynamicContentTags(context) {
14
15
  return res.tags;
15
16
  }), context.rpcClient.callRemoteProcedure('base.modifiers', {})]);
16
17
  const {
17
- 1: numbers,
18
- 2: strings
19
- } = modifiers.response.result;
18
+ result
19
+ } = modifiers.response;
20
20
  return originalTags.filter(tag => !ignoreTagTypes.includes(tag.type)).map(tag => ({
21
21
  ...tag,
22
- modifiers: tag.type === 'integer' || tag.type === 'decimal' ? numbers : strings
22
+ modifiers: numberTypes.includes(tag.type) ? result[1] : result[2]
23
23
  }));
24
24
  }
25
25
  export function useDynamicContentTags() {
@@ -0,0 +1,17 @@
1
+ export declare const TagPickerDiv: import("styled-components").StyledComponent<"div", any, {
2
+ $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
3
+ $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
4
+ $gap?: string | number | undefined;
5
+ $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
6
+ $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
7
+ $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
8
+ $margin?: string | number | undefined;
9
+ $padding?: string | number | undefined;
10
+ $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
11
+ } & {
12
+ $gridAutoFlow: string;
13
+ } & {
14
+ $gap: number;
15
+ $padding: number;
16
+ }, "$gridAutoFlow" | "$gap" | "$padding">;
17
+ export declare const FieldTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+ import { Vertical } from '@pushwoosh/kit-helpers';
3
+ export const TagPickerDiv = styled(Vertical).attrs({
4
+ $gap: 16,
5
+ $padding: 16
6
+ }).withConfig({
7
+ displayName: "TagPickerDiv",
8
+ componentId: "sc-gptaqm-0"
9
+ })(["width:240px;border-radius:4px;background:#F7F9FA;box-shadow:0 0 4px 0 rgba(0,0,0,0.06),0 4px 6px 0 rgba(0,0,0,0.06);"]);
10
+ export const FieldTitle = styled.div.withConfig({
11
+ displayName: "FieldTitle",
12
+ componentId: "sc-gptaqm-1"
13
+ })(["font-size:12px;font-style:normal;font-weight:500;line-height:130%;"]);
package/package.json CHANGED
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "pre-commit": "check",
16
16
  "dependencies": {
17
+ "@pushwoosh/kit-button": "^2.2.5",
17
18
  "@pushwoosh/kit-constants": "^1.6.5",
18
19
  "@pushwoosh/kit-helpers": "^4.6.1",
19
20
  "@pushwoosh/kit-select": "^1.1.0",
@@ -29,6 +30,7 @@
29
30
  "@types/eslint__js": "^8.42.3",
30
31
  "@types/react": "^18.3.5",
31
32
  "@types/react-dom": "^18.3.0",
33
+ "@types/react-router-dom": "^5.3.3",
32
34
  "@types/styled-components": "^5.1.34",
33
35
  "eslint": "^9.10.0",
34
36
  "react": "^18.3.1",
@@ -48,5 +50,5 @@
48
50
  "engines": {
49
51
  "node": ">= 18"
50
52
  },
51
- "version": "0.0.4"
53
+ "version": "0.1.1"
52
54
  }
package/parcel.js DELETED
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { PushwooshSPAContextProvider, usePushwooshSPAContext } from './context';
4
- import { DynamicContentPicker } from './dynamic-content-picker';
5
- function TestParcel() {
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
- const context = usePushwooshSPAContext();
8
- const [dc, setDc] = React.useState({});
9
- return React.createElement("div", null, React.createElement(DynamicContentPicker, {
10
- dc: dc,
11
- onChange: setDc
12
- }));
13
- }
14
- export function parcel(container) {
15
- const root = createRoot(container);
16
- return {
17
- render(props) {
18
- root.render(React.createElement(PushwooshSPAContextProvider, {
19
- value: props.context
20
- }, React.createElement(TestParcel, null)));
21
- },
22
- unmount() {
23
- root.unmount();
24
- }
25
- };
26
- }