PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.3
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.3
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / blocks / src / calendar / edit.js
latepoint / blocks / src / calendar Last commit date
block.json 1 year ago edit.js 1 year ago index-min.js 1 year ago index.js 1 year ago save.js 1 year ago
edit.js
174 lines
1 /**
2 * WordPress components that create the necessary UI elements for the block
3 *
4 * @see https://developer.wordpress.org/block-editor/packages/packages-components/
5 */
6 import {TextControl, SelectControl, Panel, PanelBody, PanelRow} from '@wordpress/components';
7 import {__} from '@wordpress/i18n';
8
9 /**
10 * React hook that is used to mark the block wrapper element.
11 * It provides all the necessary props like the class name.
12 *
13 * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
14 */
15 import {
16 useBlockProps,
17 InspectorControls,
18 } from '@wordpress/block-editor';
19 import styled from "@emotion/styled";
20
21
22 /**
23 * The edit function describes the structure of your block in the context of the
24 * editor. This represents what the editor will render when the block is used.
25 *
26 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
27 *
28 * @param {Object} props Properties passed to the function.
29 * @param {Object} props.attributes Available block attributes.
30 * @param {Function} props.setAttributes Function that updates individual attributes.
31 *
32 * @return {WPElement} Element to render.
33 */
34 export default function Edit({attributes, setAttributes}) {
35 const blockProps = useBlockProps();
36
37 const range = (start, end) => {
38 return Array.from({ length: end - start + 1 }, (_, index) => start + index);
39 }
40
41 const LatepointCalendarWrapper = styled.div`
42 box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.1);
43 border-radius: 4px;
44 border: 1px solid #ddd;
45 border-bottom-color: #bbb;
46 background-color: #fff;
47 padding: 20px;
48 max-width: 400px;
49 `;
50
51 const rangeTypes = [
52 {label: 'Month', value: 'month'},
53 {label: 'Week', value: 'week'},
54 ];
55
56 const LatepointCalendar = styled.div`
57 border: 1px solid #ddd;
58 border-right: none;
59 background: #fbfbfb;
60 `;
61
62 const LatepointBlockCaption = styled.div`
63 font-weight: 500;
64 margin-bottom: 10px;
65 font-size: 12px;
66 text-transform: uppercase;
67 letter-spacing: 1px;
68 `;
69
70 const LCRow = styled.div`
71 display: grid;
72 grid-template-columns: repeat(7, 1fr);
73 `;
74
75 const LCHead = styled.div`
76 border-bottom: 1px solid #ddd;
77 background: #f3f3f3;
78 `;
79
80 const LCCell = styled.div`
81 padding: 10px;
82 text-align: center;
83 border-right: 1px solid #ddd;
84 `;
85 const LCDate = styled.div`
86 padding: 5px;
87 border-radius: 4px;
88 background-color: #e1e1e1;
89 `;
90
91 const LCText = styled.div`
92 padding: 3px;
93 border-radius: 4px;
94 background-color: #ecebeb;
95 `;
96
97 const weekCells = (type) => {
98 return (
99 <>
100 {range(1, 7).map(() => (
101 <LCCell>{type === 'date' ? <LCDate></LCDate> : <LCText></LCText>}</LCCell>
102 ))}
103 </>
104 )
105 };
106
107
108 return (
109 <div {...blockProps}>
110 <InspectorControls>
111 <Panel>
112 <PanelBody title="Latepoint Calendar Settings">
113 <TextControl
114 label="Caption"
115 value={attributes.caption || ''}
116 onChange={(value) => setAttributes({caption: value})}
117 />
118 <TextControl
119 label={__('Date', 'latepoint')}
120 value={attributes.date || ''}
121 placeholder="YYYY-MM-DD"
122 onChange={(value) => setAttributes({date: value})}
123 />
124 <TextControl
125 label="Show Agents"
126 placeholder="Comma separated agent IDs"
127 value={attributes.show_agents || ''}
128 onChange={(value) => setAttributes({show_agents: value})}
129 />
130 <TextControl
131 label="Show Services"
132 placeholder="Comma separated service IDs"
133 value={attributes.show_services || ''}
134 onChange={(value) => setAttributes({show_services: value})}
135 />
136 <TextControl
137 label="Show Locations"
138 placeholder="Comma separated location IDs"
139 value={attributes.show_locations || ''}
140 onChange={(value) => setAttributes({show_locations: value})}
141 />
142
143 <SelectControl
144 label={__('View', 'latepoint')}
145 value={attributes.view || 'month'}
146 onChange={(value) => setAttributes({view: value})}
147 options={rangeTypes}
148 />
149 </PanelBody>
150 </Panel>
151 </InspectorControls>
152 <LatepointCalendarWrapper>
153 <LatepointBlockCaption>{attributes.caption}</LatepointBlockCaption>
154 <LatepointCalendar>
155 <LCHead>
156 <LCRow>
157 { weekCells('date') }
158 </LCRow>
159 </LCHead>
160
161 { range(1, 4).map(() => (
162 <LCRow>
163 { weekCells('text') }
164 </LCRow>
165 ))}
166
167 </LatepointCalendar>
168
169 </LatepointCalendarWrapper>
170
171 </div>
172 );
173 }
174