@raketa-builder/menu-builder 1.3.8 → 1.3.10

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,108 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { ReactSortable } from "react-sortablejs";
3
- import Factories from "./Factories";
4
- import { remove, update } from "./utils";
5
- import ColumnBuilder from "./ColumnBuilder";
6
- import { Delete } from "./icons";
7
- import {
8
- Button,
9
- Toolbar,
10
- Stack,
11
- Handle,
12
- Panel,
13
- PanelTitle,
14
- PanelContent,
15
- } from "@raketa-builder/ui";
16
-
17
- const RowBuilder = ({ value, onChange }) => {
18
- const [state, setState] = React.useState(value);
19
-
20
- useEffect(() => {
21
- setState(value);
22
- }, [value]);
23
-
24
- const addRow = (items, item) => {
25
- const newState = {
26
- ...state,
27
- rows: [...items, item],
28
- };
29
-
30
- setState(newState);
31
- onChange(newState);
32
- };
33
-
34
- const updateRow = (items, item) => {
35
- const newState = {
36
- ...state,
37
- rows: update(items, item),
38
- };
39
-
40
- setState(newState);
41
- onChange(newState);
42
- };
43
-
44
- const removeRow = (items, item) => {
45
- if (!confirm("Are you sure?")) return;
46
-
47
- const newState = {
48
- ...state,
49
- rows: remove(items, item),
50
- };
51
-
52
- setState(newState);
53
- onChange(newState);
54
- };
55
-
56
- const reorder = (rows) => {
57
- const newState = { ...state, rows };
58
-
59
- setState(newState);
60
- onChange(newState);
61
- };
62
-
63
- return (
64
- <React.Fragment>
65
- <ReactSortable
66
- list={state.rows}
67
- setList={(rows) => reorder(rows)}
68
- handle=".r-handle"
69
- direction="vertical"
70
- >
71
- {state.rows.map((row, idx) => (
72
- <Panel key={row.id}>
73
- <PanelTitle>
74
- <Stack className="r-stack-align-center">
75
- <Handle className="r-handle" />
76
- Row #{idx + 1}
77
- </Stack>
78
- <Button
79
- variant="secondary"
80
- onClick={() => removeRow(state.rows, row)}
81
- >
82
- <Delete />
83
- </Button>
84
- </PanelTitle>
85
-
86
- <PanelContent>
87
- <ColumnBuilder
88
- value={row}
89
- onChange={(row) => updateRow(state.rows, row)}
90
- />
91
- </PanelContent>
92
- </Panel>
93
- ))}
94
- </ReactSortable>
95
-
96
- <Toolbar>
97
- <Button
98
- variant="secondary"
99
- onClick={() => addRow(state.rows, Factories.row())}
100
- >
101
- Add row
102
- </Button>
103
- </Toolbar>
104
- </React.Fragment>
105
- );
106
- };
107
-
108
- export default RowBuilder;
@@ -1,3 +0,0 @@
1
- import React from "react";
2
-
3
- export default React.createContext();
@@ -1,118 +0,0 @@
1
- import { cn } from "@raketa-builder/ui";
2
-
3
- function filterStyle(props) {
4
- const value = props.invert ? 1 : 0;
5
-
6
- return { filter: `invert(${value})` };
7
- }
8
-
9
- export function Edit({ className, ...rest }) {
10
- return (
11
- <svg
12
- className={cn(
13
- "r-reset",
14
- "r-menu-icon",
15
- "feather",
16
- "feather-edit-2",
17
- className
18
- )}
19
- style={filterStyle(rest)}
20
- xmlns="http://www.w3.org/2000/svg"
21
- width="24"
22
- height="24"
23
- viewBox="0 0 24 24"
24
- fill="none"
25
- stroke="#000"
26
- strokeWidth="2"
27
- strokeLinecap="round"
28
- strokeLinejoin="round"
29
- {...rest}
30
- >
31
- <path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>
32
- </svg>
33
- );
34
- }
35
-
36
- export function Delete({ className, ...rest }) {
37
- return (
38
- <svg
39
- className={cn(
40
- "r-reset",
41
- "r-menu-icon",
42
- "feather",
43
- "feather-trash",
44
- className
45
- )}
46
- style={filterStyle(rest)}
47
- xmlns="http://www.w3.org/2000/svg"
48
- width="24"
49
- height="24"
50
- viewBox="0 0 24 24"
51
- fill="none"
52
- stroke="#000"
53
- strokeWidth="2"
54
- strokeLinecap="round"
55
- strokeLinejoin="round"
56
- {...rest}
57
- >
58
- <polyline points="3 6 5 6 21 6"></polyline>
59
- <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
60
- </svg>
61
- );
62
- }
63
-
64
- export function Plus({ className, ...rest }) {
65
- return (
66
- <svg
67
- className={cn(
68
- "r-reset",
69
- "r-menu-icon",
70
- "feather",
71
- "feather-plus",
72
- className
73
- )}
74
- style={filterStyle(rest)}
75
- xmlns="http://www.w3.org/2000/svg"
76
- width="24"
77
- height="24"
78
- viewBox="0 0 24 24"
79
- fill="none"
80
- stroke="#000"
81
- strokeWidth="2"
82
- strokeLinecap="round"
83
- strokeLinejoin="round"
84
- {...rest}
85
- >
86
- <line x1="12" y1="5" x2="12" y2="19"></line>
87
- <line x1="5" y1="12" x2="19" y2="12"></line>
88
- </svg>
89
- );
90
- }
91
-
92
- export function Copy({ className, ...rest }) {
93
- return (
94
- <svg
95
- className={cn(
96
- "r-reset",
97
- "r-menu-icon",
98
- "feather",
99
- "feather-copy",
100
- className
101
- )}
102
- style={filterStyle(rest)}
103
- xmlns="http://www.w3.org/2000/svg"
104
- width="24"
105
- height="24"
106
- viewBox="0 0 24 24"
107
- fill="none"
108
- stroke="#000"
109
- strokeWidth="2"
110
- strokeLinecap="round"
111
- strokeLinejoin="round"
112
- {...rest}
113
- >
114
- <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
115
- <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
116
- </svg>
117
- );
118
- }
@@ -1,93 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import React from "react";
3
- import WidgetContext from "./WidgetContext";
4
- import MainNavigation from "./MainNavigation";
5
- import ItemForm from "./ItemForm";
6
- import RowBuilder from "./RowBuilder";
7
- import { append, remove, update, rand } from "./utils";
8
- import { H } from "@raketa-builder/ui";
9
-
10
- const MenuBuilder = ({ widgets, value, onChange }) => {
11
- const [state, setState] = React.useState(value);
12
-
13
- const currentTab = state.tab;
14
- const currentItem = state.items ? state.items[currentTab] : null;
15
-
16
- const removeItem = (items, item) => {
17
- if (!confirm("Are you sure?")) return;
18
-
19
- const newState = {
20
- ...state,
21
- tab: 0,
22
- items: remove(items, item),
23
- };
24
-
25
- setState(newState);
26
- if (onChange) onChange(newState);
27
- };
28
-
29
- const updateItem = (items, item) => {
30
- const newState = {
31
- ...state,
32
- items: update(items, item),
33
- };
34
-
35
- setState(newState);
36
- if (onChange) onChange(newState);
37
- };
38
-
39
- const duplicateItem = (items, item) => {
40
- const newState = {
41
- ...state,
42
- items: append(items, {
43
- ...item,
44
- id: rand(),
45
- label: `${item.label} (copy)`,
46
- }),
47
- };
48
-
49
- setState(newState);
50
- if (onChange) onChange(newState);
51
- };
52
-
53
- return (
54
- <WidgetContext.Provider value={widgets}>
55
- <MainNavigation
56
- items={state.items}
57
- tab={currentTab}
58
- onTab={(tab) => setState({ ...state, tab })}
59
- onChange={(items) => {
60
- const newState = { ...state, items };
61
-
62
- setState(newState);
63
- if (onChange) onChange(newState);
64
- }}
65
- />
66
-
67
- {currentItem && (
68
- <div>
69
- <ItemForm
70
- item={currentItem}
71
- onChange={(item) => {
72
- updateItem(state.items, { ...currentItem, ...item });
73
- }}
74
- onRemove={() => removeItem(state.items, currentItem)}
75
- onDuplicate={() => duplicateItem(state.items, currentItem)}
76
- />
77
-
78
- <H as="h4" size="large">
79
- Menu content
80
- </H>
81
- <RowBuilder
82
- value={currentItem}
83
- onChange={(item) =>
84
- updateItem(state.items, { ...currentItem, ...item })
85
- }
86
- />
87
- </div>
88
- )}
89
- </WidgetContext.Provider>
90
- );
91
- };
92
-
93
- export default MenuBuilder;
@@ -1,14 +0,0 @@
1
- export const rand = (length) => Math.random().toString(36).substring(length);
2
-
3
- export const remove = (items, item) => {
4
- const idx = items.findIndex((i) => i.id === item.id);
5
- return [...items.slice(0, idx), ...items.slice(idx + 1)];
6
- };
7
-
8
- export const update = (items, item) => {
9
- const idx = items.findIndex((i) => i.id === item.id);
10
-
11
- return [...items.slice(0, idx), item, ...items.slice(idx + 1)];
12
- };
13
-
14
- export const append = (items, item) => [...items, item];
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- import MenuBuilder from "./MenuBuilder";
2
-
3
- export { MenuBuilder };
package/src/styles.css DELETED
@@ -1,66 +0,0 @@
1
- @layer raketa-builder {
2
- /* Add widget */
3
- .r-widget-button {
4
- width: 100%;
5
- margin-bottom: 0.5em;
6
- padding: 1em;
7
- border: 1px solid var(--r-gray);
8
- border-radius: 3px;
9
- font-weight: 500;
10
- text-align: left;
11
- }
12
-
13
- .r-widget-button:hover {
14
- border-color: var(--r-primary);
15
- background-color: var(--r-primary-light);
16
- color: var(--r-white);
17
- }
18
-
19
- /* Column Builder */
20
- .r-list {
21
- display: flex;
22
- }
23
-
24
- /* Main Navigation */
25
- .r-main-nav-item {
26
- display: inline-flex;
27
- align-items: center;
28
- margin-right: 0.5em;
29
- padding: 0;
30
- border: 2px solid var(--r-gray);
31
- border-radius: 48px;
32
- background-color: var(--r-white);
33
- font-weight: 700;
34
- transition: 0.1s ease-in-out all;
35
- }
36
-
37
- .r-main-nav-item:hover {
38
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
39
- }
40
-
41
- .r-main-nav-item.active {
42
- border: 2px solid var(--r-primary);
43
- background-color: var(--r-primary);
44
- }
45
-
46
- .r-main-nav-tab-button {
47
- padding: 0.5em 1em;
48
- color: var(--r-black);
49
- font-weight: 700;
50
- }
51
-
52
- .r-main-nav-item.active .r-main-nav-tab-button {
53
- color: var(--r-white);
54
- }
55
-
56
- .r-menu-icon {
57
- display: inline-block;
58
- width: 16px;
59
- height: 16px;
60
- background-repeat: no-repeat;
61
- background-position: center;
62
- background-size: 100%;
63
- line-height: 1;
64
- filter: invert(0);
65
- }
66
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "tsconfig/react-library.json",
3
- "include": ["src"],
4
- "exclude": ["dist", "build", "node_modules"],
5
- }